Boost logo

Boost :

From: Howard Hinnant (hinnant_at_[hidden])
Date: 2000-10-30 16:58:01


John Maddock wrote on 10/28/2000 7:27 AM
>1) All the templates will be insensitive to cv-qualifiers, except for those
>like has_trivial_xxxx, which *must* take cv-qualifiers into account.

"All" makes me a little nervous. I would expect is_same<int,const
int>::value to be false. I suspect you were not speaking of is_same when
you said "All", but I thought I'd better double check.

>3) depreciate the is_standard_xxx and is_extension_xxx templates - really
>just to simplify the library - is anyone using these?

I'm not using them.

How about adding:

is_signed
is_unsigned

Admittedly you should also be able to get this info from numeric_limits.
But is_signed is arguably more convenient.

template <class T> struct is_signed
        {static const bool value = T(-1) < T(0);};

And adding:

is_extension

True for built-in types that are not standard such as long long or
_int64. is_extension is relatively easy to have and maintain compared to
is_extension_xxx. long long would also answer true to is_integral and
is_signed.

Just browsing the remove_xxx series. How about remove_pointer? Removes
top level pointer if present.

template <class T> struct remove_pointer {typedef T
type;};
template <class T> struct remove_pointer<T*> {typedef T
type;};
template <class T> struct remove_pointer<T*const> {typedef T
type;};
template <class T> struct remove_pointer<T*volatile> {typedef T
type;};
template <class T> struct remove_pointer<T*const volatile> {typedef T
type;};

And then remove_all is also cute: remove cv, references, arrays, and
pointers until you are left with a fundamental, enum, union, class or
member pointer.

namespace details
{

        template <class T>
        struct strip
        {
                typedef typename remove_cv<
                        typename remove_pointer<
                                typename remove_reference<
                                        typename remove_bounds<T>::type
>::type
>::type
>::type type;
        };

        template <class T, class U>
        struct strip_aux
        {
                typedef typename strip_aux<typename strip<T>::type, typename
strip<U>::type>::type type;
        };

        template <class T>
        struct strip_aux<T, T>
        {
                typedef T type;
        };

}

template <class T>
struct remove_all
{
        typedef typename details::strip_aux<T, typename
details::strip<T>::type>::type type;
};

remove_all can be used to build stuff like has_extension (or has_integral
or has_floating). Returns true if type is composed of an extension:

template <class T> struct has_extension
{
        static const bool value = is_extension<typename
remove_all<T>::type>::value;
};

I'm not suggesting has_extension. I'm just demonstrating a use for
remove_all.

-Howard


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk