Fixes Issue #25

This commit is contained in:
Ion Gaztañaga
2019-04-08 00:32:28 +02:00
parent 2d00bc5d74
commit bfdfca0b88
9 changed files with 267 additions and 130 deletions
+11
View File
@@ -66,8 +66,19 @@ bool test_random_shuffled(std::size_t const element_count, std::size_t const num
return true;
}
void instantiate_smalldiff_iterators()
{
typedef randit<int, short> short_rand_it_t;
boost::movelib::adaptive_merge(short_rand_it_t(), short_rand_it_t(), short_rand_it_t(), less_int());
typedef randit<int, signed char> schar_rand_it_t;
boost::movelib::adaptive_merge(schar_rand_it_t(), schar_rand_it_t(), schar_rand_it_t(), less_int());
}
int main()
{
instantiate_smalldiff_iterators();
const std::size_t NIter = 100;
test_random_shuffled<order_move_type>(10001, 3, NIter);
test_random_shuffled<order_move_type>(10001, 65, NIter);
+12 -1
View File
@@ -38,7 +38,7 @@ bool test_random_shuffled(std::size_t const element_count, std::size_t const num
std::srand(0);
for (std::size_t i = 0; i != num_iter; ++i)
for (std::size_t it = 0; it != num_iter; ++it)
{
::random_shuffle(elements.get(), elements.get() + element_count);
for(std::size_t i = 0; i < (num_keys ? num_keys : element_count); ++i){
@@ -59,8 +59,19 @@ bool test_random_shuffled(std::size_t const element_count, std::size_t const num
return true;
}
void instantiate_smalldiff_iterators()
{
typedef randit<int, short> short_rand_it_t;
boost::movelib::adaptive_sort(short_rand_it_t(), short_rand_it_t(), less_int());
typedef randit<int, signed char> schar_rand_it_t;
boost::movelib::adaptive_sort(schar_rand_it_t(), schar_rand_it_t(), less_int());
}
int main()
{
instantiate_smalldiff_iterators();
const std::size_t NIter = 100;
test_random_shuffled<order_move_type>(10001, 3, NIter);
test_random_shuffled<order_move_type>(10001, 65, NIter);
+103
View File
@@ -14,6 +14,7 @@
#include <boost/config.hpp>
#include <boost/move/core.hpp>
#include <boost/move/detail/iterator_traits.hpp>
#include <cstddef>
#include <cstdio>
@@ -169,4 +170,106 @@ inline bool is_buffer(T *elements, std::size_t element_count)
}
//size_type iterator
template <class T, class D>
class randit
{
public:
typedef std::random_access_iterator_tag iterator_category;
typedef T value_type;
typedef D difference_type;
typedef T* pointer;
typedef T& reference;
private:
T* m_ptr;
public:
explicit randit(T* ptr)
: m_ptr(ptr)
{}
public:
//Constructors
randit()
: m_ptr() //Value initialization to achieve "null iterators" (N3644)
{}
randit(const randit& other)
: m_ptr(other.m_ptr)
{}
randit & operator=(const randit& other)
{ m_ptr = other.m_ptr; return *this; }
//T* like operators
reference operator*() const
{ return *m_ptr; }
pointer operator->() const
{ return m_ptr; }
reference operator[](difference_type off) const
{ return m_ptr[off]; }
//Increment / Decrement
randit& operator++()
{ ++m_ptr; return *this; }
randit operator++(int)
{ return randit(m_ptr++); }
randit& operator--()
{ --m_ptr; return *this; }
randit operator--(int)
{ return randit(m_ptr--); }
//Arithmetic
randit& operator+=(difference_type off)
{ m_ptr += off; return *this; }
randit& operator-=(difference_type off)
{ m_ptr -= off; return *this; }
friend randit operator+(const randit &x, difference_type off)
{ return randit(x.m_ptr+off); }
friend randit operator+(difference_type off, randit right)
{ right.m_ptr += off; return right; }
friend randit operator-(randit left, difference_type off)
{ left.m_ptr -= off; return left; }
friend difference_type operator-(const randit &left, const randit& right)
{ return difference_type(left.m_ptr - right.m_ptr); }
//Comparison operators
friend bool operator== (const randit& l, const randit& r)
{ return l.m_ptr == r.m_ptr; }
friend bool operator!= (const randit& l, const randit& r)
{ return l.m_ptr != r.m_ptr; }
friend bool operator< (const randit& l, const randit& r)
{ return l.m_ptr < r.m_ptr; }
friend bool operator<= (const randit& l, const randit& r)
{ return l.m_ptr <= r.m_ptr; }
friend bool operator> (const randit& l, const randit& r)
{ return l.m_ptr > r.m_ptr; }
friend bool operator>= (const randit& l, const randit& r)
{ return l.m_ptr >= r.m_ptr; }
};
struct less_int
{
bool operator()(int l, int r)
{ return l < r; }
};
#endif //BOOST_MOVE_TEST_ORDER_TYPE_HPP