3 * Copyright Steven Watanabe 2011
4 * Distributed under the Boost Software License, Version 1.0. (See
5 * accompanying file LICENSE_1_0.txt or copy at
6 * http://www.boost.org/LICENSE_1_0.txt)
12 #ifndef BOOST_RANDOM_TEST_CONCEPTS_HPP
13 #define BOOST_RANDOM_TEST_CONCEPTS_HPP
15 #include <boost/config.hpp>
19 #pragma warning(disable:4100)
22 #include <boost/concept_check.hpp>
28 #include <boost/concept_archetype.hpp>
29 #include <boost/concept/requires.hpp>
30 #include <boost/mpl/assert.hpp>
31 #include <boost/type_traits/is_arithmetic.hpp>
32 #include <boost/type_traits/is_integral.hpp>
33 #include <boost/type_traits/is_same.hpp>
34 #include <boost/cstdint.hpp>
35 #include <boost/static_assert.hpp>
41 #pragma warning(disable:4510)
42 #pragma warning(disable:4610)
49 template<class Base = null_archetype<> >
50 struct seed_seq_archetype : Base
53 BOOST_CONCEPT_REQUIRES(
54 ((Mutable_RandomAccessIterator<Iter>))
55 ((UnsignedInteger<typename Mutable_RandomAccessIterator<Iter>::value_type>)),
57 generate(Iter, Iter) {}
60 template<class R = unsigned, class Base = null_archetype<> >
61 struct uniform_random_number_generator_archetype : Base
63 typedef R result_type;
64 static R min BOOST_PREVENT_MACRO_SUBSTITUTION () { return 0; }
65 static R max BOOST_PREVENT_MACRO_SUBSTITUTION () { return 0; }
66 R operator()() { return 0; }
73 BOOST_CONCEPT_USAGE(SeedSeq)
79 mutable_random_access_iterator_archetype<boost::uint32_t> rb, re;
86 BOOST_CONCEPT_USAGE(Streamable)
103 // Type deduction will fail unless the arguments have the same type.
104 template <typename T>
105 void same_type(T const&, T const&) {}
108 struct RandomNumberEngine :
109 DefaultConstructible<E>,
110 CopyConstructible<E>,
112 EqualityComparable<E>,
116 typedef typename E::result_type result_type;
118 // relaxed from the standard
119 BOOST_MPL_ASSERT((boost::is_arithmetic<result_type>));
121 // backwards compatibility check
122 BOOST_STATIC_ASSERT(!E::has_fixed_range);
124 // a generator can be used to seed another generator (extension)
125 BOOST_CONCEPT_ASSERT((SeedSeq<E>));
127 BOOST_CONCEPT_USAGE(RandomNumberEngine)
129 same_type(e(), result_type());
130 same_type((E::min)(), result_type());
131 same_type((E::max)(), result_type());
152 seed_seq_archetype<> q;
153 typename detail::seed_type<result_type>::type s;
154 unsigned long long z;
156 input_iterator_archetype<boost::uint32_t> sb, se;
160 struct RandomNumberDistribution :
161 DefaultConstructible<D>,
162 CopyConstructible<D>,
164 EqualityComparable<D>,
168 typedef typename D::result_type result_type;
169 typedef typename D::param_type param_type;
170 // backwards compatibility
171 typedef typename D::input_type input_type;
173 typedef param_type P;
175 BOOST_CONCEPT_ASSERT((DefaultConstructible<P>));
176 BOOST_CONCEPT_ASSERT((CopyConstructible<P>));
177 BOOST_CONCEPT_ASSERT((Assignable<P>));
178 BOOST_CONCEPT_ASSERT((EqualityComparable<P>));
179 BOOST_CONCEPT_ASSERT((Streamable<P>));
181 BOOST_MPL_ASSERT((boost::is_same<typename P::distribution_type, D>));
183 BOOST_CONCEPT_USAGE(RandomNumberDistribution)
187 same_type(x.param(), p);
189 same_type(d(g), result_type());
190 same_type(d(g, p), result_type());
191 same_type((x.min)(), result_type());
192 same_type((x.max)(), result_type());
199 uniform_random_number_generator_archetype<> g;