Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9239843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:05:01+00:00 2026-06-18T08:05:01+00:00

For a parametric class C, I want to get always the primitive type irrespective

  • 0

For a parametric class C, I want to get always the “primitive” type irrespective of pointer, const or reference modifiers.

template<typename __T>
class C
{
public:
    typedef std::some_magic_remove_all<__T>::type T;
}

int main()
{
    C<some_type>::type a;
}

For example, for some_type equal to:

  • int&
  • int**
  • int*&
  • int const &&
  • int const * const
  • and so on

I want a is always of type int. How can I achieve it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:05:02+00:00Added an answer on June 18, 2026 at 8:05 am
    template<class T> struct remove_all { typedef T type; };
    template<class T> struct remove_all<T*> : remove_all<T> {};
    template<class T> struct remove_all<T&> : remove_all<T> {};
    template<class T> struct remove_all<T&&> : remove_all<T> {};
    template<class T> struct remove_all<T const> : remove_all<T> {};
    template<class T> struct remove_all<T volatile> : remove_all<T> {};
    template<class T> struct remove_all<T const volatile> : remove_all<T> {};
    //template<class T> struct remove_all<T[]> : remove_all<T> {};
    //template<class T, int n> struct remove_all<T[n]> : remove_all<T> {};
    

    I originally also stripped extents (arrays), but Johannes noticed that this causes ambiguities for const char[], and the question doesn’t mention them. If we also want to strip arrays (see also ideas mentioned in the comments), the following doesn’t complicate things too much:

    #include <type_traits>
    template<class U, class T = typename std::remove_cv<U>::type>
    struct remove_all { typedef T type; };
    template<class U, class T> struct remove_all<U,T*> : remove_all<T> {};
    template<class U, class T> struct remove_all<U,T&> : remove_all<T> {};
    template<class U, class T> struct remove_all<U,T&&> : remove_all<T> {};
    template<class U, class T> struct remove_all<U,T[]> : remove_all<T> {};
    template<class U, class T, int n> struct remove_all<U,T[n]> : remove_all<T> {};
    

    or with a helper class but a single template parameter:

    #include <type_traits>
    template<class T> struct remove_all_impl { typedef T type; };
    template<class T> using remove_all =
      remove_all_impl<typename std::remove_cv<T>::type>;
    template<class T> struct remove_all_impl<T*> : remove_all<T> {};
    template<class T> struct remove_all_impl<T&> : remove_all<T> {};
    template<class T> struct remove_all_impl<T&&> : remove_all<T> {};
    template<class T> struct remove_all_impl<T[]> : remove_all<T> {};
    template<class T, int n> struct remove_all_impl<T[n]> : remove_all<T> {};
    

    It is normal if all the variants start looking about the same 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a parametric variable in a type class which I would like to
I want to create an abstract base class for all paramter-type classes to inherit
Let's say we have a class that embed another parametric one, that has to
Ok, so I have a parametric interface whose implementation has an inner class. It
I have a question about Parametric Polymorphism. How do I determine the actual type
I would use them to implement factory pattern, for example: class Types{ static const
I have some kind of controller: @Controller public class DefaultController { @RequestMapping(value=/index.html, method=RequestMethod.GET) public
I get an error on my View page thats says: Cannot implicitly convert type
I understand that parametric fields (like x in the example below) behave like normal
I have a parametric curve, say two vectors of doubles where the parameter is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.