MPL:Possible Placeholder problem with transform & if_ (?)

Either something strange is happening with arg<> and transform or I did not write this code correctly. ( :) ) Any help pointing me to either conclusion appreciated. The next step is to try the same algorithm with transform_view. I really don't want a lazy sequence (how could mother be proud?), but sometimes life is disappointing. Thanks Guys. CODE: struct print_type { std::ostream & m_os; print_type(std::ostream & os = std::cout) : m_os(os) {} template <typename T> void operator()(T const& v) const { m_os << "[ " << typeid(v).name() << " ] "; } }; template <class seq_t> void _print_types(const char * pHeading) { std::cout << "** " << pHeading << std::endl; mpl::for_each<seq_t>(print_type()); std::cout << std::endl; } #define print_types(seq) _print_types<seq>(#sew); template <class T> struct YES { typedef YES type; }; template <class T> struct NO { typedef NO type; }; struct A{}; typedef mpl::vector<A> vec_t; typedef mpl::transform < vec_t, mpl::if_ < boost::is_same<mpl::_1, A >, YES< mpl::_1 >::type, NO< mpl::_1 >::type >::type
::type result;
void test() { print_types (result); /* ////////////////////////// PRINTS: ** result [ struct NO<struct A> ] SHOULD PRINT: ** result [ struct YES<struct A> ] //////////////////////////// */ }

Brian Braatz writes:
Either something strange is happening with arg<> and transform or I did not write this code correctly. ( :) )
The latter :). [...]
typedef mpl::transform < vec_t, mpl::if_ < boost::is_same<mpl::_1, A >, YES< mpl::_1 >::type, ^^^^^^ NO< mpl::_1 >::type ^^^^^^
::type ^^^^^^^ ::type result;
By requesting '::type' on a metafunction you are immediately instantiating it with the placeholder argument(s), which is not what you want. Try typedef mpl::transform< vec_t , mpl::if_< , boost::is_same<mpl::_1, A> , YES< mpl::_1 > , NO< mpl::_1 > > >::type result; instead. HTH, -- Aleksey Gurtovoy MetaCommunications Engineering
participants (2)
-
Aleksey Gurtovoy
-
Brian Braatz