mpl.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. #include <boost/proto/proto.hpp>
  8. #include <boost/fusion/mpl.hpp>
  9. #include <boost/mpl/pop_back.hpp>
  10. #include <boost/type_traits/is_same.hpp>
  11. #include <boost/static_assert.hpp>
  12. #include <boost/test/unit_test.hpp>
  13. namespace mpl = boost::mpl;
  14. namespace proto = boost::proto;
  15. namespace fusion = boost::fusion;
  16. using proto::_;
  17. template<class E>
  18. struct my_expr;
  19. struct my_domain
  20. : proto::domain<proto::generator<my_expr> >
  21. {};
  22. template<class E>
  23. struct my_expr
  24. : proto::extends<E, my_expr<E>, my_domain>
  25. {
  26. my_expr(E const &e = E())
  27. : proto::extends<E, my_expr<E>, my_domain>(e)
  28. {}
  29. typedef fusion::fusion_sequence_tag tag;
  30. };
  31. template<typename T>
  32. void test_impl(T const &)
  33. {
  34. typedef typename mpl::pop_back<T>::type result_type;
  35. BOOST_STATIC_ASSERT(
  36. (boost::is_same<
  37. result_type
  38. , my_expr<proto::basic_expr<proto::tag::plus, proto::list1<my_expr<proto::terminal<int>::type>&> > >
  39. >::value)
  40. );
  41. }
  42. // Test that we can call mpl algorithms on proto expression types, and get proto expression types back
  43. void test_mpl()
  44. {
  45. my_expr<proto::terminal<int>::type> i;
  46. test_impl(i + i);
  47. }
  48. using namespace boost::unit_test;
  49. ///////////////////////////////////////////////////////////////////////////////
  50. // init_unit_test_suite
  51. //
  52. test_suite* init_unit_test_suite( int argc, char* argv[] )
  53. {
  54. test_suite *test = BOOST_TEST_SUITE("test proto mpl integration via fusion");
  55. test->add(BOOST_TEST_CASE(&test_mpl));
  56. return test;
  57. }