sizeof... operator(since C++11)| General topics | ||||||||||||||||
| Flow control | ||||||||||||||||
| Conditional execution statements | ||||||||||||||||
| Iteration statements (loops) | ||||||||||||||||
| Jump statements | ||||||||||||||||
| Functions | ||||||||||||||||
| Function declaration | ||||||||||||||||
| Lambda function expression | ||||||||||||||||
inline specifier | ||||||||||||||||
| Dynamic exception specifications(until C++17*) | ||||||||||||||||
noexcept specifier(C++11) | ||||||||||||||||
| Exceptions | ||||||||||||||||
| Namespaces | ||||||||||||||||
| Types | ||||||||||||||||
| Specifiers | ||||||||||||||||
| ||||||||||||||||
| Storage duration specifiers | ||||||||||||||||
| Initialization | ||||||||||||||||
| Expressions | ||||||||||||||||
| Alternative representations | ||||||||||||||||
| Literals | ||||||||||||||||
| Boolean -Integer -Floating-point | ||||||||||||||||
| Character -String -nullptr(C++11) | ||||||||||||||||
| User-defined(C++11) | ||||||||||||||||
| Utilities | ||||||||||||||||
| Attributes(C++11) | ||||||||||||||||
| Types | ||||||||||||||||
typedef declaration | ||||||||||||||||
| Type alias declaration(C++11) | ||||||||||||||||
| Casts | ||||||||||||||||
| Memory allocation | ||||||||||||||||
| Classes | ||||||||||||||||
| Class-specific function properties | ||||||||||||||||
| ||||||||||||||||
| Special member functions | ||||||||||||||||
| Templates | ||||||||||||||||
| Miscellaneous | ||||||||||||||||
| General | ||||
| Literals | ||||
| Operators | ||||
| Conversions | ||||
Queries the number of elements in apack.
Contents |
sizeof...(pack) | |||||||||
Returns a constant of typestd::size_t.
Returns the number of elements in apack.
#include <array>#include <iostream>#include <type_traits> template<typename...Ts>constexprauto make_array(Ts&&...ts){using CT=std::common_type_t<Ts...>;returnstd::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 }