Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<random>: urbg.seed(urbg) does not compile #2707

Closed
strega-nil-ms opened this issue May 4, 2022 · 2 comments
Closed

<random>: urbg.seed(urbg) does not compile #2707

strega-nil-ms opened this issue May 4, 2022 · 2 comments
Labels
bug Something isn't working invalid This issue is incorrect or by design

Comments

@strega-nil-ms
Copy link
Contributor

strega-nil-ms commented May 4, 2022

For every URBG in the standard library, I believe the following should work:

#include <random>

int main() {
    std::linear_congruential_engine<unsigned, 48271U, 0U, 2147483647U> rng1, rng2;
    rng1.seed(rng2);
}

This is due to _Enable_if_seed_seq_t being overspecified - it excludes the type itself from overload resolution, which makes sense for the constructor (since we want the copy constructor to win), but does not make sense for seed.

(note that this works):

#include <random>

int main() {
    std::linear_congruential_engine<unsigned, 48271U, 0U, 2147483647U> rng1;
    std::linear_congruential_engine<unsigned, 48271U, 1U, 2147483647U> rng2;
    rng1.seed(rng2);
}

discovered while investigating #2693

@CaseyCarter CaseyCarter added the bug Something isn't working label May 4, 2022
@CaseyCarter
Copy link
Contributor

The Standard ([tab:rand.req.eng] rows 5-7) says that seed must accept no argument, a result_type value, or an argument that meets the seed sequence requirements. Generally speaking, URBGs don't meet the seed sequence requirements.

TR1 (I'm looking at N1836 Table 16 rows 4-6) says that seed must accept no arguments, a result_type value, or "an lvalue of a type other than [the type of the engine that seed is a member of] that defines a zero-argument function object returning values of unsigned integral type".

So I think this behavior is by design.

@StephanTLavavej StephanTLavavej added the invalid This issue is incorrect or by design label May 4, 2022
@StephanTLavavej
Copy link
Member

We looked at this during the weekly maintainer meeting and determined that @CaseyCarter is correct - the seed sequence requirements involve many member functions such as generate() that the engines don't provide.

@StephanTLavavej StephanTLavavej closed this as not planned Won't fix, can't repro, duplicate, stale May 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working invalid This issue is incorrect or by design
Projects
None yet
Development

No branches or pull requests

3 participants