🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #1716

Re: template operators <,>,!=

#1716
From: Etay Bogner
Date: Fri, 11 Aug 1995 03:24
83 lines
3006 bytes
You did NOT understand.

The reason N1::f() should be choosen is because it's in the SAME 
namespace as N1:g(), and NOT because it was declared before N2:f().

That's why I gave the paralel "global function versus member function" 
name resolution example.

The Examples AGAIN ( somewhat re-ordered for clarity ) :

namespace N1 { // re-ordered for clarity
        void g();
        };

namespace N2 {
        void f();
        };

namespace N1 { // moved here for clarity
        void f();
        };


using namespace N1;
using namespace N2;

void N1::g() {
        f(); // here is the BUG in the language. Should use N1::f(). See 
Below.
        }

The paralel "global function versus member function" name resolution :

void f();

class X {
        void f();
        void g();
        };

void X::g() {
        f(); // here it's OK. calls X::f() and NOT ::f()
        }

Just think of a namespace as a class declaration.

In the second example, X::f() is choosen simply because it's in the SAME 
scope as X::g().

So why not do so for namespaces ?

I think this is a logical solution to the problem of name resolution 
between namespaces. It does NOT intreduce new problems, since we already 
know that the same name resolution method is used with global functions 
and classes, as shown in the second example.

Since, for instance, only one "void f()" can exists in a namespace ( as 
in a class ), the language can choose N1::f() simply because it's in the 
SAME namespace as the calling function, N1:g(), and can make a "bad 
thing" since the rules are clear ( and already working ).

And again, this is EXACTLY what happens in the second example, X::f() is 
choosen simply because it's in the SAME name scope as the calling 
function, in this case X::g().

This will solve the problem of defining the template operator <,>,!= 
etc. functions if the classes that USES your classes will be in the SAME 
namespace as your classes, thus the calls for those template function 
will resolve to YOUR functions, instead of STL's, and this is simply ( 
everything is simple here ? ) because they are in the SAME namespace as 
your templates.

HTH,

Will someone send this proposed correction to the draft to the standard 
committe ?



-- Etay Bogner,
-- Etay_Bogner@mail.stil.scitex.com,
-- Scitex Corp.
-- Israel.
Technical Details
Message-ID: <40ebvt$88f@lyman.pppl.gov>
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage
From: Etay Bogner <Etay_Bogner@mail.stil.scitex.com>
Newsgroups: comp.std.c++
Subject: Re: template operators <,>,!=
Date: 11 Aug 1995 03:24:05 GMT
Organization: Scitex Corp.
Approved: clamage@eng.sun.com (comp.std.c++)
Message-ID: <40ebvt$88f@lyman.pppl.gov>
NNTP-Posting-Host: taumet.eng.sun.com
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Nntp-Posting-Host: applepo8.scitex.com
X-Mailer: Mozilla 1.1N (Macintosh; I; PPC)
X-Url: news:comp.std.c++
Content-Length: 2316
Originator: clamage@taumet