ソースを参照

Fix bug in Sseq constraints found by Seth Cantrell

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@129285 91177308-0d34-0410-b5e6-96231b3b80d8
Howard Hinnant 14 年 前
コミット
ef3b2e2e34

+ 22 - 12
include/random

@@ -1650,6 +1650,16 @@ class piecewise_linear_distribution
 
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 _LIBCPP_BEGIN_NAMESPACE_STD
 
 
+// __is_seed_sequence
+
+template <class _Sseq, class _Engine>
+struct __is_seed_sequence
+{
+    static const bool value =
+              !is_convertible<_Sseq, typename _Engine::result_type>::value &&
+              !is_same<typename remove_cv<_Sseq>::type, _Engine>::value;
+};
+
 // linear_congruential_engine
 // linear_congruential_engine
 
 
 template <unsigned long long __a, unsigned long long __c,
 template <unsigned long long __a, unsigned long long __c,
@@ -1848,7 +1858,7 @@ public:
         {seed(__s);}
         {seed(__s);}
     template<class _Sseq> explicit linear_congruential_engine(_Sseq& __q,
     template<class _Sseq> explicit linear_congruential_engine(_Sseq& __q,
         _LIBCPP_INLINE_VISIBILITY
         _LIBCPP_INLINE_VISIBILITY
-        typename enable_if<!is_convertible<_Sseq, result_type>::value>::type* = 0)
+        typename enable_if<__is_seed_sequence<_Sseq, linear_congruential_engine>::value>::type* = 0)
         {seed(__q);}
         {seed(__q);}
     _LIBCPP_INLINE_VISIBILITY
     _LIBCPP_INLINE_VISIBILITY
     void seed(result_type __s = default_seed)
     void seed(result_type __s = default_seed)
@@ -1858,7 +1868,7 @@ public:
         _LIBCPP_INLINE_VISIBILITY
         _LIBCPP_INLINE_VISIBILITY
         typename enable_if
         typename enable_if
         <
         <
-            !is_convertible<_Sseq, result_type>::value,
+            __is_seed_sequence<_Sseq, linear_congruential_engine>::value,
             void
             void
         >::type
         >::type
         seed(_Sseq& __q)
         seed(_Sseq& __q)
@@ -2104,14 +2114,14 @@ public:
         {seed(__sd);}
         {seed(__sd);}
     template<class _Sseq> explicit mersenne_twister_engine(_Sseq& __q,
     template<class _Sseq> explicit mersenne_twister_engine(_Sseq& __q,
         _LIBCPP_INLINE_VISIBILITY
         _LIBCPP_INLINE_VISIBILITY
-        typename enable_if<!is_convertible<_Sseq, result_type>::value>::type* = 0)
+        typename enable_if<__is_seed_sequence<_Sseq, mersenne_twister_engine>::value>::type* = 0)
         {seed(__q);}
         {seed(__q);}
     void seed(result_type __sd = default_seed);
     void seed(result_type __sd = default_seed);
     template<class _Sseq>
     template<class _Sseq>
         _LIBCPP_INLINE_VISIBILITY
         _LIBCPP_INLINE_VISIBILITY
         typename enable_if
         typename enable_if
         <
         <
-            !is_convertible<_Sseq, result_type>::value,
+            __is_seed_sequence<_Sseq, mersenne_twister_engine>::value,
             void
             void
         >::type
         >::type
         seed(_Sseq& __q)
         seed(_Sseq& __q)
@@ -2473,7 +2483,7 @@ public:
         {seed(__sd);}
         {seed(__sd);}
     template<class _Sseq> explicit subtract_with_carry_engine(_Sseq& __q,
     template<class _Sseq> explicit subtract_with_carry_engine(_Sseq& __q,
         _LIBCPP_INLINE_VISIBILITY
         _LIBCPP_INLINE_VISIBILITY
-        typename enable_if<!is_convertible<_Sseq, result_type>::value>::type* = 0)
+        typename enable_if<__is_seed_sequence<_Sseq, subtract_with_carry_engine>::value>::type* = 0)
         {seed(__q);}
         {seed(__q);}
     _LIBCPP_INLINE_VISIBILITY
     _LIBCPP_INLINE_VISIBILITY
     void seed(result_type __sd = default_seed)
     void seed(result_type __sd = default_seed)
@@ -2482,7 +2492,7 @@ public:
         _LIBCPP_INLINE_VISIBILITY
         _LIBCPP_INLINE_VISIBILITY
         typename enable_if
         typename enable_if
         <
         <
-            !is_convertible<_Sseq, result_type>::value,
+            __is_seed_sequence<_Sseq, subtract_with_carry_engine>::value,
             void
             void
         >::type
         >::type
         seed(_Sseq& __q)
         seed(_Sseq& __q)
@@ -2741,7 +2751,7 @@ public:
     template<class _Sseq>
     template<class _Sseq>
         _LIBCPP_INLINE_VISIBILITY
         _LIBCPP_INLINE_VISIBILITY
         explicit discard_block_engine(_Sseq& __q,
         explicit discard_block_engine(_Sseq& __q,
-        typename enable_if<!is_convertible<_Sseq, result_type>::value &&
+        typename enable_if<__is_seed_sequence<_Sseq, discard_block_engine>::value &&
                            !is_convertible<_Sseq, _Engine>::value>::type* = 0)
                            !is_convertible<_Sseq, _Engine>::value>::type* = 0)
         : __e_(__q), __n_(0) {}
         : __e_(__q), __n_(0) {}
     _LIBCPP_INLINE_VISIBILITY
     _LIBCPP_INLINE_VISIBILITY
@@ -2752,7 +2762,7 @@ public:
         _LIBCPP_INLINE_VISIBILITY
         _LIBCPP_INLINE_VISIBILITY
         typename enable_if
         typename enable_if
         <
         <
-            !is_convertible<_Sseq, result_type>::value,
+            __is_seed_sequence<_Sseq, discard_block_engine>::value,
             void
             void
         >::type
         >::type
         seed(_Sseq& __q) {__e_.seed(__q); __n_ = 0;}
         seed(_Sseq& __q) {__e_.seed(__q); __n_ = 0;}
@@ -2940,7 +2950,7 @@ public:
     explicit independent_bits_engine(result_type __sd) : __e_(__sd) {}
     explicit independent_bits_engine(result_type __sd) : __e_(__sd) {}
     template<class _Sseq> explicit independent_bits_engine(_Sseq& __q,
     template<class _Sseq> explicit independent_bits_engine(_Sseq& __q,
         _LIBCPP_INLINE_VISIBILITY
         _LIBCPP_INLINE_VISIBILITY
-        typename enable_if<!is_convertible<_Sseq, result_type>::value &&
+        typename enable_if<__is_seed_sequence<_Sseq, independent_bits_engine>::value &&
                            !is_convertible<_Sseq, _Engine>::value>::type* = 0)
                            !is_convertible<_Sseq, _Engine>::value>::type* = 0)
          : __e_(__q) {}
          : __e_(__q) {}
     _LIBCPP_INLINE_VISIBILITY
     _LIBCPP_INLINE_VISIBILITY
@@ -2951,7 +2961,7 @@ public:
         _LIBCPP_INLINE_VISIBILITY
         _LIBCPP_INLINE_VISIBILITY
         typename enable_if
         typename enable_if
         <
         <
-            !is_convertible<_Sseq, result_type>::value,
+            __is_seed_sequence<_Sseq, independent_bits_engine>::value,
             void
             void
         >::type
         >::type
         seed(_Sseq& __q) {__e_.seed(__q);}
         seed(_Sseq& __q) {__e_.seed(__q);}
@@ -3163,7 +3173,7 @@ public:
     explicit shuffle_order_engine(result_type __sd) : __e_(__sd) {__init();}
     explicit shuffle_order_engine(result_type __sd) : __e_(__sd) {__init();}
     template<class _Sseq> explicit shuffle_order_engine(_Sseq& __q,
     template<class _Sseq> explicit shuffle_order_engine(_Sseq& __q,
         _LIBCPP_INLINE_VISIBILITY
         _LIBCPP_INLINE_VISIBILITY
-        typename enable_if<!is_convertible<_Sseq, result_type>::value &&
+        typename enable_if<__is_seed_sequence<_Sseq, shuffle_order_engine>::value &&
                            !is_convertible<_Sseq, _Engine>::value>::type* = 0)
                            !is_convertible<_Sseq, _Engine>::value>::type* = 0)
          : __e_(__q) {__init();}
          : __e_(__q) {__init();}
     _LIBCPP_INLINE_VISIBILITY
     _LIBCPP_INLINE_VISIBILITY
@@ -3174,7 +3184,7 @@ public:
         _LIBCPP_INLINE_VISIBILITY
         _LIBCPP_INLINE_VISIBILITY
         typename enable_if
         typename enable_if
         <
         <
-            !is_convertible<_Sseq, result_type>::value,
+            __is_seed_sequence<_Sseq, shuffle_order_engine>::value,
             void
             void
         >::type
         >::type
         seed(_Sseq& __q) {__e_.seed(__q); __init();}
         seed(_Sseq& __q) {__e_.seed(__q); __init();}

+ 1 - 1
test/numerics/rand/rand.eng/rand.eng.mers/copy.pass.cpp

@@ -40,7 +40,7 @@ test2()
     typedef std::mt19937_64 E;
     typedef std::mt19937_64 E;
     E e1;
     E e1;
     e1();
     e1();
-    E e2 = e1;
+    E e2(e1);
     assert(e1 == e2);
     assert(e1 == e2);
     assert(e1() == e2());
     assert(e1() == e2());
     E::result_type k = e1();
     E::result_type k = e1();

+ 1 - 1
test/numerics/rand/rand.eng/rand.eng.sub/copy.pass.cpp

@@ -38,7 +38,7 @@ test2()
     typedef std::ranlux48_base E;
     typedef std::ranlux48_base E;
     E e1;
     E e1;
     e1();
     e1();
-    E e2 = e1;
+    E e2(e1);
     assert(e1 == e2);
     assert(e1 == e2);
     assert(e1() == e2());
     assert(e1() == e2());
     E::result_type k = e1();
     E::result_type k = e1();