| View previous topic :: View next topic |
| Author |
Message |
Erik Westlin Guest
|
Posted: Mon Nov 14, 2005 2:37 pm Post subject: Proposal: Namespace qualifying overloaded operators |
|
|
Consider:
class Foo
{
};
namespace ns
{
Foo operator*(Foo,Foo);
Foo mul(Foo,Foo);
}
void func()
{
Foo a,b;
// this works
using namespace ns;
a * b;
// or
ns::operator* (a, b);
// but
a ns::* b
// doesn't work at all.
However i think it would be useful
Think about matrix algebra with several different multiplication
operators
It would make it possible to write expressions like
a inner::* b outer::* c
Maybe that would be even better than the algebraic typo where a lot of
new
characters are invented.
well it might be too hard for the compiler to implement.
or there are some other objection?
or this may already have been done in some compiler?
I know it's just syntactic sugar but why shouldn't you be able
to namespace qualify operators when you can with everything else.
}
Cheers
Erik Westlin
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Michiel.Salters@tomtom.co Guest
|
Posted: Fri Nov 18, 2005 1:26 pm Post subject: Re: Proposal: Namespace qualifying overloaded operators |
|
|
Erik Westlin wrote:
| Quote: | Think about matrix algebra with several different multiplication
operators
It would make it possible to write expressions like
a inner::* b outer::* c
|
identifier ::* looks too much like a pointer-to-member, the parsing
problems
created aren't worth the savings. You do know you can use
inner::operator* ?
A proposal to allow infix operator* calls might make sense; I think the
use of
a keyword prevents parsing ambiguities.
Regards,
Michiel Salters
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Erik Westlin Guest
|
Posted: Thu Nov 24, 2005 5:10 pm Post subject: Re: Proposal: Namespace qualifying overloaded operators |
|
|
<Michiel.Salters (AT) tomtom (DOT) com> wrote
| Quote: | Erik Westlin wrote:
Think about matrix algebra with several different multiplication
operators
It would make it possible to write expressions like
a inner::* b outer::* c
identifier ::* looks too much like a pointer-to-member, the parsing
problems
created aren't worth the savings. You do know you can use
inner::operator* ?
A proposal to allow infix operator* calls might make sense; I think the
use of
a keyword prevents parsing ambiguities.
|
I think the purpose of infix operators are to enhance readability - that's
why we have them.
A mandatory keyword would be too verbose. I don't think anyone would
use it - just like you very seldom see/use the prefix form.
I don't think parsing this is impossible.
I wonder if they considered this when they added namespaces?
Greetings
Erik Westlin
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|