32 #ifndef __Engine_dot_hpp_ 33 #define __Engine_dot_hpp_ 35 #include "../features/compilerfeatures.h" 42 #if RANDOM_ITERATOR_R123_USE_CXX11_TYPE_TRAITS 43 #include <type_traits> 67 template <
typename CBRNG>
69 typedef CBRNG cbrng_type;
70 typedef typename CBRNG::ctr_type ctr_type;
71 typedef typename CBRNG::key_type key_type;
72 typedef typename CBRNG::ukey_type ukey_type;
73 typedef typename ctr_type::value_type result_type;
81 void fix_invariant() {
83 result_type vv = v.back();
97 explicit Engine(result_type r)
100 ukey_type x = {{
typename ukey_type::value_type(r)}};
120 v.back() = e.v.back();
127 v.back() = e.v.back();
131 template <
typename SeedSeq>
132 explicit Engine(SeedSeq& s
133 #
if RANDOM_ITERATOR_R123_USE_CXX11_TYPE_TRAITS
135 typename std::enable_if<
136 !std::is_convertible<SeedSeq, result_type>::value>::type* = 0
141 ukey_type ukey = ukey_type::seed(s);
145 void seed(result_type r) { *
this =
Engine(r); }
146 template <
typename SeedSeq>
148 #
if RANDOM_ITERATOR_R123_USE_CXX11_TYPE_TRAITS
150 typename std::enable_if<
151 !std::is_convertible<SeedSeq, result_type>::value>::type* = 0
156 void seed() { *
this =
Engine(); }
157 friend bool operator==(
const Engine& lhs,
const Engine& rhs) {
158 return lhs.c == rhs.c && lhs.v.back() == rhs.v.back() && lhs.key == rhs.key;
160 friend bool operator!=(
const Engine& lhs,
const Engine& rhs) {
161 return lhs.c != rhs.c || lhs.v.back() != rhs.v.back() || lhs.key != rhs.key;
164 friend std::ostream& operator<<(std::ostream& os,
const Engine& be) {
165 return os << be.c <<
" " << be.key <<
" " << be.v.back();
168 friend std::istream& operator>>(std::istream& is,
Engine& be) {
169 is >> be.c >> be.key >> be.v.back();
185 const static result_type _Min = 0;
186 const static result_type _Max = ~((result_type)0);
188 static RANDOM_ITERATOR_R123_CONSTEXPR result_type min
189 RANDOM_ITERATOR_R123_NO_MACRO_SUBST() {
192 static RANDOM_ITERATOR_R123_CONSTEXPR result_type max
193 RANDOM_ITERATOR_R123_NO_MACRO_SUBST() {
197 result_type operator()() {
199 return b(c.incr(), key)[0];
200 result_type& elem = v.back();
202 v = b(c.incr(), key);
203 result_type ret = v.back();
210 void discard(RANDOM_ITERATOR_R123_ULONG_LONG skip) {
212 size_t nelem = c.size();
213 size_t sub = skip % nelem;
214 result_type& elem = v.back();
231 explicit Engine(
const ukey_type& uk)
236 explicit Engine(ukey_type& uk)
241 void seed(
const ukey_type& uk) { *
this =
Engine(uk); }
242 void seed(ukey_type& uk) { *
this =
Engine(uk); }
244 #if RANDOM_ITERATOR_R123_USE_CXX11_TYPE_TRAITS 245 template <
typename DUMMY =
void>
246 explicit Engine(
const key_type& k,
247 typename std::enable_if<!std::is_same<ukey_type, key_type>::value,
254 template <
typename DUMMY =
void>
255 void seed(
const key_type& k,
256 typename std::enable_if<!std::is_same<ukey_type, key_type>::value,
264 ctr_type operator()(
const ctr_type& c)
const {
return b(c, key); }
266 key_type getkey()
const {
return key; }
271 void setkey(
const key_type& k) {
279 std::pair<ctr_type, result_type> getcounter()
const {
280 return std::make_pair(c, v.back());
284 void setcounter(
const ctr_type& _c, result_type _elem) {
285 static const size_t nelem = c.size();
287 throw std::range_error(
"Engine::setcounter called with elem out of range");
293 void setcounter(
const std::pair<ctr_type, result_type>& ce) {
294 setcounter(ce.first, ce.second);
If G satisfies the requirements of a CBRNG, and has a ctr_type whose value_type is an unsigned integr...