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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:22:28+00:00 2026-06-15T23:22:28+00:00

I have a map as follows: std::map<A, long> myMap The ordering of this map

  • 0

I have a map as follows:

std::map<A, long> myMap

The ordering of this map is important so I am trying to figure out how the map will be ordered. I have found that on the documentation of this class it says Internally, the elements in the map are sorted from lower to higher key value following a specific strict weak ordering criterion set on construction but I don’t understand what this means. Will it call the ‘<‘ operator on the two objects to figure out the ordering?

I am also aware that I could just pass the map a struct as follows on initialisation and it will do as I want. I am just curious as to what it does by default.

struct classcomp {
  bool operator() (const A& lhs, const A& rhs) const
   {return lhs<rhs;}
};
  • 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-15T23:22:29+00:00Added an answer on June 15, 2026 at 11:22 pm

    Will it call the ‘<‘ operator on the two objects to figure out the ordering?

    Yes, it will:

    struct A {
        bool operator<(const A& other) const
        {
            return ...; // return true if *this is less than other; false otherwise
        }
    };
    

    Make sure that the “less than” relation defined by your operator< is transitive, i.e. if A < B and B < C, then A must be less than C as well.

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

Sidebar

Related Questions

I have a map declared as follows - Map<Date, Long[]> myMap = new TreeMap<Date,
I have a std::map<std::string, myClass*> myMap then I am inserting like follow: if(!myKey.empty()) {
I have a HashMap as follows: Map<String, String> myMap = new HashMap<String,String>(); myMap.put(apple,mac); JSONArray
Say I have an std::map type which for example is defined as follows. std::map<int,
I have an std:map defined as follows: std:map<std::string country, std::vector<SomeClass> events>; Holds some events
I have a std::map object as follows typedef std::map<int,int> RoutingTable; RoutingTable rtable; and then
I have the following code: void cStatisticDBSerializer::GetStats (std::map <std::string, long long >& ioCounterStats, std::map
I have a map named valueMap as follows: typedef std::map<std::string, std::string>MAP; MAP valueMap; ...
I have a map declared as follows: map < string , list < string
I have a Map to sort as follows: Map<String, String> map = new HashMap();

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.