Consider the following minimal example:
// main.cpp
#include <random>
int main(int, char **)
{
std::seed_seq seed1{1337, 42};
std::seed_seq seed2(seed1);
std::seed_seq seed3 = seed2;
return 0;
}
According to the C++ standard, this shouldn't compile, as std::seed_seq
is neither copy constructible, nor copy assignable.
However, this compiles fine with both g++ 4.9
, and clang 3.4
g++-4.9 -std=c++11 -Wall main.cpp
clang++ -std=c++11 -Wall main.cpp
The android ndk's llvm-libc++
implementation seems to follow the "not copyable" property of seed_seq
. Which can be confirmed in the source at
android-ndk-r10d/sources/cxx-stl/llvm-libc++/libcxx/include/random:3553
Or by compiling the minimal example using
${NDK_HOME}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ \
-std=c++11 -c -Wall \
-I${NDK_HOME}/sources/cxx-stl/llvm-libc++/libcxx/include \
-I${NDK_HOME}/sources/cxx-stl/llvm-libc++/../llvm-libc++abi/libcxxabi/include \
-I${NDK_HOME}/sources/cxx-stl/llvm-libc++/../../android/support/include \
-isystem ${NDK_HOME}/platforms/android-18/arch-arm/usr/include \
main.cpp
I've previously used this (without being aware of my non-conforming code) to store a copy of the seed for logging purposes.*
I'm left wondering:
Why it is that seed_seq
isn't copyable?
This is the first time I've encountered g++
and clang
to not conform to the standard. Is it a conscious decision to deviate from the standard, or is this an implementation bug? How prevalent is this? I'd like to learn more.
* I realized that I was thinking of seed_seq
wrong, and that if I'm only interested in the seed_seq::param
values (the seed_seeq
's initial seed values), that I should instead keep my copy in a vector<T>
, instead of a type that is meant to generate integers.
For those who see this in the future, as per T.C. and ecatmur, this is libstdc++ bug 65631. There's no ETA on a fix though; the behavior conformed with the original proposal, but this was changed to remove copyability from the concept to address LWG issue 1069, as per the N3037 paper.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With