My question is about the lack of conversions between std::initializer_list
types where the contained type is more or less cv qualified when those conversions appear to be easily doable.
Consider the following code which is invalid:
std::initializer_list<int> x{1,2,3,4,5,6};
std::initializer_list<int const> y = x; // error! cannot convert!
Now consider std::optional
and ignore the ridiculous types:
std::optional<std::vector<int>> x{std::in_place, {1,2,3,4,5}}; // OK
std::optional<std::vector<int const>> y{std::in_place, {1,2,3,4,5}}; // error!
I assume the language spec requires deducing non cv qualified U
's for std::initializer_list<U>
by default.
As far as I can tell, the whole point of std::optional
(and std::any
and std::variant
) having std::initializer_list
constructor overloads is to avoid specifying the exact type of the initializer list. To get the second line of the above code to compile, that's exactly what you must do.
std::initializer_list
already holds a const*
to it's data (in libc++
anyhow). There's no reason I can see for the above code not to work? Is this a solvable issue in the language, or am I missing something?