Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many types can std::variant define?

Tags:

c++

c++17

variant

I've learned there is a std::variant type in c++17. Looks like there are no predefined data types supported by the variant container but for each variant type the user may define her own data-type set.

std::variant<int, float> v;

I wonder, how long may the list of types be? Does the library has a predefined templates for a maximal number of parameter in Aleksandrescu manner, or is the variant supported by the compiler and the number of types is not limited?

like image 687
Valentin H Avatar asked Sep 30 '16 12:09

Valentin H


1 Answers

The maximum number of template parameters is limited by the compiler implementation.

The C++ standard says:

Because computers are finite, C ++ implementations are inevitably limited in the size of the programs they can successfully process. Every implementation shall document those limitations where known. This docu mentation may cite fixed limits where they exist, say how to compute variable limits as a function of available resources, or say that fixed limits do not exist or are unknown.

The limits may constrain quantities that include those described below or others. The bracketed number following each quantity is recommended as the minimum for that quantity. However, these quantities are only guidelines and do not determine compliance.

...

Template arguments in a template declaration [1024]

like image 118
Maxim Egorushkin Avatar answered Oct 17 '22 03:10

Maxim Egorushkin