sizeof...
operator (since C++11)
From cppreference.com
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
C++ language
General topics
Conditional execution statements
Iteration statements (loops)
Jump statements
Dynamic exception specifications (until C++17*)
noexcept
specifier (C++11) Exceptions
Namespaces
Types
Specifiers
User-defined (C++11)
Utilities
Attributes (C++11)
Types
Type alias declaration (C++11)
Casts
Memory allocation
Class-specific function properties
Special member functions
Miscellaneous
Expressions
General
Literals
Operators
Conversions
Templates
Variable templates (C++14)
Packs (C++11)
sizeof... (C++11)
Fold expressions (C++17)
Pack indexing (C++26)
Constraints and concepts (C++20)
requires expression (C++20)
Queries the number of elements in a pack.
Contents
[edit] Syntax
sizeof...(
pack )
Returns a constant of type std::size_t .
[edit] Explanation
Returns the number of elements in a pack.
[edit] Keywords
[edit] Example
Run this code
#include <array> #include <iostream> #include <type_traits> template<typename... Ts> constexpr auto make_array(Ts&&... ts) { using CT = std::common_type_t <Ts...>; return std::array <CT, sizeof...(Ts)>{std::forward <CT>(ts)...}; } int main() { std::array <double, 4ul> arr = make_array(1, 2.71f, 3.14, '*'); std::cout << "arr = { "; for (auto s{arr.size()}; double elem : arr) std::cout << elem << (--s ? ", " : " "); std::cout << "}\n"; }
Output:
arr = { 1, 2.71, 3.14, 42 }