简体   繁体   English

我们可以假设 std::is_default_constructible<t> 和 std::is_constructible<t> 平等吗?</t></t>

[英]Can we assume std::is_default_constructible<T> and std::is_constructible<T> to be equal?

Pretty short question here:这里的问题很短:

Will std::is_default_constructible<T> and std::is_constructible<T> give the same result? std::is_default_constructible<T>std::is_constructible<T>会给出相同的结果吗? And what about to the new concepts std::default_initializable and std::constructible_from .以及新概念std::default_initializablestd::constructible_from呢?

It might be important to know the distinctions when making templated factory or emplace functions.在创建模板化工厂或 emplace 函数时了解它们的区别可能很重要。

So I finally got to reading the specification.所以我终于开始阅读规范了。 Here's what I found:这是我发现的:

20.15.4.3 is_default_constructible<T> : 20.15.4.3 is_default_constructible<T>

As pointed out by @Raymon Chen in the comments: true precisely when is_constructible<T> holds true .正如@Raymon Chen 在评论中指出的那样:恰好当is_constructible<T> true true

18.4.11 constructible_from<T> : 18.4.11 constructible_from<T>

Is defined in term of is_constructible<T> , but also poses the additional requirement destructible<T> .是根据is_constructible<T>定义的,但也提出了额外的要求destructible<T>

18.4.12 default_initializable<T> : 18.4.12 default_initializable<T>

Is defined in term of constructible_from<T> , but also requires T{} to be well-formed.根据constructible_from<T>定义,但也要求T{}格式正确。 Defining a variable of type T must be possible too;定义类型 T 的变量也必须是可能的; Ie the statement T var{};即语句T var{}; should be well-formed.应该是良构的。

Source: N4861 Working Draft, Standard for Programming Language C++资料来源:N4861 工作草案,编程语言标准 C++

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM