mutate.hpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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/detail/lightweight_test.hpp>
  8. #include <boost/fusion/sequence/intrinsic/at.hpp>
  9. #if !defined(FUSION_AT)
  10. #define FUSION_AT at_c
  11. #endif
  12. namespace test_detail
  13. {
  14. // no public default constructor
  15. class foo
  16. {
  17. public:
  18. explicit foo(int v) : val(v) {}
  19. bool operator==(const foo& other) const
  20. {
  21. return val == other.val;
  22. }
  23. private:
  24. foo() {}
  25. int val;
  26. };
  27. }
  28. void
  29. test()
  30. {
  31. using namespace boost::fusion;
  32. using namespace test_detail;
  33. FUSION_SEQUENCE<int, float, bool, foo> t1(5, 12.2f, true, foo(4));
  34. FUSION_AT<0>(t1) = 6;
  35. FUSION_AT<1>(t1) = 2.2f;
  36. FUSION_AT<2>(t1) = false;
  37. FUSION_AT<3>(t1) = foo(5);
  38. BOOST_TEST(FUSION_AT<0>(t1) == 6);
  39. BOOST_TEST(FUSION_AT<1>(t1) > 2.1f && FUSION_AT<1>(t1) < 2.3f);
  40. BOOST_TEST(FUSION_AT<2>(t1) == false);
  41. BOOST_TEST(FUSION_AT<3>(t1) == foo(5));
  42. }