std::begin(std::initializer_list)

1
2
template< class E >
const E* begin( initializer_list<E> il );
(since C++11)
(until C++14)
1
2
template< class E >
constexpr const E* begin( initializer_list<E> il );
(since C++14)

The overload of std::begin for initializer_list returns a pointer to the first element of il.

Parameters

il - an initializer_list

Return value

il.begin().

Exceptions

noexcept specification:
noexcept

Example

1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include <initializer_list>
  
int main()
{
    std::initializer_list<int> il = {3, 1, 4, 1};
    for(auto it = std::begin(il); it != std::end(il); ++it) {
        std::cout << *it << '\n';
    }
}

Output:

1
2
3
4
3
1
4
1

See also

returns a pointer to the first element
(public member function)
doc_CPP
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.