// Copyright 2006 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 #include #include #include #include #include #include #include #include #include "../objects/fwd.hpp" #include "./metafunctions.hpp" #include "./helpers.hpp" #include "./equivalent.hpp" namespace test { template struct equals_to_compare2 : public boost::mpl::identity > { }; template struct equals_to_compare : public boost::mpl::eval_if< boost::is_same, boost::mpl::identity, equals_to_compare2 > { }; template void compare_range(X1 const& x1, X2 const& x2) { typedef typename non_const_value_type::type value_type; std::vector values1, values2; values1.reserve(x1.size()); values2.reserve(x2.size()); std::copy(x1.begin(), x1.end(), std::back_inserter(values1)); std::copy(x2.begin(), x2.end(), std::back_inserter(values2)); std::sort(values1.begin(), values1.end()); std::sort(values2.begin(), values2.end()); BOOST_TEST(values1.size() == values2.size() && std::equal(values1.begin(), values1.end(), values2.begin(), test::equivalent)); } template void compare_pairs(X1 const& x1, X2 const& x2, T*) { std::vector values1, values2; values1.reserve(std::distance(x1.first, x1.second)); values2.reserve(std::distance(x2.first, x2.second)); std::copy(x1.first, x1.second, std::back_inserter(values1)); std::copy(x2.first, x2.second, std::back_inserter(values2)); std::sort(values1.begin(), values1.end()); std::sort(values2.begin(), values2.end()); BOOST_TEST(values1.size() == values2.size() && std::equal(values1.begin(), values1.end(), values2.begin(), test::equivalent)); } template struct ordered_set : public boost::mpl::if_< test::has_unique_keys, std::set::type>, std::multiset::type> > {}; template struct ordered_map : public boost::mpl::if_< test::has_unique_keys, std::map::type>, std::multimap::type> > {}; template struct ordered_base : public boost::mpl::eval_if< test::is_set, test::ordered_set, test::ordered_map > { }; 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& compare) : base(compare) {} 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 non_const_value_type::type*) 0 ); } template void insert_range(It begin, It end) { while(begin != end) { this->insert(*begin); ++begin; } } }; template typename equals_to_compare::type create_compare( Equals const& equals) { 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