![](/img/trans.png)
[英]std::is_default_constructible<T> error, if constructor is private
[英]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_initializable
和std::constructible_from
呢?
在創建模板化工廠或 emplace 函數時了解它們的區別可能很重要。
所以我終於開始閱讀規范了。 這是我發現的:
20.15.4.3 is_default_constructible<T>
:
正如@Raymon Chen 在評論中指出的那樣:恰好當is_constructible<T>
true
true
18.4.11 constructible_from<T>
:
是根據is_constructible<T>
定義的,但也提出了額外的要求destructible<T>
。
18.4.12 default_initializable<T>
:
根據constructible_from<T>
定義,但也要求T{}
格式正確。 定義類型 T 的變量也必須是可能的; 即語句T var{};
應該是良構的。
資料來源:N4861 工作草案,編程語言標准 C++
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.