Przejdź do głównej zawartości

std::initializer_list size() method

// Const version only
size_type size() const noexcept;

Returns the number of elements in the container, i.e. std::distance(begin(), end()).

Parameters

(none)

Return value

The number of elements in the initializer list.

Complexity

Constant - O(1).

Example

Main.cpp
#include <initializer_list>
int main() {
static_assert(std::initializer_list{1,2,3,4}.size() == 4);
}
This article originates from this CppReference page. It was likely altered for improvements or editors' preference. Click "Edit this page" to see all changes made to this document.
Hover to see the original license.

std::initializer_list size() method

// Const version only
size_type size() const noexcept;

Returns the number of elements in the container, i.e. std::distance(begin(), end()).

Parameters

(none)

Return value

The number of elements in the initializer list.

Complexity

Constant - O(1).

Example

Main.cpp
#include <initializer_list>
int main() {
static_assert(std::initializer_list{1,2,3,4}.size() == 4);
}
This article originates from this CppReference page. It was likely altered for improvements or editors' preference. Click "Edit this page" to see all changes made to this document.
Hover to see the original license.