]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/serialization/test/A.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / serialization / test / A.cpp
CommitLineData
7c673cae
FG
1/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
2// A.cpp simple class test
3
4// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
5// Use, modification and distribution is subject to the Boost Software
6// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8
9// See http://www.boost.org for updates, documentation, and revision history.
10
11#include <cassert>
12#include <cstdlib> // rand()
13#include <cstddef> // size_t
14#include <boost/math/special_functions/next.hpp>
15
16#include <boost/config.hpp>
17#if defined(BOOST_NO_STDC_NAMESPACE)
18namespace std{
19 using ::rand;
20 using ::size_t;
21}
22#endif
23
24#include <boost/detail/workaround.hpp>
25#if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1)
26#include <boost/archive/dinkumware.hpp>
27#endif
28
29#include "A.hpp"
30
31template<class S>
32void randomize(S &x)
33{
34 assert(0 == x.size());
35 for(;;){
36 unsigned int i = std::rand() % 27;
37 if(0 == i)
38 break;
39 x += static_cast<typename S::value_type>('a' - 1 + i);
40 }
41}
42
43template<class T>
44void accumulate(std::size_t & s, const T & t){
45 const char * tptr = (const char *)(& t);
46 unsigned int count = sizeof(t);
47 while(count-- > 0){
48 s += *tptr++;
49 }
50}
b32b8144 51A_DLL_DECL
7c673cae
FG
52A::operator std::size_t () const {
53 std::size_t retval = 0;
54 accumulate(retval, b);
55 #ifndef BOOST_NO_INT64_T
56 accumulate(retval, f);
57 accumulate(retval, g);
58 #endif
59 accumulate(retval, l);
60 accumulate(retval, m);
61 accumulate(retval, n);
62 accumulate(retval, o);
63 accumulate(retval, p);
64 accumulate(retval, q);
65 #ifndef BOOST_NO_CWCHAR
66 accumulate(retval, r);
67 #endif
68 accumulate(retval, c);
69 accumulate(retval, s);
70 accumulate(retval, t);
71 accumulate(retval, u);
72 accumulate(retval, v);
73 return retval;
74}
75
76#if defined(_MSC_VER)
77#pragma warning(push) // Save warning settings.
78#pragma warning(disable : 4244) // Disable possible loss of data warning
b32b8144 79#endif
7c673cae 80
b32b8144 81A_DLL_DECL
7c673cae
FG
82A::A() :
83 b(true),
84 #ifndef BOOST_NO_INT64_T
85 f(std::rand() * std::rand()),
86 g(std::rand() * std::rand()),
87 #endif
88 l(static_cast<enum h>(std::rand() % 3)),
89 m(std::rand()),
90 n(std::rand()),
91 o(std::rand()),
92 p(std::rand()),
93 q(std::rand()),
94 #ifndef BOOST_NO_CWCHAR
95 r(std::rand()),
96 #endif
97 c(0xff & std::rand()),
98 s(0xff & std::rand()),
99 t(0xff & std::rand()),
100 u(std::rand()),
101 v(std::rand()),
102 w((float)std::rand()),
103 x((double)std::rand())
104{
105 randomize(y);
106 #ifndef BOOST_NO_STD_WSTRING
107 randomize(z);
108 #endif
109}
110
111#if defined(_MSC_VER)
112#pragma warning(pop) // Restore warnings to previous state.
113#endif
114
b32b8144
FG
115A_DLL_DECL bool
116A::operator==(const A &rhs) const {
7c673cae
FG
117 if(b != rhs.b)
118 return false;
119 if(l != rhs.l)
120 return false;
121 #ifndef BOOST_NO_INT64_T
122 if(f != rhs.f)
123 return false;
124 if(g != rhs.g)
125 return false;
126 #endif
127 if(m != rhs.m)
128 return false;
129 if(n != rhs.n)
130 return false;
131 if(o != rhs.o)
132 return false;
133 if(p != rhs.p)
134 return false;
135 if(q != rhs.q)
136 return false;
137 #ifndef BOOST_NO_CWCHAR
138 if(r != rhs.r)
139 return false;
140 #endif
141 if(c != rhs.c)
142 return false;
143 if(s != rhs.s)
144 return false;
145 if(t != rhs.t)
146 return false;
147 if(u != rhs.u)
148 return false;
149 if(v != rhs.v)
150 return false;
151 if(std::abs( boost::math::float_distance(w, rhs.w)) > 1)
152 return false;
153 if(std::abs( boost::math::float_distance(x, rhs.x)) > 1)
154 return false;
155 if(0 != y.compare(rhs.y))
156 return false;
157 #ifndef BOOST_NO_STD_WSTRING
158 if(0 != z.compare(rhs.z))
159 return false;
160 #endif
161 return true;
162}
163
b32b8144
FG
164A_DLL_DECL bool
165A::operator!=(const A &rhs) const {
7c673cae
FG
166 return ! (*this == rhs);
167}
168
b32b8144
FG
169A_DLL_DECL bool
170A::operator<(const A &rhs) const {
7c673cae
FG
171 if(b != rhs.b)
172 return b < rhs.b;
173 #ifndef BOOST_NO_INT64_T
174 if(f != rhs.f)
175 return f < rhs.f;
176 if(g != rhs.g)
177 return g < rhs.g;
178 #endif
179 if(l != rhs.l )
180 return l < rhs.l;
181 if(m != rhs.m )
182 return m < rhs.m;
183 if(n != rhs.n )
184 return n < rhs.n;
185 if(o != rhs.o )
186 return o < rhs.o;
187 if(p != rhs.p )
188 return p < rhs.p;
189 if(q != rhs.q )
190 return q < rhs.q;
191 #ifndef BOOST_NO_CWCHAR
192 if(r != rhs.r )
193 return r < rhs.r;
194 #endif
195 if(c != rhs.c )
196 return c < rhs.c;
197 if(s != rhs.s )
198 return s < rhs.s;
199 if(t != rhs.t )
200 return t < rhs.t;
201 if(u != rhs.u )
202 return u < rhs.u;
203 if(v != rhs.v )
204 return v < rhs.v;
205 if(w != rhs.w )
206 return w < rhs.w;
207 if(x != rhs.x )
208 return x < rhs.x;
209 int i = y.compare(rhs.y);
210 if(i != 0 )
211 return i < 0;
212 #ifndef BOOST_NO_STD_WSTRING
213 int j = z.compare(rhs.z);
214 if(j != 0 )
215 return j < 0;
216 #endif
217 return false;
218}