简体   繁体   中英

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? And what about to the new concepts std::default_initializable and std::constructible_from .

It might be important to know the distinctions when making templated factory or emplace functions.

So I finally got to reading the specification. Here's what I found:

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 .

18.4.11 constructible_from<T> :

Is defined in term of is_constructible<T> , but also poses the additional requirement destructible<T> .

18.4.12 default_initializable<T> :

Is defined in term of constructible_from<T> , but also requires T{} to be well-formed. Defining a variable of type T must be possible too; Ie the statement T var{}; should be well-formed.

Source: N4861 Working Draft, Standard for Programming Language C++

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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