seed.hpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. #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. namespace boost {
  21. namespace random {
  22. namespace detail {
  23. template<class T>
  24. struct disable_seed : boost::disable_if<boost::is_arithmetic<T> > {};
  25. template<class Engine, class T>
  26. struct disable_constructor : disable_seed<T> {};
  27. template<class Engine>
  28. struct disable_constructor<Engine, Engine> {};
  29. #define BOOST_RANDOM_DETAIL_GENERATOR_CONSTRUCTOR(Self, Generator, gen) \
  30. template<class Generator> \
  31. explicit Self(Generator& gen, typename ::boost::random::detail::disable_constructor<Self, Generator>::type* = 0)
  32. #define BOOST_RANDOM_DETAIL_GENERATOR_SEED(Self, Generator, gen) \
  33. template<class Generator> \
  34. void seed(Generator& gen, typename ::boost::random::detail::disable_seed<Generator>::type* = 0)
  35. #define BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(Self, SeedSeq, seq) \
  36. template<class SeedSeq> \
  37. explicit Self(SeedSeq& seq, typename ::boost::random::detail::disable_constructor<Self, SeedSeq>::type* = 0)
  38. #define BOOST_RANDOM_DETAIL_SEED_SEQ_SEED(Self, SeedSeq, seq) \
  39. template<class SeedSeq> \
  40. void seed(SeedSeq& seq, typename ::boost::random::detail::disable_seed<SeedSeq>::type* = 0)
  41. #define BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(Self, T, x) \
  42. explicit Self(const T& x)
  43. #define BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(Self, T, x) \
  44. void seed(const T& x)
  45. }
  46. }
  47. }
  48. #else
  49. #include <boost/type_traits/is_arithmetic.hpp>
  50. #include <boost/mpl/bool.hpp>
  51. #define BOOST_RANDOM_DETAIL_GENERATOR_CONSTRUCTOR(Self, Generator, gen) \
  52. Self(Self& other) { *this = other; } \
  53. Self(const Self& other) { *this = other; } \
  54. template<class Generator> \
  55. explicit Self(Generator& gen) { \
  56. boost_random_constructor_impl(gen, ::boost::is_arithmetic<Generator>());\
  57. } \
  58. template<class Generator> \
  59. void boost_random_constructor_impl(Generator& gen, ::boost::mpl::false_)
  60. #define BOOST_RANDOM_DETAIL_GENERATOR_SEED(Self, Generator, gen) \
  61. template<class Generator> \
  62. void seed(Generator& gen) { \
  63. boost_random_seed_impl(gen, ::boost::is_arithmetic<Generator>());\
  64. }\
  65. template<class Generator>\
  66. void boost_random_seed_impl(Generator& gen, ::boost::mpl::false_)
  67. #define BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(Self, SeedSeq, seq) \
  68. Self(Self& other) { *this = other; } \
  69. Self(const Self& other) { *this = other; } \
  70. template<class SeedSeq> \
  71. explicit Self(SeedSeq& seq) { \
  72. boost_random_constructor_impl(seq, ::boost::is_arithmetic<SeedSeq>());\
  73. } \
  74. template<class SeedSeq> \
  75. void boost_random_constructor_impl(SeedSeq& seq, ::boost::mpl::false_)
  76. #define BOOST_RANDOM_DETAIL_SEED_SEQ_SEED(Self, SeedSeq, seq) \
  77. template<class SeedSeq> \
  78. void seed(SeedSeq& seq) { \
  79. boost_random_seed_impl(seq, ::boost::is_arithmetic<SeedSeq>()); \
  80. } \
  81. template<class SeedSeq> \
  82. void boost_random_seed_impl(SeedSeq& seq, ::boost::mpl::false_)
  83. #define BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(Self, T, x) \
  84. explicit Self(const T& x) { boost_random_constructor_impl(x, ::boost::mpl::true_()); }\
  85. void boost_random_constructor_impl(const T& x, ::boost::mpl::true_)
  86. #define BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(Self, T, x) \
  87. void seed(const T& x) { boost_random_seed_impl(x, ::boost::mpl::true_()); }\
  88. void boost_random_seed_impl(const T& x, ::boost::mpl::true_)
  89. #endif
  90. #endif