Search code examples
c++pointerspass-by-referenceinitializer-listpass-by-value

Using data on an initializer_list


So I'm looking at the data function and I see that it has this overload:

template <class E>
constexpr const E* data(std::initializer_list<E> il) noexcept;

Let's say that I call foo(data({ 0, 13, 42 })) with:

void foo(const int* param) {
    cout << param[0] << ' ' << param[1] << ' ' << param[2] << endl;
}

Am I in fact making a copy of the initializer_list?


Solution

  • Yes, you are making a copy of the initializer_list.

    But, you are not making a copy of the "list of integers".

    An initializer_list is basically a pointer and a length.