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 7988221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:22:37+00:00 2026-06-04T12:22:37+00:00

So I have a template class that I would like to accept an std::map

  • 0

So I have a template class that I would like to accept an std::map where the data type is either a raw pointer or an std::unique_ptr. Then in this class I would like to get the type of the underlying pointer:

typedef typename boost::mpl::if_<
    boost::is_pointer<typename Container::mapped_type>,
    typename Container::mapped_type,
    typename Container::mapped_type::element_type*
>::type data_type

However I get the following error when instantiating the class using a map with a raw pointer type:

error: 'std::map<int, ValueType*>::mapped_type {aka ValueType*}' is not a class, struct, or union type

It seems to me like it is evaluating typename Container::mapped_type::element_type* on the raw pointer, I thought that with template metaprogramming it would not evaluate that when the if_ succeeded. Should I be going about this a different way?

  • 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-04T12:22:38+00:00Added an answer on June 4, 2026 at 12:22 pm

    You need a lazy if – try boost::mpl::eval_if instead of boost::mpl::if_:

    #include <boost/type_traits/is_pointer.hpp>
    #include <boost/mpl/eval_if.hpp>
    #include <boost/mpl/identity.hpp>
    
    template<typename T>
    struct extract_element_type
    {
        typedef typename T::element_type* type;
    };
    
    template<typename Container>
    struct foo
    {
        typedef typename boost::mpl::eval_if<
            boost::is_pointer<typename Container::mapped_type>,
            boost::mpl::identity<typename Container::mapped_type>,
            extract_element_type<typename Container::mapped_type>
        >::type data_type;
    };
    

    I.e., when in doubt, add an extra layer of indirection.

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

Sidebar

Related Questions

I have a class template Z that I would like specialize when passed a
I have a class that looks roughly like this: template<std::size_t dim> class Foo {
I have a class that contains some data, and I would like to add
We have some code that looks like this: class Serializer { public: template<class Type>
I want to have a template class that looks something like what I have
I have a custom iterator template class that wraps up a std::list iterator. In
I have a templated container class that looks something like this: template <class ItemType>
I have code that looks like this: template<class T> class list { public: class
I have a xml that looks like below <xsl:template match=//xml> <xsl:for-each select=//z:row> <ul class
If possible, I would like to have a function in a class that returns

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.