seed.hpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. #ifndef BOOST_RANDOM_DETAIL_SEED_HPP
  13. #define BOOST_RANDOM_DETAIL_SEED_HPP
  14. #include <boost/config.hpp>
  15. // Sun seems to have trouble with the use of SFINAE for the
  16. // templated constructor. So does Borland.
  17. #if !defined(BOOST_NO_SFINAE) && !defined(__SUNPRO_CC) && !defined(__BORLANDC__)
  18. #include <boost/utility/enable_if.hpp>
  19. #include <boost/type_traits/is_arithmetic.hpp>
  20. #include <boost/mpl/bool.hpp>
  21. namespace boost {
  22. namespace random {
  23. namespace detail {
  24. template<class T>
  25. struct disable_seed : boost::disable_if<boost::is_arithmetic<T> > {};
  26. template<class Engine, class T>
  27. struct disable_constructor : disable_seed<T> {};
  28. template<class Engine>
  29. struct disable_constructor<Engine, Engine> {};
  30. #define BOOST_RANDOM_DETAIL_GENERATOR_CONSTRUCTOR(Self, Generator, gen) \
  31. template<class Generator> \
  32. explicit Self(Generator& gen, typename ::boost::random::detail::disable_constructor<Self, Generator>::type* = 0)
  33. #define BOOST_RANDOM_DETAIL_GENERATOR_SEED(Self, Generator, gen) \
  34. template<class Generator> \
  35. void seed(Generator& gen, typename ::boost::random::detail::disable_seed<Generator>::type* = 0)
  36. #define BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(Self, SeedSeq, seq) \
  37. template<class SeedSeq> \
  38. explicit Self(SeedSeq& seq, typename ::boost::random::detail::disable_constructor<Self, SeedSeq>::type* = 0)
  39. #define BOOST_RANDOM_DETAIL_SEED_SEQ_SEED(Self, SeedSeq, seq) \
  40. template<class SeedSeq> \
  41. void seed(SeedSeq& seq, typename ::boost::random::detail::disable_seed<SeedSeq>::type* = 0)
  42. #define BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(Self, T, x) \
  43. explicit Self(const T& x)
  44. #define BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(Self, T, x) \
  45. void seed(const T& x)
  46. }
  47. }
  48. }
  49. #else
  50. #include <boost/type_traits/is_arithmetic.hpp>
  51. #include <boost/mpl/bool.hpp>
  52. #define BOOST_RANDOM_DETAIL_GENERATOR_CONSTRUCTOR(Self, Generator, gen) \
  53. Self(Self& other) { *this = other; } \
  54. Self(const Self& other) { *this = other; } \
  55. template<class Generator> \
  56. explicit Self(Generator& gen) { \
  57. boost_random_constructor_impl(gen, ::boost::is_arithmetic<Generator>());\
  58. } \
  59. template<class Generator> \
  60. void boost_random_constructor_impl(Generator& gen, ::boost::mpl::false_)
  61. #define BOOST_RANDOM_DETAIL_GENERATOR_SEED(Self, Generator, gen) \
  62. template<class Generator> \
  63. void seed(Generator& gen) { \
  64. boost_random_seed_impl(gen, ::boost::is_arithmetic<Generator>());\
  65. }\
  66. template<class Generator>\
  67. void boost_random_seed_impl(Generator& gen, ::boost::mpl::false_)
  68. #define BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(Self, SeedSeq, seq) \
  69. Self(Self& other) { *this = other; } \
  70. Self(const Self& other) { *this = other; } \
  71. template<class SeedSeq> \
  72. explicit Self(SeedSeq& seq) { \
  73. boost_random_constructor_impl(seq, ::boost::is_arithmetic<SeedSeq>());\
  74. } \
  75. template<class SeedSeq> \
  76. void boost_random_constructor_impl(SeedSeq& seq, ::boost::mpl::false_)
  77. #define BOOST_RANDOM_DETAIL_SEED_SEQ_SEED(Self, SeedSeq, seq) \
  78. template<class SeedSeq> \
  79. void seed(SeedSeq& seq) { \
  80. boost_random_seed_impl(seq, ::boost::is_arithmetic<SeedSeq>()); \
  81. } \
  82. template<class SeedSeq> \
  83. void boost_random_seed_impl(SeedSeq& seq, ::boost::mpl::false_)
  84. #define BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(Self, T, x) \
  85. explicit Self(const T& x) { boost_random_constructor_impl(x, ::boost::mpl::true_()); }\
  86. void boost_random_constructor_impl(const T& x, ::boost::mpl::true_)
  87. #define BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(Self, T, x) \
  88. void seed(const T& x) { boost_random_seed_impl(x, ::boost::mpl::true_()); }\
  89. void boost_random_seed_impl(const T& x, ::boost::mpl::true_)
  90. #endif
  91. #endif