Replace boost::next with a simpler version

Less optimized, but hopefully it won't cause any warnings.
This commit is contained in:
Daniel James
2016-10-11 13:36:41 +01:00
parent a316d3fa46
commit 74abdd6973
5 changed files with 47 additions and 35 deletions

View File

@ -8,7 +8,7 @@
#include "../helpers/random_values.hpp"
#include "../helpers/invariants.hpp"
#include "../helpers/strong.hpp"
#include <boost/utility.hpp>
#include "../helpers/helpers.hpp"
#include <cmath>
test::seed_t initialize_seed(747373);
@ -112,7 +112,7 @@ struct insert_test4 : public insert_test_base<T>
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<T>
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<T>
BOOST_DEDUCED_TYPENAME T::const_iterator pos = x.cbegin();
for(BOOST_DEDUCED_TYPENAME test::random_values<T>::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<T>
int count = 0;
for(BOOST_DEDUCED_TYPENAME test::random_values<T>::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<T>
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<T>
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.

View File

@ -38,6 +38,26 @@ namespace test
{
return get_key_impl<Container>::get_key(x);
}
// test::next
//
// Increments an iterator by 1 or a given value.
// Like boost::next, but simpler and slower.
template <typename Iterator>
Iterator next(Iterator it)
{
return ++it;
}
template <typename Iterator, typename IntType>
Iterator next(Iterator it, IntType x)
{
for(; x > 0; --x) {
++it;
}
return it;
}
}
#endif

View File

@ -13,10 +13,10 @@
#include "../helpers/test.hpp"
#include "../helpers/list.hpp"
#include "../helpers/invariants.hpp"
#include "../helpers/helpers.hpp"
#include <set>
#include <iostream>
#include <iterator>
#include <boost/next_prior.hpp>
#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 <class Container>
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);

View File

@ -9,7 +9,6 @@
#include "../helpers/postfix.hpp"
#include "../helpers/test.hpp"
#include <boost/next_prior.hpp>
#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<difference_type>(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<Container>(*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<difference_type>(start)),
boost::next(iterators.begin(),
static_cast<difference_type>(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<c_iterator>::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<difference_type>(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<Container>(*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;

View File

@ -9,7 +9,6 @@
#include "../helpers/postfix.hpp"
#include "../helpers/test.hpp"
#include <boost/next_prior.hpp>
#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);