functional and type_traits cleanup

François Dumont frs.dumont@gmail.com
Fri Apr 5 20:13:00 GMT 2013


On 04/05/2013 12:20 AM, Jonathan Wakely wrote:
> On 4 April 2013 21:16, François Dumont wrote:
> I think this is mostly very good, thanks for cleaning it up. The 
> indentiation of the closing brace for __is_assignable_helper looks 
> wrong. Is there a reason that __is_assignable_helper::__test uses a 
> default template argument but __is_convertible_helper::__test uses 
> decltype(expr, type) in the function return type? I think the 
> decltype(__test_aux<_Tp1>(...)) expression would work as a default 
> template argument too, which I find easier to read because it doesn't 
> clutter up the return type. 

In fact my first attempt was a very simple one:

   template<typename _From, typename _To>
     class __is_convertible_helper<_From, _To, false>
     {
       template<typename _To1>
     static true_type
     __test(_To1);

       template<typename>
     static false_type
     __test(...);

     public:
       typedef decltype(__test<_To>(std::declval<_From>())) type;
     };

But some tests failed like:
In file included from 
/home/fdt/dev/gcc/build/x86_64-unknown-linux-gnu/libstdc++-v3/include/bits/move.h:57:0,
                  from 
/home/fdt/dev/gcc/build/x86_64-unknown-linux-gnu/libstdc++-v3/include/bits/stl_pair.h:59,
                  from 
/home/fdt/dev/gcc/build/x86_64-unknown-linux-gnu/libstdc++-v3/include/utility:70,
                  from 
/home/fdt/dev/gcc/build/x86_64-unknown-linux-gnu/libstdc++-v3/include/tuple:38,
                  from 
/home/fdt/dev/gcc/build/x86_64-unknown-linux-gnu/libstdc++-v3/include/functional:55,
                  from 
/home/fdt/dev/gcc/src/libstdc++-v3/testsuite/20_util/bind/38889.cc:23:
/home/fdt/dev/gcc/build/x86_64-unknown-linux-gnu/libstdc++-v3/include/type_traits: 
In instantiation of 'struct std::__is_convertible_helper<const 
std::tuple<std::_Placeholder<1> >&, std::_Placeholder<1>, false>':
/home/fdt/dev/gcc/build/x86_64-unknown-linux-gnu/libstdc++-v3/include/type_traits:1321:12: 
required from 'struct std::is_convertible<const 
std::tuple<std::_Placeholder<1> >&, std::_Placeholder<1> >'
/home/fdt/dev/gcc/build/x86_64-unknown-linux-gnu/libstdc++-v3/include/type_traits:111:12: 
required from 'struct std::__and_<std::is_convertible<const 
std::tuple<std::_Placeholder<1> >&, std::_Placeholder<1> > >'
/home/fdt/dev/gcc/build/x86_64-unknown-linux-gnu/libstdc++-v3/include/tuple:400:40: 
required from 'struct std::_Bind<void (*(std::_Placeholder<1>))(int)>'
/home/fdt/dev/gcc/src/libstdc++-v3/testsuite/20_util/bind/38889.cc:28:41: required 
from here
/home/fdt/dev/gcc/build/x86_64-unknown-linux-gnu/libstdc++-v3/include/type_traits:1316:30: 
error: 'std::_Placeholder<1>' is an inaccessible base of 
'std::tuple<std::_Placeholder<1> >'
        typedef decltype(__test<_To>(std::declval<_From>())) type;
                               ^
/home/fdt/dev/gcc/build/x86_64-unknown-linux-gnu/libstdc++-v3/include/type_traits:1309:2: 
error:   initializing argument 1 of 'static std::true_type 
std::__is_convertible_helper<_From, _To, false>::__test(_To1) [with _To1 
= std::_Placeholder<1>; _From = const std::tuple<std::_Placeholder<1> 
 >&; _To = std::_Placeholder<1>; std::true_type = 
std::integral_constant<bool, true>]'
   __test(_To1);
   ^

 From my point of view this is an other example of use case for which 
gcc is not SFINAE friendly enough, no ?

But the version with the default template parameter is fine and more 
consistent with the other helpers implementation so, adopted! Here is an 
other version of the patch for validation.

     Daniel, I agree that inheritance with integral_constant is not as 
obvious as before but it is still there and it is just what the compiler 
need. I even hope that it also simplified a (very) little bit the job 
for the compiler.

Ok to commit ?

François

-------------- next part --------------
A non-text attachment was scrubbed...
Name: cleanup.patch
Type: text/x-patch
Size: 14515 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20130405/3824187c/attachment.bin>


More information about the Libstdc++ mailing list