Re: std::rel_ops

Discussion in 'C++' started by Dhruv, Jul 1, 2003.

  1. Dhruv

    Dhruv Guest

    On Mon, 30 Jun 2003 23:22:54 -0400, Davis King wrote:

    > Why aren't the templates in std::rel_ops implemented like
    > template <typename A, typename B> bool operator> (const A& a, const B&
    > b) { return b < a; }
    > ?
    > The reason I'm asking is that I would like to create just such a
    > template but since it isn't in std::rel_ops I worry that there is some
    > reason why that's a bad idea in the first place. I have no idea why it
    > would be a problem though.


    Because it would be illegal to do something like this:

    struct foo { };

    int a;
    foo f;

    a < f;

    -Dhruv.
    Dhruv, Jul 1, 2003
    #1
    1. Advertising

  2. Dhruv

    Davis King Guest

    Dhruv wrote:

    > On Mon, 30 Jun 2003 23:22:54 -0400, Davis King wrote:
    >
    > > Why aren't the templates in std::rel_ops implemented like
    > > template <typename A, typename B> bool operator> (const A& a, const B&
    > > b) { return b < a; }
    > > ?
    > > The reason I'm asking is that I would like to create just such a
    > > template but since it isn't in std::rel_ops I worry that there is some
    > > reason why that's a bad idea in the first place. I have no idea why it
    > > would be a problem though.

    >
    > Because it would be illegal to do something like this:
    >
    > struct foo { };
    >
    > int a;
    > foo f;
    >
    > a < f;


    What do you mean? That shouldn't compile anyways since there is no function
    which defines operator< for an int and a foo right?
    Having the above templated operator < doesn't change that.
    Davis King, Jul 1, 2003
    #2
    1. Advertising

  3. Dhruv

    Dhruv Guest

    On Tue, 01 Jul 2003 07:36:17 -0400, Davis King wrote:

    [snip]......

    >> Because it would be illegal to do something like this:
    >>
    >> struct foo { };
    >>
    >> int a;
    >> foo f;
    >>
    >> a < f;

    >
    > What do you mean? That shouldn't compile anyways since there is no function
    > which defines operator< for an int and a foo right?
    > Having the above templated operator < doesn't change that.


    What I'm saying is that it would be stupid to compare if a lion is less
    than a tiger. Ok, is one lion less than another would be saner, then
    again, we have to defne what attribute of the lion we want to compare,
    height, weight, age, etc...

    -Dhruv.
    Dhruv, Jul 1, 2003
    #3
    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. Victor Bazarov

    Re: std::rel_ops

    Victor Bazarov, Jul 1, 2003, in forum: C++
    Replies:
    1
    Views:
    445
    Davis King
    Jul 1, 2003
  2. Peter Jansson
    Replies:
    5
    Views:
    6,276
    Ivan Vecerina
    Mar 17, 2005
  3. Vinu
    Replies:
    4
    Views:
    347
    Jim Langston
    Jul 7, 2005
  4. Vinu
    Replies:
    0
    Views:
    345
  5. Replies:
    0
    Views:
    369
Loading...

Share This Page