Article View: comp.std.c++
Article #2576Re: [Q] Templates in namespaces?
From: Sean A Corfield
Date: Thu, 16 Nov 1995 03:21
Date: Thu, 16 Nov 1995 03:21
61 lines
2412 bytes
2412 bytes
In article <48bdf0$cou@panix.com>,
ajb@panix.com (Atman Binstock) wrote:
|> Can a namespace be a template argument?
|> ex:
|> template<namespace N> void f()
|> {
|> N::Fast_real r;
|> //...
No. We discussed this a fair bit in the committee. I was basically in
favour but there are some complications based on the fact that you can
extend a namespace and this makes it harder to specify the lookup rules for
name binding in templates. You can work around it with a struct with only
static members:
struct N {
static void f();
typedef int T;
};
template<typename FakeNamespace> class A {
typename FakeNamespace::T i;
void g() { FakeNamespace::f(); }
};
A<N> an;
[note: typename is required in the declaration of A::i]
Perhaps C++ v2.0 will get everything templatised (we don't have template
variables, typedefs or namespaces but they can all, to some extent, be
synthesised today).
|> What is name injection??
You don't want to know, honest! :-)
template<typename T> class X {
friend void f();
};
// f not visible here
X<int> xi; // cause friend declaration to be injected
// f is now visible and can be called
This is different to non-template classes where friend declarations are
'injected' immediately:
class C {
friend void f();
};
// f _is_ visible here
But there's all sorts of nasty problems with name injection (I could write
a book :-) and we're trying to figure out how to achieve the desirable
parts without the undesirable parts.
Sean A. Corfield
Object Consultancy Services
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<ACCF898B9668110054@corf.demon.co.uk>Path:
arc1-ca.pugleaf.net!in1.uu.net!bounce-backReferences:
<481d4h$fr7@dingo.cc.uq.oz.au> <ACCCFC90966811A2B6@corf.demon.co.uk> <48bdf0$cou@panix.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back Date: 16 Nov 95 03:21:03 GMT Approved: fjh@cs.mu.oz.au From: Sean A Corfield <sean@corf.demon.co.uk> Newsgroups: comp.std.c++ Subject: Re: [Q] Templates in namespaces? X-Original-Date: Wed, 15 Nov 1995 12:11:55 +0000 Organization: OCS Message-ID: <ACCF898B9668110054@corf.demon.co.uk> References: <481d4h$fr7@dingo.cc.uq.oz.au> <ACCCFC90966811A2B6@corf.demon.co.uk> <48bdf0$cou@panix.com> X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUBMKquLeEDnX0m9pzZAQGgWAF/RmTqvNqcrMUpQX9vmlH2vfC/KuIbJnqG 4j6P+xYrQKW7eON5veiUGBiq0ZckR+ms =A4PN