[type_traits] is_constructible, ... when decltype is supported?

Hi, when decltype is supported (as it is the case for gcc 4.6.0) we can define the C++0x traits is_constructible, is_assignable and the ones that depend on them. These traits are really important to conform with some of the C++11 interfaces. Next follows one examples from the standard: template (*class... UTypes*) explicit tuple(UTypes&&... u) noexcept; 8 Requires: sizeof...(Types) == sizeof...(UTypes). is_constructible(*Ti, Ui&& *)::value is true for all i. 10 Remark: This constructor shall not participate in overload resolution unless each type in UTypes is implicitly convertible to its corresponding type in Types. In Boost there are some libraries as Boost.Array, Boost.Fusion tuple that defines these kind of constructors or assignments and that require that the template types must be constructible or assignable. The problem when these constructors/assignments don't use of SFINAE to avoid that these functions participate on overload resolution is that is_constructible or is_assignable will give false positive results as the expression could be valid, even if the definition doesn't compiles. I don't know if it is worth including these traits in Boost when the compiler supports decltype so we can start writing conforming interfaces, but at least it would be nice if the Boost libraries start using these standard traits when them are available. Any thoughts? Best, Vicente -- View this message in context: http://boost.2283326.n4.nabble.com/type-traits-is-constructible-when-decltyp... Sent from the Boost - Dev mailing list archive at Nabble.com.

AMDG On 06/05/2011 11:06 AM, Vicente Botet wrote:
when decltype is supported (as it is the case for gcc 4.6.0) we can define the C++0x traits is_constructible, is_assignable and the ones that depend on them.
How exactly does decltype allow you to implement is_constructible? In Christ, Steven Watanabe

Steven Watanabe-4 wrote:
AMDG
On 06/05/2011 11:06 AM, Vicente Botet wrote:
when decltype is supported (as it is the case for gcc 4.6.0) we can define the C++0x traits is_constructible, is_assignable and the ones that depend on them.
How exactly does decltype allow you to implement is_constructible?
We can use it as the return type of the test function. FOr example to test if T can be constructed with two parameters A1, A2 decltype((T(declval<A1>(),declval<A2>()), true_type())) test(int); false_type test(...); Unfortunately, Boost.TypeOf can not be used for the failing checks, as compilation fails. I have committed them in the sandbox under conversion/boost/conversion/type_traits. Best, Vicente -- View this message in context: http://boost.2283326.n4.nabble.com/type-traits-is-constructible-when-decltyp... Sent from the Boost - Dev mailing list archive at Nabble.com.

We can use it as the return type of the test function. FOr example to test if T can be constructed with two parameters A1, A2
decltype((T(declval<A1>(),declval<A2>()), true_type())) test(int); false_type test(...);
Unfortunately, Boost.TypeOf can not be used for the failing checks, as compilation fails.
I have committed them in the sandbox under conversion/boost/conversion/type_traits.
Cool! I think it would be good to have these in type_traits, currently though it seems that only GCC will compile the code - VC10 fails irrespective of whether BOOST_NO_DECLTYPE is set or not :-( I don't suppose there's any chance of a fix/workaround for this? I couldn't see one from a quick hack around, but I thought I'd ask anyway ;-) Cheers, John.

AMDG On 06/07/2011 03:40 AM, John Maddock wrote:
We can use it as the return type of the test function. FOr example to test if T can be constructed with two parameters A1, A2
decltype((T(declval<A1>(),declval<A2>()), true_type())) test(int); false_type test(...);
Unfortunately, Boost.TypeOf can not be used for the failing checks, as compilation fails.
I have committed them in the sandbox under conversion/boost/conversion/type_traits.
I think it would be good to have these in type_traits, currently though it seems that only GCC will compile the code - VC10 fails irrespective of whether BOOST_NO_DECLTYPE is set or not :-( I don't suppose there's any chance of a fix/workaround for this? I couldn't see one from a quick hack around, but I thought I'd ask anyway ;-)
That's because decltype is only incidental to the implementation. The important thing is BOOST_NO_SFINAE_EXPR. In Christ, Steven Watanabe

On 05/06/2011 22:32, Vicente Botet wrote:
We can use it as the return type of the test function. FOr example to test if T can be constructed with two parameters A1, A2
decltype((T(declval<A1>(),declval<A2>()), true_type())) test(int); false_type test(...);
You realize you can do the same thing with sizeof in C++03, when BOOST_NO_SFINAE_EXPR is not defined? Also you shouldn't use decltype directly in the return type if you want portability, it caused mangling problems with some GCC versions. Attached is a C++03-compatible version.

Mathias Gaunard-2 wrote:
On 05/06/2011 22:32, Vicente Botet wrote:
We can use it as the return type of the test function. FOr example to test if T can be constructed with two parameters A1, A2
decltype((T(declval<A1>(),declval<A2>()), true_type())) test(int); false_type test(...);
You realize you can do the same thing with sizeof in C++03, when BOOST_NO_SFINAE_EXPR is not defined?
Also you shouldn't use decltype directly in the return type if you want portability, it caused mangling problems with some GCC versions.
Attached is a C++03-compatible version.
Hi, glad to see that a C++03 version works. Unfortunately it seems that only gcc since 4.4 supports this. Anyway I agree that your solution should be more portable. Best, Vicente -- View this message in context: http://boost.2283326.n4.nabble.com/type-traits-is-constructible-when-decltyp... Sent from the Boost - Dev mailing list archive at Nabble.com.
participants (4)
-
John Maddock
-
Mathias Gaunard
-
Steven Watanabe
-
Vicente Botet