container_tests9b.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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::vector<int> const init_vector()
  24. {
  25. typedef std::vector<int> int_vector;
  26. int const data[] = { -4, -3, -2, -1, 0 };
  27. int_vector::size_type const data_size = sizeof(data) / sizeof(data[0]);
  28. return int_vector(data, data + data_size);
  29. }
  30. std::vector<int> const build_vector()
  31. {
  32. typedef std::vector<int> int_vector;
  33. static int_vector data = init_vector();
  34. int_vector::size_type const size = data.size();
  35. int_vector::iterator it = data.begin();
  36. int_vector::iterator const end = data.end();
  37. for (; it != end; ++it)
  38. *it += size;
  39. return data;
  40. }
  41. int
  42. main()
  43. {
  44. BOOST_STATIC_ASSERT((phx::stl::has_mapped_type<std::unordered_map<int, int> >::value));
  45. BOOST_STATIC_ASSERT((phx::stl::has_key_type<std::unordered_map<int, int> >::value));
  46. std::unordered_map<int, int> const data = build_unordered_map();
  47. test_map_insert(data);
  48. //test_key_comp(data);
  49. test_max_size(data);
  50. //test_rbegin(data);
  51. //test_rend(data);
  52. test_size(data);
  53. //test_value_comp(data);
  54. return boost::report_errors();
  55. }