Jeff Thompson | 86b6d64 | 2013-10-17 15:01:56 -0700 | [diff] [blame^] | 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: seed.hpp 71018 2011-04-05 21:27:52Z steven_watanabe $ |
| 11 | */ |
| 12 | |
| 13 | #ifndef NDNBOOST_RANDOM_DETAIL_SEED_HPP |
| 14 | #define NDNBOOST_RANDOM_DETAIL_SEED_HPP |
| 15 | |
| 16 | #include <ndnboost/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(NDNBOOST_NO_SFINAE) && !defined(__SUNPRO_CC) && !defined(__BORLANDC__) |
| 21 | |
| 22 | #include <ndnboost/utility/enable_if.hpp> |
| 23 | #include <ndnboost/type_traits/is_arithmetic.hpp> |
| 24 | |
| 25 | namespace ndnboost { |
| 26 | namespace random { |
| 27 | namespace detail { |
| 28 | |
| 29 | template<class T> |
| 30 | struct disable_seed : ndnboost::disable_if<ndnboost::is_arithmetic<T> > {}; |
| 31 | |
| 32 | template<class Engine, class T> |
| 33 | struct disable_constructor : disable_seed<T> {}; |
| 34 | |
| 35 | template<class Engine> |
| 36 | struct disable_constructor<Engine, Engine> {}; |
| 37 | |
| 38 | #define NDNBOOST_RANDOM_DETAIL_GENERATOR_CONSTRUCTOR(Self, Generator, gen) \ |
| 39 | template<class Generator> \ |
| 40 | explicit Self(Generator& gen, typename ::ndnboost::random::detail::disable_constructor<Self, Generator>::type* = 0) |
| 41 | |
| 42 | #define NDNBOOST_RANDOM_DETAIL_GENERATOR_SEED(Self, Generator, gen) \ |
| 43 | template<class Generator> \ |
| 44 | void seed(Generator& gen, typename ::ndnboost::random::detail::disable_seed<Generator>::type* = 0) |
| 45 | |
| 46 | #define NDNBOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(Self, SeedSeq, seq) \ |
| 47 | template<class SeedSeq> \ |
| 48 | explicit Self(SeedSeq& seq, typename ::ndnboost::random::detail::disable_constructor<Self, SeedSeq>::type* = 0) |
| 49 | |
| 50 | #define NDNBOOST_RANDOM_DETAIL_SEED_SEQ_SEED(Self, SeedSeq, seq) \ |
| 51 | template<class SeedSeq> \ |
| 52 | void seed(SeedSeq& seq, typename ::ndnboost::random::detail::disable_seed<SeedSeq>::type* = 0) |
| 53 | |
| 54 | #define NDNBOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(Self, T, x) \ |
| 55 | explicit Self(const T& x) |
| 56 | |
| 57 | #define NDNBOOST_RANDOM_DETAIL_ARITHMETIC_SEED(Self, T, x) \ |
| 58 | void seed(const T& x) |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | #else |
| 64 | |
| 65 | #include <ndnboost/type_traits/is_arithmetic.hpp> |
| 66 | #include <ndnboost/mpl/bool.hpp> |
| 67 | |
| 68 | #define NDNBOOST_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, ::ndnboost::is_arithmetic<Generator>());\ |
| 74 | } \ |
| 75 | template<class Generator> \ |
| 76 | void boost_random_constructor_impl(Generator& gen, ::ndnboost::mpl::false_) |
| 77 | |
| 78 | #define NDNBOOST_RANDOM_DETAIL_GENERATOR_SEED(Self, Generator, gen) \ |
| 79 | template<class Generator> \ |
| 80 | void seed(Generator& gen) { \ |
| 81 | boost_random_seed_impl(gen, ::ndnboost::is_arithmetic<Generator>());\ |
| 82 | }\ |
| 83 | template<class Generator>\ |
| 84 | void boost_random_seed_impl(Generator& gen, ::ndnboost::mpl::false_) |
| 85 | |
| 86 | #define NDNBOOST_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, ::ndnboost::is_arithmetic<SeedSeq>());\ |
| 92 | } \ |
| 93 | template<class SeedSeq> \ |
| 94 | void boost_random_constructor_impl(SeedSeq& seq, ::ndnboost::mpl::false_) |
| 95 | |
| 96 | #define NDNBOOST_RANDOM_DETAIL_SEED_SEQ_SEED(Self, SeedSeq, seq) \ |
| 97 | template<class SeedSeq> \ |
| 98 | void seed(SeedSeq& seq) { \ |
| 99 | boost_random_seed_impl(seq, ::ndnboost::is_arithmetic<SeedSeq>()); \ |
| 100 | } \ |
| 101 | template<class SeedSeq> \ |
| 102 | void boost_random_seed_impl(SeedSeq& seq, ::ndnboost::mpl::false_) |
| 103 | |
| 104 | #define NDNBOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(Self, T, x) \ |
| 105 | explicit Self(const T& x) { boost_random_constructor_impl(x, ::ndnboost::mpl::true_()); }\ |
| 106 | void boost_random_constructor_impl(const T& x, ::ndnboost::mpl::true_) |
| 107 | |
| 108 | #define NDNBOOST_RANDOM_DETAIL_ARITHMETIC_SEED(Self, T, x) \ |
| 109 | void seed(const T& x) { boost_random_seed_impl(x, ::ndnboost::mpl::true_()); }\ |
| 110 | void boost_random_seed_impl(const T& x, ::ndnboost::mpl::true_) |
| 111 | |
| 112 | #endif |
| 113 | |
| 114 | #endif |