1///////////////////////////////////////////////////////////////////////////////
2// mpl.hpp
3//
4// Copyright 2012 Eric Niebler. Distributed under the Boost
5// Software License, Version 1.0. (See accompanying file
6// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7
8#include <boost/proto/proto.hpp>
9#include <boost/fusion/mpl.hpp>
10#include <boost/mpl/pop_back.hpp>
11#include <boost/type_traits/is_same.hpp>
12#include <boost/static_assert.hpp>
13#include <boost/test/unit_test.hpp>
14namespace mpl = boost::mpl;
15namespace proto = boost::proto;
16namespace fusion = boost::fusion;
17using proto::_;
18
19template<class E>
20struct my_expr;
21
22struct my_domain
23 : proto::domain<proto::generator<my_expr> >
24{};
25
26template<class E>
27struct my_expr
28 : proto::extends<E, my_expr<E>, my_domain>
29{
30 my_expr(E const &e = E())
31 : proto::extends<E, my_expr<E>, my_domain>(e)
32 {}
33
34 typedef fusion::fusion_sequence_tag tag;
35};
36
37template<typename T>
38void test_impl(T const &)
39{
40 typedef typename mpl::pop_back<T>::type result_type;
41 BOOST_STATIC_ASSERT(
42 (boost::is_same<
43 result_type
44 , my_expr<proto::basic_expr<proto::tag::plus, proto::list1<my_expr<proto::terminal<int>::type>&> > >
45 >::value)
46 );
47}
48
49// Test that we can call mpl algorithms on proto expression types, and get proto expression types back
50void test_mpl()
51{
52 my_expr<proto::terminal<int>::type> i;
53 test_impl(i + i);
54}
55
56using namespace boost::unit_test;
57///////////////////////////////////////////////////////////////////////////////
58// init_unit_test_suite
59//
60test_suite* init_unit_test_suite( int argc, char* argv[] )
61{
62 test_suite *test = BOOST_TEST_SUITE("test proto mpl integration via fusion");
63
64 test->add(BOOST_TEST_CASE(&test_mpl));
65
66 return test;
67}
68

source code of boost/libs/proto/test/mpl.cpp