This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++11 status.

1436. Random number engine constructor concerns

Section: 28.5.4 [rand.eng] Status: C++11 Submitter: BSI Opened: 2010-08-25 Last modified: 2016-01-28

Priority: Not Prioritized

View all other issues in [rand.eng].

View all issues with C++11 status.

Discussion:

Addresses GB-121

All the random number engine types in this clause have a constructor taking an unsigned integer type, and a constructor template for seed sequences. This means that an attempt to create a random number engine seeded by an integer literal must remember to add the appropriate unsigned suffix to the literal, as a signed integer will attempt to use the seed sequence template, yielding undefined behaviour, as per 26.5.1.1p1a. It would be helpful if at least these anticipated cases produced a defined behaviour, either an erroneous program with diagnostic, or a conversion to unsigned int forwarding to the appropriate constructor.

[ 2010-11-03 Daniel comments and provides a proposed resolution: ]

I suggest to apply a similar solution as recently suggested for 1234. It is basically a requirement for an implementation to constrain the template.

[ 2010-11-04 Howard suggests to use !is_convertible<Sseq, result_type>::value as minimum requirement instead of the originally proposed !is_scalar<Sseq>::value. This would allow for a user-defined type BigNum, that is convertible to result_type, to be used as argument for a seed instead of a seed sequence. The wording has been updated to reflect this suggestion. ]

[ 2010 Batavia: There were some initial concerns regarding the portability and reproducibility of results when seeded with a negative signed value, but these concerns were allayed after discussion. Thus, after reviewing the issue, the working group concurred with the issue's Proposed Resolution. ]

[ Adopted at 2010-11 Batavia ]

Proposed resolution:

Add the following paragraph at the end of 28.5.4 [rand.eng]:

5 Each template specified in this section [rand.eng] requires one or more relationships, involving the value(s) of its non-type template parameter(s), to hold. A program instantiating any of these templates is ill-formed if any such required relationship fails to hold.

? For every random number engine and for every random number engine adaptor X defined in this sub-clause [rand.eng] and in sub-clause [rand.adapt]:

The extent to which an implementation determines that a type cannot be a seed sequence is unspecified, except that as a minimum a type shall not qualify as seed sequence, if it is implicitly convertible to X::result_type.