public member function

std::initializer_list::begin

<initializer_list>
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 (iterator) is the same as const E* (where E 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>
#include <string>
#include <sstream>
#include <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 << std::endl;
  return 0;
}


Output:
myobject contains: 10 20 30

See also