1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
|
/* concepts.hpp
*
* Copyright Steven Watanabe 2011
* Distributed under the Boost Software License, Version 1.0. (See
* accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* $Id$
*
*/
#ifndef BOOST_RANDOM_TEST_CONCEPTS_HPP
#define BOOST_RANDOM_TEST_CONCEPTS_HPP
#include <boost/config.hpp>
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable:4100)
#endif
#include <boost/concept_check.hpp>
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
#include <boost/random/detail/seed.hpp>
#include <boost/random/detail/seed_impl.hpp>
#include <boost/concept_archetype.hpp>
#include <boost/concept/requires.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/type_traits/is_arithmetic.hpp>
#include <boost/type_traits/is_integral.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/cstdint.hpp>
#include <boost/static_assert.hpp>
#include <istream>
#include <ostream>
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable:4510)
#pragma warning(disable:4610)
#endif
namespace boost {
namespace random {
namespace test {
template<class Base = null_archetype<> >
struct seed_seq_archetype : Base
{
template<class Iter>
BOOST_CONCEPT_REQUIRES(
((Mutable_RandomAccessIterator<Iter>))
((UnsignedInteger<typename Mutable_RandomAccessIterator<Iter>::value_type>)),
(void))
generate(Iter, Iter) {}
};
template<class R = unsigned, class Base = null_archetype<> >
struct uniform_random_number_generator_archetype : Base
{
typedef R result_type;
static R min BOOST_PREVENT_MACRO_SUBSTITUTION () { return 0; }
static R max BOOST_PREVENT_MACRO_SUBSTITUTION () { return 0; }
R operator()() { return 0; }
};
template<class SSeq>
struct SeedSeq
{
public:
BOOST_CONCEPT_USAGE(SeedSeq)
{
q.generate(rb, re);
}
private:
SSeq q;
mutable_random_access_iterator_archetype<boost::uint32_t> rb, re;
};
template<class T>
struct Streamable
{
public:
BOOST_CONCEPT_USAGE(Streamable)
{
os << x;
is >> v;
wos << x;
wis >> v;
}
private:
const T x;
T v;
std::istream is;
std::ostream os;
std::wistream wis;
std::wostream wos;
};
// Type deduction will fail unless the arguments have the same type.
template <typename T>
void same_type(T const&, T const&) {}
template <class E>
struct RandomNumberEngine :
DefaultConstructible<E>,
CopyConstructible<E>,
Assignable<E>,
EqualityComparable<E>,
Streamable<E>
{
public:
typedef typename E::result_type result_type;
// relaxed from the standard
BOOST_MPL_ASSERT((boost::is_arithmetic<result_type>));
// backwards compatibility check
BOOST_STATIC_ASSERT(!E::has_fixed_range);
// a generator can be used to seed another generator (extension)
BOOST_CONCEPT_ASSERT((SeedSeq<E>));
BOOST_CONCEPT_USAGE(RandomNumberEngine)
{
same_type(e(), result_type());
same_type((E::min)(), result_type());
same_type((E::max)(), result_type());
(void)E();
(void)E(s);
(void)E(q);
e.seed();
e.seed(s);
e.seed(q);
e.discard(z);
// extension
#if 0
(void)E(sb, se);
e.seed(sb, se);
#endif
}
private:
E e;
E v;
const E x;
seed_seq_archetype<> q;
typename boost::random::detail::seed_type<result_type>::type s;
uintmax_t z;
input_iterator_archetype<boost::uint32_t> sb, se;
};
template<class D>
struct RandomNumberDistribution :
DefaultConstructible<D>,
CopyConstructible<D>,
Assignable<D>,
EqualityComparable<D>,
Streamable<D>
{
public:
typedef typename D::result_type result_type;
typedef typename D::param_type param_type;
// backwards compatibility
typedef typename D::input_type input_type;
typedef param_type P;
BOOST_CONCEPT_ASSERT((DefaultConstructible<P>));
BOOST_CONCEPT_ASSERT((CopyConstructible<P>));
BOOST_CONCEPT_ASSERT((Assignable<P>));
BOOST_CONCEPT_ASSERT((EqualityComparable<P>));
BOOST_CONCEPT_ASSERT((Streamable<P>));
BOOST_MPL_ASSERT((boost::is_same<typename P::distribution_type, D>));
BOOST_CONCEPT_USAGE(RandomNumberDistribution)
{
(void)D(p);
d.reset();
same_type(x.param(), p);
d.param(p);
same_type(d(g), result_type());
same_type(d(g, p), result_type());
same_type((x.min)(), result_type());
same_type((x.max)(), result_type());
}
private:
D d;
const D x;
const P p;
uniform_random_number_generator_archetype<> g;
};
}
}
}
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
#endif
|