A.cpp 5.0 KB

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