为什么大小不是std :: initializer_list的模板参数? [英] Why is the size not a template argument of std::initializer_list?
问题描述
std :: initializer_list
由编译器从括号括起的init列表构建,并且此列表的大小必须是编译时常量。
std::initializer_list
is constructed by the compiler from a brace-enclosed init list and the size of this list must be a compile time constant.
那么为什么委员会决定从模板参数中忽略大小呢?这可能会阻止一些优化,并使某些事情变得不可能(从 std :: initializer_list
中初始化 std :: array
)。
So why did the committee decide to omit the size from the template arguments? This possibly prevents some optimizations and makes some things impossible (initializing std::array
from a std::initializer_list
).
推荐答案
现有系统的一个优点是,您可以导出需要 initializer_list
从DLL。如果它是在模板上的大小,他们必须作为来源。
One upside of the existing system is that you can export functions which take an initializer_list
from a DLL. If it were templated on the size, they would have to be shipped as source.
这篇关于为什么大小不是std :: initializer_list的模板参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!