container_tests10b.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*=============================================================================
  2. Copyright (c) 2004 Angus Leeming
  3. Copyright (c) 2017 Kohei Takahashi
  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 "container_tests.hpp"
  8. #include <boost/static_assert.hpp>
  9. std::unordered_map<int, int> const build_unordered_map()
  10. {
  11. typedef std::unordered_map<int, int> int_map;
  12. typedef std::vector<int> int_vector;
  13. int_map result;
  14. int_vector const data = build_vector();
  15. int_vector::const_iterator it = data.begin();
  16. int_vector::const_iterator const end = data.end();
  17. for (; it != end; ++it) {
  18. int const value = *it;
  19. result[value] = 100 * value;
  20. }
  21. return result;
  22. }
  23. std::unordered_multimap<int, int> const build_unordered_multimap()
  24. {
  25. typedef std::unordered_map<int, int> int_map;
  26. typedef std::unordered_multimap<int, int> int_multimap;
  27. int_map const data = build_unordered_map();
  28. return int_multimap(data.begin(), data.end());
  29. }
  30. std::vector<int> const init_vector()
  31. {
  32. typedef std::vector<int> int_vector;
  33. int const data[] = { -4, -3, -2, -1, 0 };
  34. int_vector::size_type const data_size = sizeof(data) / sizeof(data[0]);
  35. return int_vector(data, data + data_size);
  36. }
  37. std::vector<int> const build_vector()
  38. {
  39. typedef std::vector<int> int_vector;
  40. static int_vector data = init_vector();
  41. int_vector::size_type const size = data.size();
  42. int_vector::iterator it = data.begin();
  43. int_vector::iterator const end = data.end();
  44. for (; it != end; ++it)
  45. *it += size;
  46. return data;
  47. }
  48. int
  49. main()
  50. {
  51. BOOST_STATIC_ASSERT((phx::stl::has_mapped_type<std::unordered_multimap<int, int> >::value));
  52. BOOST_STATIC_ASSERT((phx::stl::has_key_type<std::unordered_multimap<int, int> >::value));
  53. std::unordered_multimap<int, int> const data = build_unordered_multimap();
  54. test_multimap_insert(data);
  55. //test_key_comp(data);
  56. test_max_size(data);
  57. //test_rbegin(data);
  58. //test_rend(data);
  59. test_size(data);
  60. //test_value_comp(data);
  61. return boost::report_errors();
  62. }