/* 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 #ifdef BOOST_MSVC #pragma warning(push) #pragma warning(disable:4100) #endif #include #ifdef BOOST_MSVC #pragma warning(pop) #endif #include #include #include #include #include #include #include #include #include #include #ifdef BOOST_MSVC #pragma warning(push) #pragma warning(disable:4510) #pragma warning(disable:4610) #endif namespace boost { namespace random { namespace test { template > struct seed_seq_archetype : Base { template BOOST_CONCEPT_REQUIRES( ((Mutable_RandomAccessIterator)) ((UnsignedInteger::value_type>)), (void)) generate(Iter, Iter) {} }; template > 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 struct SeedSeq { public: BOOST_CONCEPT_USAGE(SeedSeq) { q.generate(rb, re); } private: SSeq q; mutable_random_access_iterator_archetype rb, re; }; template 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 void same_type(T const&, T const&) {} template struct RandomNumberEngine : DefaultConstructible, CopyConstructible, Assignable, EqualityComparable, Streamable { public: typedef typename E::result_type result_type; // relaxed from the standard BOOST_MPL_ASSERT((boost::is_arithmetic)); // backwards compatibility check BOOST_STATIC_ASSERT(!E::has_fixed_range); // a generator can be used to seed another generator (extension) BOOST_CONCEPT_ASSERT((SeedSeq)); 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 (void)E(sb, se); e.seed(sb, se); } private: E e; E v; const E x; seed_seq_archetype<> q; typename detail::seed_type::type s; uintmax_t z; input_iterator_archetype sb, se; }; template struct RandomNumberDistribution : DefaultConstructible, CopyConstructible, Assignable, EqualityComparable, Streamable { 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

)); BOOST_CONCEPT_ASSERT((CopyConstructible

)); BOOST_CONCEPT_ASSERT((Assignable

)); BOOST_CONCEPT_ASSERT((EqualityComparable

)); BOOST_CONCEPT_ASSERT((Streamable

)); BOOST_MPL_ASSERT((boost::is_same)); 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