// Copyright 2006-2009 Daniel James. // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // This header contains metafunctions/functions to get the equivalent // associative container for an unordered container, and compare the contents. #if !defined(BOOST_UNORDERED_TEST_HELPERS_TRACKER_HEADER) #define BOOST_UNORDERED_TEST_HELPERS_TRACKER_HEADER #include "../objects/fwd.hpp" #include "./equivalent.hpp" #include "./helpers.hpp" #include "./list.hpp" #include "./metafunctions.hpp" #include #include #include #include namespace test { template struct equals_to_compare { typedef std::less type; }; template <> struct equals_to_compare { typedef test::less type; }; template void compare_range(X1 const& x1, X2 const& x2) { typedef test::list value_list; value_list values1(x1.begin(), x1.end()); value_list values2(x2.begin(), x2.end()); values1.sort(); values2.sort(); BOOST_TEST(values1.size() == values2.size() && test::equal(values1.begin(), values1.end(), values2.begin(), test::equivalent)); } template void compare_pairs(X1 const& x1, X2 const& x2, T*) { test::list values1(x1.first, x1.second); test::list values2(x2.first, x2.second); values1.sort(); values2.sort(); BOOST_TEST(values1.size() == values2.size() && test::equal(values1.begin(), values1.end(), values2.begin(), test::equivalent)); } template ::value, bool has_unique_keys = test::has_unique_keys::value> struct ordered_base; template struct ordered_base { typedef std::set::type> type; }; template struct ordered_base { typedef std::multiset::type> type; }; template struct ordered_base { typedef std::map::type> type; }; template struct ordered_base { typedef std::multimap::type> type; }; template class ordered : public ordered_base::type { typedef typename ordered_base::type base; public: typedef typename base::key_compare key_compare; ordered() : base() {} explicit ordered(key_compare const& kc) : base(kc) {} void compare(X const& x) { compare_range(x, *this); } void compare_key(X const& x, typename X::value_type const& val) { compare_pairs(x.equal_range(get_key(val)), this->equal_range(get_key(val)), (typename X::value_type*)0); } template void insert_range(It b, It e) { while (b != e) { this->insert(*b); ++b; } } }; template typename equals_to_compare::type create_compare(Equals const&) { typename equals_to_compare::type x; return x; } template ordered create_ordered(X const& container) { return ordered(create_compare(container.key_eq())); } template void check_container(X1 const& container, X2 const& values) { ordered tracker = create_ordered(container); tracker.insert_range(values.begin(), values.end()); tracker.compare(container); } } #endif