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
32 order_perf_type(const order_perf_type& other)
33 : key(other.key), val(other.val)
39 order_perf_type & operator=(const order_perf_type& other)
52 static void reset_stats()
58 friend bool operator< (const order_perf_type& left, const order_perf_type& right)
59 { ++num_compare; return left.key < right.key; }
61 static boost::ulong_long_type num_compare;
62 static boost::ulong_long_type num_copy;
63 static boost::ulong_long_type num_elements;
66 boost::ulong_long_type order_perf_type::num_compare = 0;
67 boost::ulong_long_type order_perf_type::num_copy = 0;
68 boost::ulong_long_type order_perf_type::num_elements = 0;
71 struct order_move_type
73 BOOST_MOVABLE_BUT_NOT_COPYABLE(order_move_type)
79 static const std::size_t moved_constr_mark = std::size_t(-1);
80 static const std::size_t moved_assign_mark = std::size_t(-2);
86 order_move_type(BOOST_RV_REF(order_move_type) other)
87 : key(other.key), val(other.val)
89 other.key = other.val = std::size_t(-1);
92 order_move_type & operator=(BOOST_RV_REF(order_move_type) other)
96 other.key = other.val = std::size_t(-2);
100 friend bool operator< (const order_move_type& left, const order_move_type& right)
101 { return left.key < right.key; }
105 key = val = std::size_t(-3);
109 struct order_type_less
111 template<class T, class U>
112 bool operator()(const T &a, U const &b) const
117 inline bool is_order_type_ordered(T *elements, std::size_t element_count, bool stable = true)
119 for(std::size_t i = 1; i < element_count; ++i){
120 if(order_type_less()(elements[i], elements[i-1])){
121 std::printf("\n Ord KO !!!!");
124 if( stable && !(order_type_less()(elements[i-1], elements[i])) && (elements[i-1].val > elements[i].val) ){
125 std::printf("\n Stb KO !!!! ");
134 namespace detail_adaptive {
141 inline bool is_key(T *elements, std::size_t element_count)
143 for(std::size_t i = 1; i < element_count; ++i){
144 if(elements[i].key >= element_count){
145 std::printf("\n Key.key KO !!!!");
148 if(elements[i].val != std::size_t(-1)){
149 std::printf("\n Key.val KO !!!!");
157 inline bool is_buffer(T *elements, std::size_t element_count)
159 for(std::size_t i = 1; i < element_count; ++i){
160 if(elements[i].key != std::size_t(-1)){
161 std::printf("\n Buf.key KO !!!!");
164 if(elements[i].val >= element_count){
165 std::printf("\n Buf.val KO !!!!");
174 template <class T, class D>
178 typedef std::random_access_iterator_tag iterator_category;
179 typedef T value_type;
180 typedef D difference_type;
182 typedef T& reference;
188 explicit randit(T* ptr)
196 : m_ptr() //Value initialization to achieve "null iterators" (N3644)
199 randit(const randit& other)
203 randit & operator=(const randit& other)
204 { m_ptr = other.m_ptr; return *this; }
207 reference operator*() const
210 pointer operator->() const
213 reference operator[](difference_type off) const
214 { return m_ptr[off]; }
216 //Increment / Decrement
218 { ++m_ptr; return *this; }
220 randit operator++(int)
221 { return randit(m_ptr++); }
224 { --m_ptr; return *this; }
226 randit operator--(int)
227 { return randit(m_ptr--); }
230 randit& operator+=(difference_type off)
231 { m_ptr += off; return *this; }
233 randit& operator-=(difference_type off)
234 { m_ptr -= off; return *this; }
236 friend randit operator+(const randit &x, difference_type off)
237 { return randit(x.m_ptr+off); }
239 friend randit operator+(difference_type off, randit right)
240 { right.m_ptr += off; return right; }
242 friend randit operator-(randit left, difference_type off)
243 { left.m_ptr -= off; return left; }
245 friend difference_type operator-(const randit &left, const randit& right)
246 { return difference_type(left.m_ptr - right.m_ptr); }
248 //Comparison operators
249 friend bool operator== (const randit& l, const randit& r)
250 { return l.m_ptr == r.m_ptr; }
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; }
270 bool operator()(int l, int r)
275 #endif //BOOST_MOVE_TEST_ORDER_TYPE_HPP