Search code examples
c++standards

Temporary materialization on std::initializer_list<T>


I am reading about Temporarily Materialization, and got stuck on this point:

Temporary materialization occurs:

  • when initializing an object of type std::initializer_list<T> from a braced-init-list;

Does this mean that in this case:

std::initializer_list<int> x = std::initializer_list<int>{1,3,5};

the initializer_list is an actual prvalue that is going to be materialized? If that's the case, does this mean that there's no copy elision going on here, even though after C++17 it should apply?


Solution

  • Strictly speaking, it really doesn't matter, because there's no way you could ever observe whether a temporary std::initializer_list object is created.

    But I think the answer is that the "materialization" described is the materialization of a temporary object with type int[3] (array of 3 ints) as described in [dcl.init.list]/5, to which the initializer_list object x is bound; it is not the materialization of a temporary initializer_list object. Copy elision is mandatory in this example.