assign.copy.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright Louis Dionne 2013-2017
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  4. #include <boost/hana/assert.hpp>
  5. #include <boost/hana/at_key.hpp>
  6. #include <boost/hana/map.hpp>
  7. #include <boost/hana/pair.hpp>
  8. #include <laws/base.hpp>
  9. #include <string>
  10. namespace hana = boost::hana;
  11. namespace test = hana::test;
  12. int main() {
  13. {
  14. using Map = hana::map<>;
  15. Map map0;
  16. Map map;
  17. map0 = map;
  18. }
  19. {
  20. using Map = hana::map<hana::pair<test::ct_eq<0>, int>>;
  21. Map map0 = hana::make_map(hana::make_pair(test::ct_eq<0>{}, 999));
  22. Map map = hana::make_map(hana::make_pair(test::ct_eq<0>{}, 4));
  23. map0 = map;
  24. BOOST_HANA_RUNTIME_CHECK(hana::at_key(map0, test::ct_eq<0>{}) == 4);
  25. }
  26. {
  27. using Map = hana::map<hana::pair<test::ct_eq<0>, int>,
  28. hana::pair<test::ct_eq<1>, char>>;
  29. Map map0 = hana::make_map(hana::make_pair(test::ct_eq<0>{}, 999),
  30. hana::make_pair(test::ct_eq<1>{}, 'z'));
  31. Map map = hana::make_map(hana::make_pair(test::ct_eq<0>{}, 4),
  32. hana::make_pair(test::ct_eq<1>{}, 'a'));
  33. map0 = map;
  34. BOOST_HANA_RUNTIME_CHECK(hana::at_key(map0, test::ct_eq<0>{}) == 4);
  35. BOOST_HANA_RUNTIME_CHECK(hana::at_key(map0, test::ct_eq<1>{}) == 'a');
  36. }
  37. {
  38. using Map = hana::map<hana::pair<test::ct_eq<0>, int>,
  39. hana::pair<test::ct_eq<1>, char>,
  40. hana::pair<test::ct_eq<2>, std::string>>;
  41. Map map0 = hana::make_map(hana::make_pair(test::ct_eq<0>{}, 999),
  42. hana::make_pair(test::ct_eq<1>{}, 'z'),
  43. hana::make_pair(test::ct_eq<2>{}, std::string{"zzzzzzzz"}));
  44. Map map = hana::make_map(hana::make_pair(test::ct_eq<0>{}, 4),
  45. hana::make_pair(test::ct_eq<1>{}, 'a'),
  46. hana::make_pair(test::ct_eq<2>{}, std::string{"abc"}));
  47. map0 = map;
  48. BOOST_HANA_RUNTIME_CHECK(hana::at_key(map0, test::ct_eq<0>{}) == 4);
  49. BOOST_HANA_RUNTIME_CHECK(hana::at_key(map0, test::ct_eq<1>{}) == 'a');
  50. BOOST_HANA_RUNTIME_CHECK(hana::at_key(map0, test::ct_eq<2>{}) == "abc");
  51. }
  52. }