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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:28:24+00:00 2026-05-20T08:28:24+00:00

I want to create a class like below class enumClass { int msdnEnum; std::string

  • 0

I want to create a class like below

class enumClass
{
    int msdnEnum;
    std::string msdnEnumString; 
    int localEnum;
    std::string localEnumString;
}

std::set<enumClass_Objects> enums; // all msdnEnums are unique, same aplies to other three.

enums.find(given_msdnEnum)->FourthVariable;
enums.find(given_localEnum)->FirstVariable;
enums.find(given_msdnEnumStr)->anyVariable;
enums.find(given_localEnumStr)->anyVariable;

I referred boost::multiIndex. But I don’t think that it helps on this case. Can anybody say the way to achieve this?

EDIT
I am not that much good in reading template classes. As for as I am concerning I didn’t find any “find” methods in multiIndex. I saw only sorting out things in that example(the first basic example:link). Suggestions&advices are always welcomed

  • 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-20T08:28:24+00:00Added an answer on May 20, 2026 at 8:28 am

    Here’s a simple example using boost.multi_index:

    #include <string>
    #include <boost/multi_index_container.hpp>
    #include <boost/multi_index/ordered_index.hpp>
    #include <boost/multi_index/member.hpp>
    
    struct enumClass
    {
      int msdnEnum;
      std::string msdnEnumString; 
      int localEnum;
      std::string localEnumString;
    };
    
    namespace bmi = boost::multi_index;
    
    typedef bmi::multi_index_container<
      enumClass,
      bmi::indexed_by<
        bmi::ordered_unique<bmi::member<enumClass, int, &enumClass::msdnEnum> >,
        bmi::ordered_unique<bmi::member<enumClass, std::string, &enumClass::msdnEnumString> >,
        bmi::ordered_unique<bmi::member<enumClass, int, &enumClass::localEnum> >,
        bmi::ordered_unique<bmi::member<enumClass, std::string, &enumClass::localEnumString> >
      >
    > enumClassSet;
    
    int main()
    {
      enumClassSet enums;
      enums.get<0>().find(/*given_msdnEnum*/);     // index 0 is enumClass::msdnEnum
      enums.get<1>().find(/*given_msdnEnumStr*/);  // index 1 is enumClass::msdnEnumString
      enums.get<2>().find(/*given_localEnum*/);    // index 2 is enumClass::localEnum
      enums.get<3>().find(/*given_localEnumStr*/); // index 3 is enumClass::localEnumString
    }
    

    Tag classes could be used to access the indices by name rather than ordinal index as well, usage of which would look like this:

    struct byMsdnEnum;
    struct byMsdnEnumStr;
    struct byLocalEnum;
    struct byLocalEnumStr;
    
    typedef bmi::multi_index_container<
      enumClass,
      bmi::indexed_by<
        bmi::ordered_unique<bmi::tag<byMsdnEnum>, bmi::member<enumClass, int, &enumClass::msdnEnum> >,
        bmi::ordered_unique<bmi::tag<byMsdnEnumStr>, bmi::member<enumClass, std::string, &enumClass::msdnEnumString> >,
        bmi::ordered_unique<bmi::tag<byLocalEnum>, bmi::member<enumClass, int, &enumClass::localEnum> >,
        bmi::ordered_unique<bmi::tag<byLocalEnumStr>, bmi::member<enumClass, std::string, &enumClass::localEnumString> >
      >
    > enumClassSet;
    
    int main()
    {
      enumClassSet enums;
      enums.get<byMsdnEnum>().find(/*given_msdnEnum*/);
      enums.get<byMsdnEnumStr>().find(/*given_msdnEnumStr*/);
      enums.get<byLocalEnum>().find(/*given_localEnum*/);
      enums.get<byLocalEnumStr>().find(/*given_localEnumString*/);
    }
    

    The difference between the two approaches is purely aesthetic, and of course the tag classes could be named whatever you want rather than byMsdnEnum, etc. Also note that hashed indices could be used rather than ordered indices, which would give your indices the behavior of std::unordered_map rather than std::map.

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

Sidebar

Related Questions

I want to create whois class like that public class DomainInfo { public string
Hi I want create an effect like below: http://img27.imageshack.us/i/19466828.png/ There is a class in
I create a form based on a model , like seen below: class ContactSelectionForm(forms.ModelForm):
I want to create a method like example below to make sure that a
I want to create header for my website widgets. The header is like below
I've got a definition like below and essentially, I want to create this in
I want to create a class for storing attributes of the many data files
I want to create a class which is derived from QLineEdit ,but I can
I want to create a class with a nested enum. public class Foo {
I want to create a class that initializes a timer which will be used

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.