[PATCH] D41316: [libcxx] Allow random_device to be built optionally

Weiming Zhao via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 5 14:59:24 PST 2018


weimingz added a comment.

We can wrap the random_device as a minstd_rand, a linear congruential enginer that a lot of C lib uses for rand().
However based on documentation, we should just provides dummy implementation which throws an exception in the constructor of random_device [1,2]
But compared with run-time exception, a link time error is better if we simply skip the implementation. Any thoughts?

[1]

> explicit random_device(const string& token = implementation-defined );
>  ...
>  Throws: A value of an implementation-defined type derived from exception if the random_device could not be initialized.

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4659.pdf section 29.6.6  Class random_device (page 1082)

[2]

> Notice that random devices may not always be available to produce random numbers (and in some systems, they may even never be available). This is signaled by throwing an exception derived from the standard exception or when a number is requested with operator()

http://www.cplusplus.com/reference/random/random_device/


Repository:
  rCXX libc++

https://reviews.llvm.org/D41316





More information about the cfe-commits mailing list