Reputation: 60268
While going through the various rules on list-initialization, I found this in dcl.init.list#3.6:
Otherwise, if T is a specialization of
std::initializer_list<E>
, the object is constructed as described below.
On the other hand, in the synopsis of std::initializer_list
, in support.initlist, I found the following statement:
If an explicit specialization or partial specialization of
initializer_list
is declared, the program is ill-formed.
These appear to be contradictory statements, so what am I misunderstanding?
Upvotes: 0
Views: 261
Reputation: 96719
"A template specialization" has two distinct meanings:
"Explicit (full) specialization" or "partial specialization" - a language construct that changes the meaning of a template for some combination of template parameters.
Something that was generated from a template by substituting template arguments into it.
In other words, if you specify template arguments for a template, the resulting type/function/variable/... is a specialization of that template. E.g. std::vector<int>
is a specialization of std::vector
.
Looks like the first passage you quote uses (2).
So "if T
is a specialization of std::initializer_list<E>
" roughly means "if there exists such E
that std::is_same_v<T, std::initializer_list<E>>
", or "if T
is a std::initializer_list<E>
".
Upvotes: 4
Reputation: 180955
There is no contradiction.
If an explicit specialization or partial specialization of initializer_list is declared, the program is ill-formed.
Means you cannot declare a specialization. The compiler itself is allowed to stamp out specializations of std::initializer_list
The thing that might be causing you issue is that the concrete type you get out of a template is called a specialization. This is what the first paragraph is talking about. The second paragraph is talking about actually defining/declaring a specialization for std::initializer_list
Upvotes: 2