Comparing is_pointer with true_

Hello. I need to compare is_const<T> with true_ or false_. I don't find an easy way to do it. I have tried: void foo(mpl::true_) { cout << "true" << endl; } void foo(mpl::false_) { cout << "false" << endl; } int _tmain(int argc, _TCHAR* argv[]) { foo(is_same< mpl::true_, is_pointer<void*>() >()); foo(is_same< mpl::true_, is_pointer<void*>::type() >()); foo(is_convertible< is_pointer<void*>(), mpl::true_ >()); foo(is_base_of< mpl::true_, is_pointer<void*>() >()); return 0; } (in case you wonder why I don't simply pass is_pointer to foo(), here's why: I have a function object that is called twice with a bool_ template argument; the first time it handles all non-pointer types and in a second pass it handles the pointer types; in fact I'm trying to implement the equivalent of b1 == b2, where b1 and b2 are bools). I understand that is_pointer<T> derives either from true_type or false_type. Thus it's normal that is_same fails. But what of the others? Jean-Louis = = = = = = = = = = = = = = = = = = = = = = = = = Fortis disclaimer : http://www.fortis.be/legal/disclaimer.htm Privacy policy related to banking activities of Fortis: http://www.fortis.be/legal/privacy_policy.htm = = = = = = = = = = = = = = = = = = = = = = = = =

AMDG jean-louis.a.leroy@fortis.com wrote:
I need to compare is_const<T> with true_ or false_. I don't find an easy way to do it. I have tried:
void foo(mpl::true_) { cout << "true" << endl; } void foo(mpl::false_) { cout << "false" << endl; }
int _tmain(int argc, _TCHAR* argv[]) { foo(is_same< mpl::true_, is_pointer<void*>() >()); foo(is_same< mpl::true_, is_pointer<void*>::type() >()); foo(is_convertible< is_pointer<void*>(), mpl::true_ >()); foo(is_base_of< mpl::true_, is_pointer<void*>() >()); return 0; }
(in case you wonder why I don't simply pass is_pointer to foo(), here's why: I have a function object that is called twice with a bool_ template argument; the first time it handles all non-pointer types and in a second pass it handles the pointer types; in fact I'm trying to implement the equivalent of b1 == b2, where b1 and b2 are bools).
I'm quite sure that I follow. Do you mean that you have a template like this: template<bool B> void f(mpl::bool_<B>);
I understand that is_pointer<T> derives either from true_type or false_type. Thus it's normal that is_same fails. But what of the others?
Remove the () after is_pointer<>. is_pointer<void*>() is a function type. In Christ, Steven Watanabe

I'm quite sure that I follow. Do you mean that you have a template like this: template<bool B> void f(mpl::bool_<B>);
Nearly. It's more like this: template<class WritePointers, ...> struct WriteAttributes { template<class Attribute> void operator ()(Attribute a) const { typedef ... attribute_type; write(is_convertible<is_pointer<attribute_type>, WritePointers>(), ...); } template<...> void write(mpl::false_, ...); // non-pointer pass template<...> void write(mpl::true_, ...); // pointer pass // ... }; (dots are just for brevity) which I use like this: mirror::for_each< meta_class<Class>::attributes >(WriteAttributes<false_, ...>(ar, obj)); mirror::for_each< meta_class<Class>::attributes >(WriteAttributes<true_, ...>(ar, obj));
I understand that is_pointer<T> derives either from true_type or false_type. Thus it's normal that is_same fails. But what of the others?
Remove the () after is_pointer<>. is_pointer<void*>() is a function type.
Indeed. Thanks a lot :-) Regards, Jean-Louis = = = = = = = = = = = = = = = = = = = = = = = = = Fortis disclaimer : http://www.fortis.be/legal/disclaimer.htm Privacy policy related to banking activities of Fortis: http://www.fortis.be/legal/privacy_policy.htm = = = = = = = = = = = = = = = = = = = = = = = = =

AMDG jean-louis.a.leroy@fortis.com wrote:
I'm quite sure that I follow. Do you mean that you have a template like this: template<bool B> void f(mpl::bool_<B>);
Nearly. It's more like this:
template<class WritePointers, ...> struct WriteAttributes { template<class Attribute> void operator ()(Attribute a) const { typedef ... attribute_type; write(is_convertible<is_pointer<attribute_type>, WritePointers>(), ...); } template<...> void write(mpl::false_, ...); // non-pointer pass template<...> void write(mpl::true_, ...); // pointer pass // ... };
I see. How about boost::mpl::equal_to<is_pointer<attribute_type>, WritePointers> In Christ, Steven Watanabe
participants (2)
-
jean-louis.a.leroy@fortis.com
-
Steven Watanabe