map_mutate.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*=============================================================================
  2. Copyright (c) 1999-2003 Jaakko Jarvi
  3. Copyright (c) 2001-2011 Joel de Guzman
  4. Copyright (c) 2006
  5. Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. ==============================================================================*/
  8. #include <boost/fusion/container/map/map.hpp>
  9. #include <boost/detail/lightweight_test.hpp>
  10. #include <boost/fusion/sequence/intrinsic/at.hpp>
  11. struct k1 {};
  12. struct k2 {};
  13. struct k3 {};
  14. struct k4 {};
  15. namespace test_detail
  16. {
  17. // no public default constructor
  18. class foo
  19. {
  20. public:
  21. explicit foo(int v) : val(v) {}
  22. bool operator==(const foo& other) const
  23. {
  24. return val == other.val;
  25. }
  26. private:
  27. foo() {}
  28. int val;
  29. };
  30. }
  31. void
  32. test()
  33. {
  34. using namespace boost::fusion;
  35. using namespace test_detail;
  36. map<
  37. pair<k1, int>,
  38. pair<k1, float>,
  39. pair<k1, bool>,
  40. pair<k1, foo>
  41. > t1(5, 12.2f, true, foo(4));
  42. at_c<0>(t1).second = 6;
  43. at_c<1>(t1).second = 2.2f;
  44. at_c<2>(t1).second = false;
  45. at_c<3>(t1).second = foo(5);
  46. BOOST_TEST(at_c<0>(t1).second == 6);
  47. BOOST_TEST(at_c<1>(t1).second > 2.1f && at_c<1>(t1).second < 2.3f);
  48. BOOST_TEST(at_c<2>(t1).second == false);
  49. BOOST_TEST(at_c<3>(t1).second == foo(5));
  50. }
  51. int
  52. main()
  53. {
  54. test();
  55. return boost::report_errors();
  56. }