| 1 | /* boost random/detail/seed.hpp header file |
| 2 | * |
| 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) |
| 7 | * |
| 8 | * See http://www.boost.org for most recent version including documentation. |
| 9 | * |
| 10 | * $Id$ |
| 11 | */ |
| 12 | |
| 13 | #ifndef BOOST_RANDOM_DETAIL_SEED_HPP |
| 14 | #define BOOST_RANDOM_DETAIL_SEED_HPP |
| 15 | |
| 16 | #include <boost/config.hpp> |
| 17 | |
| 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__) |
| 21 | |
| 22 | #include <boost/utility/enable_if.hpp> |
| 23 | #include <boost/type_traits/is_arithmetic.hpp> |
| 24 | #include <boost/mpl/bool.hpp> |
| 25 | |
| 26 | namespace boost { |
| 27 | namespace random { |
| 28 | namespace detail { |
| 29 | |
| 30 | template<class T> |
| 31 | struct disable_seed : boost::disable_if<boost::is_arithmetic<T> > {}; |
| 32 | |
| 33 | template<class Engine, class T> |
| 34 | struct disable_constructor : disable_seed<T> {}; |
| 35 | |
| 36 | template<class Engine> |
| 37 | struct disable_constructor<Engine, Engine> {}; |
| 38 | |
| 39 | #define BOOST_RANDOM_DETAIL_GENERATOR_CONSTRUCTOR(Self, Generator, gen) \ |
| 40 | template<class Generator> \ |
| 41 | explicit Self(Generator& gen, typename ::boost::random::detail::disable_constructor<Self, Generator>::type* = 0) |
| 42 | |
| 43 | #define BOOST_RANDOM_DETAIL_GENERATOR_SEED(Self, Generator, gen) \ |
| 44 | template<class Generator> \ |
| 45 | void seed(Generator& gen, typename ::boost::random::detail::disable_seed<Generator>::type* = 0) |
| 46 | |
| 47 | #define BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(Self, SeedSeq, seq) \ |
| 48 | template<class SeedSeq> \ |
| 49 | explicit Self(SeedSeq& seq, typename ::boost::random::detail::disable_constructor<Self, SeedSeq>::type* = 0) |
| 50 | |
| 51 | #define BOOST_RANDOM_DETAIL_SEED_SEQ_SEED(Self, SeedSeq, seq) \ |
| 52 | template<class SeedSeq> \ |
| 53 | void seed(SeedSeq& seq, typename ::boost::random::detail::disable_seed<SeedSeq>::type* = 0) |
| 54 | |
| 55 | #define BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(Self, T, x) \ |
| 56 | explicit Self(const T& x) |
| 57 | |
| 58 | #define BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(Self, T, x) \ |
| 59 | void seed(const T& x) |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | #else |
| 65 | |
| 66 | #include <boost/type_traits/is_arithmetic.hpp> |
| 67 | #include <boost/mpl/bool.hpp> |
| 68 | |
| 69 | #define BOOST_RANDOM_DETAIL_GENERATOR_CONSTRUCTOR(Self, Generator, gen) \ |
| 70 | Self(Self& other) { *this = other; } \ |
| 71 | Self(const Self& other) { *this = other; } \ |
| 72 | template<class Generator> \ |
| 73 | explicit Self(Generator& gen) { \ |
| 74 | boost_random_constructor_impl(gen, ::boost::is_arithmetic<Generator>());\ |
| 75 | } \ |
| 76 | template<class Generator> \ |
| 77 | void boost_random_constructor_impl(Generator& gen, ::boost::mpl::false_) |
| 78 | |
| 79 | #define BOOST_RANDOM_DETAIL_GENERATOR_SEED(Self, Generator, gen) \ |
| 80 | template<class Generator> \ |
| 81 | void seed(Generator& gen) { \ |
| 82 | boost_random_seed_impl(gen, ::boost::is_arithmetic<Generator>());\ |
| 83 | }\ |
| 84 | template<class Generator>\ |
| 85 | void boost_random_seed_impl(Generator& gen, ::boost::mpl::false_) |
| 86 | |
| 87 | #define BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(Self, SeedSeq, seq) \ |
| 88 | Self(Self& other) { *this = other; } \ |
| 89 | Self(const Self& other) { *this = other; } \ |
| 90 | template<class SeedSeq> \ |
| 91 | explicit Self(SeedSeq& seq) { \ |
| 92 | boost_random_constructor_impl(seq, ::boost::is_arithmetic<SeedSeq>());\ |
| 93 | } \ |
| 94 | template<class SeedSeq> \ |
| 95 | void boost_random_constructor_impl(SeedSeq& seq, ::boost::mpl::false_) |
| 96 | |
| 97 | #define BOOST_RANDOM_DETAIL_SEED_SEQ_SEED(Self, SeedSeq, seq) \ |
| 98 | template<class SeedSeq> \ |
| 99 | void seed(SeedSeq& seq) { \ |
| 100 | boost_random_seed_impl(seq, ::boost::is_arithmetic<SeedSeq>()); \ |
| 101 | } \ |
| 102 | template<class SeedSeq> \ |
| 103 | void boost_random_seed_impl(SeedSeq& seq, ::boost::mpl::false_) |
| 104 | |
| 105 | #define BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(Self, T, x) \ |
| 106 | explicit Self(const T& x) { boost_random_constructor_impl(x, ::boost::mpl::true_()); }\ |
| 107 | void boost_random_constructor_impl(const T& x, ::boost::mpl::true_) |
| 108 | |
| 109 | #define BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(Self, T, x) \ |
| 110 | void seed(const T& x) { boost_random_seed_impl(x, ::boost::mpl::true_()); }\ |
| 111 | void boost_random_seed_impl(const T& x, ::boost::mpl::true_) |
| 112 | |
| 113 | #endif |
| 114 | |
| 115 | #endif |
| 116 | |