我们可以假设 std::is_default_constructible<T> 和 std::is_constructible<T> 相等吗?

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

这里的问题很短:

std::is_default_constructible<T>std::is_constructible<T>会得到相同的结果吗? 那么新概念 std::default_initializablestd::constructible_from.

了解制作模板化工厂或 emplace 函数时的区别可能很重要。

所以我终于开始阅读规范了。这是我的发现:

20.15.4.3 is_default_constructible<T>:

正如@Raymon Chen 在评论中指出的那样:true 正是当 is_­constructible<T> 成立时 true

18.4.11 constructible_from<T>:

是根据 is_constructible<T> 定义的,但也提出了附加要求 destructible<T>

18.4.12 default_initializable<T>:

是根据constructible_from<T>定义的,但也要求T{}是well-formed。定义类型 T 的变量也必须是可能的; IE。语句 T var{}; 应该是 well-formed.

来源:N4861 工作草案,编程标准 语言 C++