convert.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*=============================================================================
  2. Copyright (c) 2015 Kohei Takahashi
  3. Use modification and distribution are subject to the Boost Software
  4. License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt).
  6. ==============================================================================*/
  7. #include <string>
  8. #include <boost/config.hpp>
  9. #include <boost/core/lightweight_test.hpp>
  10. #include <boost/fusion/include/convert.hpp>
  11. #include <boost/fusion/include/at.hpp>
  12. #include <boost/fusion/include/vector.hpp>
  13. #include <boost/fusion/include/deque.hpp>
  14. #include <boost/fusion/include/list.hpp>
  15. #include <boost/fusion/include/boost_tuple.hpp>
  16. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  17. #include <boost/fusion/include/std_tuple.hpp>
  18. #endif
  19. template <typename Tag>
  20. void test(FUSION_SEQUENCE<int, std::string> const& seq)
  21. {
  22. typedef typename
  23. boost::fusion::result_of::convert<
  24. Tag
  25. , FUSION_SEQUENCE<int, std::string>
  26. >::type
  27. type;
  28. type v = boost::fusion::convert<Tag>(seq);
  29. BOOST_TEST((boost::fusion::at_c<0>(v) == 123));
  30. BOOST_TEST((boost::fusion::at_c<1>(v) == "Hola!!!"));
  31. }
  32. int main()
  33. {
  34. FUSION_SEQUENCE<int, std::string> seq(123, "Hola!!!");
  35. test<boost::fusion::vector_tag>(seq);
  36. test<boost::fusion::deque_tag>(seq);
  37. test<boost::fusion::cons_tag>(seq);
  38. test<boost::fusion::boost_tuple_tag>(seq);
  39. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  40. test<boost::fusion::std_tuple_tag>(seq);
  41. #endif
  42. return boost::report_errors();
  43. }