1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <random> 11 12 // template<class Engine, size_t k> 13 // class shuffle_order_engine 14 // { 15 // public: 16 // // types 17 // typedef typename Engine::result_type result_type; 18 19 #include <random> 20 #include <type_traits> 21 22 #include "test_macros.h" 23 24 template <class UIntType, UIntType Min, UIntType Max> 25 class rand1 26 { 27 public: 28 // types 29 typedef UIntType result_type; 30 31 private: 32 result_type x_; 33 34 static_assert(Min < Max, "rand1 invalid parameters"); 35 public: 36 37 #if TEST_STD_VER < 11 && defined(_LIBCPP_VERSION) 38 // Workaround for lack of constexpr in C++03 39 static const result_type _Min = Min; 40 static const result_type _Max = Max; 41 #endif 42 43 static TEST_CONSTEXPR result_type min() {return Min;} 44 static TEST_CONSTEXPR result_type max() {return Max;} 45 46 explicit rand1(result_type sd = Min) : x_(sd) 47 { 48 if (x_ < Min) 49 x_ = Min; 50 if (x_ > Max) 51 x_ = Max; 52 } 53 54 result_type operator()() 55 { 56 result_type r = x_; 57 if (x_ < Max) 58 ++x_; 59 else 60 x_ = Min; 61 return r; 62 } 63 }; 64 65 void 66 test1() 67 { 68 static_assert((std::is_same< 69 std::shuffle_order_engine<rand1<unsigned long, 0, 10>, 16>::result_type, 70 unsigned long>::value), ""); 71 } 72 73 void 74 test2() 75 { 76 static_assert((std::is_same< 77 std::shuffle_order_engine<rand1<unsigned long long, 0, 10>, 16>::result_type, 78 unsigned long long>::value), ""); 79 } 80 81 int main() 82 { 83 test1(); 84 test2(); 85 } 86