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

  • Home
  • SEARCH
  • 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 572523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:37:19+00:00 2026-05-13T13:37:19+00:00

I have a boost multi index container thus. using namespace boost::multi_index; template < typename

  • 0

I have a boost multi index container thus.

using namespace boost::multi_index;
template < typename O >
class Container
{
public:
    multi_index_container<
        O,
        indexed_by<
            ordered_unique<
                const_mem_fun< O, std::string, &O::name >
            >
        >
    > _container;
};

As you can see, by this design every object I use to create this container has to have a member function returning a string with the name “name”.

This is obviously not ideal. I tried a couple of ways of passing in the “key” but I can’t get any of them to work..

I tried this..

using namespace boost::multi_index;
template < typename O, typename KT, typename KM >
class Container
{
public:
    multi_index_container<
        O,
        indexed_by<
            ordered_unique<
                const_mem_fun< O, KT, &KM >
            >
        >
    > _container;
};

int main( int c, char *v[] )
{
    Container< Object, std::string, Object::name > container;
}

but no joy..

the compiler complains that Object::name isn’t a type but I’m not sure how to correct this. And even if I work out how to supply a type to the template, I’ll still need a concrete instance of “Object::name” to be used by the container..

maybe I have to hand in the types and then and in the member function at construction? but then how do I construct the container .. My head hurts!?!

Alexy, below, kindly offered this solution

using namespace boost::multi_index;
template < typename O, typename KT, KT (O::* KM)() >
class Container
{
public:
    multi_index_container<
        O,
        indexed_by<
            ordered_unique<
                const_mem_fun< O, KT, KM >
            >
        >
    > _container;
};

int main( int c, char *v[] )
{
    Container< Object, std::string, &Object::name > container;  // <<---- ERROR HERE
}

However, this produded the following compiler error.

Template parameter KM requires an expression of type std::string (Object::*)().

at the line marked..

Ok. It turns out this was my fault by handing in an incorrectly signatured “&Object::name” parameter… I have fixed this..

  • 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-05-13T13:37:19+00:00Added an answer on May 13, 2026 at 1:37 pm

    Change class definition.

    template < typename O, typename KT, KT (O::* KM)() >
    class Container 
    //...
    

    and use KM instead of &KM.

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

Sidebar

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.