1 /* boost random/detail/seed.hpp header file
3 * Copyright Steven Watanabe 2009
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)
8 * See http://www.boost.org for most recent version including documentation.
10 * $Id: seed.hpp 71018 2011-04-05 21:27:52Z steven_watanabe $
13 #ifndef BOOST_RANDOM_DETAIL_SEED_HPP
14 #define BOOST_RANDOM_DETAIL_SEED_HPP
16 #include <boost/config.hpp>
18 // Sun seems to have trouble with the use of SFINAE for the
19 // templated constructor. So does Borland.
20 #if !defined(BOOST_NO_SFINAE) && !defined(__SUNPRO_CC) && !defined(__BORLANDC__)
22 #include <boost/utility/enable_if.hpp>
23 #include <boost/type_traits/is_arithmetic.hpp>
30 struct disable_seed : boost::disable_if<boost::is_arithmetic<T> > {};
32 template<class Engine, class T>
33 struct disable_constructor : disable_seed<T> {};
35 template<class Engine>
36 struct disable_constructor<Engine, Engine> {};
38 #define BOOST_RANDOM_DETAIL_GENERATOR_CONSTRUCTOR(Self, Generator, gen) \
39 template<class Generator> \
40 explicit Self(Generator& gen, typename ::boost::random::detail::disable_constructor<Self, Generator>::type* = 0)
42 #define BOOST_RANDOM_DETAIL_GENERATOR_SEED(Self, Generator, gen) \
43 template<class Generator> \
44 void seed(Generator& gen, typename ::boost::random::detail::disable_seed<Generator>::type* = 0)
46 #define BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(Self, SeedSeq, seq) \
47 template<class SeedSeq> \
48 explicit Self(SeedSeq& seq, typename ::boost::random::detail::disable_constructor<Self, SeedSeq>::type* = 0)
50 #define BOOST_RANDOM_DETAIL_SEED_SEQ_SEED(Self, SeedSeq, seq) \
51 template<class SeedSeq> \
52 void seed(SeedSeq& seq, typename ::boost::random::detail::disable_seed<SeedSeq>::type* = 0)
54 #define BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(Self, T, x) \
55 explicit Self(const T& x)
57 #define BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(Self, T, x) \
65 #include <boost/type_traits/is_arithmetic.hpp>
66 #include <boost/mpl/bool.hpp>
68 #define BOOST_RANDOM_DETAIL_GENERATOR_CONSTRUCTOR(Self, Generator, gen) \
69 Self(Self& other) { *this = other; } \
70 Self(const Self& other) { *this = other; } \
71 template<class Generator> \
72 explicit Self(Generator& gen) { \
73 boost_random_constructor_impl(gen, ::boost::is_arithmetic<Generator>());\
75 template<class Generator> \
76 void boost_random_constructor_impl(Generator& gen, ::boost::mpl::false_)
78 #define BOOST_RANDOM_DETAIL_GENERATOR_SEED(Self, Generator, gen) \
79 template<class Generator> \
80 void seed(Generator& gen) { \
81 boost_random_seed_impl(gen, ::boost::is_arithmetic<Generator>());\
83 template<class Generator>\
84 void boost_random_seed_impl(Generator& gen, ::boost::mpl::false_)
86 #define BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(Self, SeedSeq, seq) \
87 Self(Self& other) { *this = other; } \
88 Self(const Self& other) { *this = other; } \
89 template<class SeedSeq> \
90 explicit Self(SeedSeq& seq) { \
91 boost_random_constructor_impl(seq, ::boost::is_arithmetic<SeedSeq>());\
93 template<class SeedSeq> \
94 void boost_random_constructor_impl(SeedSeq& seq, ::boost::mpl::false_)
96 #define BOOST_RANDOM_DETAIL_SEED_SEQ_SEED(Self, SeedSeq, seq) \
97 template<class SeedSeq> \
98 void seed(SeedSeq& seq) { \
99 boost_random_seed_impl(seq, ::boost::is_arithmetic<SeedSeq>()); \
101 template<class SeedSeq> \
102 void boost_random_seed_impl(SeedSeq& seq, ::boost::mpl::false_)
104 #define BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(Self, T, x) \
105 explicit Self(const T& x) { boost_random_constructor_impl(x, ::boost::mpl::true_()); }\
106 void boost_random_constructor_impl(const T& x, ::boost::mpl::true_)
108 #define BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(Self, T, x) \
109 void seed(const T& x) { boost_random_seed_impl(x, ::boost::mpl::true_()); }\
110 void boost_random_seed_impl(const T& x, ::boost::mpl::true_)