tuples_tests.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*=============================================================================
  2. Phoenix V1.2.1
  3. Copyright (c) 2001-2003 Joel de Guzman
  4. Use, modification and distribution is subject to the Boost Software
  5. License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. ==============================================================================*/
  8. #include <iostream>
  9. #include <string>
  10. #include <boost/detail/lightweight_test.hpp>
  11. #include <boost/spirit/include/phoenix1_tuples.hpp>
  12. using namespace phoenix;
  13. using namespace phoenix::tuple_index_names;
  14. using std::cout;
  15. using std::endl;
  16. using std::string;
  17. int
  18. main()
  19. {
  20. {
  21. typedef tuple<int, char> tuple_t;
  22. tuple_t ttt(3, 'c');
  23. tuple_element<0, tuple_t>::type& e0 = ttt[_1];
  24. tuple_element<1, tuple_t>::type& e1 = ttt[_2];
  25. BOOST_TEST(e0 == 3);
  26. BOOST_TEST(e1 == 'c');
  27. cout << e0 << endl;
  28. cout << e1 << endl;
  29. }
  30. {
  31. typedef tuple<int, char, char const*> tuple_t;
  32. tuple_t ttt(3, 'c', "hello world");
  33. cout << ttt.length << endl;
  34. tuple_element<0, tuple_t>::type& e0 = ttt[_1];
  35. tuple_element<1, tuple_t>::type& e1 = ttt[_2];
  36. tuple_element<2, tuple_t>::type& e2 = ttt[_3];
  37. BOOST_TEST(e0 == 3);
  38. BOOST_TEST(e1 == 'c');
  39. BOOST_TEST(string(e2) == "hello world");
  40. cout << e0 << endl;
  41. cout << e1 << endl;
  42. cout << e2 << endl;
  43. }
  44. return boost::report_errors();
  45. }