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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:48:20+00:00 2026-06-14T16:48:20+00:00

I have asked in another question about std::multiset , but now I see I

  • 0

I have asked in another question about std::multiset, but now I see I need a decent understanding and cannot find any more complicated example in the internet.

Can you explain to me, maybe exemplarize, how std::multiset<A,B> works and what function is here of A and of B, and also if any of those can be omitted? Can I put A or B to some variable?
I’d really appreciate some short example, or reference,

  • 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-14T16:48:22+00:00Added an answer on June 14, 2026 at 4:48 pm

    The std::multiset class template has a first template parameter specifying the type of objects to be stored in the set, and a second one specifying the type of a comparison functor. We can ignore the third template parameter for now.

    The second, optional, parameter, B, must implement strict weak ordering and is used to order the set/multiset. This ordering is required to ensure the logarithmic complexity of element look-up operations. Here is an example:

    struct A
    {
      int x;
    };
    
    struct B
    {
      bool operator()(const A& lhs, const A& rhs) const {
        return lhs.x < rhs.x;
      }
    };
    

    This class B has an operator(), which means that it can be called, for example

    B comp;
    A a1, a2;
    bool a1lessThana2 = comp(a1, a2);
    

    This is needed for the set/multiset to place elements in the correct location, and figure out if two elements are the same. If there is an operator< for your type, the second template parameter can be omitted.

    bool operator<(constA& lhs, const A& rhs) { return lhs.x < rhs.x; }
    

    This is an example of usage:

    int main()
    {
      std::multiset<A, B> m;
      A a1, a2;
      a1.x = 23;
      a2.x = 100;
      m.insert(a1);
      m.insert(a2);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I already asked a question about this yesterday, but now I have another :)
I asked this question earlier. I am intrigued by std::set but I have another
i have asked a question about manytomanyfield here which i solved but now a
Another question asked about attributes, but I would like to extend the question to
I asked another question about HTML and PHP separation as I have seen references
Another Newbie question in XSLT transformation. (I have asked similar question before, but in
This question is related to another question I asked Basically, I have 2 horizontally
I have asked this question before but did not get the satisfied answer as
I have asked a similar question about command line arguments in C++ some hours
I have asked this before but I didn't get the question right so the

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.