Easy way to write comparison functions?

J

Jayden

I have a class with an attribute of type std::string. I'd like to provide some comparison operator functions like <, >, ==, <=, and >= for the class by comparing the attribute.

My questions is that: any easy way or tool to

(1) just write one or two functions, such as the one for operator < (and ==), others can be automatically generated.

(2) or even simpler since the class comparison is depending on its attribute of type std::string whose comparison functions are already provided.

Thank you so much!

Jayden
 
M

Marc

Jayden said:
I have a class with an attribute of type std::string. I'd like to provide some comparison operator functions like <, >, ==, <=, and >= for the class by comparing the attribute.

My questions is that: any easy way or tool to

(1) just write one or two functions, such as the one for operator < (and ==), others can be automatically generated.

Look at Boost.Operators, which does exactly this.
 

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

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top