public member function
<initializer_list>
const T* begin() const noexcept;
constexpr const T* begin() const noexcept;
Return iterator to beginning
Return Value
A pointer to the first element in the initializer_list.
T is the type of the elements in the initializer_list (i.e., 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
|
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.