From -5783731454779018470
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,c6490c4b353e55ed,start
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2001-02-02 16:13:03 PST
Path: supernews.google.com!sn-xit-02!supernews.com!news.tele.dk!194.213.69.151!news.algonet.se!algonet!newspeer.clara.net!news.clara.net!dispose.news.demon.net!news.demon.co.uk!demon!mail2news.demon.co.uk!not-for-mail
From: Ewgenij Gawrilow <gawrilow@math.tu-berlin.de>
Newsgroups: comp.std.c++
Subject: multiple using declarations in namespace scope
Date: Fri,  2 Feb 2001 23:45:46 GMT
Organization: Deja.com
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
Message-ID: <95ecdm$rbe$1@nnrp1.deja.com>
X-Trace: mail2news.demon.co.uk 981159124 mail2news:9476 mail2news mail2news.demon.co.uk
X-Complaints-To: abuse@demon.net
X-Mail2News-Path: news.demon.net!mulga.cs.mu.oz.au
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Article-Creation-Date: Fri Feb 02 13:24:12 2001 GMT
X-Http-User-Agent: Mozilla/4.75 [en] (X11; U; SunOS 5.7 sun4u; Nav)
X-Http-Proxy: 1.0 x63.deja.com:80 (Squid/1.1.22) for client 130.149.12.73
X-MyDeja-Info: XMYDJUIDewgenij_gawrilow
Lines: 93
Xref: supernews.google.com comp.std.c++:3487

Let's imagine a class library defining two top-level classes. Each is
declared in a separate header file, as they can be used independently
from each other. Besides them, there is a lot of helper classes being of
little interest for library users. In such a situation
I'd prefer to introduce two distinct namespaces:

// file A.h
namespace implementation {
  class A { ... };
  // ...
  // a useful function
  void f(A);
};
namespace export_stuff {
  using implementation::A;
};

// file B.h
namespace  {
  class B { ... };
  // ...
  // a useful function again
  void f(B);
};
namespace export_stuff {
  using implementation::B;
};

The application program can then be written as follows:

#include <A.h>
#include <B.h>

using namespace export_stuff;
int main() {
   A a;
   B b;
   f(a); f(b);  // both will be found via Koenig's lookup
}

So far, so nice. My problem only begins here. Our useful function
suddenly turns out to be a function template with a template parameter
occuring in the return value and hence not deducible from the arguments:

// file A.h
namespace implementation {
  template <class X>
  X f(A);
};

and the same about B.

Now we can't rely on the Koenig's lookup in the application program any
more as the compiler complains about parse errors in the expression
f<int>(a). This could be cured, however, with

namespace export_stuff {
  using implementation::f;
};

The only question is: where to place this declaration? As I've already
said, A and B can be used separately, so it should be placed in both
header files. However, while the first declaration (in A.h) exports A::f
in the global namespace (conforming to [7.3.3] par.9), the second
declaration has simply no effect and leaves B::f invisible, although it
is already defined at this point.

I haven't found an explicit treatement of such a situation in the
Standard; I feel, however, that the using declarations, due to the
position-dependent effects, could be handled a bit differently from
typedefs or class forward declarations.

What's the experts' opinion?

PS: the workaround is easy - just full qualifying f in the application.
But it would go against the nice concept of the export namespace.
--
With best regards,
Ewgenij Gawrilow
Dept. of Mathematics
Technical University Berlin, Germany


Sent via Deja.com
http://www.deja.com/

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]



