This question is in regards to the initialization of the variable value_type value;
I can see that the struct foo is typed as the wrapper<int> but cannot find how wrapped_value.value becomes 42? I don't see an initialization list or a constructor in the foo struct, just f{ 42 }?
Basically, foo<wrapper<int>> and wrapper are "aggregates" because all data members are public and there are no user-declared constructors, that's why you can initialize like that.
Basically, foo<wrapper<int>> and wrapper are "aggregates" because all data members are public and there are no user-declared constructors, that's why you can initialize like that.
this is only for structs, not classes? Thanks for your help btw.
which might make more sense to you because you can think of the outer pair of braces as belonging to the foo<wrapper<int>> object and the inner pair of braces belonging to the wrapper<int> object.
The {} initialization syntax has this rule that you can often remove extra braces (this goes back to C) which is why you can write it with only one pair of braces.
Compare this to how you can initialize a multidimensional array like this:
Technically there is no difference between "class" and "struct" in C++ except for the default accessibility (struct defaults to public while class defaults to private). Your example would work exactly the same if you used the class keyword and explicitly made the members public.