|
|
 |
 |
 |
 |
boost::is_convertible with private inner class
Hi, I have an Array<T> template that specializes on T's in my program that inherit from a base class that I've defined called CtorDtorLess. In my array template, I check if boost::is_convertible<T*, CtorDtorLess*> returns true, and then don't use placement new to construct. I've checked in the debugger and everything works with T's that are public classes. However, I also have some "inner classes" that are declared in the private section of another, and then use Array<MyInnerClass> where appropriate. For some reason, my debugger does not allow me to step thru code pertaining to MyInnerClass within Array<T>. Therefore I cannot verify that boost returns true for is_convertible<T*, CtorDtorLess*> when T is MyInnerClass. My question is whether the fact that T is an inner class declared in a private section of another would cause is_convertible<T*, CtorDtorLess*>::value to return false. My guess is that everything is fine. Andy
andrew_n @yahoo.com wrote: > My question is whether the fact that T is an inner class declared in a > private section of another would cause is_convertible<T*, > CtorDtorLess*>::value to return false. My guess is that everything is > fine.
A debugger is not a testing tool. Write code whose output depends on the result of that test. -- -- Pete Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The Standard C++ Library Extensions: a Tutorial and Reference." (www.petebecker.com/tr1book)
On 2 Jun, 21:35, andrew_n@yahoo.com wrote: > Hi, > I have an Array<T> template that specializes on T's in my program that > inherit from a base class that I've defined called CtorDtorLess. In > my array template, I check if boost::is_convertible<T*, CtorDtorLess*> > returns true, and then don't use placement new to construct. > I've checked in the debugger and everything works with T's that are > public classes. However, I also have some "inner classes" that are > declared in the private section of another, and then use > Array<MyInnerClass> where appropriate. For some reason, my debugger > does not allow me to step thru code pertaining to MyInnerClass within > Array<T>. Therefore I cannot verify that boost returns true for > is_convertible<T*, CtorDtorLess*> when T is MyInnerClass.
debugger has nothing to do with compilation > My question is whether the fact that T is an inner class declared in a > private section of another would cause is_convertible<T*, > CtorDtorLess*>::value to return false. My guess is that everything is > fine.
only if the inner class is not convertible to CtorDtorLess try this: #include <iostream> #include <boost/type_traits/is_convertible.hpp> struct CtorDtorLess {}; struct T1 : CtorDtorLess {}; struct T2 {}; struct T3 { struct T1 : CtorDtorLess {}; struct T2 {}; };
template<class T, bool b> struct Array; template<class T> struct Array<T, true> { Array() { std::cout << "convertible\n"; } };
template<class T> struct Array<T, false> { Array() { std::cout << "non convertible\n"; } };
int main() { Array<T1, boost::is_convertible<T1*, CtorDtorLess*>::value > a1; Array<T2, boost::is_convertible<T2*, CtorDtorLess*>::value> a2; Array<T3::T1, boost::is_convertible<T3::T1*, CtorDtorLess*>::value> a31; Array<T3::T2, boost::is_convertible<T3::T2*, CtorDtorLess*>::value> a32; return 0; }
DS
|
 |
 |
 |
 |
|