tuple_construction.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*=============================================================================
  2. Copyright (c) 1999-2003 Jaakko Jarvi
  3. Copyright (c) 2001-2011 Joel de Guzman
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. ==============================================================================*/
  7. #include <boost/fusion/tuple/tuple.hpp>
  8. #include <boost/fusion/adapted/mpl.hpp>
  9. #define NO_CONSTRUCT_FROM_NIL
  10. #define FUSION_SEQUENCE tuple
  11. #define FUSION_AT get
  12. #include "construction.hpp"
  13. // Bug in C++03 tuple? Cannot construct from a std::pair without including
  14. // std::pair fusion adaption
  15. #if !defined(BOOST_FUSION_HAS_VARIADIC_TUPLE)
  16. # include <boost/fusion/adapted/std_pair.hpp>
  17. #endif
  18. struct test_conversion
  19. {
  20. test_conversion(int value) : value_(value) {}
  21. int value_;
  22. };
  23. int
  24. main()
  25. {
  26. test();
  27. {
  28. using namespace boost::fusion;
  29. const tuple<int, test_conversion> instance(std::pair<int, int>(1, 9));
  30. BOOST_TEST(boost::fusion::get<0>(instance) == 1);
  31. BOOST_TEST(boost::fusion::get<1>(instance).value_ == 9);
  32. }
  33. {
  34. using namespace boost::fusion;
  35. const std::pair<int, int> init(16, 4);
  36. const tuple<int, test_conversion> instance(init);
  37. BOOST_TEST(boost::fusion::get<0>(instance) == 16);
  38. BOOST_TEST(boost::fusion::get<1>(instance).value_ == 4);
  39. }
  40. return boost::report_errors();
  41. }