lundi 30 mars 2015

Why is std::seed_seq non-copyable according to C++11, and why doesn't gcc/clang conform?

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/opt/android-ndk-r10d/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:




  1. Why it is that seed_seq isn't copyable?




  2. 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.


Aucun commentaire:

Enregistrer un commentaire