This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [v3] ext/type_traits.h


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]