test_sequence_to_tuple.cxx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // (C) Copyright Edward Diener 2011-2015
  2. // Use, modification and distribution are subject to the Boost Software License,
  3. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt).
  5. #include <boost/vmd/is_empty.hpp>
  6. #include <boost/vmd/is_list.hpp>
  7. #include <boost/vmd/to_tuple.hpp>
  8. #include <boost/vmd/equal.hpp>
  9. #include <boost/detail/lightweight_test.hpp>
  10. #include <boost/preprocessor/seq/elem.hpp>
  11. #include <boost/preprocessor/tuple/elem.hpp>
  12. int main()
  13. {
  14. #if BOOST_PP_VARIADICS
  15. #define BOOST_VMD_REGISTER_ggh (ggh)
  16. #define BOOST_VMD_DETECT_ggh_ggh
  17. #define BOOST_VMD_REGISTER_dvd (dvd)
  18. #define BOOST_VMD_DETECT_dvd_dvd
  19. #define ANIDENTIFIER ggh
  20. #define ANIDENTIFIER2 dvd
  21. #define ANUMBER 249
  22. #define ANUMBER2 17
  23. #define ASEQ (25)(26)(27)
  24. #define ATUPLE (0,1,2,3,((a,b))((c,d))((e))((f,g,h)))
  25. #define ALIST (0,(1,(2,(3,BOOST_PP_NIL))))
  26. #define ANARRAY (3,(a,b,38))
  27. #define ASEQUENCE ANUMBER ALIST ATUPLE ANIDENTIFIER ANARRAY ASEQ
  28. #define ASEQUENCE2 ANIDENTIFIER2 ASEQ ALIST ANUMBER ATUPLE
  29. #define ASEQUENCE3 ASEQ ANUMBER2 ATUPLE
  30. #define ASEQUENCE4
  31. /* TO_TUPLE */
  32. BOOST_TEST(BOOST_VMD_EQUAL(BOOST_PP_TUPLE_ELEM(0,BOOST_PP_TUPLE_ELEM(2,BOOST_VMD_TO_TUPLE(ASEQUENCE3,BOOST_VMD_RETURN_TYPE))),BOOST_VMD_TYPE_TUPLE,BOOST_VMD_TYPE_TYPE));
  33. BOOST_TEST(BOOST_VMD_IS_EMPTY(BOOST_VMD_TO_TUPLE(ASEQUENCE4,BOOST_VMD_RETURN_TYPE)));
  34. BOOST_TEST_EQ(BOOST_PP_SEQ_ELEM(2,BOOST_PP_TUPLE_ELEM(1,BOOST_PP_TUPLE_ELEM(1,BOOST_VMD_TO_TUPLE(ASEQUENCE2,BOOST_VMD_RETURN_TYPE)))),27);
  35. BOOST_TEST_EQ(BOOST_PP_TUPLE_ELEM(1,BOOST_PP_TUPLE_ELEM(0,BOOST_VMD_TO_TUPLE(ASEQUENCE,BOOST_VMD_RETURN_TYPE))),249);
  36. /* TO_TUPLE_DATA */
  37. BOOST_TEST_EQ(BOOST_PP_TUPLE_ELEM(1,BOOST_VMD_TO_TUPLE(ASEQUENCE3)),17);
  38. BOOST_TEST(BOOST_VMD_IS_EMPTY(BOOST_VMD_TO_TUPLE(ASEQUENCE4)));
  39. BOOST_TEST(BOOST_VMD_IS_LIST(BOOST_PP_TUPLE_ELEM(1,BOOST_VMD_TO_TUPLE(ASEQUENCE))));
  40. BOOST_TEST_EQ(BOOST_PP_SEQ_ELEM(2,BOOST_PP_TUPLE_ELEM(1,BOOST_VMD_TO_TUPLE(ASEQUENCE2))),27);
  41. #else
  42. BOOST_ERROR("No variadic macro support");
  43. #endif
  44. return boost::report_errors();
  45. }