seed.hpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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(BOOST_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. #define BOOST_RANDOM_DETAIL_GENERATOR_CONSTRUCTOR(Self, Generator, gen) \
  51. Self(Self& other) { *this = other; } \
  52. Self(const Self& other) { *this = other; } \
  53. template<class Generator> \
  54. explicit Self(Generator& gen) { \
  55. boost_random_constructor_impl(gen, ::boost::is_arithmetic<Generator>());\
  56. } \
  57. template<class Generator> \
  58. void boost_random_constructor_impl(Generator& gen, ::boost::false_type)
  59. #define BOOST_RANDOM_DETAIL_GENERATOR_SEED(Self, Generator, gen) \
  60. template<class Generator> \
  61. void seed(Generator& gen) { \
  62. boost_random_seed_impl(gen, ::boost::is_arithmetic<Generator>());\
  63. }\
  64. template<class Generator>\
  65. void boost_random_seed_impl(Generator& gen, ::boost::false_type)
  66. #define BOOST_RANDOM_DETAIL_SEED_SEQ_CONSTRUCTOR(Self, SeedSeq, seq) \
  67. Self(Self& other) { *this = other; } \
  68. Self(const Self& other) { *this = other; } \
  69. template<class SeedSeq> \
  70. explicit Self(SeedSeq& seq) { \
  71. boost_random_constructor_impl(seq, ::boost::is_arithmetic<SeedSeq>());\
  72. } \
  73. template<class SeedSeq> \
  74. void boost_random_constructor_impl(SeedSeq& seq, ::boost::false_type)
  75. #define BOOST_RANDOM_DETAIL_SEED_SEQ_SEED(Self, SeedSeq, seq) \
  76. template<class SeedSeq> \
  77. void seed(SeedSeq& seq) { \
  78. boost_random_seed_impl(seq, ::boost::is_arithmetic<SeedSeq>()); \
  79. } \
  80. template<class SeedSeq> \
  81. void boost_random_seed_impl(SeedSeq& seq, ::boost::false_type)
  82. #define BOOST_RANDOM_DETAIL_ARITHMETIC_CONSTRUCTOR(Self, T, x) \
  83. explicit Self(const T& x) { boost_random_constructor_impl(x, ::boost::true_type()); }\
  84. void boost_random_constructor_impl(const T& x, ::boost::true_type)
  85. #define BOOST_RANDOM_DETAIL_ARITHMETIC_SEED(Self, T, x) \
  86. void seed(const T& x) { boost_random_seed_impl(x, ::boost::true_type()); }\
  87. void boost_random_seed_impl(const T& x, ::boost::true_type)
  88. #endif
  89. #endif