sizeof... operator

Queries the number of elements in a parameter pack.

Syntax

sizeof...( parameter_pack ) (since C++11)

Returns a constant of type std::size_t.

Explanation

Returns the number of elements in a parameter pack.

Keywords

sizeof.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <array>
  
template<typename... Ts>
constexpr auto make_array(Ts&&... ts)
    -> std::array<std::common_type_t<Ts...>,sizeof...(ts)>
{
    return { std::forward<Ts>(ts)... };
}
  
int main()
{
    auto b = make_array(1, 2, 3);
    std::cout << b.size() << '\n';
    for (auto i : b)
        std::cout << i << ' ';
}

Output:

1
2
3
1 2 3

See also

doc_CPP
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.