C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Proposal: Namespace qualifying overloaded operators

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Erik Westlin
Guest





PostPosted: Mon Nov 14, 2005 2:37 pm    Post subject: Proposal: Namespace qualifying overloaded operators Reply with quote



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





PostPosted: Fri Nov 18, 2005 1:26 pm    Post subject: Re: Proposal: Namespace qualifying overloaded operators Reply with quote



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





PostPosted: Thu Nov 24, 2005 5:10 pm    Post subject: Re: Proposal: Namespace qualifying overloaded operators Reply with quote




<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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.