Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

reference type as type traits / concept argument

In the specification-mandated implementation of the concept std::uniform_random_bit_generator, it is required that invoking operator() on an instance of type G satisfying this concept should return the same type as G::min() and G::max().

Why is std::same_as<std::invoke_result_t<G&>> used instead of
std::same_as<std::invoke_result_t<G>>? What the difference?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

std::invocable<G&> checks whether an lvalue of type G can be invoked (without arguments). std::invocable<G> checks whether a rvalue of type G can be invoked (without arguments).

std::invoke_result_t is equivalently the corresponding return type.

In other words this guarantees that the generator can be declared as a variable and then invoked, e.g.

G g{/*args*/};
auto res = g();

But it does not guarantee that a temporary of type G can be invoked directly, e.g.

auto res = G{/*args*/}();

This is not how a random number generator is commonly used.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading