Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Any way to bind an object with an integer (http://www.velocityreviews.com/forums/t806083-any-way-to-bind-an-object-with-an-integer.html)

Jayden Shui 11-19-2011 10:37 PM

Any way to bind an object with an integer
 
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


Victor Bazarov 11-21-2011 05:04 PM

Re: Any way to bind an object with an integer
 
On 11/19/2011 5:37 PM, Jayden Shui wrote:
> 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
--
I do not respond to top-posted replies, please don't ask

SG 11-22-2011 09:09 AM

Re: Any way to bind an object with an integer
 
On 19 Nov., 23:37, Jayden Shui wrote:
>
> 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


All times are GMT. The time now is 09:00 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.