Opened 11 years ago

Closed 4 years ago

#6577 closed Feature Requests (obsolete)

Add meta-function to extract the raw type, meta-function to compare raw types

Reported by: Daryle Walker Owned by: John Maddock
Milestone: Boost 1.50.0 Component: type_traits
Version: Boost Development Trunk Severity: Not Applicable
Keywords: Cc:

Description

Based on the work I did on change-set [77046], can we add my two type-traits to the general library?

The first one extracts the raw type, that removes the top-level reference, const, and/or volatile qualifiers from a type expression. You need the raw type if you want to make a new object and/or apply your own transformations.

template < typename T >
struct remove_cv_ref
{
    typedef typename ::boost::remove_cv<
     typename ::boost::remove_reference<
     typename ::boost::remove_cv<T>::type>::type>::type  type;
};

Unlike my patch code, the version here can handle "T const & volatile". (I don't think automatic code can add a cv-qualifier after a reference, that's why I didn't have it. We have to be more general here.)

The second trait would work like is_same, but compare the raw types.

template < typename T, typename U > 
struct is_related 
    : public ::boost::is_same< 
     typename ::boost::detail::remove_cv_ref<T>::type, 
     typename ::boost::detail::remove_cv_ref<U>::type > 
{};

Like the guy I got the idea from, you could use a template alias to implement this in C++2011.

Change History (1)

comment:1 by John Maddock, 4 years ago

Resolution: obsolete
Status: newclosed

Remove_cv_ref is now in the lib.

Note: See TracTickets for help on using tickets.