[has_xxx] How can it work at all???
Hello *! As already asked many times in the list about the broken HAS_XXX ( BOOST_MPL_HAS_XXX_TRAIT_DEFhttp://www.boost.org/libs/mpl/doc/refmanual/has-xxx-trait-def.html) mpl I would like to ask following: If I use this code (on MSVC 7.1 compiler) and I have a type like: struct test { int xxx; }; and use the macro namespace x { BOOST_MPL_HAS_XXX_TRAIT_DEF(xxx); } This will result in the following code fragment: -------------------------------------------------------------------------------------------- /// included code from has_xxx.hpp namespace boost { namespace mpl { namespace aux { template< typename T > struct msvc71_sfinae_helper { typedef void type; }; } } } namespace sn { template< typename T, typename U = void > struct has_xxx_impl_ { static const bool value = false; typedef boost::mpl::bool_<value> type; }; template< typename T > struct has_xxx_impl_< T , typename boost::mpl::aux::msvc71_sfinae_helper< typename T::xxx >::type > { static const bool value = true; typedef boost::mpl::bool_<value> type; }; template< typename T, typename fallback_ = boost::mpl::bool_<false> > struct has_xxx : has_xxx_impl_<T> { }; } -------------------------------------------------------------------------------------------------- For me this will clearly fail, since T::xxx is not a type but an integer member of the struct. If xxx would be a member function it would not be a type as well, so has_xxx can only determine if there is some nested class type or a typedef within the inspected type. Is this correct? Many thanks, Ovanes
Ovanes Markarian wrote:
For me this will clearly fail, since T::xxx is not a type but an integer member of the struct. If xxx would be a member function it would not be a type as well, so has_xxx can only determine if there is some nested class type or a typedef within the inspected type. Is this correct?
As I understand it, this traits class is intended to identify nested types only - certainly that's the only use case I've used it for. HTH, John.
On Thu, Feb 21, 2008 at 12:52 PM, John Maddock
Ovanes Markarian wrote: ... As I understand it, this traits class is intended to identify nested types only - certainly that's the only use case I've used it for.
HTH, John.
Ohhh stupid me!!! I have overseen in the docs example the ASSERT_!!!NOT!!! and thought this assertion is true. BOOST_MPL_HAS_XXX_TRAIT_DEF(has_xxx) struct test1 {}; struct test2 { void xxx(); }; struct test3 { int xxx; }; struct test4 { static int xxx(); }; struct test5 { template< typename T > struct xxx {}; }; struct test6 { typedef int xxx; }; struct test7 { struct xxx; }; struct test8 { typedef void (*xxx)(); }; struct test9 { typedef void (xxx)(); }; BOOST_MPL_ASSERT_NOT(( has_xxx<test1> )); BOOST_MPL_ASSERT_NOT(( has_xxx<test2> )); BOOST_MPL_ASSERT_NOT(( has_xxx<test3> )); BOOST_MPL_ASSERT_NOT(( has_xxx<test4> )); BOOST_MPL_ASSERT_NOT(( has_xxx<test5> )); ... Many thanks for your reply! Ovanes
John Maddock
Ovanes Markarian wrote:
For me this will clearly fail, since T::xxx is not a type but an integer member of the struct. If xxx would be a member function it would not be a type as well, so has_xxx can only determine if there is some nested class type or a typedef within the inspected type. Is this correct?
As I understand it, this traits class is intended to identify nested types only - certainly that's the only use case I've used it for.
HTH, John.
Here: http://www.rsdn.ru/forum/message/2720363.1.aspx http://www.rsdn.ru/forum/message/2759773.1.aspx presented interresting solution for detecting specific member functions without specifying function signature. It will also work for member function templates. Later version allows to check whether the call is possible. Gennadiy
Thanks a lot! I will later on read the entire post! Such a luck to speak
Russian ;)
On Thu, Feb 21, 2008 at 5:13 PM, Gennadiy Rozental
...
Here:
http://www.rsdn.ru/forum/message/2720363.1.aspx http://www.rsdn.ru/forum/message/2759773.1.aspx
presented interresting solution for detecting specific member functions without specifying function signature. It will also work for member function templates. Later version allows to check whether the call is possible.
Gennadiy
Gennadiy Rozental
Here:
http://www.rsdn.ru/forum/message/2720363.1.aspx http://www.rsdn.ru/forum/message/2759773.1.aspx
Thanks Gennadiy for the links, especially for the second one.
Two days ago I added recently reviewed boost::switch_ to my project
and was thinking of moving default case closer to all other cases.
So rather than
Cases f; Default dft;
switch_(n, f, dft);
I would like to switch_(n, f);
where Cases is
struct Cases {
template<class N>
void operator()(N) const { ... }
void operator()(default_t) const { ... }
};
The trick posted on RSDN lets me check whether the last call operator
exists and take this into account.
One useful generalisation of this trick is something like
result_of_with_default
Alexander Nasonov
struct Cases { template<class N> void operator()(N) const { ... }
void operator()(default_t) const { ... } };
The trick posted on RSDN lets me check whether the last call operator exists and take this into account.
One useful generalisation of this trick is something like
result_of_with_default
In order for the above to work, Cases::operator()(N) must be more specialised:
struct Cases {
template<int N>
void operator()(mpl::int_<N>) const { ... }
// void operator()(default_t) const { ... }
};
So, result_of_with_default
participants (4)
-
Alexander Nasonov
-
Gennadiy Rozental
-
John Maddock
-
Ovanes Markarian