Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Re: std::rel_ops

Reply
Thread Tools

Re: std::rel_ops

 
 
Dhruv
Guest
Posts: n/a
 
      07-01-2003
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.







 
Reply With Quote
 
 
 
 
Davis King
Guest
Posts: n/a
 
      07-01-2003


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.

 
Reply With Quote
 
 
 
 
Dhruv
Guest
Posts: n/a
 
      07-01-2003
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.






 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments