The header file <random> allows for the seed sequence’s internal sequence to be initialized. An object of class seed_seq can be constructed in multiple ways. I am curious about one of the ways, specifically what C++ technique is being used.
I am looking at the website here: http://www.cplusplus.com/reference/std/random/seed_seq/seed_seq/
And in the example section, I see this line:
std::seed_seq seed2 = {102,406,7892};
What exactly is happening here? It appears a class object is being assigned to an array. I have looked at the initializer-list construct, copy assignment constructor, and I am still confused on what exactly is happening.
I understand std::seed_seq seed3 (foo.begin(),foo.end()); and std::seed_seq seed1;. The first code snippet (seed3) is calling the seed_seq constructor with arguments foo.begin() and foo.end(), and the second code snippet (seed1) is being constructed using the default constructor.
I am not sure I entirely understood your question, as you have almost given the answer yourself. Using something like
{102,406,7892}is a initializer list. A constructor method (or actually any method) with a signature likeMyClass::MyClass(std::initializer_list<int> args)can take this.You may iterate over it using the normal iterator methods
begin()andend(). Its basicly just a convenient way to pass a list of arbitary length in code without having to instancinate a “normal”std::listorstd::vector(and keep callingpush_back()on that) or an array.As a bonus, you can also construct the standard containers using initializer lists:
std::vector<std::string> vec {"hello", "world"}. This allows you to use the standard containers as argument types for functions that can still be called using an initializer_list.