JiaHao Xu
JiaHao Xu

Reputation: 2748

When is std::initializer_list trivially constructible?

In my opinion, I think when the objects of type Ts... used to initialize std::initializer_list<T> can be used to construct T trivially, then std::initializer_list<T> is trivially constructible from Ts... because according to list initialization, each element of std::initializer_list<T> is either direct_initialized or copy_initialized.

However, I'm not sure whether I'm right, so I posted this.

Upvotes: 0

Views: 124

Answers (1)

Nicol Bolas
Nicol Bolas

Reputation: 474126

The question itself does not make sense. That is, you are asking about the presence of a property for an operation for which the property simply doesn't apply.

The 6 special member functions (default constructor, copy/move constructor/assignment operator, and destructor) can be trivial. But these are the only things which can be trivial, for which the term "trivial" has a well-defined meaning.

List initialization isn't doing any of those. At least, not directly.

The process of list initializing an initializer_list involves the creation of a temporary array, putting the values from the braced-init-list into it, and creating an initializer_list that points to that array. None of these are operations for which triviality is even in question, so asking whether they are "trivial" doesn't make sense.

Upvotes: 3

Related Questions