1 //////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2015-2016.
4 // Distributed under the Boost Software License, Version 1.0.
5 // (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
8 // See http://www.boost.org/libs/move for documentation.
10 //////////////////////////////////////////////////////////////////////////////
12 #ifndef BOOST_MOVE_TEST_ORDER_TYPE_HPP
13 #define BOOST_MOVE_TEST_ORDER_TYPE_HPP
15 #include <boost/config.hpp>
16 #include <boost/move/core.hpp>
17 #include <boost/move/detail/iterator_traits.hpp>
21 struct order_perf_type
33 order_perf_type(const order_perf_type& other)
34 : key(other.key), val(other.val)
40 order_perf_type & operator=(const order_perf_type& other)
53 static void reset_stats()
59 friend bool operator< (const order_perf_type& left, const order_perf_type& right)
60 { ++num_compare; return left.key < right.key; }
62 static boost::ulong_long_type num_compare;
63 static boost::ulong_long_type num_copy;
64 static boost::ulong_long_type num_elements;
67 boost::ulong_long_type order_perf_type::num_compare = 0;
68 boost::ulong_long_type order_perf_type::num_copy = 0;
69 boost::ulong_long_type order_perf_type::num_elements = 0;
72 struct order_move_type
74 BOOST_MOVABLE_BUT_NOT_COPYABLE(order_move_type)
80 static const std::size_t moved_constr_mark = std::size_t(-1);
81 static const std::size_t moved_assign_mark = std::size_t(-2);
87 order_move_type(BOOST_RV_REF(order_move_type) other)
88 : key(other.key), val(other.val)
90 assert(this != &other);
91 other.key = other.val = std::size_t(-1);
94 order_move_type & operator=(BOOST_RV_REF(order_move_type) other)
96 assert(this != &other);
99 other.key = other.val = std::size_t(-2);
103 friend bool operator< (const order_move_type& left, const order_move_type& right)
104 { return left.key < right.key; }
108 key = val = std::size_t(-3);
112 struct order_type_less
114 template<class T, class U>
115 bool operator()(const T &a, U const &b) const
120 inline bool is_order_type_ordered(T *elements, std::size_t element_count, bool stable = true)
122 for(std::size_t i = 1; i < element_count; ++i){
123 if(order_type_less()(elements[i], elements[i-1])){
124 std::printf("\n Ord KO !!!!");
127 if( stable && !(order_type_less()(elements[i-1], elements[i])) && (elements[i-1].val > elements[i].val) ){
128 std::printf("\n Stb KO !!!! ");
137 namespace detail_adaptive {
144 inline bool is_key(T *elements, std::size_t element_count)
146 for(std::size_t i = 1; i < element_count; ++i){
147 if(elements[i].key >= element_count){
148 std::printf("\n Key.key KO !!!!");
151 if(elements[i].val != std::size_t(-1)){
152 std::printf("\n Key.val KO !!!!");
160 inline bool is_buffer(T *elements, std::size_t element_count)
162 for(std::size_t i = 1; i < element_count; ++i){
163 if(elements[i].key != std::size_t(-1)){
164 std::printf("\n Buf.key KO !!!!");
167 if(elements[i].val >= element_count){
168 std::printf("\n Buf.val KO !!!!");
177 template <class T, class D>
181 typedef std::random_access_iterator_tag iterator_category;
182 typedef T value_type;
183 typedef D difference_type;
185 typedef T& reference;
191 explicit randit(T* ptr)
199 : m_ptr() //Value initialization to achieve "null iterators" (N3644)
202 randit(const randit& other)
206 randit & operator=(const randit& other)
207 { m_ptr = other.m_ptr; return *this; }
210 reference operator*() const
213 pointer operator->() const
216 reference operator[](difference_type off) const
217 { return m_ptr[off]; }
219 //Increment / Decrement
221 { ++m_ptr; return *this; }
223 randit operator++(int)
224 { return randit(m_ptr++); }
227 { --m_ptr; return *this; }
229 randit operator--(int)
230 { return randit(m_ptr--); }
233 randit& operator+=(difference_type off)
234 { m_ptr += off; return *this; }
236 randit& operator-=(difference_type off)
237 { m_ptr -= off; return *this; }
239 friend randit operator+(const randit &x, difference_type off)
240 { return randit(x.m_ptr+off); }
242 friend randit operator+(difference_type off, randit right)
243 { right.m_ptr += off; return right; }
245 friend randit operator-(randit left, difference_type off)
246 { left.m_ptr -= off; return left; }
248 friend difference_type operator-(const randit &left, const randit& right)
249 { return difference_type(left.m_ptr - right.m_ptr); }
251 //Comparison operators
252 friend bool operator== (const randit& l, const randit& r)
253 { return l.m_ptr == r.m_ptr; }
255 friend bool operator!= (const randit& l, const randit& r)
256 { return l.m_ptr != r.m_ptr; }
258 friend bool operator< (const randit& l, const randit& r)
259 { return l.m_ptr < r.m_ptr; }
261 friend bool operator<= (const randit& l, const randit& r)
262 { return l.m_ptr <= r.m_ptr; }
264 friend bool operator> (const randit& l, const randit& r)
265 { return l.m_ptr > r.m_ptr; }
267 friend bool operator>= (const randit& l, const randit& r)
268 { return l.m_ptr >= r.m_ptr; }
273 bool operator()(int l, int r)
278 #endif //BOOST_MOVE_TEST_ORDER_TYPE_HPP