[英]Deprecated std::is_literal_type in C++17
According to cppreference , the trait std::is_literal_type
is deprecated in C++17. 根据cppreference ,特性
std::is_literal_type
在C ++ 17中已弃用。 The question is why and what is the preferred replacement for the future to check whether a type is a literal type . 问题是为什么以及什么是未来的首选替代品来检查类型是否是文字类型 。
As stated in P0174 : 如P0174所述 :
The
is_literal
type trait offers negligible value to generic code, as what is really needed is the ability to know that a specific construction would produce constant initialization.is_literal
类型特征为通用代码提供的值可忽略不计,因为真正需要的是能够知道特定构造将产生持续初始化。 The core term of a literal type having at least one constexpr constructor is too weak to be used meaningfully.具有至少一个constexpr构造函数的文字类型的核心术语太弱而无法有意义地使用。
Basically, what it's saying is that there's no code you can guard with is_literal_type_v
and have that be sufficient to ensure that your code actually is constexpr. 基本上,它所说的是没有代码可以用
is_literal_type_v
来保护,并且这足以确保你的代码实际上是constexpr。 This isn't good enough: 这还不够好:
template<typename T>
std::enable_if_t<std::is_literal_type_v<T>, void> SomeFunc()
{
constexpr T t{};
}
There's no guarantee that this is legal. 不保证这是合法的。 Even if you guard it with
is_default_constructible<T>
that doesn't mean that it's constexpr default constructible. 即使用
is_default_constructible<T>
来保护它,也不意味着它是constexpr默认的可构造性。
What you would need is an is_constexpr_constructible
trait. 你需要的是一个
is_constexpr_constructible
特征。 Which does not as of yet exist. 哪个尚未存在。
However, the (already implemented) trait does no harm, and allows compile-time introspection for which core-language type-categories a given template parameter might satisfy.
但是,(已经实现的)特性没有任何损害,并允许编译时内省检查给定模板参数可能满足的核心语言类型类别。 Until the Core Working Group retire the notion of a literal type, the corresponding library trait should be preserved.
在核心工作组退出文字类型的概念之前,应保留相应的库特征。
The next step towards removal (after deprecation) would be to write a paper proposing to remove the term from the core language while deprecating/removing the type trait.
删除(弃用之后)的下一步是撰写一篇文章,建议在弃用/删除类型特征时从核心语言中删除该术语。
So the plan is to eventually get rid of the whole definition of "literal types", replacing it with something more fine-grained. 所以计划最终要摆脱“文字类型”的整个定义,用更细粒度的东西取而代之。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.