From 74abdd6973367255e7eccf2804705d840ddbda02 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Tue, 11 Oct 2016 13:36:41 +0100 Subject: [PATCH] Replace boost::next with a simpler version Less optimized, but hopefully it won't cause any warnings. --- test/exception/insert_exception_tests.cpp | 18 +++++++++------- test/helpers/helpers.hpp | 20 +++++++++++++++++ test/unordered/erase_equiv_tests.cpp | 15 ++++++------- test/unordered/erase_tests.cpp | 26 +++++++++-------------- test/unordered/insert_tests.cpp | 3 +-- 5 files changed, 47 insertions(+), 35 deletions(-) diff --git a/test/exception/insert_exception_tests.cpp b/test/exception/insert_exception_tests.cpp index c2e2999a..588a6713 100644 --- a/test/exception/insert_exception_tests.cpp +++ b/test/exception/insert_exception_tests.cpp @@ -8,7 +8,7 @@ #include "../helpers/random_values.hpp" #include "../helpers/invariants.hpp" #include "../helpers/strong.hpp" -#include +#include "../helpers/helpers.hpp" #include test::seed_t initialize_seed(747373); @@ -112,7 +112,7 @@ struct insert_test4 : public insert_test_base it != end; ++it) { strong.store(x, test::detail::tracker.count_allocations); - x.insert(it, boost::next(it)); + x.insert(it, test::next(it)); } } }; @@ -136,7 +136,7 @@ struct insert_test_rehash1 : public insert_test_base ceil((double) bucket_count * (double) x.max_load_factor()) - 1); BOOST_TEST(initial_elements < this->values.size()); x.insert(this->values.begin(), - this->values.begin() + initial_elements); + test::next(this->values.begin(), initial_elements)); BOOST_TEST(bucket_count == x.bucket_count()); return x; } @@ -147,7 +147,8 @@ struct insert_test_rehash1 : public insert_test_base BOOST_DEDUCED_TYPENAME T::const_iterator pos = x.cbegin(); for(BOOST_DEDUCED_TYPENAME test::random_values::const_iterator - it = this->values.begin() + x.size(), end = this->values.end(); + it = test::next(this->values.begin(), x.size()), + end = this->values.end(); it != end && count < 10; ++it, ++count) { strong.store(x, test::detail::tracker.count_allocations); @@ -170,7 +171,7 @@ struct insert_test_rehash2 : public insert_test_rehash1 int count = 0; for(BOOST_DEDUCED_TYPENAME test::random_values::const_iterator - it = this->values.begin(), x.size()), + it = test::next(this->values.begin(), x.size()), end = this->values.end(); it != end && count < 10; ++it, ++count) { @@ -207,7 +208,8 @@ struct insert_test_rehash3 : public insert_test_base rehash_bucket_count > 5 ? rehash_bucket_count - 5 : 1; BOOST_TEST(initial_elements < this->values.size()); - x.insert(this->values.begin(), this->values.begin() + initial_elements); + x.insert(this->values.begin(), + test::next(this->values.begin(), initial_elements)); BOOST_TEST(original_bucket_count == x.bucket_count()); return x; } @@ -215,8 +217,8 @@ struct insert_test_rehash3 : public insert_test_base void run(T& x) const { BOOST_DEDUCED_TYPENAME T::size_type bucket_count = x.bucket_count(); - x.insert(this->values.begin() + x.size(), - this->values.begin() + x.size() + 20); + x.insert(test::next(this->values.begin(), x.size()), + test::next(this->values.begin(), x.size() + 20)); // This isn't actually a failure, but it means the test isn't doing its // job. diff --git a/test/helpers/helpers.hpp b/test/helpers/helpers.hpp index 2293f23f..96e90cdc 100644 --- a/test/helpers/helpers.hpp +++ b/test/helpers/helpers.hpp @@ -38,6 +38,26 @@ namespace test { return get_key_impl::get_key(x); } + + // test::next + // + // Increments an iterator by 1 or a given value. + // Like boost::next, but simpler and slower. + + template + Iterator next(Iterator it) + { + return ++it; + } + + template + Iterator next(Iterator it, IntType x) + { + for(; x > 0; --x) { + ++it; + } + return it; + } } #endif diff --git a/test/unordered/erase_equiv_tests.cpp b/test/unordered/erase_equiv_tests.cpp index 98da1e6d..b55bc202 100644 --- a/test/unordered/erase_equiv_tests.cpp +++ b/test/unordered/erase_equiv_tests.cpp @@ -13,10 +13,10 @@ #include "../helpers/test.hpp" #include "../helpers/list.hpp" #include "../helpers/invariants.hpp" +#include "../helpers/helpers.hpp" #include #include #include -#include #include "../objects/test.hpp" #if BOOST_WORKAROUND(BOOST_MSVC, < 1400) @@ -111,8 +111,8 @@ UNORDERED_AUTO_TEST(two_equivalent_item_tests) { collide_map x(init.begin(), init.end()); - int value = boost::next(x.begin())->second; - x.erase(x.begin(), boost::next(x.begin())); + int value = test::next(x.begin())->second; + x.erase(x.begin(), test::next(x.begin())); BOOST_TEST(x.count(1) == 1 && x.size() == 1 && x.begin()->first == 1 && x.begin()->second == value); test::check_equivalent_keys(x); @@ -121,7 +121,7 @@ UNORDERED_AUTO_TEST(two_equivalent_item_tests) { collide_map x(init.begin(), init.end()); int value = x.begin()->second; - x.erase(boost::next(x.begin()), x.end()); + x.erase(test::next(x.begin()), x.end()); BOOST_TEST(x.count(1) == 1 && x.size() == 1 && x.begin()->first == 1 && x.begin()->second == value); test::check_equivalent_keys(x); @@ -143,13 +143,10 @@ bool compare(Range1 const& x, Range2 const& y) template bool general_erase_range_test(Container& x, std::size_t start, std::size_t end) { - typedef BOOST_DEDUCED_TYPENAME Container::difference_type difference_type; - difference_type start2 = start, end2 = end; - collide_list l(x.begin(), x.end()); - l.erase(boost::next(l.begin(), start2), boost::next(l.begin(), end2)); - x.erase(boost::next(x.begin(), start2), boost::next(x.begin(), end2)); + l.erase(test::next(l.begin(), start), test::next(l.begin(), end)); + x.erase(test::next(x.begin(), start), test::next(x.begin(), end)); test::check_equivalent_keys(x); return compare(l, x); diff --git a/test/unordered/erase_tests.cpp b/test/unordered/erase_tests.cpp index 5d986a7f..34d7ec9e 100644 --- a/test/unordered/erase_tests.cpp +++ b/test/unordered/erase_tests.cpp @@ -9,7 +9,6 @@ #include "../helpers/postfix.hpp" #include "../helpers/test.hpp" -#include #include "../objects/test.hpp" #include "../helpers/random_values.hpp" #include "../helpers/tracker.hpp" @@ -30,7 +29,6 @@ void erase_tests1(Container*, test::random_generator generator) { typedef BOOST_DEDUCED_TYPENAME Container::iterator iterator; typedef BOOST_DEDUCED_TYPENAME Container::const_iterator c_iterator; - typedef BOOST_DEDUCED_TYPENAME Container::difference_type difference_type; std::cerr<<"Erase by key.\n"; { @@ -91,11 +89,10 @@ void erase_tests1(Container*, test::random_generator generator) prev = pos = x.begin(); } else { - prev = boost::next(x.begin(), - static_cast(index - 1)); - pos = boost::next(prev); + prev = test::next(x.begin(), index - 1); + pos = test::next(prev); } - next = boost::next(pos); + next = test::next(pos); BOOST_DEDUCED_TYPENAME Container::key_type key = test::get_key(*pos); std::size_t count = x.count(key); @@ -104,7 +101,7 @@ void erase_tests1(Container*, test::random_generator generator) --size; if(size > 0) BOOST_TEST(index == 0 ? next == x.begin() : - next == boost::next(prev)); + next == test::next(prev)); BOOST_TEST(x.count(key) == count - 1); if (x.count(key) != count - 1) { std::cerr << count << " => " << x.count(key) << std::endl; @@ -163,10 +160,8 @@ void erase_tests1(Container*, test::random_generator generator) std::size_t length = test::random_value(iterators.size() - start); x.erase(iterators[start], iterators[start + length]); iterators.erase( - boost::next(iterators.begin(), - static_cast(start)), - boost::next(iterators.begin(), - static_cast(start + length))); + test::next(iterators.begin(), start), + test::next(iterators.begin(), start + length)); BOOST_TEST(x.size() == iterators.size() - 1); BOOST_DEDUCED_TYPENAME std::vector::const_iterator @@ -221,11 +216,10 @@ void erase_tests1(Container*, test::random_generator generator) prev = pos = x.begin(); } else { - prev = boost::next(x.begin(), - static_cast(index - 1)); - pos = boost::next(prev); + prev = test::next(x.begin(), index - 1); + pos = test::next(prev); } - next = boost::next(pos); + next = test::next(pos); BOOST_DEDUCED_TYPENAME Container::key_type key = test::get_key(*pos); std::size_t count = x.count(key); @@ -234,7 +228,7 @@ void erase_tests1(Container*, test::random_generator generator) --size; if(size > 0) BOOST_TEST(index == 0 ? next == x.begin() : - next == boost::next(prev)); + next == test::next(prev)); BOOST_TEST(x.count(key) == count - 1); if (x.count(key) != count - 1) { std::cerr << count << " => " << x.count(key) << std::endl; diff --git a/test/unordered/insert_tests.cpp b/test/unordered/insert_tests.cpp index 07b30932..3f13ea0f 100644 --- a/test/unordered/insert_tests.cpp +++ b/test/unordered/insert_tests.cpp @@ -9,7 +9,6 @@ #include "../helpers/postfix.hpp" #include "../helpers/test.hpp" -#include #include "../objects/test.hpp" #include "../helpers/random_values.hpp" #include "../helpers/tracker.hpp" @@ -208,7 +207,7 @@ void insert_tests2(X*, test::random_generator generator) old_bucket_count = x.bucket_count(); float b = x.max_load_factor(); - x.insert(it, boost::next(it)); + x.insert(it, test::next(it)); tracker.insert(*it); tracker.compare_key(x, *it);