|
Boost Users : |
From: Bruno Martínez Aguerre (br1_at_[hidden])
Date: 2005-03-03 19:54:56
Hi,
I'm stuck at exercise 3-6 of the book. I have to write twice (see below)
as a lambda expression. I don't understand why the same transformation
that works for quasi fails for twice. Any help, please?
#include <boost/type_traits/add_pointer.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/mpl/plus.hpp>
#include <boost/mpl/int.hpp>
#include <boost/mpl/placeholders.hpp>
#include <boost/mpl/apply.hpp>
#include <boost/mpl/lambda.hpp>
#include <boost/mpl/equal_to.hpp>
using namespace boost;
using namespace boost::mpl;
using namespace boost::mpl::placeholders;
template <class F, class A>
struct twice : apply<F, typename apply<F, A>::type > {};
BOOST_MPL_ASSERT(( is_same<twice<add_pointer<_1>,int>::type, int**> ));
template <class F, class A>
struct quasi : plus<F, typename plus<F, A>::type > {};
BOOST_MPL_ASSERT(( equal_to<quasi<int_<2>,int_<3> >, int_<7> > ));
template <class F, class A>
struct quasi2 : apply<plus<_1, plus<_1,_2> >, F, A >::type {};
BOOST_MPL_ASSERT(( equal_to<quasi2<int_<2>,int_<3> >, int_<7> > ));
template <class F, class A>
struct twice2 : apply<apply<_1, apply<_1,_2> >, F, A >::type {};
BOOST_MPL_ASSERT(( is_same<twice2<add_pointer<_1>,int>::type, int**> ));
-
Bruno
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net