public member function
<initializer_list>

std::initializer_list::begin

iterator begin() const noexcept;
Return iterator to beginning
Returns a pointer to the first element in the initializer_list.

Parameters

none

Return Value

A pointer to the first element in the initializer_list.

The return type (member type iterator) is the same as const T* (where T is the class template parameter).

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// initializer_list::begin/end
#include <iostream>          // std::cout
#include <string>            // std::string
#include <sstream>           // std::stringstream
#include <initializer_list>  // std::initializer_list

struct myclass {
  std::string str;
  myclass(std::initializer_list<int> args) {
    std::stringstream ss;
    std::initializer_list<int>::iterator it;  // same as: const int* it
    for ( it=args.begin(); it!=args.end(); ++it) ss << ' ' << *it;
    str = ss.str();
  }
};

int main ()
{
  myclass myobject {10, 20, 30};
  std::cout << "myobject contains:" << myobject.str << '\n';
  return 0;
}


Output:
myobject contains: 10 20 30

Complexity

Constant.

Data races

The object is accessed. All contained elements are constant: Concurrently accessing them is always safe.

Exception safety

No-throw guarantee: this member function never throws exceptions.

See also