Any way to bind an object with an integer

J

Jayden Shui

Hello All,

I think usually we require to bind an object with a data, such as an
integer. From this object, we can easily and quickly get its bound
integer. std::map requires the object to be compared. Any other way to
do it?

Thank you very much for your kind help!

Best regards,

Jayden
 
V

Victor Bazarov

I think usually we require to bind an object with a data, such as an
integer. From this object, we can easily and quickly get its bound
integer. std::map requires the object to be compared. Any other way to
do it?

A derived class that adds an integer as a data member? You disclose too
little of the requirements to recommend anything specific...

V
 
S

SG

I think usually we require to bind an object with a data, such as an
integer. From this object, we can easily and quickly get its bound
integer.

What do you mean by "bind" and "bound" in this context?
std::map requires the object to be compared.

It requires the key type to be comparable somehow, yes. Either using
the default predicate -- std::less<key_type> -- or with a custom
predicate. As long as this binary predicate represents a strict weak
ordering you'll be fine.
Any other way to do it?

What is "it" ?

Cheers!
SG
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top