gpt4 book ai didi

c++ - std::variant 可以定义多少种类型?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:28:18 28 4
gpt4 key购买 nike

我了解到有一个 std::variant输入 c++17。看起来变体容器不支持预定义的数据类型,但对于每个变体类型,用户可以定义她自己的数据类型集。

std::variant<int, float> v;

我想知道,类型列表可能有多长?该库是否以 Aleksandrescu 方式为最大数量的参数预定义模板,或者编译器支持的变体并且类型数量不受限制?

最佳答案

模板参数的最大数量受编译器实现的限制。

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]

关于c++ - std::variant 可以定义多少种类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39791916/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com