Skip to content

Search topics & cppreference

Search all study topics, concept maps, and 6,587 C++ and C reference pages.

std::initializer_list<T>::size

Obtains the number of elements in the initializer list.

Utility
  • C++11
  • C++14
1 min readView on cppreference
NotebookLM
size_type size() const noexcept;
(since C++11)
(constexpr since C++14)

Obtains the number of elements in the initializer list.

Parameters

(none)

Return value

std::distance(begin(), end())

Complexity

Constant

Example

example.cpp
#include <initializer_list>
 
static_assert(std::initializer_list{1, 2, 3}.size() == 3);
 
int main() {}

Content from this page on cppreference.com, licensed under CC-BY-SA 3.0 and GFDL. Modified: restyled, site navigation removed, code windows added. Offline snapshot of 9 February 2025.