[Home]CPPTM Answers - Exercise 3-4

BOOST WIKI | RecentChanges | Preferences | Page List | Links List

Showing revision 3
 // (by Ariel Badichi)
 #include <boost/static_assert.hpp>
 #include <boost/type_traits/is_same.hpp>
 #include <boost/type_traits/add_pointer.hpp>
 #include <boost/mpl/apply.hpp>
 #include <boost/mpl/placeholders.hpp>
 #include <boost/mpl/lambda.hpp>

 namespace mpl = boost::mpl;
 using namespace mpl::placeholders;

 template<typename F, typename T>
 struct twice : mpl::apply<F, typename mpl::apply<F, T>::type> {};

 int main()
 {
     typedef mpl::lambda<boost::add_pointer<_> >::type add_pointer_lambda;
     typedef twice<twice<add_pointer_lambda, _>, int>::type p;

     BOOST_STATIC_ASSERT((boost::is_same<int ****, p>::value));

     return 0;
 }

Can anyone explain why the explicit lambda call is necessary? I had thought that the apply embedded in twice would deal with the add_pointer placeholder expression, but GCC 3.3.3 gives a compile error with the following:

 BOOST_STATIC_ASSERT((
   boost::is_same<
     twice<
       twice<
         boost::add_pointer<_1>,  // needs to be wrapped in mpl::lambda<...>::type ???
         _1
       >,
       int
     >::type,
     int****
   >::value
 ));

Any ideas? -- Matt Brecknell

Section 3.3 has a nice explanation for why this won't work. - Ariel


BOOST WIKI | RecentChanges | Preferences | Page List | Links List
Edit revision 3 of this page | View other revisions | View current revision
Edited March 31, 2005 12:41 pm (diff)
Search:
Disclaimer: This site not officially maintained by Boost Developers