🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

4 total messages Started by Tony Coates Sat, 11 Nov 1995 06:10
[Q] Templates in namespaces?
#2522
Author: Tony Coates
Date: Sat, 11 Nov 1995 06:10
13 lines
1313 bytes
Can anyone tell me (hope this isn't a FAQ ...) what the status is on whether
templates can be placed in namespaces?  My understanding was this was a matter
of recent debate, with some compilers currently making all template definitions

global.  For my own part, I think it would be a sad decision to make template
definitions compulsorily global, and hence effectively downgrade template
definitions with respect to non-template definitions.
						Cheers,
								Tony.
---
[ 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. ]
Re: [Q] Templates in namespaces?
#2578
Author: Sean A Corfield
Date: Mon, 13 Nov 1995 16:06
36 lines
2066 bytes
In article <481d4h$fr7@dingo.cc.uq.oz.au>,
Tony Coates <coates@mailbox.uq.oz.au> wrote:

|> Can anyone tell me (hope this isn't a FAQ ...) what the status is on
|> whether templates can be placed in namespaces?  My understanding was
|> this was a matter of recent debate, with some compilers currently
|> making all template definitions global.  For my own part, I think it
|> would be a sad decision to make template definitions compulsorily
|> global, and hence effectively downgrade template definitions with
|> respect to non-template definitions.

Templates can indeed be placed in namespaces. The current WP says that
specialisations of such templates must also go inside the same namespace:

  namespace Lib {
    template<typename T> class X { };
  }

  // must reopen namespace to define specialisation
  namespace Lib {
    template<> class X<int> { };
  }

[note: the example uses recently adopted syntax 'typename' as an
alternative to 'class' and 'template<>' to introduce a specialisation]

The other major issue which has an impact on templates & namespaces is name
injection -- the committee are debating this subject at the moment.

Sean A. Corfield
Object Consultancy Services -- voting member of X3J16
C++ - Beyond the ARM http://uptown.turnpike.net/~scorf/cplusext.html
---
[ 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. ]
Re: [Q] Templates in namespaces?
#2556
Author: Atman Binstock
Date: Wed, 15 Nov 1995 02:03
28 lines
1214 bytes
In article <ACCCFC90966811A2B6@corf.demon.co.uk>,
Sean A Corfield  <sean@corf.demon.co.uk> wrote:
>Templates can indeed be placed in namespaces. The current WP says that
>specialisations of such templates must also go inside the same namespace:
>

Can a namespace be a template argument?
ex:
template<namespace N> void f()
{
	N::Fast_real r;
	//...

>The other major issue which has an impact on templates & namespaces is name
>injection -- the committee are debating this subject at the moment.

What is name injection??

Thanks,
Atman Binstock
ajb@panix.com


---
[ 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. ]
Re: [Q] Templates in namespaces?
#2576
Author: Sean A Corfield
Date: Thu, 16 Nov 1995 03:21
61 lines
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. ]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads