C ++ 11 static_assert(及其中使用的函数) [英] C++11 static_assert (and functions to be used therein)
问题描述
static_assert
似乎是一个很好的功能与模板。
static_assert
seems to be a very nice feature together with templates.
在标准库中用于在编译时进行各种测试。
However, I have trouble finding functions in the standard library for doing various tests at compile time.
例如,我正在寻找一个函数来检查类型是否是另一个类型的子类型。 boost :: is_base_of
但是,这个工作是std中的一个类似的功能,所以我不需要依赖boost。
For example, I am looking for a function to check whether a type is a subtype of another one. boost::is_base_of
does the job, however, is a comparable function in std, so I do not need to rely on boost.
基本上,有一个很好的函数列表,可以在 static_assert
中使用, C ++ 11的标准库?
Basically, is there a good source for a list of functions which can be used in static_assert
and are contained in the standard library of C++11?
何时执行 static_assert
?我可以把它放在模板中的任何地方,并对每个模板实例进行评估吗?是否可以用于将模板参数限制为类的特定子类型?
When is static_assert
executed? Can I put it anywhere in a template and it is evaluated for each template instanciation? Could it be used to constrain template parameters to be a specific subtype of a class?
推荐答案
href =http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3242.pdf =nofollow> C ++ 11草稿,第20.7节,特别是< type_traits>
头。
Take a look at the final C++11 draft, section 20.7, particularly the <type_traits>
header.
你要求的是: std: :is_base_of< base,derived> :: value;
关于您的问题: static_assert
- 在模板中:如果表达式使用依赖的名称,在instatiation时间;
这篇关于C ++ 11 static_assert(及其中使用的函数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!