[type_traits] copy constructor

Hello all, What's the most portable way to detect if a type T is CopyConstructible? Actually, I would need a metafunction that is true_ iff a type T has a const-correct copy construct: T::T( T const& other) { /* copy this T from the other T */ } (I've been looking at boost::has_trivial_copy and boost::has_nothrow_copy but I wanted to double check with the ML.) Thanks a lot. --Lorenzo

What's the most portable way to detect if a type T is CopyConstructible?
Actually, I would need a metafunction that is true_ iff a type T has a const-correct copy construct:
T::T( T const& other) { /* copy this T from the other T */ }
(I've been looking at boost::has_trivial_copy and boost::has_nothrow_copy but I wanted to double check with the ML.)
There's no trait for that because we could think of no way of implementing it: it would basically require a "does this code compile" compiler intrinsic which vendors have been very reluctant to provide (read that as v. difficult for them to implement). HTH, John.

Le 29/09/11 04:57, Lorenzo Caminiti a écrit :
Hello all,
What's the most portable way to detect if a type T is CopyConstructible?
Actually, I would need a metafunction that is true_ iff a type T has a const-correct copy construct:
T::T( T const& other) { /* copy this T from the other T */ }
(I've been looking at boost::has_trivial_copy and boost::has_nothrow_copy but I wanted to double check with the ML.)
Hi, The proposed Boost.Conversion provides some interesting traits (included in C++11) that you could be interested in. is_constructible, is_default_constructible, is_copy_constructible, is_move_constructible as well as is_assignable, is_copy_assignable and is_move_assignable. If John is interested in we can work together to include them in TypeTraits. Best, Vicente

Vicente Botet wrote:
Le 29/09/11 04:57, Lorenzo Caminiti a écrit :
Hello all,
What's the most portable way to detect if a type T is CopyConstructible?
Actually, I would need a metafunction that is true_ iff a type T has a const-correct copy construct:
T::T( T const& other) { /* copy this T from the other T */ }
(I've been looking at boost::has_trivial_copy and boost::has_nothrow_copy but I wanted to double check with the ML.)
Hi,
The proposed Boost.Conversion provides some interesting traits (included in C++11) that you could be interested in. is_constructible, is_default_constructible, is_copy_constructible, is_move_constructible as well as is_assignable, is_copy_assignable and is_move_assignable.
If John is interested in we can work together to include them in TypeTraits.
Thanks a lot Vicente. For now, I'm sticking with C++03 but I have a list of extra features that Boost.Contract could support with C++11 for future work. I'll add this (important) feature to the list. --Lorenzo -- View this message in context: http://boost.2283326.n4.nabble.com/type-traits-copy-constructor-tp3854192p38... Sent from the Boost - Dev mailing list archive at Nabble.com.

Le 29/09/11 19:12, lcaminiti a écrit :
Vicente Botet wrote:
Le 29/09/11 04:57, Lorenzo Caminiti a écrit :
Hello all,
What's the most portable way to detect if a type T is CopyConstructible?
Actually, I would need a metafunction that is true_ iff a type T has a const-correct copy construct:
T::T( T const& other) { /* copy this T from the other T */ }
(I've been looking at boost::has_trivial_copy and boost::has_nothrow_copy but I wanted to double check with the ML.)
Hi,
The proposed Boost.Conversion provides some interesting traits (included in C++11) that you could be interested in. is_constructible, is_default_constructible, is_copy_constructible, is_move_constructible as well as is_assignable, is_copy_assignable and is_move_assignable.
If John is interested in we can work together to include them in TypeTraits.
Thanks a lot Vicente. For now, I'm sticking with C++03 but I have a list of extra features that Boost.Contract could support with C++11 for future work. I'll add this (important) feature to the list.
The definition of these traits relies on SFINAE for expressions which is an optional feature for C++03 and mandatory for C++11. Unfortunately this feature is not supported most of C++03 compilers and even msvc 10 which supports some c++11 features doesn't support it. Best, Vicente Best, Vicente

The proposed Boost.Conversion provides some interesting traits (included in C++11) that you could be interested in. is_constructible, is_default_constructible, is_copy_constructible, is_move_constructible as well as is_assignable, is_copy_assignable and is_move_assignable.
If John is interested in we can work together to include them in TypeTraits.
For sure, care to provide a submission/patch? Thanks, John.

John Maddock-3 wrote:
The proposed Boost.Conversion provides some interesting traits (included in C++11) that you could be interested in. is_constructible, is_default_constructible, is_copy_constructible, is_move_constructible as well as is_assignable, is_copy_assignable and is_move_assignable.
If John is interested in we can work together to include them in TypeTraits.
For sure, care to provide a submission/patch?
Thanks, John.
If these (IMO very useful) traits are added, I'd suggest to have macros #defined when the traits can actually do the job-- same as BOOST_HAS_TRIVIAL_COPY, etc. For example, I'd use it this way: template< typename T > struct has_oldof : #if defined(BOOST_HAS_COPY_CONSTRUCTOR) boost::has_copy_constructor<T> // from Boost.Conversion's is_copy_constructible #else boost::mpl::true_ // user specializes has_oldof when can't copy T :( #endif {}; Thanks, --Lorenzo -- View this message in context: http://boost.2283326.n4.nabble.com/type-traits-copy-constructor-tp3854192p38... Sent from the Boost - Dev mailing list archive at Nabble.com.
participants (4)
-
John Maddock
-
lcaminiti
-
Lorenzo Caminiti
-
Vicente J. Botet Escriba