[v3] ext/type_traits.h

Howard Hinnant hhinnant@apple.com
Thu Sep 28 21:29:00 GMT 2006


On Sep 28, 2006, at 4:45 PM, Martin Sebor wrote:

> Peter Dimov wrote:
>> Martin Sebor wrote:
>>> The standalone add_unsigned critters would be okay too. They
>>> would be in line with all the other little traits classes. I
>>> don't see a big advantage of one approach over the other.
>> The standalone to_unsigned can be used as a metafunction.
>
> Ah, neat. I hadn't thought of that. And the limits one couldn't
> because...? It doesn't have the right name?

Iiuc, yes.  Here's a trivial trait that takes a metafunction as a  
template template parameter (F):

template <template <class> class F, class T>
struct test_identity
{
     static const bool value = std::is_same<typename F<T>::type,  
T>::value;
};

For:

     std::cout << test_identity<std::remove_pointer, int>::value <<  
'\n';
     std::cout << test_identity<std::remove_pointer, int*>::value <<  
'\n';
     std::cout << test_identity<std::add_pointer, int>::value << '\n';
     std::cout << test_identity<std::add_pointer, int*>::value << '\n';

should print out:

1
0
0
0

meaning remove_pointer is the identity operation for int, but not  
int*.  And add_pointer is the identity operation for neither of those  
two types.

One might imagine some similar test or trait where supplying  
add_unsigned would work, because it has a nested "type", and  
numeric_limits would fail.

-Howard



More information about the Libstdc++ mailing list