[cfe-commits] [libcxx] r104946 - in /libcxx/trunk: include/random test/numerics/rand/rand.adapt/rand.adapt.disc/ctor_engine_copy.pass.cpp test/numerics/rand/rand.adapt/rand.adapt.disc/ctor_engine_move.pass.cpp test/numerics/rand/rand.adapt/rand.adapt.ibits/ctor_engine_copy.pass.cpp test/numerics/rand/rand.adapt/rand.adapt.ibits/ctor_engine_move.pass.cpp test/numerics/rand/rand.adapt/rand.adapt.shuf/ctor_engine_copy.pass.cpp test/numerics/rand/rand.adapt/rand.adapt.shuf/ctor_engine_move.pass.cpp
Howard Hinnant
hhinnant at apple.com
Fri May 28 08:49:54 PDT 2010
Author: hhinnant
Date: Fri May 28 10:49:54 2010
New Revision: 104946
URL: http://llvm.org/viewvc/llvm-project?rev=104946&view=rev
Log:
Implemented some adaptor constructors which I had missed.
Added:
libcxx/trunk/test/numerics/rand/rand.adapt/rand.adapt.disc/ctor_engine_copy.pass.cpp
libcxx/trunk/test/numerics/rand/rand.adapt/rand.adapt.disc/ctor_engine_move.pass.cpp
libcxx/trunk/test/numerics/rand/rand.adapt/rand.adapt.ibits/ctor_engine_copy.pass.cpp
libcxx/trunk/test/numerics/rand/rand.adapt/rand.adapt.ibits/ctor_engine_move.pass.cpp
libcxx/trunk/test/numerics/rand/rand.adapt/rand.adapt.shuf/ctor_engine_copy.pass.cpp
libcxx/trunk/test/numerics/rand/rand.adapt/rand.adapt.shuf/ctor_engine_move.pass.cpp
Modified:
libcxx/trunk/include/random
Modified: libcxx/trunk/include/random
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/random?rev=104946&r1=104945&r2=104946&view=diff
==============================================================================
--- libcxx/trunk/include/random (original)
+++ libcxx/trunk/include/random Fri May 28 10:49:54 2010
@@ -1834,7 +1834,8 @@
// constructors and seeding functions
explicit linear_congruential_engine(result_type __s = default_seed)
{seed(__s);}
- template<class _Sseq> explicit linear_congruential_engine(_Sseq& __q)
+ template<class _Sseq> explicit linear_congruential_engine(_Sseq& __q,
+ typename enable_if<!is_convertible<_Sseq, result_type>::value>::type* = 0)
{seed(__q);}
void seed(result_type __s = default_seed)
{seed(integral_constant<bool, __m == 0>(),
@@ -2073,7 +2074,8 @@
// constructors and seeding functions
explicit mersenne_twister_engine(result_type __sd = default_seed)
{seed(__sd);}
- template<class _Sseq> explicit mersenne_twister_engine(_Sseq& __q)
+ template<class _Sseq> explicit mersenne_twister_engine(_Sseq& __q,
+ typename enable_if<!is_convertible<_Sseq, result_type>::value>::type* = 0)
{seed(__q);}
void seed(result_type __sd = default_seed);
template<class _Sseq>
@@ -2431,7 +2433,8 @@
// constructors and seeding functions
explicit subtract_with_carry_engine(result_type __sd = default_seed)
{seed(__sd);}
- template<class _Sseq> explicit subtract_with_carry_engine(_Sseq& __q)
+ template<class _Sseq> explicit subtract_with_carry_engine(_Sseq& __q,
+ typename enable_if<!is_convertible<_Sseq, result_type>::value>::type* = 0)
{seed(__q);}
void seed(result_type __sd = default_seed)
{seed(__sd, integral_constant<unsigned, 1 + (__w - 1) / 32>());}
@@ -2680,14 +2683,26 @@
// constructors and seeding functions
discard_block_engine() : __n_(0) {}
-// explicit discard_block_engine(const _Engine& __e);
-// explicit discard_block_engine(_Engine&& __e);
+ explicit discard_block_engine(const _Engine& __e)
+ : __e_(__e), __n_(0) {}
+#ifdef _LIBCPP_MOVE
+ explicit discard_block_engine(_Engine&& __e)
+ : __e_(_STD::move(__e)), __n_(0) {}
+#endif
explicit discard_block_engine(result_type __sd) : __e_(__sd), __n_(0) {}
- template<class _Sseq> explicit discard_block_engine(_Sseq& __q)
+ template<class _Sseq> explicit discard_block_engine(_Sseq& __q,
+ typename enable_if<!is_convertible<_Sseq, result_type>::value &&
+ !is_convertible<_Sseq, _Engine>::value>::type* = 0)
: __e_(__q), __n_(0) {}
void seed() {__e_.seed(); __n_ = 0;}
void seed(result_type __sd) {__e_.seed(__sd); __n_ = 0;}
- template<class _Sseq> void seed(_Sseq& __q) {__e_.seed(__q); __n_ = 0;}
+ template<class _Sseq>
+ typename enable_if
+ <
+ !is_convertible<_Sseq, result_type>::value,
+ void
+ >::type
+ seed(_Sseq& __q) {__e_.seed(__q); __n_ = 0;}
// generating functions
result_type operator()();
@@ -2855,14 +2870,26 @@
// constructors and seeding functions
independent_bits_engine() {}
-// explicit independent_bits_engine(const _Engine& __e);
-// explicit independent_bits_engine(_Engine&& __e);
+ explicit independent_bits_engine(const _Engine& __e)
+ : __e_(__e) {}
+#ifdef _LIBCPP_MOVE
+ explicit independent_bits_engine(_Engine&& __e)
+ : __e_(_STD::move(__e)) {}
+#endif
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,
+ typename enable_if<!is_convertible<_Sseq, result_type>::value &&
+ !is_convertible<_Sseq, _Engine>::value>::type* = 0)
: __e_(__q) {}
void seed() {__e_.seed();}
void seed(result_type __sd) {__e_.seed(__sd);}
- template<class _Sseq> void seed(_Sseq& __q) {__e_.seed(__q);}
+ template<class _Sseq>
+ typename enable_if
+ <
+ !is_convertible<_Sseq, result_type>::value,
+ void
+ >::type
+ seed(_Sseq& __q) {__e_.seed(__q);}
// generating functions
result_type operator()() {return __eval(integral_constant<bool, _R != 0>());}
@@ -3051,14 +3078,26 @@
// constructors and seeding functions
shuffle_order_engine() {__init();}
-// explicit shuffle_order_engine(const _Engine& __e);
-// explicit shuffle_order_engine(_Engine&& e);
+ explicit shuffle_order_engine(const _Engine& __e)
+ : __e_(__e) {__init();}
+#ifdef _LIBCPP_MOVE
+ explicit shuffle_order_engine(_Engine&& __e)
+ : __e_(_STD::move(__e)) {__init();}
+#endif
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,
+ typename enable_if<!is_convertible<_Sseq, result_type>::value &&
+ !is_convertible<_Sseq, _Engine>::value>::type* = 0)
: __e_(__q) {__init();}
void seed() {__e_.seed(); __init();}
void seed(result_type __sd) {__e_.seed(__sd); __init();}
- template<class _Sseq> void seed(_Sseq& __q) {__e_.seed(__q); __init();}
+ template<class _Sseq>
+ typename enable_if
+ <
+ !is_convertible<_Sseq, result_type>::value,
+ void
+ >::type
+ seed(_Sseq& __q) {__e_.seed(__q); __init();}
// generating functions
result_type operator()() {return __eval(integral_constant<bool, _R != 0>());}
Added: libcxx/trunk/test/numerics/rand/rand.adapt/rand.adapt.disc/ctor_engine_copy.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.adapt/rand.adapt.disc/ctor_engine_copy.pass.cpp?rev=104946&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.adapt/rand.adapt.disc/ctor_engine_copy.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.adapt/rand.adapt.disc/ctor_engine_copy.pass.cpp Fri May 28 10:49:54 2010
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class Engine, size_t p, size_t r>
+// class discard_block_engine
+
+// explicit discard_block_engine(const Engine& e);
+
+#include <random>
+#include <cassert>
+
+int main()
+{
+ {
+ typedef std::ranlux24_base Engine;
+ typedef std::ranlux24 Adaptor;
+ Engine e;
+ Adaptor a(e);
+ assert(a.base() == e);
+ }
+}
Added: libcxx/trunk/test/numerics/rand/rand.adapt/rand.adapt.disc/ctor_engine_move.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.adapt/rand.adapt.disc/ctor_engine_move.pass.cpp?rev=104946&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.adapt/rand.adapt.disc/ctor_engine_move.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.adapt/rand.adapt.disc/ctor_engine_move.pass.cpp Fri May 28 10:49:54 2010
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class Engine, size_t p, size_t r>
+// class discard_block_engine
+
+// explicit discard_block_engine(const Engine& e);
+
+#include <random>
+#include <cassert>
+
+int main()
+{
+ {
+ typedef std::ranlux24_base Engine;
+ typedef std::ranlux24 Adaptor;
+ Engine e;
+ Engine e0 = e;
+ Adaptor a(std::move(e0));
+ assert(a.base() == e);
+ }
+}
Added: libcxx/trunk/test/numerics/rand/rand.adapt/rand.adapt.ibits/ctor_engine_copy.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.adapt/rand.adapt.ibits/ctor_engine_copy.pass.cpp?rev=104946&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.adapt/rand.adapt.ibits/ctor_engine_copy.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.adapt/rand.adapt.ibits/ctor_engine_copy.pass.cpp Fri May 28 10:49:54 2010
@@ -0,0 +1,29 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class Engine, size_t w, class UIntType>
+// class independent_bits_engine
+
+// explicit independent_bits_engine(const Engine& e);
+
+#include <random>
+#include <cassert>
+
+int main()
+{
+ {
+ typedef std::mt19937 Engine;
+ typedef std::independent_bits_engine<Engine, 24, unsigned> Adaptor;
+ Engine e;
+ Adaptor a(e);
+ assert(a.base() == e);
+ }
+}
Added: libcxx/trunk/test/numerics/rand/rand.adapt/rand.adapt.ibits/ctor_engine_move.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.adapt/rand.adapt.ibits/ctor_engine_move.pass.cpp?rev=104946&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.adapt/rand.adapt.ibits/ctor_engine_move.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.adapt/rand.adapt.ibits/ctor_engine_move.pass.cpp Fri May 28 10:49:54 2010
@@ -0,0 +1,30 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class Engine, size_t w, class UIntType>
+// class independent_bits_engine
+
+// explicit independent_bits_engine(const Engine& e);
+
+#include <random>
+#include <cassert>
+
+int main()
+{
+ {
+ typedef std::mt19937 Engine;
+ typedef std::independent_bits_engine<Engine, 24, unsigned> Adaptor;
+ Engine e;
+ Engine e0 = e;
+ Adaptor a(std::move(e0));
+ assert(a.base() == e);
+ }
+}
Added: libcxx/trunk/test/numerics/rand/rand.adapt/rand.adapt.shuf/ctor_engine_copy.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.adapt/rand.adapt.shuf/ctor_engine_copy.pass.cpp?rev=104946&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.adapt/rand.adapt.shuf/ctor_engine_copy.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.adapt/rand.adapt.shuf/ctor_engine_copy.pass.cpp Fri May 28 10:49:54 2010
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class Engine, size_t k>
+// class shuffle_order_engine
+
+// explicit shuffle_order_engine(const Engine& e);
+
+#include <random>
+#include <cassert>
+
+int main()
+{
+ {
+ typedef std::minstd_rand0 Engine;
+ typedef std::knuth_b Adaptor;
+ Engine e;
+ Adaptor a(e);
+ for (unsigned k = 0; k <= Adaptor::table_size; ++k)
+ e();
+ assert(a.base() == e);
+ }
+}
Added: libcxx/trunk/test/numerics/rand/rand.adapt/rand.adapt.shuf/ctor_engine_move.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/numerics/rand/rand.adapt/rand.adapt.shuf/ctor_engine_move.pass.cpp?rev=104946&view=auto
==============================================================================
--- libcxx/trunk/test/numerics/rand/rand.adapt/rand.adapt.shuf/ctor_engine_move.pass.cpp (added)
+++ libcxx/trunk/test/numerics/rand/rand.adapt/rand.adapt.shuf/ctor_engine_move.pass.cpp Fri May 28 10:49:54 2010
@@ -0,0 +1,32 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <random>
+
+// template<class Engine, size_t k>
+// class shuffle_order_engine
+
+// explicit shuffle_order_engine(const Engine& e);
+
+#include <random>
+#include <cassert>
+
+int main()
+{
+ {
+ typedef std::minstd_rand0 Engine;
+ typedef std::knuth_b Adaptor;
+ Engine e;
+ Engine e0 = e;
+ Adaptor a(std::move(e0));
+ for (unsigned k = 0; k <= Adaptor::table_size; ++k)
+ e();
+ assert(a.base() == e);
+ }
+}
More information about the cfe-commits
mailing list