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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:50:03+00:00 2026-05-23T13:50:03+00:00

I want to map objects of a given class to objects of another. The

  • 0

I want to map objects of a given class to objects of another. The class I want to use as key, however, was not written by me and is a simple struct with a few values. std::map orders it’s contents, and I was wondering how it does it, and if any arbitrary class can be used as a key or if there’s a set of requirements (operators and what not) that need to be defined.

If so, I could create a wrapper for the class implementing the operators map uses. I just need to know what I need to implement first, and none of the references for the class I found online specify them.

  • 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-23T13:50:04+00:00Added an answer on May 23, 2026 at 1:50 pm

    All that is required of the key is that it be copiable and assignable.
    The ordering within the map is defined by the third argument to the
    template (and the argument to the constructor, if used). This
    defaults to std::less<KeyType>, which defaults to the < operator,
    but there’s no requirement to use the defaults. Just write a comparison
    operator (preferably as a functional object):

    struct CmpMyType
    {
        bool operator()( MyType const& lhs, MyType const& rhs ) const
        {
            //  ...
        }
    };
    

    Note that it must define a strict ordering, i.e. if CmpMyType()( a, b
    )
    returns true, then CmpMyType()( b, a ) must return false, and if
    both return false, the elements are considered equal (members of the
    same equivalence class).

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

Sidebar

Related Questions

I have a situation where I want to map a pair of objects to
I have Java Map (out of Strings and Ints) objects that I want to
I want my map generator to fill some part of map with given tile,
Given a range of indexes (identifiers), where I want to map each index to
I want to create a Map object that can lose value only if we
I want to map a INI file as a python object. So if the
I have one very general object that I want to map to a destination
I have this object graph, I want to map: abstract Account (username, password, ...)
I haev an object with a DateTime property. I want to map the time
I have a map that represents a DB object. I want to get 'well

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.