Member Functions of std::initializer_list

The following are some of the commonly used member functions of the std::initialzer_list class:

S. No.

Function Name

Description

1

begin()

Returns a pointer to the first element of the initializer list.

2

end()

Returns a pointer to the last element of the initializer list.

3

size()

The size() function returns the number of elements present in the initializer list.

4

empty()

This function returns true if the initializer list is empty. False otherwise.

5

data()

Returns a pointer to the underlying array container.

std::initializer_list in C++ 11

The std::initializer_list class template was added in C++ 11 and contains many built-in functions to perform various operations with the initializer list. It provides member functions like a size(), begin(), end(), and constructor to construct, iterate, and access elements of the initializer list.

To use initializer_list, you need to include the <initializer_list> header in your C++ program.

Similar Reads

std::initializer_list in C++

In C++, the std::initializer_list is a class template that allows us to initialize a lightweight object with a list of values. An initializer list is used to set values to variables, arrays, classes, functions, constructors of classes, and standard containers like vectors in a convenient way....

Examples of std::initializer_list in C++

Example 1:...

Member Functions of std::initializer_list

...

Applications of initializer_list

...

Limitations of initializer_list

The following are some of the commonly used member functions of the std::initialzer_list class:...

Contact Us