]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/move/test/order_type.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / move / test / order_type.hpp
CommitLineData
7c673cae
FG
1//////////////////////////////////////////////////////////////////////////////
2//
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)
7//
8// See http://www.boost.org/libs/move for documentation.
9//
10//////////////////////////////////////////////////////////////////////////////
11
12#ifndef BOOST_MOVE_TEST_ORDER_TYPE_HPP
13#define BOOST_MOVE_TEST_ORDER_TYPE_HPP
14
15#include <boost/config.hpp>
b32b8144 16#include <boost/move/core.hpp>
7c673cae
FG
17#include <cstddef>
18#include <cstdio>
19
b32b8144 20struct order_perf_type
7c673cae
FG
21{
22 public:
23 std::size_t key;
24 std::size_t val;
25
b32b8144 26 order_perf_type()
7c673cae
FG
27 {
28 ++num_elements;
29 }
30
b32b8144 31 order_perf_type(const order_perf_type& other)
7c673cae
FG
32 : key(other.key), val(other.val)
33 {
34 ++num_elements;
35 ++num_copy;
36 }
37
b32b8144 38 order_perf_type & operator=(const order_perf_type& other)
7c673cae
FG
39 {
40 ++num_copy;
41 key = other.key;
42 val = other.val;
43 return *this;
44 }
45
b32b8144 46 ~order_perf_type ()
7c673cae
FG
47 {
48 --num_elements;
49 }
50
b32b8144
FG
51 static void reset_stats()
52 {
53 num_compare=0;
54 num_copy=0;
55 }
56
57 friend bool operator< (const order_perf_type& left, const order_perf_type& right)
58 { ++num_compare; return left.key < right.key; }
59
7c673cae
FG
60 static boost::ulong_long_type num_compare;
61 static boost::ulong_long_type num_copy;
62 static boost::ulong_long_type num_elements;
63};
64
b32b8144
FG
65boost::ulong_long_type order_perf_type::num_compare = 0;
66boost::ulong_long_type order_perf_type::num_copy = 0;
67boost::ulong_long_type order_perf_type::num_elements = 0;
68
69
70struct order_move_type
71{
72 BOOST_MOVABLE_BUT_NOT_COPYABLE(order_move_type)
73
74 public:
75 std::size_t key;
76 std::size_t val;
77
78 order_move_type()
79 : key(0u), val(0u)
80 {}
81
82 order_move_type(BOOST_RV_REF(order_move_type) other)
83 : key(other.key), val(other.val)
84 {
85 other.key = other.val = std::size_t(-1);
86 }
87
88 order_move_type & operator=(BOOST_RV_REF(order_move_type) other)
89 {
90 key = other.key;
91 val = other.val;
92 other.key = other.val = std::size_t(-2);
93 return *this;
94 }
95
96 friend bool operator< (const order_move_type& left, const order_move_type& right)
97 { return left.key < right.key; }
98
99 ~order_move_type ()
100 {
101 key = val = std::size_t(-3);
102 }
103};
7c673cae 104
7c673cae
FG
105struct order_type_less
106{
b32b8144
FG
107 template<class T>
108 bool operator()(const T &a, T const &b) const
109 { return a < b; }
7c673cae
FG
110};
111
112template<class T>
113inline bool is_order_type_ordered(T *elements, std::size_t element_count, bool stable = true)
114{
115 for(std::size_t i = 1; i < element_count; ++i){
b32b8144 116 if(order_type_less()(elements[i], elements[i-1])){
7c673cae
FG
117 std::printf("\n Ord KO !!!!");
118 return false;
119 }
b32b8144 120 if( stable && !(order_type_less()(elements[i-1], elements[i])) && (elements[i-1].val > elements[i].val) ){
7c673cae
FG
121 std::printf("\n Stb KO !!!! ");
122 return false;
123 }
124 }
125 return true;
126}
127
b32b8144
FG
128namespace boost {
129namespace movelib {
130namespace detail_adaptive {
131
132
133
134}}}
135
136template<class T>
137inline bool is_key(T *elements, std::size_t element_count)
138{
139 for(std::size_t i = 1; i < element_count; ++i){
140 if(elements[i].key >= element_count){
141 std::printf("\n Key.key KO !!!!");
142 return false;
143 }
144 if(elements[i].val != std::size_t(-1)){
145 std::printf("\n Key.val KO !!!!");
146 return false;
147 }
148 }
149 return true;
150}
151
152template<class T>
153inline bool is_buffer(T *elements, std::size_t element_count)
154{
155 for(std::size_t i = 1; i < element_count; ++i){
156 if(elements[i].key != std::size_t(-1)){
157 std::printf("\n Buf.key KO !!!!");
158 return false;
159 }
160 if(elements[i].val >= element_count){
161 std::printf("\n Buf.val KO !!!!");
162 return false;
163 }
164 }
165 return true;
166}
167
168
7c673cae 169#endif //BOOST_MOVE_TEST_ORDER_TYPE_HPP