C++ Logo


Advanced search

Re: Allow use of constants and types from not-instantiation-ed template

From: Jens Maurer <Jens.Maurer_at_[hidden]>
Date: Mon, 20 Dec 2021 22:32:32 +0100
On 20/12/2021 19.08, Hani Deek via Std-Proposals wrote:
>> Hello,
>> So, let's just allow use of a types and static constants from
>> not-instantiation-ed template class (if possible):
>> template<typename T>
>> struct Foo{
>> constexpr static int bar = 0x01;
>> };
>> int i = Foo::bar; // Doesn't compile now, but could
>> int j = Foo<class Nonexisting>::bar; // Ugly hack but works
> I think the proposal should be to allow a namespace to have the same name as a class template.
> For example,
> ---------------------------------
> namespace Foo
> {
> constexpr int bar = 0x01;
> }
> template<typename T>
> struct Foo
> {
> static constexpr T bar = 0x02;
> };
> int i = Foo::bar; //Foo is a namespace name
> int j = Foo<short>::bar; //Foo is a class template name
> ---------------------------------
> In order for this proposal to work, we will need to add new rules to the name lookup rules. We will need to define contexts in which a name is assumed to be a namespace name rather than a template name, and other contexts for the opposite assumption. We will also need a disambiguation mechanism for contexts where both a namespace name and a template name may be used.
> Adding those new name lookup rules will be a radical change to C++, [...]
The name lookup concern also applies to the original proposal.

I'd like to understand more how the modified name lookup rules are
supposed to work, with special attention to backward compatibility
concerns, i.e. how existing code might change meaning under the new


Received on 2021-12-20 15:32:37