Index: boost/range/algorithm/unique.hpp =================================================================== --- boost/range/algorithm/unique.hpp (revision 77845) +++ boost/range/algorithm/unique.hpp (working copy) @@ -89,11 +89,11 @@ unique( ForwardRange& rng, BinaryPredicate pred ) { BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); - return ::boost::range::unique(rng); + return ::boost::range::unique(rng, pred); } /// \overload template< class ForwardRange, class BinaryPredicate > -inline BOOST_DEDUCED_TYPENAME range_iterator::type +inline BOOST_DEDUCED_TYPENAME range_return::type unique( const ForwardRange& rng, BinaryPredicate pred ) { BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept )); Index: libs/range/test/test_driver/range_overload_test_driver.hpp =================================================================== --- libs/range/test/test_driver/range_overload_test_driver.hpp (revision 0) +++ libs/range/test/test_driver/range_overload_test_driver.hpp (working copy) @@ -0,0 +1,71 @@ +// Copyright Neil Groves 2009. Use, modification and +// distribution is subject to 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) +// +// +// For more information, see http://www.boost.org/libs/range/ +// +#ifndef BOOST_RANGE_TEST_TEST_DRIVER_RANGE_OVERLOAD_TEST_DRIVER_HPP_INCLUDED +#define BOOST_RANGE_TEST_TEST_DRIVER_RANGE_OVERLOAD_TEST_DRIVER_HPP_INCLUDED + +#include "range_return_test_driver.hpp" +#include +#include +#include + +namespace boost +{ + namespace range_test + { + + // A test driver to exercise a test through range_return_test_driver + // plus the overload that determines the return_type by overload + // + // The test driver also contains the code required to check the + // return value correctness. + // + // The TestPolicy needs to implement all those required by + // range_return_test_driver, and additionally + // + // - perform the boost range version of the algorithm that determines + // the return_type by overload + class range_overload_test_driver : range_return_test_driver + { + public: + template< class Container, + class TestPolicy > + void operator()(Container& cont, TestPolicy policy) + { + range_return_test_driver::operator()(cont, policy); + test_range_overload()(cont, policy); + } + + private: + template< class Container, class TestPolicy > + struct test_range_overload + { + void operator()(Container& cont, TestPolicy policy) + { + typedef BOOST_DEDUCED_TYPENAME range_iterator::type iterator_t; + typedef BOOST_DEDUCED_TYPENAME TestPolicy::template test_range_overload test_range_overload_t; + const range_return_value result_type = test_range_overload_t::result_type; + typedef BOOST_DEDUCED_TYPENAME range_return::type range_return_t; + + Container reference(cont); + Container test_cont(cont); + + test_range_overload_t test_range_overload_fn; + range_return_t range_result = test_range_overload_fn(policy, test_cont); + + iterator_t reference_it = policy.reference(reference); + + check_results::test(test_cont, reference, + range_result, reference_it); + } + }; + }; + } +} + +#endif // include guard Index: libs/range/test/algorithm_test/unique.cpp =================================================================== --- libs/range/test/algorithm_test/unique.cpp (revision 77845) +++ libs/range/test/algorithm_test/unique.cpp (working copy) @@ -9,13 +9,15 @@ // For more information, see http://www.boost.org/libs/range/ // #include +#include #include #include #include #include -#include "../test_driver/range_return_test_driver.hpp" +#include +#include "../test_driver/range_overload_test_driver.hpp" #include #include #include @@ -61,6 +63,30 @@ }; template< class Container > + struct test_range_overload + { + BOOST_STATIC_CONSTANT(::boost::range_return_value, result_type = ::boost::return_begin_found); + + template< class Policy > + BOOST_DEDUCED_TYPENAME boost::range_return::type + operator()(Policy& policy, Container& cont) + { + typedef BOOST_DEDUCED_TYPENAME boost::range_return::type result_t; + + Container cont2(cont); + + result_t result = boost::unique(cont); + + boost::unique(boost::make_iterator_range(cont2)); + + BOOST_CHECK_EQUAL_COLLECTIONS( cont.begin(), cont.end(), + cont2.begin(), cont2.end() ); + + return result; + } + }; + + template< class Container > BOOST_DEDUCED_TYPENAME boost::range_iterator::type reference(Container& cont) { @@ -107,6 +133,30 @@ }; template< class Container > + struct test_range_overload + { + BOOST_STATIC_CONSTANT(::boost::range_return_value, result_type = ::boost::return_begin_found); + + template< class Policy > + BOOST_DEDUCED_TYPENAME boost::range_return::type + operator()(Policy& policy, Container& cont) + { + typedef BOOST_DEDUCED_TYPENAME boost::range_return::type result_t; + + Container cont2(cont); + + result_t result = boost::unique(cont, policy.pred()); + + boost::unique(boost::make_iterator_range(cont2), policy.pred()); + + BOOST_CHECK_EQUAL_COLLECTIONS( cont.begin(), cont.end(), + cont2.begin(), cont2.end() ); + + return result; + } + }; + + template< class Container > BOOST_DEDUCED_TYPENAME boost::range_iterator::type reference(Container& cont) { @@ -121,7 +171,7 @@ typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t; - boost::range_test::range_return_test_driver test_driver; + boost::range_test::range_overload_test_driver test_driver; Container cont; @@ -146,6 +196,15 @@ test_driver(cont, policy); } + template + struct greater_by_two + { + bool operator()(const T& left, const T& right) const + { + return left / 2 == right / 2; + } + }; + template void test_unique_impl() { @@ -155,14 +214,18 @@ ); test_unique_impl( - unique_pred_test_policy >(), + unique_pred_test_policy >(), std::less() ); - test_unique_impl( - unique_pred_test_policy >(), + unique_pred_test_policy >(), std::greater() ); + + test_unique_impl( + unique_pred_test_policy >(), + std::less() + ); } void test_unique()