diff --git a/test/algorithm_test/find.cpp b/test/algorithm_test/find.cpp index 6eb1528..d785ac8 100644 --- a/test/algorithm_test/find.cpp +++ b/test/algorithm_test/find.cpp @@ -22,85 +22,82 @@ #include #include -namespace boost +namespace boost_range_test_algorithm_find { - namespace + class find_test_policy { - class find_test_policy + public: + template + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + test_iter(Container& cont) { - public: - template - BOOST_DEDUCED_TYPENAME range_iterator::type - test_iter(Container& cont) + typedef BOOST_DEDUCED_TYPENAME boost::range_iterator::type iter_t; + iter_t result = boost::find(cont, 3); + iter_t result2 = boost::find(boost::make_iterator_range(cont), 3); + BOOST_CHECK( result == result2 ); + return result; + } + + template + struct test_range + { + template + BOOST_DEDUCED_TYPENAME boost::range_return::type + operator()(Policy&, Container& cont) { - typedef BOOST_DEDUCED_TYPENAME range_iterator::type iter_t; - iter_t result = boost::find(cont, 3); - iter_t result2 = boost::find(boost::make_iterator_range(cont), 3); + typedef BOOST_DEDUCED_TYPENAME boost::range_return::type result_t; + result_t result = boost::find(cont, 3); + result_t result2 = boost::find(boost::make_iterator_range(cont), 3); BOOST_CHECK( result == result2 ); return result; } - - template - struct test_range - { - template - BOOST_DEDUCED_TYPENAME range_return::type - operator()(Policy&, Container& cont) - { - typedef BOOST_DEDUCED_TYPENAME range_return::type result_t; - result_t result = boost::find(cont, 3); - result_t result2 = boost::find(boost::make_iterator_range(cont), 3); - BOOST_CHECK( result == result2 ); - return result; - } - }; - - template - BOOST_DEDUCED_TYPENAME range_iterator::type - reference(Container& cont) - { - return std::find(cont.begin(), cont.end(), 3); - } }; template - void test_find_container() + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + reference(Container& cont) { - using namespace boost::assign; - - typedef BOOST_DEDUCED_TYPENAME remove_const::type container_t; - - range_test::range_return_test_driver test_driver; - - container_t mcont; - Container& cont = mcont; - test_driver(cont, find_test_policy()); - - mcont.clear(); - mcont += 1; - test_driver(cont, find_test_policy()); - - mcont.clear(); - mcont += 1,2,3,4,5,6,7,8,9; - test_driver(cont, find_test_policy()); + return std::find(cont.begin(), cont.end(), 3); } + }; - void test_find() - { - test_find_container< std::vector >(); - test_find_container< std::list >(); - test_find_container< std::deque >(); + template + void test_find_container() + { + using namespace boost::assign; - test_find_container< const std::vector >(); - test_find_container< const std::list >(); - test_find_container< const std::deque >(); + typedef BOOST_DEDUCED_TYPENAME boost::remove_const::type container_t; - std::vector vi; - const std::vector& cvi = vi; - std::vector::const_iterator it = boost::find(vi, 0); - std::vector::const_iterator it2 = boost::find(cvi, 0); - BOOST_CHECK( it == it2 ); - } + boost::range_test::range_return_test_driver test_driver; + + container_t mcont; + Container& cont = mcont; + test_driver(cont, find_test_policy()); + + mcont.clear(); + mcont += 1; + test_driver(cont, find_test_policy()); + + mcont.clear(); + mcont += 1,2,3,4,5,6,7,8,9; + test_driver(cont, find_test_policy()); + } + + void test_find() + { + test_find_container< std::vector >(); + test_find_container< std::list >(); + test_find_container< std::deque >(); + + test_find_container< const std::vector >(); + test_find_container< const std::list >(); + test_find_container< const std::deque >(); + + std::vector vi; + const std::vector& cvi = vi; + std::vector::const_iterator it = boost::find(vi, 0); + std::vector::const_iterator it2 = boost::find(cvi, 0); + BOOST_CHECK( it == it2 ); } } @@ -110,7 +107,7 @@ init_unit_test_suite(int argc, char* argv[]) boost::unit_test::test_suite* test = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.find" ); - test->add( BOOST_TEST_CASE( &boost::test_find ) ); + test->add( BOOST_TEST_CASE( &boost_range_test_algorithm_find::test_find ) ); return test; } diff --git a/test/algorithm_test/find_end.cpp b/test/algorithm_test/find_end.cpp index 0592d5f..b4d77a0 100644 --- a/test/algorithm_test/find_end.cpp +++ b/test/algorithm_test/find_end.cpp @@ -21,173 +21,170 @@ #include #include -namespace boost +namespace boost_range_test_algorithm_find_end { - namespace + template + class find_end_test_policy { - template - class find_end_test_policy + typedef Container2 container2_t; + public: + explicit find_end_test_policy(const Container2& cont) + : m_cont(cont) { - typedef Container2 container2_t; - public: - explicit find_end_test_policy(const Container2& cont) - : m_cont(cont) - { - } + } - container2_t cont() { return m_cont; } + container2_t cont() { return m_cont; } - template - BOOST_DEDUCED_TYPENAME range_iterator::type - test_iter(Container& cont) + template + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + test_iter(Container& cont) + { + typedef BOOST_DEDUCED_TYPENAME boost::range_iterator::type iter_t; + iter_t result = boost::find_end(cont, m_cont); + BOOST_CHECK( result == boost::find_end(boost::make_iterator_range(cont), m_cont) ); + BOOST_CHECK( result == boost::find_end(cont, boost::make_iterator_range(m_cont)) ); + BOOST_CHECK( result == boost::find_end(boost::make_iterator_range(cont), boost::make_iterator_range(m_cont)) ); + return result; + } + + template + struct test_range + { + template + BOOST_DEDUCED_TYPENAME boost::range_return::type + operator()(Policy& policy, Container& cont) { - typedef BOOST_DEDUCED_TYPENAME range_iterator::type iter_t; - iter_t result = boost::find_end(cont, m_cont); - BOOST_CHECK( result == boost::find_end(boost::make_iterator_range(cont), m_cont) ); - BOOST_CHECK( result == boost::find_end(cont, boost::make_iterator_range(m_cont)) ); - BOOST_CHECK( result == boost::find_end(boost::make_iterator_range(cont), boost::make_iterator_range(m_cont)) ); + typedef BOOST_DEDUCED_TYPENAME boost::range_return::type result_t; + result_t result = boost::find_end(cont, policy.cont()); + BOOST_CHECK( result == boost::find_end(boost::make_iterator_range(cont), policy.cont()) ); + BOOST_CHECK( result == boost::find_end(cont, boost::make_iterator_range(policy.cont())) ); + BOOST_CHECK( result == boost::find_end(boost::make_iterator_range(cont), + boost::make_iterator_range(policy.cont())) ); return result; } - - template - struct test_range - { - template - BOOST_DEDUCED_TYPENAME range_return::type - operator()(Policy& policy, Container& cont) - { - typedef BOOST_DEDUCED_TYPENAME range_return::type result_t; - result_t result = boost::find_end(cont, policy.cont()); - BOOST_CHECK( result == boost::find_end(boost::make_iterator_range(cont), policy.cont()) ); - BOOST_CHECK( result == boost::find_end(cont, boost::make_iterator_range(policy.cont())) ); - BOOST_CHECK( result == boost::find_end(boost::make_iterator_range(cont), - boost::make_iterator_range(policy.cont())) ); - return result; - } - }; - - template - BOOST_DEDUCED_TYPENAME range_iterator::type - reference(Container& cont) - { - return std::find_end(cont.begin(), cont.end(), - m_cont.begin(), m_cont.end()); - } - - private: - Container2 m_cont; }; - template - class find_end_pred_test_policy + template + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + reference(Container& cont) { - typedef Container2 container2_t; - public: - explicit find_end_pred_test_policy(const Container2& cont) - : m_cont(cont) + return std::find_end(cont.begin(), cont.end(), + m_cont.begin(), m_cont.end()); + } + + private: + Container2 m_cont; + }; + + template + class find_end_pred_test_policy + { + typedef Container2 container2_t; + public: + explicit find_end_pred_test_policy(const Container2& cont) + : m_cont(cont) + { + } + + container2_t& cont() { return m_cont; } + BinaryPredicate& pred() { return m_pred; } + + template + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + test_iter(Container& cont) + { + typedef BOOST_DEDUCED_TYPENAME boost::range_iterator::type iter_t; + iter_t it = boost::find_end(cont, m_cont, m_pred); + BOOST_CHECK( it == boost::find_end(boost::make_iterator_range(cont), m_cont, m_pred) ); + BOOST_CHECK( it == boost::find_end(cont, boost::make_iterator_range(m_cont), m_pred) ); + BOOST_CHECK( it == boost::find_end(boost::make_iterator_range(cont), boost::make_iterator_range(m_cont), m_pred) ); + return it; + } + + template + struct test_range + { + template + BOOST_DEDUCED_TYPENAME boost::range_return::type + operator()(Policy& policy, Container& cont) { + typedef BOOST_DEDUCED_TYPENAME boost::range_return::type result_t; + result_t result = boost::find_end(cont, policy.cont(), policy.pred()); + BOOST_CHECK( result == boost::find_end(boost::make_iterator_range(cont), policy.cont(), policy.pred()) ); + BOOST_CHECK( result == boost::find_end(cont, boost::make_iterator_range(policy.cont()), policy.pred()) ); + BOOST_CHECK( result == boost::find_end(boost::make_iterator_range(cont), + boost::make_iterator_range(policy.cont()), policy.pred()) ); + return boost::find_end(cont, policy.cont(), policy.pred()); } - - container2_t& cont() { return m_cont; } - BinaryPredicate& pred() { return m_pred; } - - template - BOOST_DEDUCED_TYPENAME range_iterator::type - test_iter(Container& cont) - { - typedef BOOST_DEDUCED_TYPENAME range_iterator::type iter_t; - iter_t it = boost::find_end(cont, m_cont, m_pred); - BOOST_CHECK( it == boost::find_end(boost::make_iterator_range(cont), m_cont, m_pred) ); - BOOST_CHECK( it == boost::find_end(cont, boost::make_iterator_range(m_cont), m_pred) ); - BOOST_CHECK( it == boost::find_end(boost::make_iterator_range(cont), boost::make_iterator_range(m_cont), m_pred) ); - return it; - } - - template - struct test_range - { - template - BOOST_DEDUCED_TYPENAME range_return::type - operator()(Policy& policy, Container& cont) - { - typedef BOOST_DEDUCED_TYPENAME range_return::type result_t; - result_t result = boost::find_end(cont, policy.cont(), policy.pred()); - BOOST_CHECK( result == boost::find_end(boost::make_iterator_range(cont), policy.cont(), policy.pred()) ); - BOOST_CHECK( result == boost::find_end(cont, boost::make_iterator_range(policy.cont()), policy.pred()) ); - BOOST_CHECK( result == boost::find_end(boost::make_iterator_range(cont), - boost::make_iterator_range(policy.cont()), policy.pred()) ); - return boost::find_end(cont, policy.cont(), policy.pred()); - } - }; - - template - BOOST_DEDUCED_TYPENAME range_iterator::type - reference(Container& cont) - { - return std::find_end(cont.begin(), cont.end(), - m_cont.begin(), m_cont.end(), - m_pred); - } - - private: - Container2 m_cont; - BinaryPredicate m_pred; }; - template - void run_tests(Container1& cont1, Container2& cont2) + template + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + reference(Container& cont) { - range_test::range_return_test_driver test_driver; - test_driver(cont1, find_end_test_policy(cont2)); - test_driver(cont1, find_end_pred_test_policy >(cont2)); - test_driver(cont2, find_end_pred_test_policy >(cont2)); + return std::find_end(cont.begin(), cont.end(), + m_cont.begin(), m_cont.end(), + m_pred); } - template - void test_find_end_impl() - { - using namespace boost::assign; + private: + Container2 m_cont; + BinaryPredicate m_pred; + }; - typedef BOOST_DEDUCED_TYPENAME remove_const::type container1_t; - typedef BOOST_DEDUCED_TYPENAME remove_const::type container2_t; + template + void run_tests(Container1& cont1, Container2& cont2) + { + boost::range_test::range_return_test_driver test_driver; + test_driver(cont1, find_end_test_policy(cont2)); + test_driver(cont1, find_end_pred_test_policy >(cont2)); + test_driver(cont2, find_end_pred_test_policy >(cont2)); + } - container1_t mcont1; - Container1& cont1 = mcont1; - container2_t mcont2; - Container2& cont2 = mcont2; + template + void test_find_end_impl() + { + using namespace boost::assign; - run_tests(cont1, cont2); + typedef BOOST_DEDUCED_TYPENAME boost::remove_const::type container1_t; + typedef BOOST_DEDUCED_TYPENAME boost::remove_const::type container2_t; - mcont1 += 1; - run_tests(cont1, cont2); + container1_t mcont1; + Container1& cont1 = mcont1; + container2_t mcont2; + Container2& cont2 = mcont2; - mcont2 += 1; - run_tests(cont1, cont2); + run_tests(cont1, cont2); - mcont1 += 2,3,4,5,6,7,8,9; - mcont2 += 2,3,4; - run_tests(cont1, cont2); + mcont1 += 1; + run_tests(cont1, cont2); - mcont2.clear(); - mcont2 += 7,8,9; - run_tests(cont1, cont2); - } + mcont2 += 1; + run_tests(cont1, cont2); - void test_find_end() - { - test_find_end_impl< std::vector, std::vector >(); - test_find_end_impl< std::list, std::list >(); - test_find_end_impl< std::deque, std::deque >(); - test_find_end_impl< const std::vector, const std::vector >(); - test_find_end_impl< const std::list, const std::list >(); - test_find_end_impl< const std::deque, const std::deque >(); - test_find_end_impl< const std::vector, const std::list >(); - test_find_end_impl< const std::list, const std::vector >(); - test_find_end_impl< const std::vector, std::list >(); - test_find_end_impl< const std::list, std::vector >(); - test_find_end_impl< std::vector, std::list >(); - test_find_end_impl< std::list, std::vector >(); - } + mcont1 += 2,3,4,5,6,7,8,9; + mcont2 += 2,3,4; + run_tests(cont1, cont2); + + mcont2.clear(); + mcont2 += 7,8,9; + run_tests(cont1, cont2); + } + + void test_find_end() + { + test_find_end_impl< std::vector, std::vector >(); + test_find_end_impl< std::list, std::list >(); + test_find_end_impl< std::deque, std::deque >(); + test_find_end_impl< const std::vector, const std::vector >(); + test_find_end_impl< const std::list, const std::list >(); + test_find_end_impl< const std::deque, const std::deque >(); + test_find_end_impl< const std::vector, const std::list >(); + test_find_end_impl< const std::list, const std::vector >(); + test_find_end_impl< const std::vector, std::list >(); + test_find_end_impl< const std::list, std::vector >(); + test_find_end_impl< std::vector, std::list >(); + test_find_end_impl< std::list, std::vector >(); } } @@ -197,7 +194,7 @@ init_unit_test_suite(int argc, char* argv[]) boost::unit_test::test_suite* test = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.find_end" ); - test->add( BOOST_TEST_CASE( &boost::test_find_end ) ); + test->add( BOOST_TEST_CASE( &boost_range_test_algorithm_find_end::test_find_end ) ); return test; } diff --git a/test/algorithm_test/find_first_of.cpp b/test/algorithm_test/find_first_of.cpp index c96d36a..296b8fc 100644 --- a/test/algorithm_test/find_first_of.cpp +++ b/test/algorithm_test/find_first_of.cpp @@ -21,171 +21,168 @@ #include #include -namespace boost +namespace boost_range_test_algorithm_find_first_of { - namespace + template + class find_first_of_test_policy { - template - class find_first_of_test_policy + typedef Container2 container2_t; + public: + explicit find_first_of_test_policy(const Container2& cont) + : m_cont(cont) { - typedef Container2 container2_t; - public: - explicit find_first_of_test_policy(const Container2& cont) - : m_cont(cont) - { - } + } - container2_t& cont() { return m_cont; } + container2_t& cont() { return m_cont; } - template - BOOST_DEDUCED_TYPENAME range_iterator::type - test_iter(Container& cont) + template + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + test_iter(Container& cont) + { + typedef BOOST_DEDUCED_TYPENAME boost::range_iterator::type iter_t; + iter_t result = boost::find_first_of(cont, m_cont); + BOOST_CHECK( result == boost::find_first_of(boost::make_iterator_range(cont), m_cont) ); + BOOST_CHECK( result == boost::find_first_of(cont, boost::make_iterator_range(m_cont)) ); + BOOST_CHECK( result == boost::find_first_of(boost::make_iterator_range(cont), boost::make_iterator_range(m_cont)) ); + return result; + } + + template + struct test_range + { + template + BOOST_DEDUCED_TYPENAME boost::range_return::type + operator()(Policy& policy, Container& cont) { - typedef BOOST_DEDUCED_TYPENAME range_iterator::type iter_t; - iter_t result = boost::find_first_of(cont, m_cont); - BOOST_CHECK( result == boost::find_first_of(boost::make_iterator_range(cont), m_cont) ); - BOOST_CHECK( result == boost::find_first_of(cont, boost::make_iterator_range(m_cont)) ); - BOOST_CHECK( result == boost::find_first_of(boost::make_iterator_range(cont), boost::make_iterator_range(m_cont)) ); + typedef BOOST_DEDUCED_TYPENAME boost::range_return::type result_t; + result_t result = boost::find_first_of(cont, policy.cont()); + BOOST_CHECK( result == boost::find_first_of(boost::make_iterator_range(cont), policy.cont()) ); + BOOST_CHECK( result == boost::find_first_of(cont, boost::make_iterator_range(policy.cont())) ); + BOOST_CHECK( result == boost::find_first_of(boost::make_iterator_range(cont), boost::make_iterator_range(policy.cont())) ); return result; } - - template - struct test_range - { - template - BOOST_DEDUCED_TYPENAME range_return::type - operator()(Policy& policy, Container& cont) - { - typedef BOOST_DEDUCED_TYPENAME range_return::type result_t; - result_t result = boost::find_first_of(cont, policy.cont()); - BOOST_CHECK( result == boost::find_first_of(boost::make_iterator_range(cont), policy.cont()) ); - BOOST_CHECK( result == boost::find_first_of(cont, boost::make_iterator_range(policy.cont())) ); - BOOST_CHECK( result == boost::find_first_of(boost::make_iterator_range(cont), boost::make_iterator_range(policy.cont())) ); - return result; - } - }; - - template - BOOST_DEDUCED_TYPENAME range_iterator::type - reference(Container& cont) - { - return std::find_first_of(cont.begin(), cont.end(), - m_cont.begin(), m_cont.end()); - } - - private: - Container2 m_cont; }; - template - class find_first_of_pred_test_policy + template + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + reference(Container& cont) { - typedef Container2 container2_t; - public: - explicit find_first_of_pred_test_policy(const Container2& cont) - : m_cont(cont) - { - } + return std::find_first_of(cont.begin(), cont.end(), + m_cont.begin(), m_cont.end()); + } - container2_t& cont() { return m_cont; } - BinaryPredicate& pred() { return m_pred; } + private: + Container2 m_cont; + }; - template - BOOST_DEDUCED_TYPENAME range_iterator::type - test_iter(Container& cont) + template + class find_first_of_pred_test_policy + { + typedef Container2 container2_t; + public: + explicit find_first_of_pred_test_policy(const Container2& cont) + : m_cont(cont) + { + } + + container2_t& cont() { return m_cont; } + BinaryPredicate& pred() { return m_pred; } + + template + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + test_iter(Container& cont) + { + typedef BOOST_DEDUCED_TYPENAME boost::range_iterator::type iter_t; + iter_t result = boost::find_first_of(cont, m_cont, m_pred); + BOOST_CHECK( result == boost::find_first_of(boost::make_iterator_range(cont), m_cont, m_pred) ); + BOOST_CHECK( result == boost::find_first_of(cont, boost::make_iterator_range(m_cont), m_pred) ); + BOOST_CHECK( result == boost::find_first_of(boost::make_iterator_range(cont), boost::make_iterator_range(m_cont), m_pred) ); + return result; + } + + template + struct test_range + { + template + BOOST_DEDUCED_TYPENAME boost::range_return::type + operator()(Policy& policy, Container& cont) { - typedef BOOST_DEDUCED_TYPENAME range_iterator::type iter_t; - iter_t result = boost::find_first_of(cont, m_cont, m_pred); - BOOST_CHECK( result == boost::find_first_of(boost::make_iterator_range(cont), m_cont, m_pred) ); - BOOST_CHECK( result == boost::find_first_of(cont, boost::make_iterator_range(m_cont), m_pred) ); - BOOST_CHECK( result == boost::find_first_of(boost::make_iterator_range(cont), boost::make_iterator_range(m_cont), m_pred) ); + typedef BOOST_DEDUCED_TYPENAME boost::range_return::type result_t; + result_t result = boost::find_first_of(cont, policy.cont(), policy.pred()); + BOOST_CHECK( result == boost::find_first_of(boost::make_iterator_range(cont), policy.cont(), policy.pred()) ); + BOOST_CHECK( result == boost::find_first_of(cont, boost::make_iterator_range(policy.cont()), policy.pred()) ); + BOOST_CHECK( result == boost::find_first_of(boost::make_iterator_range(cont), boost::make_iterator_range(policy.cont()), policy.pred()) ); return result; } - - template - struct test_range - { - template - BOOST_DEDUCED_TYPENAME range_return::type - operator()(Policy& policy, Container& cont) - { - typedef BOOST_DEDUCED_TYPENAME range_return::type result_t; - result_t result = boost::find_first_of(cont, policy.cont(), policy.pred()); - BOOST_CHECK( result == boost::find_first_of(boost::make_iterator_range(cont), policy.cont(), policy.pred()) ); - BOOST_CHECK( result == boost::find_first_of(cont, boost::make_iterator_range(policy.cont()), policy.pred()) ); - BOOST_CHECK( result == boost::find_first_of(boost::make_iterator_range(cont), boost::make_iterator_range(policy.cont()), policy.pred()) ); - return result; - } - }; - - template - BOOST_DEDUCED_TYPENAME range_iterator::type - reference(Container& cont) - { - return std::find_first_of(cont.begin(), cont.end(), - m_cont.begin(), m_cont.end(), - m_pred); - } - - private: - Container2 m_cont; - BinaryPredicate m_pred; }; - template - void run_tests(Container1& cont1, Container2& cont2) + template + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + reference(Container& cont) { - range_test::range_return_test_driver test_driver; - test_driver(cont1, find_first_of_test_policy(cont2)); - test_driver(cont1, find_first_of_pred_test_policy >(cont2)); - test_driver(cont2, find_first_of_pred_test_policy >(cont2)); + return std::find_first_of(cont.begin(), cont.end(), + m_cont.begin(), m_cont.end(), + m_pred); } - template - void test_find_first_of_impl() - { - using namespace boost::assign; + private: + Container2 m_cont; + BinaryPredicate m_pred; + }; - typedef BOOST_DEDUCED_TYPENAME remove_const::type container1_t; - typedef BOOST_DEDUCED_TYPENAME remove_const::type container2_t; + template + void run_tests(Container1& cont1, Container2& cont2) + { + boost::range_test::range_return_test_driver test_driver; + test_driver(cont1, find_first_of_test_policy(cont2)); + test_driver(cont1, find_first_of_pred_test_policy >(cont2)); + test_driver(cont2, find_first_of_pred_test_policy >(cont2)); + } - container1_t mcont1; - Container1& cont1 = mcont1; - container2_t mcont2; - Container2& cont2 = mcont2; + template + void test_find_first_of_impl() + { + using namespace boost::assign; - run_tests(cont1, cont2); + typedef BOOST_DEDUCED_TYPENAME boost::remove_const::type container1_t; + typedef BOOST_DEDUCED_TYPENAME boost::remove_const::type container2_t; - mcont1 += 1; - run_tests(cont1, cont2); + container1_t mcont1; + Container1& cont1 = mcont1; + container2_t mcont2; + Container2& cont2 = mcont2; - mcont2 += 1; - run_tests(cont1, cont2); + run_tests(cont1, cont2); - mcont1 += 2,3,4,5,6,7,8,9; - mcont2 += 2,3,4; - run_tests(cont1, cont2); + mcont1 += 1; + run_tests(cont1, cont2); - mcont2.clear(); - mcont2 += 7,8,9; - run_tests(cont1, cont2); - } + mcont2 += 1; + run_tests(cont1, cont2); - void test_find_first_of() - { - test_find_first_of_impl< std::vector, std::vector >(); - test_find_first_of_impl< std::list, std::list >(); - test_find_first_of_impl< std::deque, std::deque >(); - test_find_first_of_impl< const std::vector, const std::vector >(); - test_find_first_of_impl< const std::list, const std::list >(); - test_find_first_of_impl< const std::deque, const std::deque >(); - test_find_first_of_impl< const std::vector, const std::list >(); - test_find_first_of_impl< const std::list, const std::vector >(); - test_find_first_of_impl< const std::vector, std::list >(); - test_find_first_of_impl< const std::list, std::vector >(); - test_find_first_of_impl< std::vector, std::list >(); - test_find_first_of_impl< std::list, std::vector >(); - } + mcont1 += 2,3,4,5,6,7,8,9; + mcont2 += 2,3,4; + run_tests(cont1, cont2); + + mcont2.clear(); + mcont2 += 7,8,9; + run_tests(cont1, cont2); + } + + void test_find_first_of() + { + test_find_first_of_impl< std::vector, std::vector >(); + test_find_first_of_impl< std::list, std::list >(); + test_find_first_of_impl< std::deque, std::deque >(); + test_find_first_of_impl< const std::vector, const std::vector >(); + test_find_first_of_impl< const std::list, const std::list >(); + test_find_first_of_impl< const std::deque, const std::deque >(); + test_find_first_of_impl< const std::vector, const std::list >(); + test_find_first_of_impl< const std::list, const std::vector >(); + test_find_first_of_impl< const std::vector, std::list >(); + test_find_first_of_impl< const std::list, std::vector >(); + test_find_first_of_impl< std::vector, std::list >(); + test_find_first_of_impl< std::list, std::vector >(); } } @@ -195,7 +192,7 @@ init_unit_test_suite(int argc, char* argv[]) boost::unit_test::test_suite* test = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.find_first_of" ); - test->add( BOOST_TEST_CASE( &boost::test_find_first_of ) ); + test->add( BOOST_TEST_CASE( &boost_range_test_algorithm_find_first_of::test_find_first_of ) ); return test; } diff --git a/test/algorithm_test/find_if.cpp b/test/algorithm_test/find_if.cpp index 04fe6f2..3ab22c9 100644 --- a/test/algorithm_test/find_if.cpp +++ b/test/algorithm_test/find_if.cpp @@ -23,97 +23,94 @@ #include #include -namespace boost +namespace boost_range_test_algorithm_find_if { - namespace + template + class find_if_test_policy { - template - class find_if_test_policy - { - public: - explicit find_if_test_policy(UnaryPredicate pred) - : m_pred(pred) {} - - template - BOOST_DEDUCED_TYPENAME range_iterator::type - test_iter(Container& cont) - { - typedef BOOST_DEDUCED_TYPENAME range_iterator::type iter_t; - iter_t result = boost::find_if(cont, m_pred); - BOOST_CHECK( result == boost::find_if(boost::make_iterator_range(cont), m_pred) ); - return result; - } - - template - struct test_range - { - template - BOOST_DEDUCED_TYPENAME range_return::type - operator()(find_if_test_policy& policy, Container& cont) - { - typedef BOOST_DEDUCED_TYPENAME range_return::type result_t; - result_t result = boost::find_if(cont, policy.pred()); - BOOST_CHECK( result == boost::find_if(boost::make_iterator_range(cont), policy.pred()) ); - return result; - } - }; - - template - BOOST_DEDUCED_TYPENAME range_iterator::type - reference(Container& cont) - { - return std::find_if(cont.begin(), cont.end(), m_pred); - } - - UnaryPredicate& pred() { return m_pred; } - - private: - UnaryPredicate m_pred; - }; - - template - find_if_test_policy - make_policy(UnaryPredicate pred) - { - return find_if_test_policy(pred); - } + public: + explicit find_if_test_policy(UnaryPredicate pred) + : m_pred(pred) {} template - void test_find_if_container() + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + test_iter(Container& cont) { - using namespace boost::assign; - using namespace boost::range_test_function; - - typedef BOOST_DEDUCED_TYPENAME remove_const::type container_t; - - range_test::range_return_test_driver test_driver; - - container_t mcont; - Container& cont = mcont; - test_driver(cont, make_policy(greater_than_x(5))); - test_driver(cont, make_policy(false_predicate())); - - mcont.clear(); - mcont += 1; - test_driver(cont, make_policy(greater_than_x(5))); - test_driver(cont, make_policy(false_predicate())); - - mcont.clear(); - mcont += 1,2,3,4,5,6,7,8,9; - test_driver(cont, make_policy(greater_than_x(5))); - test_driver(cont, make_policy(false_predicate())); + typedef BOOST_DEDUCED_TYPENAME boost::range_iterator::type iter_t; + iter_t result = boost::find_if(cont, m_pred); + BOOST_CHECK( result == boost::find_if(boost::make_iterator_range(cont), m_pred) ); + return result; } - void test_find_if() + template + struct test_range { - test_find_if_container< std::vector >(); - test_find_if_container< std::list >(); - test_find_if_container< std::deque >(); + template + BOOST_DEDUCED_TYPENAME boost::range_return::type + operator()(find_if_test_policy& policy, Container& cont) + { + typedef BOOST_DEDUCED_TYPENAME boost::range_return::type result_t; + result_t result = boost::find_if(cont, policy.pred()); + BOOST_CHECK( result == boost::find_if(boost::make_iterator_range(cont), policy.pred()) ); + return result; + } + }; - test_find_if_container< const std::vector >(); - test_find_if_container< const std::list >(); - test_find_if_container< const std::deque >(); + template + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + reference(Container& cont) + { + return std::find_if(cont.begin(), cont.end(), m_pred); } + + UnaryPredicate& pred() { return m_pred; } + + private: + UnaryPredicate m_pred; + }; + + template + find_if_test_policy + make_policy(UnaryPredicate pred) + { + return find_if_test_policy(pred); + } + + template + void test_find_if_container() + { + using namespace boost::assign; + using namespace boost::range_test_function; + + typedef BOOST_DEDUCED_TYPENAME boost::remove_const::type container_t; + + boost::range_test::range_return_test_driver test_driver; + + container_t mcont; + Container& cont = mcont; + test_driver(cont, make_policy(greater_than_x(5))); + test_driver(cont, make_policy(false_predicate())); + + mcont.clear(); + mcont += 1; + test_driver(cont, make_policy(greater_than_x(5))); + test_driver(cont, make_policy(false_predicate())); + + mcont.clear(); + mcont += 1,2,3,4,5,6,7,8,9; + test_driver(cont, make_policy(greater_than_x(5))); + test_driver(cont, make_policy(false_predicate())); + } + + void test_find_if() + { + test_find_if_container< std::vector >(); + test_find_if_container< std::list >(); + test_find_if_container< std::deque >(); + + test_find_if_container< const std::vector >(); + test_find_if_container< const std::list >(); + test_find_if_container< const std::deque >(); } } @@ -123,7 +120,7 @@ init_unit_test_suite(int argc, char* argv[]) boost::unit_test::test_suite* test = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.find_if" ); - test->add( BOOST_TEST_CASE( &boost::test_find_if ) ); + test->add( BOOST_TEST_CASE( &boost_range_test_algorithm_find_if::test_find_if ) ); return test; } diff --git a/test/algorithm_test/lower_bound.cpp b/test/algorithm_test/lower_bound.cpp index e627708..2a120a4 100644 --- a/test/algorithm_test/lower_bound.cpp +++ b/test/algorithm_test/lower_bound.cpp @@ -22,164 +22,160 @@ #include #include -namespace boost +namespace boost_range_test_algorithm_lower_bound { - namespace + class lower_bound_policy { - class lower_bound_policy + public: + template< class Container > + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + test_iter(Container& cont) { - public: - template< class Container > - BOOST_DEDUCED_TYPENAME range_iterator::type - test_iter(Container& cont) - { - typedef BOOST_DEDUCED_TYPENAME range_iterator::type iter_t; - iter_t result = boost::lower_bound(cont, 5); - BOOST_CHECK( result == boost::lower_bound(boost::make_iterator_range(cont), 5) ); - return result; - } - - template - struct test_range - { - template - BOOST_DEDUCED_TYPENAME range_return::type - operator()(Policy&, Container& cont) - { - typedef BOOST_DEDUCED_TYPENAME range_return::type result_t; - result_t result = boost::lower_bound(cont, 5); - BOOST_CHECK( result == boost::lower_bound(boost::make_iterator_range(cont), 5) ); - return result; - } - }; - - template< class Container > - BOOST_DEDUCED_TYPENAME range_iterator::type - reference(Container& cont) - { - return std::lower_bound(cont.begin(), cont.end(), 5); - } - }; - - template< class BinaryPredicate > - struct lower_bound_pred_policy - { - template< class Container > - BOOST_DEDUCED_TYPENAME range_iterator::type - test_iter(Container& cont) - { - typedef BOOST_DEDUCED_TYPENAME range_iterator::type iter_t; - iter_t result = boost::lower_bound(cont, 5, m_pred); - BOOST_CHECK( result == boost::lower_bound( - boost::make_iterator_range(cont), 5, m_pred) ); - return result; - } - - template< range_return_value return_type > - struct test_range - { - template - BOOST_DEDUCED_TYPENAME range_return::type - operator()(Policy& policy, Container& cont) - { - typedef BOOST_DEDUCED_TYPENAME range_return::type result_t; - result_t result = boost::lower_bound(cont, 5, policy.pred()); - BOOST_CHECK( result == boost::lower_bound( - boost::make_iterator_range(cont), 5, policy.pred()) ); - return result; - } - }; - - template - BOOST_DEDUCED_TYPENAME range_iterator::type - reference(Container& cont) - { - return std::lower_bound( - cont.begin(), cont.end(), 5, m_pred); - } - - BinaryPredicate& pred() { return m_pred; } - - private: - BinaryPredicate m_pred; - }; - - template - void test_lower_bound_impl(TestPolicy policy, BinaryPredicate pred) - { - using namespace boost::assign; - - typedef BOOST_DEDUCED_TYPENAME remove_const::type container_t; - typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t; - - range_test::range_return_test_driver test_driver; - - container_t mcont; - Container& cont = mcont; - - test_driver(cont, policy); - - mcont.clear(); - mcont += 1; - - std::vector temp(mcont.begin(), mcont.end()); - std::sort(temp.begin(), temp.end(), pred); - mcont.assign(temp.begin(), temp.end()); - - test_driver(cont, policy); - - mcont.clear(); - mcont += 1,2,3,4,5,6,7,8,9; - - temp.assign(mcont.begin(), mcont.end()); - std::sort(temp.begin(), temp.end(), pred); - mcont.assign(temp.begin(), temp.end()); - - test_driver(cont, policy); + typedef BOOST_DEDUCED_TYPENAME boost::range_iterator::type iter_t; + iter_t result = boost::lower_bound(cont, 5); + BOOST_CHECK( result == boost::lower_bound(boost::make_iterator_range(cont), 5) ); + return result; } + template + struct test_range + { + template + BOOST_DEDUCED_TYPENAME boost::range_return::type + operator()(Policy&, Container& cont) + { + typedef BOOST_DEDUCED_TYPENAME boost::range_return::type result_t; + result_t result = boost::lower_bound(cont, 5); + BOOST_CHECK( result == boost::lower_bound(boost::make_iterator_range(cont), 5) ); + return result; + } + }; + + template< class Container > + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + reference(Container& cont) + { + return std::lower_bound(cont.begin(), cont.end(), 5); + } + }; + + template< class BinaryPredicate > + struct lower_bound_pred_policy + { + template< class Container > + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + test_iter(Container& cont) + { + typedef BOOST_DEDUCED_TYPENAME boost::range_iterator::type iter_t; + iter_t result = boost::lower_bound(cont, 5, m_pred); + BOOST_CHECK( result == boost::lower_bound( + boost::make_iterator_range(cont), 5, m_pred) ); + return result; + } + + template< boost::range_return_value return_type > + struct test_range + { + template + BOOST_DEDUCED_TYPENAME boost::range_return::type + operator()(Policy& policy, Container& cont) + { + typedef BOOST_DEDUCED_TYPENAME boost::range_return::type result_t; + result_t result = boost::lower_bound(cont, 5, policy.pred()); + BOOST_CHECK( result == boost::lower_bound( + boost::make_iterator_range(cont), 5, policy.pred()) ); + return result; + } + }; + template - void test_lower_bound_impl() + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + reference(Container& cont) { - test_lower_bound_impl( - lower_bound_policy(), - std::less() - ); - - test_lower_bound_impl( - lower_bound_pred_policy >(), - std::less() - ); - - test_lower_bound_impl( - lower_bound_pred_policy >(), - std::greater() - ); + return std::lower_bound( + cont.begin(), cont.end(), 5, m_pred); } - void test_lower_bound() - { - test_lower_bound_impl< std::vector >(); - test_lower_bound_impl< std::list >(); - test_lower_bound_impl< std::deque >(); + BinaryPredicate& pred() { return m_pred; } - test_lower_bound_impl< const std::vector >(); - test_lower_bound_impl< const std::list >(); - test_lower_bound_impl< const std::deque >(); - } + private: + BinaryPredicate m_pred; + }; + + template + void test_lower_bound_impl(TestPolicy policy, BinaryPredicate pred) + { + using namespace boost::assign; + + typedef BOOST_DEDUCED_TYPENAME boost::remove_const::type container_t; + typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t; + + boost::range_test::range_return_test_driver test_driver; + + container_t mcont; + Container& cont = mcont; + + test_driver(cont, policy); + + mcont.clear(); + mcont += 1; + + std::vector temp(mcont.begin(), mcont.end()); + std::sort(temp.begin(), temp.end(), pred); + mcont.assign(temp.begin(), temp.end()); + + test_driver(cont, policy); + + mcont.clear(); + mcont += 1,2,3,4,5,6,7,8,9; + + temp.assign(mcont.begin(), mcont.end()); + std::sort(temp.begin(), temp.end(), pred); + mcont.assign(temp.begin(), temp.end()); + + test_driver(cont, policy); + } + + template + void test_lower_bound_impl() + { + test_lower_bound_impl( + lower_bound_policy(), + std::less() + ); + + test_lower_bound_impl( + lower_bound_pred_policy >(), + std::less() + ); + + test_lower_bound_impl( + lower_bound_pred_policy >(), + std::greater() + ); + } + + void test_lower_bound() + { + test_lower_bound_impl< std::vector >(); + test_lower_bound_impl< std::list >(); + test_lower_bound_impl< std::deque >(); + + test_lower_bound_impl< const std::vector >(); + test_lower_bound_impl< const std::list >(); + test_lower_bound_impl< const std::deque >(); } } - boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) { boost::unit_test::test_suite* test = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.lower_bound" ); - test->add( BOOST_TEST_CASE( &boost::test_lower_bound ) ); + test->add( BOOST_TEST_CASE( &boost_range_test_algorithm_lower_bound::test_lower_bound ) ); return test; } diff --git a/test/algorithm_test/max_element.cpp b/test/algorithm_test/max_element.cpp index c4c6cb9..9a26099 100644 --- a/test/algorithm_test/max_element.cpp +++ b/test/algorithm_test/max_element.cpp @@ -22,134 +22,131 @@ #include #include -namespace boost +namespace boost_range_test_algorithm_max_element { - namespace + class max_element_test_policy { - class max_element_test_policy + public: + template< class Container > + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + test_iter(Container& cont) { - public: - template< class Container > - BOOST_DEDUCED_TYPENAME range_iterator::type - test_iter(Container& cont) + typedef BOOST_DEDUCED_TYPENAME boost::range_iterator::type iter_t; + iter_t result = boost::max_element(cont); + BOOST_CHECK( result == boost::max_element( + boost::make_iterator_range(cont)) ); + return result; + } + + template + struct test_range + { + template + BOOST_DEDUCED_TYPENAME boost::range_return::type + operator()(Policy&, Container& cont) { - typedef BOOST_DEDUCED_TYPENAME range_iterator::type iter_t; - iter_t result = boost::max_element(cont); - BOOST_CHECK( result == boost::max_element( + typedef BOOST_DEDUCED_TYPENAME boost::range_return::type result_t; + result_t result = boost::max_element(cont); + BOOST_CHECK( result == boost::max_element( boost::make_iterator_range(cont)) ); return result; } - - template - struct test_range - { - template - BOOST_DEDUCED_TYPENAME range_return::type - operator()(Policy&, Container& cont) - { - typedef BOOST_DEDUCED_TYPENAME range_return::type result_t; - result_t result = boost::max_element(cont); - BOOST_CHECK( result == boost::max_element( - boost::make_iterator_range(cont)) ); - return result; - } - }; - - template< class Container > - BOOST_DEDUCED_TYPENAME range_iterator::type - reference(Container& cont) - { - return std::max_element(cont.begin(), cont.end()); - } }; - template - class max_element_pred_test_policy + template< class Container > + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + reference(Container& cont) { - public: - template< class Container > - BOOST_DEDUCED_TYPENAME range_iterator::type - test_iter(Container& cont) + return std::max_element(cont.begin(), cont.end()); + } + }; + + template + class max_element_pred_test_policy + { + public: + template< class Container > + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + test_iter(Container& cont) + { + typedef BOOST_DEDUCED_TYPENAME boost::range_iterator::type iter_t; + iter_t result = boost::max_element(cont, Pred()); + BOOST_CHECK( result == boost::max_element( + boost::make_iterator_range(cont), Pred()) ); + return result; + } + + Pred pred() const { return Pred(); } + + template< boost::range_return_value return_type > + struct test_range + { + template< class Container, class Policy > + BOOST_DEDUCED_TYPENAME boost::range_return::type + operator()(Policy& policy, Container& cont) { - typedef BOOST_DEDUCED_TYPENAME range_iterator::type iter_t; - iter_t result = boost::max_element(cont, Pred()); - BOOST_CHECK( result == boost::max_element( - boost::make_iterator_range(cont), Pred()) ); + typedef BOOST_DEDUCED_TYPENAME boost::range_return::type result_t; + result_t result = boost::max_element(cont, policy.pred()); + BOOST_CHECK( result == boost::max_element( + boost::make_iterator_range(cont), policy.pred()) ); return result; } - - Pred pred() const { return Pred(); } - - template< range_return_value return_type > - struct test_range - { - template< class Container, class Policy > - BOOST_DEDUCED_TYPENAME range_return::type - operator()(Policy& policy, Container& cont) - { - typedef BOOST_DEDUCED_TYPENAME range_return::type result_t; - result_t result = boost::max_element(cont, policy.pred()); - BOOST_CHECK( result == boost::max_element( - boost::make_iterator_range(cont), policy.pred()) ); - return result; - } - }; - - template< class Container > - BOOST_DEDUCED_TYPENAME range_iterator::type - reference(Container& cont) - { - return std::max_element(cont.begin(), cont.end(), Pred()); - } }; - template - void test_max_element_impl(TestPolicy policy) + template< class Container > + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + reference(Container& cont) { - using namespace boost::assign; - - typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t; - typedef BOOST_DEDUCED_TYPENAME remove_const::type container_t; - - range_test::range_return_test_driver test_driver; - - container_t cont; - - test_driver(cont, policy); - - cont.clear(); - cont += 1; - - test_driver(cont, policy); - - cont.clear(); - cont += 1,2,2,2,3,4,5,6,7,8,9; - - test_driver(cont, policy); + return std::max_element(cont.begin(), cont.end(), Pred()); } + }; - template - void test_max_element_impl() - { - test_max_element_impl(max_element_test_policy()); - - test_max_element_impl( - max_element_pred_test_policy >()); + template + void test_max_element_impl(TestPolicy policy) + { + using namespace boost::assign; - test_max_element_impl( - max_element_pred_test_policy >()); - } + typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t; + typedef BOOST_DEDUCED_TYPENAME boost::remove_const::type container_t; - void test_max_element() - { - test_max_element_impl< const std::vector >(); - test_max_element_impl< const std::deque >(); - test_max_element_impl< const std::list >(); + boost::range_test::range_return_test_driver test_driver; - test_max_element_impl< std::vector >(); - test_max_element_impl< std::deque >(); - test_max_element_impl< std::list >(); - } + container_t cont; + + test_driver(cont, policy); + + cont.clear(); + cont += 1; + + test_driver(cont, policy); + + cont.clear(); + cont += 1,2,2,2,3,4,5,6,7,8,9; + + test_driver(cont, policy); + } + + template + void test_max_element_impl() + { + test_max_element_impl(max_element_test_policy()); + + test_max_element_impl( + max_element_pred_test_policy >()); + + test_max_element_impl( + max_element_pred_test_policy >()); + } + + void test_max_element() + { + test_max_element_impl< const std::vector >(); + test_max_element_impl< const std::deque >(); + test_max_element_impl< const std::list >(); + + test_max_element_impl< std::vector >(); + test_max_element_impl< std::deque >(); + test_max_element_impl< std::list >(); } } @@ -159,7 +156,7 @@ init_unit_test_suite(int argc, char* argv[]) boost::unit_test::test_suite* test = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.max_element" ); - test->add( BOOST_TEST_CASE( &boost::test_max_element ) ); + test->add( BOOST_TEST_CASE( &boost_range_test_algorithm_max_element::test_max_element ) ); return test; } diff --git a/test/algorithm_test/min_element.cpp b/test/algorithm_test/min_element.cpp index c8fceda..0f9fa68 100644 --- a/test/algorithm_test/min_element.cpp +++ b/test/algorithm_test/min_element.cpp @@ -22,132 +22,129 @@ #include #include -namespace boost +namespace boost_range_test_algorithm_min_element { - namespace + class min_element_test_policy { - class min_element_test_policy + public: + template< class Container > + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + test_iter(Container& cont) { - public: - template< class Container > - BOOST_DEDUCED_TYPENAME range_iterator::type - test_iter(Container& cont) + typedef BOOST_DEDUCED_TYPENAME boost::range_iterator::type iter_t; + iter_t result = boost::min_element(cont); + BOOST_CHECK( result == boost::min_element(boost::make_iterator_range(cont)) ); + return result; + } + + template< boost::range_return_value return_type > + struct test_range + { + template< class Container, class Policy > + BOOST_DEDUCED_TYPENAME boost::range_return::type + operator()(Policy&, Container& cont) { - typedef BOOST_DEDUCED_TYPENAME range_iterator::type iter_t; - iter_t result = boost::min_element(cont); - BOOST_CHECK( result == boost::min_element(boost::make_iterator_range(cont)) ); + typedef BOOST_DEDUCED_TYPENAME boost::range_return::type result_t; + result_t result = boost::min_element(cont); + BOOST_CHECK( result == boost::min_element(boost::make_iterator_range(cont)) ); return result; } - - template< range_return_value return_type > - struct test_range - { - template< class Container, class Policy > - BOOST_DEDUCED_TYPENAME range_return::type - operator()(Policy&, Container& cont) - { - typedef BOOST_DEDUCED_TYPENAME range_return::type result_t; - result_t result = boost::min_element(cont); - BOOST_CHECK( result == boost::min_element(boost::make_iterator_range(cont)) ); - return result; - } - }; - - template< class Container > - BOOST_DEDUCED_TYPENAME range_iterator::type - reference(Container& cont) - { - return std::min_element(cont.begin(), cont.end()); - } }; - template - class min_element_pred_test_policy + template< class Container > + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + reference(Container& cont) { - public: - template< class Container > - BOOST_DEDUCED_TYPENAME range_iterator::type - test_iter(Container& cont) + return std::min_element(cont.begin(), cont.end()); + } + }; + + template + class min_element_pred_test_policy + { + public: + template< class Container > + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + test_iter(Container& cont) + { + typedef BOOST_DEDUCED_TYPENAME boost::range_iterator::type iter_t; + iter_t result = boost::min_element(cont, Pred()); + BOOST_CHECK( result == boost::min_element( + boost::make_iterator_range(cont), Pred()) ); + return result; + } + + Pred pred() const { return Pred(); } + + template< boost::range_return_value return_type > + struct test_range + { + template< class Container, class Policy > + BOOST_DEDUCED_TYPENAME boost::range_return::type + operator()(Policy& policy, Container& cont) { - typedef BOOST_DEDUCED_TYPENAME range_iterator::type iter_t; - iter_t result = boost::min_element(cont, Pred()); - BOOST_CHECK( result == boost::min_element( - boost::make_iterator_range(cont), Pred()) ); + typedef BOOST_DEDUCED_TYPENAME boost::range_return::type result_t; + result_t result = boost::min_element(cont, policy.pred()); + BOOST_CHECK( result == boost::min_element( + boost::make_iterator_range(cont), policy.pred()) ); return result; } - - Pred pred() const { return Pred(); } - - template< range_return_value return_type > - struct test_range - { - template< class Container, class Policy > - BOOST_DEDUCED_TYPENAME range_return::type - operator()(Policy& policy, Container& cont) - { - typedef BOOST_DEDUCED_TYPENAME range_return::type result_t; - result_t result = boost::min_element(cont, policy.pred()); - BOOST_CHECK( result == boost::min_element( - boost::make_iterator_range(cont), policy.pred()) ); - return result; - } - }; - - template< class Container > - BOOST_DEDUCED_TYPENAME range_iterator::type - reference(Container& cont) - { - return std::min_element(cont.begin(), cont.end(), Pred()); - } }; - template - void test_min_element_impl(TestPolicy policy) + template< class Container > + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + reference(Container& cont) { - using namespace boost::assign; - - typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t; - typedef BOOST_DEDUCED_TYPENAME remove_const::type container_t; - - range_test::range_return_test_driver test_driver; - - container_t cont; - - test_driver(cont, policy); - - cont.clear(); - cont += 1; - - test_driver(cont, policy); - - cont.clear(); - cont += 1,2,2,2,3,4,5,6,7,8,9; - - test_driver(cont, policy); + return std::min_element(cont.begin(), cont.end(), Pred()); } + }; - template - void test_min_element_impl() - { - test_min_element_impl(min_element_test_policy()); - - test_min_element_impl( - min_element_pred_test_policy >()); + template + void test_min_element_impl(TestPolicy policy) + { + using namespace boost::assign; - test_min_element_impl( - min_element_pred_test_policy >()); - } + typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t; + typedef BOOST_DEDUCED_TYPENAME boost::remove_const::type container_t; - void test_min_element() - { - test_min_element_impl< const std::vector >(); - test_min_element_impl< const std::deque >(); - test_min_element_impl< const std::list >(); + boost::range_test::range_return_test_driver test_driver; - test_min_element_impl< std::vector >(); - test_min_element_impl< std::deque >(); - test_min_element_impl< std::list >(); - } + container_t cont; + + test_driver(cont, policy); + + cont.clear(); + cont += 1; + + test_driver(cont, policy); + + cont.clear(); + cont += 1,2,2,2,3,4,5,6,7,8,9; + + test_driver(cont, policy); + } + + template + void test_min_element_impl() + { + test_min_element_impl(min_element_test_policy()); + + test_min_element_impl( + min_element_pred_test_policy >()); + + test_min_element_impl( + min_element_pred_test_policy >()); + } + + void test_min_element() + { + test_min_element_impl< const std::vector >(); + test_min_element_impl< const std::deque >(); + test_min_element_impl< const std::list >(); + + test_min_element_impl< std::vector >(); + test_min_element_impl< std::deque >(); + test_min_element_impl< std::list >(); } } @@ -157,7 +154,7 @@ init_unit_test_suite(int argc, char* argv[]) boost::unit_test::test_suite* test = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.min_element" ); - test->add( BOOST_TEST_CASE( &boost::test_min_element ) ); + test->add( BOOST_TEST_CASE( &boost_range_test_algorithm_min_element::test_min_element ) ); return test; } diff --git a/test/algorithm_test/partition.cpp b/test/algorithm_test/partition.cpp index 0160dae..22aefd6 100644 --- a/test/algorithm_test/partition.cpp +++ b/test/algorithm_test/partition.cpp @@ -21,109 +21,106 @@ #include #include -namespace boost +namespace boost_range_test_algorithm_partition { - namespace + struct equal_to_5 { - struct equal_to_5 - { - typedef bool result_type; - typedef int argument_type; - bool operator()(int x) const { return x == 5; } - }; + typedef bool result_type; + typedef int argument_type; + bool operator()(int x) const { return x == 5; } + }; - // test the 'partition' algorithm - template - class partition_test_policy + // test the 'partition' algorithm + template + class partition_test_policy + { + public: + template< class Container > + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + test_iter(Container& cont) { - public: - template< class Container > - BOOST_DEDUCED_TYPENAME range_iterator::type - test_iter(Container& cont) + typedef BOOST_DEDUCED_TYPENAME boost::range_iterator::type iter_t; + + const Container old_cont(cont); + Container cont2(old_cont); + iter_t result = boost::partition(cont, UnaryPredicate()); + + boost::partition(cont2, UnaryPredicate()); + cont2 = old_cont; + boost::partition( + boost::make_iterator_range(cont2), UnaryPredicate()); + + BOOST_CHECK_EQUAL_COLLECTIONS( cont.begin(), cont.end(), + cont2.begin(), cont2.end() ); + + return result; + } + + UnaryPredicate pred() const { return UnaryPredicate(); } + + template< boost::range_return_value return_type > + struct test_range + { + template< class Container, class Policy > + BOOST_DEDUCED_TYPENAME boost::range_return::type + operator()(Policy& policy, Container& cont) { - typedef BOOST_DEDUCED_TYPENAME range_iterator::type iter_t; + typedef BOOST_DEDUCED_TYPENAME boost::range_return::type result_t; const Container old_cont(cont); Container cont2(old_cont); - iter_t result = boost::partition(cont, UnaryPredicate()); + result_t result = boost::partition(cont, policy.pred()); - boost::partition(cont2, UnaryPredicate()); - cont2 = old_cont; - boost::partition( - boost::make_iterator_range(cont2), UnaryPredicate()); + // Test that operation a temporary created by using + // make_iterator_range. + boost::partition( + boost::make_iterator_range(cont2), policy.pred()); BOOST_CHECK_EQUAL_COLLECTIONS( cont.begin(), cont.end(), cont2.begin(), cont2.end() ); return result; } - - UnaryPredicate pred() const { return UnaryPredicate(); } - - template< range_return_value return_type > - struct test_range - { - template< class Container, class Policy > - BOOST_DEDUCED_TYPENAME range_return::type - operator()(Policy& policy, Container& cont) - { - typedef BOOST_DEDUCED_TYPENAME range_return::type result_t; - - const Container old_cont(cont); - Container cont2(old_cont); - result_t result = boost::partition(cont, policy.pred()); - - // Test that operation a temporary created by using - // make_iterator_range. - boost::partition( - 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 range_iterator::type - reference(Container& cont) - { - return std::partition(cont.begin(), cont.end(), UnaryPredicate()); - } }; - template - void test_partition_impl() + template< class Container > + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + reference(Container& cont) { - using namespace boost::assign; - - range_test::range_return_test_driver test_driver; - - partition_test_policy< equal_to_5 > policy; - - Container cont; - test_driver(cont, policy); - - cont.clear(); - cont += 1; - test_driver(cont, policy); - - cont.clear(); - cont += 1,2,2,2,2,2,3,4,5,6,7,8,9; - test_driver(cont, policy); - - cont.clear(); - cont += 1,2,2,2,2,2,3,3,3,3,4,4,4,4,4,4,4,5,6,7,8,9; - test_driver(cont, policy); + return std::partition(cont.begin(), cont.end(), UnaryPredicate()); } + }; - void test_partition() - { - test_partition_impl< std::vector >(); - test_partition_impl< std::list >(); - test_partition_impl< std::deque >(); - } + template + void test_partition_impl() + { + using namespace boost::assign; + + boost::range_test::range_return_test_driver test_driver; + + partition_test_policy< equal_to_5 > policy; + + Container cont; + test_driver(cont, policy); + + cont.clear(); + cont += 1; + test_driver(cont, policy); + + cont.clear(); + cont += 1,2,2,2,2,2,3,4,5,6,7,8,9; + test_driver(cont, policy); + + cont.clear(); + cont += 1,2,2,2,2,2,3,3,3,3,4,4,4,4,4,4,4,5,6,7,8,9; + test_driver(cont, policy); + } + + void test_partition() + { + test_partition_impl< std::vector >(); + test_partition_impl< std::list >(); + test_partition_impl< std::deque >(); } } @@ -133,7 +130,7 @@ init_unit_test_suite(int argc, char* argv[]) boost::unit_test::test_suite* test = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.partition" ); - test->add( BOOST_TEST_CASE( &boost::test_partition ) ); + test->add( BOOST_TEST_CASE( &boost_range_test_algorithm_partition::test_partition ) ); return test; } diff --git a/test/algorithm_test/stable_partition.cpp b/test/algorithm_test/stable_partition.cpp index 5f55b7d..3bf20e2 100644 --- a/test/algorithm_test/stable_partition.cpp +++ b/test/algorithm_test/stable_partition.cpp @@ -21,116 +21,112 @@ #include #include -namespace boost +namespace boost_range_test_algorithm_stable_partition { - namespace + struct equal_to_5 { - struct equal_to_5 - { - typedef bool result_type; - typedef int argument_type; - bool operator()(int x) const { return x == 5; } - }; + typedef bool result_type; + typedef int argument_type; + bool operator()(int x) const { return x == 5; } + }; - // test the 'partition' algorithm - template - class stable_partition_test_policy + // test the 'partition' algorithm + template + class stable_partition_test_policy + { + public: + template< class Container > + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + test_iter(Container& cont) { - public: - template< class Container > - BOOST_DEDUCED_TYPENAME range_iterator::type - test_iter(Container& cont) + Container cont2(cont); + + typedef BOOST_DEDUCED_TYPENAME boost::range_iterator::type iter_t; + iter_t result = boost::stable_partition(cont, UnaryPredicate()); + + iter_t temp_result = boost::stable_partition( + boost::make_iterator_range(cont2), UnaryPredicate()); + + BOOST_CHECK_EQUAL( std::distance(cont.begin(), result), + std::distance(cont2.begin(), temp_result) ); + + BOOST_CHECK_EQUAL_COLLECTIONS( cont.begin(), cont.end(), + cont2.begin(), cont2.end() ); + + return result; + } + + UnaryPredicate pred() const { return UnaryPredicate(); } + + template< boost::range_return_value return_type > + struct test_range + { + template< class Container, 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); - - typedef BOOST_DEDUCED_TYPENAME range_iterator::type iter_t; - iter_t result = boost::stable_partition(cont, UnaryPredicate()); - - iter_t temp_result = boost::stable_partition( - boost::make_iterator_range(cont2), UnaryPredicate()); - - BOOST_CHECK_EQUAL( std::distance(cont.begin(), result), - std::distance(cont2.begin(), temp_result) ); - - BOOST_CHECK_EQUAL_COLLECTIONS( cont.begin(), cont.end(), - cont2.begin(), cont2.end() ); - + result_t result = boost::stable_partition(cont, policy.pred()); + + result_t result2 = boost::stable_partition( + boost::make_iterator_range(cont2), policy.pred()); + + BOOST_CHECK_EQUAL_COLLECTIONS( cont2.begin(), cont2.end(), + cont.begin(), cont.end() ); + return result; } - - UnaryPredicate pred() const { return UnaryPredicate(); } - - template< range_return_value return_type > - struct test_range - { - template< class Container, class Policy > - BOOST_DEDUCED_TYPENAME range_return::type - operator()(Policy& policy, Container& cont) - { - typedef BOOST_DEDUCED_TYPENAME range_return::type result_t; - Container cont2(cont); - result_t result = boost::stable_partition(cont, policy.pred()); - - result_t result2 = boost::stable_partition( - boost::make_iterator_range(cont2), policy.pred()); - - BOOST_CHECK_EQUAL_COLLECTIONS( cont2.begin(), cont2.end(), - cont.begin(), cont.end() ); - - return result; - } - }; - - template< class Container > - BOOST_DEDUCED_TYPENAME range_iterator::type - reference(Container& cont) - { - return std::stable_partition(cont.begin(), cont.end(), UnaryPredicate()); - } }; - template - void test_stable_partition_impl() + template< class Container > + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + reference(Container& cont) { - using namespace boost::assign; - - range_test::range_return_test_driver test_driver; - - stable_partition_test_policy< equal_to_5 > policy; - - Container cont; - test_driver(cont, policy); - - cont.clear(); - cont += 1; - test_driver(cont, policy); - - cont.clear(); - cont += 1,2,2,2,2,2,3,4,5,6,7,8,9; - test_driver(cont, policy); - - cont.clear(); - cont += 1,2,2,2,2,2,3,3,3,3,4,4,4,4,4,4,4,5,6,7,8,9; - test_driver(cont, policy); + return std::stable_partition(cont.begin(), cont.end(), UnaryPredicate()); } + }; - void test_stable_partition() - { - test_stable_partition_impl< std::vector >(); - test_stable_partition_impl< std::list >(); - test_stable_partition_impl< std::deque >(); - } + template + void test_stable_partition_impl() + { + using namespace boost::assign; + + boost::range_test::range_return_test_driver test_driver; + + stable_partition_test_policy< equal_to_5 > policy; + + Container cont; + test_driver(cont, policy); + + cont.clear(); + cont += 1; + test_driver(cont, policy); + + cont.clear(); + cont += 1,2,2,2,2,2,3,4,5,6,7,8,9; + test_driver(cont, policy); + + cont.clear(); + cont += 1,2,2,2,2,2,3,3,3,3,4,4,4,4,4,4,4,5,6,7,8,9; + test_driver(cont, policy); + } + + void test_stable_partition() + { + test_stable_partition_impl< std::vector >(); + test_stable_partition_impl< std::list >(); + test_stable_partition_impl< std::deque >(); } } - boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) { boost::unit_test::test_suite* test = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.stable_partition" ); - test->add( BOOST_TEST_CASE( &boost::test_stable_partition ) ); + test->add( BOOST_TEST_CASE( &boost_range_test_algorithm_stable_partition::test_stable_partition ) ); return test; } diff --git a/test/algorithm_test/unique.cpp b/test/algorithm_test/unique.cpp index 49af0e3..880c131 100644 --- a/test/algorithm_test/unique.cpp +++ b/test/algorithm_test/unique.cpp @@ -23,156 +23,153 @@ #include #include -namespace boost +namespace boost_range_test_algorithm_unique { - namespace + // test the 'unique' algorithm without a predicate + class unique_test_policy { - // test the 'unique' algorithm without a predicate - class unique_test_policy + public: + template< class Container > + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + test_iter(Container& cont) { - public: - template< class Container > - BOOST_DEDUCED_TYPENAME range_iterator::type - test_iter(Container& cont) - { - // There isn't an iterator return version of boost::unique, so just - // perform the standard algorithm - return std::unique(cont.begin(), cont.end()); - } + // There isn't an iterator return version of boost::unique, so just + // perform the standard algorithm + return std::unique(cont.begin(), cont.end()); + } - template< range_return_value return_type > - struct test_range + template< boost::range_return_value return_type > + struct test_range + { + template< class Container, class Policy > + BOOST_DEDUCED_TYPENAME boost::range_return::type + operator()(Policy&, Container& cont) { - template< class Container, class Policy > - BOOST_DEDUCED_TYPENAME range_return::type - operator()(Policy&, Container& cont) - { - typedef BOOST_DEDUCED_TYPENAME 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; - } - }; + typedef BOOST_DEDUCED_TYPENAME boost::range_return::type result_t; - template< class Container > - BOOST_DEDUCED_TYPENAME range_iterator::type - reference(Container& cont) - { - return std::unique(cont.begin(), cont.end()); + 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; } }; - // test the 'unique' algorithm with a predicate - template - class unique_pred_test_policy + template< class Container > + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + reference(Container& cont) { - public: - template< class Container > - BOOST_DEDUCED_TYPENAME range_iterator::type - test_iter(Container& cont) - { - // There isn't an iterator return version of boost::unique, so just - // perform the standard algorithm - return std::unique(cont.begin(), cont.end(), Pred()); - } + return std::unique(cont.begin(), cont.end()); + } + }; - Pred pred() const { return Pred(); } + // test the 'unique' algorithm with a predicate + template + class unique_pred_test_policy + { + public: + template< class Container > + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + test_iter(Container& cont) + { + // There isn't an iterator return version of boost::unique, so just + // perform the standard algorithm + return std::unique(cont.begin(), cont.end(), Pred()); + } - template< range_return_value return_type > - struct test_range - { - template< class Container, class Policy > - BOOST_DEDUCED_TYPENAME range_return::type - operator()(Policy& policy, Container& cont) - { - typedef BOOST_DEDUCED_TYPENAME 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; - } - }; + Pred pred() const { return Pred(); } - template< class Container > - BOOST_DEDUCED_TYPENAME range_iterator::type - reference(Container& cont) + template< boost::range_return_value return_type > + struct test_range + { + template< class Container, class Policy > + BOOST_DEDUCED_TYPENAME boost::range_return::type + operator()(Policy& policy, Container& cont) { - return std::unique(cont.begin(), cont.end(), Pred()); + 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 - void test_unique_impl(TestPolicy policy, Pred pred) + template< class Container > + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + reference(Container& cont) { - using namespace boost::assign; - - typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t; - - range_test::range_return_test_driver test_driver; - - Container cont; - - test_driver(cont, policy); - - cont.clear(); - cont += 1; - - std::vector temp(cont.begin(), cont.end()); - std::sort(temp.begin(), temp.end(), pred); - cont.assign(temp.begin(), temp.end()); - - test_driver(cont, policy); - - cont.clear(); - cont += 1,2,2,2,2,3,4,5,6,7,8,9; - - temp.assign(cont.begin(), cont.end()); - std::sort(temp.begin(), temp.end(), pred); - cont.assign(temp.begin(), temp.end()); - - test_driver(cont, policy); + return std::unique(cont.begin(), cont.end(), Pred()); } + }; - template - void test_unique_impl() - { - test_unique_impl( - unique_test_policy(), - std::less() - ); + template + void test_unique_impl(TestPolicy policy, Pred pred) + { + using namespace boost::assign; - test_unique_impl( - unique_pred_test_policy >(), - std::less() - ); - - test_unique_impl( - unique_pred_test_policy >(), - std::greater() - ); - } + typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t; - void test_unique() - { - test_unique_impl< std::vector >(); - test_unique_impl< std::list >(); - test_unique_impl< std::deque >(); - } + boost::range_test::range_return_test_driver test_driver; + + Container cont; + + test_driver(cont, policy); + + cont.clear(); + cont += 1; + + std::vector temp(cont.begin(), cont.end()); + std::sort(temp.begin(), temp.end(), pred); + cont.assign(temp.begin(), temp.end()); + + test_driver(cont, policy); + + cont.clear(); + cont += 1,2,2,2,2,3,4,5,6,7,8,9; + + temp.assign(cont.begin(), cont.end()); + std::sort(temp.begin(), temp.end(), pred); + cont.assign(temp.begin(), temp.end()); + + test_driver(cont, policy); + } + + template + void test_unique_impl() + { + test_unique_impl( + unique_test_policy(), + std::less() + ); + + test_unique_impl( + unique_pred_test_policy >(), + std::less() + ); + + test_unique_impl( + unique_pred_test_policy >(), + std::greater() + ); + } + + void test_unique() + { + test_unique_impl< std::vector >(); + test_unique_impl< std::list >(); + test_unique_impl< std::deque >(); } } @@ -182,7 +179,7 @@ init_unit_test_suite(int argc, char* argv[]) boost::unit_test::test_suite* test = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.unique" ); - test->add( BOOST_TEST_CASE( &boost::test_unique ) ); + test->add( BOOST_TEST_CASE( &boost_range_test_algorithm_unique::test_unique ) ); return test; } diff --git a/test/algorithm_test/upper_bound.cpp b/test/algorithm_test/upper_bound.cpp index 95e3965..daae764 100644 --- a/test/algorithm_test/upper_bound.cpp +++ b/test/algorithm_test/upper_bound.cpp @@ -21,144 +21,141 @@ #include #include -namespace boost +namespace boost_range_test_algorithm_upper_bound { - namespace + class upper_bound_policy { - class upper_bound_policy + public: + template< class Container > + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + test_iter(Container& cont) { - public: - template< class Container > - BOOST_DEDUCED_TYPENAME range_iterator::type - test_iter(Container& cont) - { - typedef BOOST_DEDUCED_TYPENAME range_iterator::type iter_t; - iter_t result = boost::upper_bound(cont, 5); - BOOST_CHECK( result == boost::upper_bound(boost::make_iterator_range(cont), 5) ); - return result; - } - - template - struct test_range - { - template - BOOST_DEDUCED_TYPENAME range_return::type - operator()(Policy&, Container& cont) - { - typedef BOOST_DEDUCED_TYPENAME range_return::type result_t; - result_t result = boost::upper_bound(cont, 5); - BOOST_CHECK( result == boost::upper_bound(boost::make_iterator_range(cont), 5) ); - return result; - } - }; - - template< class Container > - BOOST_DEDUCED_TYPENAME range_iterator::type - reference(Container& cont) - { - return std::upper_bound(cont.begin(), cont.end(), 5); - } - }; - - template< class BinaryPredicate > - struct upper_bound_pred_policy - { - template< class Container > - BOOST_DEDUCED_TYPENAME range_iterator::type - test_iter(Container& cont) - { - typedef BOOST_DEDUCED_TYPENAME range_iterator::type iter_t; - iter_t result = boost::upper_bound(cont, 5, BinaryPredicate()); - BOOST_CHECK( result == boost::upper_bound(boost::make_iterator_range(cont), 5, BinaryPredicate()) ); - return result; - } - - template< range_return_value result_type> - struct test_range - { - template< class Container, class Policy > - BOOST_DEDUCED_TYPENAME range_return::type - operator()(Policy& policy, Container& cont) - { - typedef BOOST_DEDUCED_TYPENAME range_return::type result_t; - - result_t result = boost::upper_bound(cont, 5, policy.pred()); - - BOOST_CHECK( result == boost::upper_bound( - boost::make_iterator_range(cont), 5, policy.pred()) ); - - return result; - } - }; - - template - BOOST_DEDUCED_TYPENAME range_iterator::type - reference(Container& cont) - { - return std::upper_bound( - cont.begin(), cont.end(), 5, BinaryPredicate()); - } - - BinaryPredicate& pred() { return m_pred; } - - private: - BinaryPredicate m_pred; - }; - - template - void test_upper_bound_impl(TestPolicy policy, BinaryPredicate pred) - { - using namespace boost::assign; - - typedef BOOST_DEDUCED_TYPENAME remove_const::type container_t; - typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t; - - range_test::range_return_test_driver test_driver; - - container_t mcont; - Container& cont = mcont; - - test_driver(cont, policy); - - mcont.clear(); - mcont += 1; - - std::vector temp(mcont.begin(), mcont.end()); - std::sort(temp.begin(), temp.end(), pred); - mcont.assign(temp.begin(), temp.end()); - - test_driver(cont, policy); - - mcont.clear(); - mcont += 1,2,3,4,5,6,7,8,9; - - temp.assign(mcont.begin(), mcont.end()); - std::sort(temp.begin(), temp.end(), pred); - mcont.assign(temp.begin(), temp.end()); - - test_driver(cont, policy); + typedef BOOST_DEDUCED_TYPENAME boost::range_iterator::type iter_t; + iter_t result = boost::upper_bound(cont, 5); + BOOST_CHECK( result == boost::upper_bound(boost::make_iterator_range(cont), 5) ); + return result; } + template + struct test_range + { + template + BOOST_DEDUCED_TYPENAME boost::range_return::type + operator()(Policy&, Container& cont) + { + typedef BOOST_DEDUCED_TYPENAME boost::range_return::type result_t; + result_t result = boost::upper_bound(cont, 5); + BOOST_CHECK( result == boost::upper_bound(boost::make_iterator_range(cont), 5) ); + return result; + } + }; + + template< class Container > + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + reference(Container& cont) + { + return std::upper_bound(cont.begin(), cont.end(), 5); + } + }; + + template< class BinaryPredicate > + struct upper_bound_pred_policy + { + template< class Container > + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + test_iter(Container& cont) + { + typedef BOOST_DEDUCED_TYPENAME boost::range_iterator::type iter_t; + iter_t result = boost::upper_bound(cont, 5, BinaryPredicate()); + BOOST_CHECK( result == boost::upper_bound(boost::make_iterator_range(cont), 5, BinaryPredicate()) ); + return result; + } + + template< boost::range_return_value result_type> + struct test_range + { + template< class Container, class Policy > + BOOST_DEDUCED_TYPENAME boost::range_return::type + operator()(Policy& policy, Container& cont) + { + typedef BOOST_DEDUCED_TYPENAME boost::range_return::type result_t; + + result_t result = boost::upper_bound(cont, 5, policy.pred()); + + BOOST_CHECK( result == boost::upper_bound( + boost::make_iterator_range(cont), 5, policy.pred()) ); + + return result; + } + }; + template - void test_upper_bound_impl() + BOOST_DEDUCED_TYPENAME boost::range_iterator::type + reference(Container& cont) { - test_upper_bound_impl( - upper_bound_policy(), - std::less() - ); - - test_upper_bound_impl( - upper_bound_pred_policy >(), - std::less() - ); - - test_upper_bound_impl( - upper_bound_pred_policy >(), - std::greater() - ); + return std::upper_bound( + cont.begin(), cont.end(), 5, BinaryPredicate()); } + + BinaryPredicate& pred() { return m_pred; } + + private: + BinaryPredicate m_pred; + }; + + template + void test_upper_bound_impl(TestPolicy policy, BinaryPredicate pred) + { + using namespace boost::assign; + + typedef BOOST_DEDUCED_TYPENAME boost::remove_const::type container_t; + typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t; + + boost::range_test::range_return_test_driver test_driver; + + container_t mcont; + Container& cont = mcont; + + test_driver(cont, policy); + + mcont.clear(); + mcont += 1; + + std::vector temp(mcont.begin(), mcont.end()); + std::sort(temp.begin(), temp.end(), pred); + mcont.assign(temp.begin(), temp.end()); + + test_driver(cont, policy); + + mcont.clear(); + mcont += 1,2,3,4,5,6,7,8,9; + + temp.assign(mcont.begin(), mcont.end()); + std::sort(temp.begin(), temp.end(), pred); + mcont.assign(temp.begin(), temp.end()); + + test_driver(cont, policy); + } + + template + void test_upper_bound_impl() + { + test_upper_bound_impl( + upper_bound_policy(), + std::less() + ); + + test_upper_bound_impl( + upper_bound_pred_policy >(), + std::less() + ); + + test_upper_bound_impl( + upper_bound_pred_policy >(), + std::greater() + ); } void test_upper_bound() @@ -179,7 +176,7 @@ init_unit_test_suite(int argc, char* argv[]) boost::unit_test::test_suite* test = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.upper_bound" ); - test->add( BOOST_TEST_CASE( &boost::test_upper_bound ) ); + test->add( BOOST_TEST_CASE( &boost_range_test_algorithm_upper_bound::test_upper_bound ) ); return test; }