From 3ec31849dfebedd223d6c1ab4271afe67ef1c8e8 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Fri, 28 May 2010 15:49:54 +0000 Subject: [PATCH] Implemented some adaptor constructors which I had missed. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@104946 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/random | 69 +++++++++++++++---- .../rand.adapt.disc/ctor_engine_copy.pass.cpp | 29 ++++++++ .../rand.adapt.disc/ctor_engine_move.pass.cpp | 30 ++++++++ .../ctor_engine_copy.pass.cpp | 29 ++++++++ .../ctor_engine_move.pass.cpp | 30 ++++++++ .../rand.adapt.shuf/ctor_engine_copy.pass.cpp | 31 +++++++++ .../rand.adapt.shuf/ctor_engine_move.pass.cpp | 32 +++++++++ 7 files changed, 235 insertions(+), 15 deletions(-) create mode 100644 test/numerics/rand/rand.adapt/rand.adapt.disc/ctor_engine_copy.pass.cpp create mode 100644 test/numerics/rand/rand.adapt/rand.adapt.disc/ctor_engine_move.pass.cpp create mode 100644 test/numerics/rand/rand.adapt/rand.adapt.ibits/ctor_engine_copy.pass.cpp create mode 100644 test/numerics/rand/rand.adapt/rand.adapt.ibits/ctor_engine_move.pass.cpp create mode 100644 test/numerics/rand/rand.adapt/rand.adapt.shuf/ctor_engine_copy.pass.cpp create mode 100644 test/numerics/rand/rand.adapt/rand.adapt.shuf/ctor_engine_move.pass.cpp diff --git a/include/random b/include/random index f3e6656c0..86663afab 100644 --- a/include/random +++ b/include/random @@ -1834,7 +1834,8 @@ public: // constructors and seeding functions explicit linear_congruential_engine(result_type __s = default_seed) {seed(__s);} - template explicit linear_congruential_engine(_Sseq& __q) + template explicit linear_congruential_engine(_Sseq& __q, + typename enable_if::value>::type* = 0) {seed(__q);} void seed(result_type __s = default_seed) {seed(integral_constant(), @@ -2073,7 +2074,8 @@ public: // constructors and seeding functions explicit mersenne_twister_engine(result_type __sd = default_seed) {seed(__sd);} - template explicit mersenne_twister_engine(_Sseq& __q) + template explicit mersenne_twister_engine(_Sseq& __q, + typename enable_if::value>::type* = 0) {seed(__q);} void seed(result_type __sd = default_seed); template @@ -2431,7 +2433,8 @@ public: // constructors and seeding functions explicit subtract_with_carry_engine(result_type __sd = default_seed) {seed(__sd);} - template explicit subtract_with_carry_engine(_Sseq& __q) + template explicit subtract_with_carry_engine(_Sseq& __q, + typename enable_if::value>::type* = 0) {seed(__q);} void seed(result_type __sd = default_seed) {seed(__sd, integral_constant());} @@ -2680,14 +2683,26 @@ public: // 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 explicit discard_block_engine(_Sseq& __q) + template explicit discard_block_engine(_Sseq& __q, + typename enable_if::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 void seed(_Sseq& __q) {__e_.seed(__q); __n_ = 0;} + template + 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 @@ public: // 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 explicit independent_bits_engine(_Sseq& __q) + template explicit independent_bits_engine(_Sseq& __q, + typename enable_if::value && + !is_convertible<_Sseq, _Engine>::value>::type* = 0) : __e_(__q) {} void seed() {__e_.seed();} void seed(result_type __sd) {__e_.seed(__sd);} - template void seed(_Sseq& __q) {__e_.seed(__q);} + template + 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());} @@ -3051,14 +3078,26 @@ public: // 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 explicit shuffle_order_engine(_Sseq& __q) + template explicit shuffle_order_engine(_Sseq& __q, + typename enable_if::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 void seed(_Sseq& __q) {__e_.seed(__q); __init();} + template + 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());} diff --git a/test/numerics/rand/rand.adapt/rand.adapt.disc/ctor_engine_copy.pass.cpp b/test/numerics/rand/rand.adapt/rand.adapt.disc/ctor_engine_copy.pass.cpp new file mode 100644 index 000000000..3b1ce9287 --- /dev/null +++ b/test/numerics/rand/rand.adapt/rand.adapt.disc/ctor_engine_copy.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// + +// template +// class discard_block_engine + +// explicit discard_block_engine(const Engine& e); + +#include +#include + +int main() +{ + { + typedef std::ranlux24_base Engine; + typedef std::ranlux24 Adaptor; + Engine e; + Adaptor a(e); + assert(a.base() == e); + } +} diff --git a/test/numerics/rand/rand.adapt/rand.adapt.disc/ctor_engine_move.pass.cpp b/test/numerics/rand/rand.adapt/rand.adapt.disc/ctor_engine_move.pass.cpp new file mode 100644 index 000000000..fc2f1aac0 --- /dev/null +++ b/test/numerics/rand/rand.adapt/rand.adapt.disc/ctor_engine_move.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// + +// template +// class discard_block_engine + +// explicit discard_block_engine(const Engine& e); + +#include +#include + +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); + } +} diff --git a/test/numerics/rand/rand.adapt/rand.adapt.ibits/ctor_engine_copy.pass.cpp b/test/numerics/rand/rand.adapt/rand.adapt.ibits/ctor_engine_copy.pass.cpp new file mode 100644 index 000000000..122e4da30 --- /dev/null +++ b/test/numerics/rand/rand.adapt/rand.adapt.ibits/ctor_engine_copy.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// + +// template +// class independent_bits_engine + +// explicit independent_bits_engine(const Engine& e); + +#include +#include + +int main() +{ + { + typedef std::mt19937 Engine; + typedef std::independent_bits_engine Adaptor; + Engine e; + Adaptor a(e); + assert(a.base() == e); + } +} diff --git a/test/numerics/rand/rand.adapt/rand.adapt.ibits/ctor_engine_move.pass.cpp b/test/numerics/rand/rand.adapt/rand.adapt.ibits/ctor_engine_move.pass.cpp new file mode 100644 index 000000000..0de24c65d --- /dev/null +++ b/test/numerics/rand/rand.adapt/rand.adapt.ibits/ctor_engine_move.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// + +// template +// class independent_bits_engine + +// explicit independent_bits_engine(const Engine& e); + +#include +#include + +int main() +{ + { + typedef std::mt19937 Engine; + typedef std::independent_bits_engine Adaptor; + Engine e; + Engine e0 = e; + Adaptor a(std::move(e0)); + assert(a.base() == e); + } +} diff --git a/test/numerics/rand/rand.adapt/rand.adapt.shuf/ctor_engine_copy.pass.cpp b/test/numerics/rand/rand.adapt/rand.adapt.shuf/ctor_engine_copy.pass.cpp new file mode 100644 index 000000000..5937a129a --- /dev/null +++ b/test/numerics/rand/rand.adapt/rand.adapt.shuf/ctor_engine_copy.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// + +// template +// class shuffle_order_engine + +// explicit shuffle_order_engine(const Engine& e); + +#include +#include + +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); + } +} diff --git a/test/numerics/rand/rand.adapt/rand.adapt.shuf/ctor_engine_move.pass.cpp b/test/numerics/rand/rand.adapt/rand.adapt.shuf/ctor_engine_move.pass.cpp new file mode 100644 index 000000000..1538cfa3f --- /dev/null +++ b/test/numerics/rand/rand.adapt/rand.adapt.shuf/ctor_engine_move.pass.cpp @@ -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. +// +//===----------------------------------------------------------------------===// + +// + +// template +// class shuffle_order_engine + +// explicit shuffle_order_engine(const Engine& e); + +#include +#include + +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); + } +}