- friend bool operator==(const subtract_with_carry& x, const subtract_with_carry& y)
- {
- for(unsigned int j = 0; j < r; ++j)
- if(x.compute(j) != y.compute(j))
- return false;
- return true;
- }
-
- friend bool operator!=(const subtract_with_carry& x, const subtract_with_carry& y)
- { return !(x == y); }
-#else
- // Use a member function; Streamable concept not supported.
- bool operator==(const subtract_with_carry& rhs) const
- {
- for(unsigned int j = 0; j < r; ++j)
- if(compute(j) != rhs.compute(j))
- return false;
- return true;
- }
-
- bool operator!=(const subtract_with_carry& rhs) const
- { return !(*this == rhs); }
-#endif
+ /**
+ * Seeds the generator with values from a range. Updates @c first to
+ * point one past the last consumed value. If the range does not
+ * contain enough elements to fill the entire state of the generator,
+ * throws @c std::invalid_argument.
+ */
+ template<class It>
+ void seed(It& first, It last)
+ {
+ detail::fill_array_int<w>(first, last, x);
+ carry = (x[long_lag-1] == 0);
+ k = 0;
+ }
+
+ /** Returns the smallest value that the generator can produce. */
+ static result_type min BOOST_PREVENT_MACRO_SUBSTITUTION ()
+ { return 0; }
+ /** Returns the largest value that the generator can produce. */
+ static result_type max BOOST_PREVENT_MACRO_SUBSTITUTION ()
+ { return boost::low_bits_mask_t<w>::sig_bits; }
+
+ /** Returns the next value of the generator. */
+ result_type operator()()
+ {
+ std::size_t short_index =
+ (k < short_lag)?
+ (k + long_lag - short_lag) :
+ (k - short_lag);
+ carry = do_update(k, short_index, carry);
+ IntType result = x[k];
+ ++k;
+ if(k >= long_lag)
+ k = 0;
+ return result;
+ }
+
+ /** Advances the state of the generator by @c z. */
+ void discard(boost::uintmax_t z)
+ {
+ detail::subtract_with_carry_discard::apply(*this, z);
+ }
+
+ /** Fills a range with random values. */
+ template<class It>
+ void generate(It first, It last)
+ { detail::generate_from_int(*this, first, last); }
+
+ /** Writes a @c subtract_with_carry_engine to a @c std::ostream. */
+ BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, subtract_with_carry_engine, f)
+ {
+ for(unsigned int j = 0; j < f.long_lag; ++j)
+ os << f.compute(j) << ' ';
+ os << f.carry;
+ return os;
+ }
+
+ /** Reads a @c subtract_with_carry_engine from a @c std::istream. */
+ BOOST_RANDOM_DETAIL_ISTREAM_OPERATOR(is, subtract_with_carry_engine, f)
+ {
+ for(unsigned int j = 0; j < f.long_lag; ++j)
+ is >> f.x[j] >> std::ws;
+ is >> f.carry;
+ f.k = 0;
+ return is;
+ }
+
+ /**
+ * Returns true if the two generators will produce identical
+ * sequences of values.
+ */
+ BOOST_RANDOM_DETAIL_EQUALITY_OPERATOR(subtract_with_carry_engine, x, y)
+ {
+ for(unsigned int j = 0; j < r; ++j)
+ if(x.compute(j) != y.compute(j))
+ return false;
+ return true;
+ }
+
+ /**
+ * Returns true if the two generators will produce different
+ * sequences of values.
+ */
+ BOOST_RANDOM_DETAIL_INEQUALITY_OPERATOR(subtract_with_carry_engine)