C++ Logo


Advanced search

Subject: Re: [std-proposals] Proposal of Namespace Templates (DRAFT 1)
From: Andrew Tomazos (andrewtomazos_at_[hidden])
Date: 2019-09-24 09:48:28

Thanks for your feedback Tom. You'll find my questions and comments

On Tue, Sep 24, 2019 at 11:59 PM Tom Honermann <tom_at_[hidden]> wrote:

> I have some sympathy for the problem this proposal purports to address.
> I think the proposed distinction for initial namespace templates and
> namespace template extensions is not well motivated, introduces gratuitous
> deviation from existing template syntax, and introduces the following new
> problems:
> 1) Lookup is confusing. Consider the following:
> template<int i>
> namespace N {}
> int i;
> namespace template N {
> void f() {
> i; // Ambiguous, ::i, or the i parameter of N?
> }
> }
> I think this would be a novel and confusing lookup rule no matter which
> way the above question is resolved. Some existing cases that require such
> semantic lookup as opposed to lexical lookup are for class members in out
> of line class member definitions and ADL. For the former, some guidelines
> require prefixing class data members with 'm_' or similar to remind
> programmers that they are referencing something defined outside of the
> lexical context. For the latter, well, issues with ADL are well known.

I don't see why you're reading this any differently than:

namespace N { int i; }
int i;
namespace N {
  void f() {

Anyway - let's say, for sake of argument, I agreed with you. What change
to the proposal are you suggesting? The motivation of having the template
parameters implicitly declared in namespace template extensions is so that
you only have to define the library configuration once, in one source file.

> 2) Parameters of namespace templates can effectively never be omitted
> since names are not re-introduced in extensions.
> The ability to omit names for unreferenced parameters within a given scope
> has a long history in C and C++ and is useful in some cases to prevent
> unintended references or to allow different names to be used in different
> contexts. In particular for this proposal, I can imagine that some
> parameters of namespace templates would only be needed in some namespace
> extensions. The traditional template declaration syntax allows the
> following:
> template<typename, int>
> namespace N {}
> template<typename T, int>
> namespace N {
> void foo(T);
> }
> template<typename, int I>
> namespace N {
> int bar() { return I; }
> template<typename T> // No possible confusion with an outer 'T'.
> void ft(T) { ... }
> }

As proposed the above is ill-formed as you can only have a single initial
namespace template, the remainder must be namespace template extensions -
in order to maintain a single definition of the library configuration.

If your point is that if we modified the proposal to have namespace
template extensions redeclare their template parameters, then this would
allow finer-grained name omission - then I don't think this trumps the
point above. ie It's more important that we define the library
configuration once.

Unrelated to the above, I think the proposal might benefit from some
> mechanism for a member of the namespace template to opt out of template
> dependency. This would avoid having to introduce additional, effectively
> implementation detail namespaces like in the following example (though,
> perhaps this approach wouldn't be so bad either):
> namespace non_dependent_things_for_N {
> void baz();
> }
> template<typename>
> namespace N {
> using namespace non_dependent_things_for_N;
> }

By what mechanism (if any) can you opt out members of class templates from
template dependency?

What is your motivation for wanting to do that?

> Tom.
> On 9/24/19 2:17 AM, Andrew Tomazos via Std-Proposals wrote:
> Please find attached DRAFT 1 of:
> Proposal of Namespace Templates
> Feedback appreciated.
> -Andrew.

STD-PROPOSALS list run by herb.sutter at gmail.com

Standard Proposals Archives on Google Groups