Easy way to write comparison functions?

Discussion in 'C++' started by Jayden, Dec 17, 2012.

  1. Jayden

    Jayden Guest

    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
    Jayden, Dec 17, 2012
    #1
    1. Advertising

  2. Jayden

    Marc Guest

    Jayden wrote:

    > 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.
    Marc, Dec 22, 2012
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hazzard
    Replies:
    2
    Views:
    632
    Hazzard
    Apr 6, 2004
  2. Kaidi
    Replies:
    2
    Views:
    3,787
    Ferenc Hechler
    Nov 26, 2004
  3. Nonee
    Replies:
    3
    Views:
    925
    Manchild
    Sep 2, 2005
  4. Nonee
    Replies:
    1
    Views:
    374
  5. Deepu
    Replies:
    1
    Views:
    236
    ccc31807
    Feb 7, 2011
Loading...

Share This Page