Why does one still need to disambiguate a dependent type with typename in the RHS of a using statement?

后端 未结 2 944
傲寒
傲寒 2021-02-01 13:57

I know very well why one needs to use typename for dependent types, since the compiler may not be able to disambiguate between a type and a variable declaration whe

相关标签:
2条回答
  • 2021-02-01 14:24

    There is no hard reason. As ralismark said, a paper was discussed this year (for C++20, not 17!). There are concerns, but also counterpoints:

    1. It could be seen as making the language less regular (as codeshot said), but the new idea is that disambiguating typename will become rare enough as to have near-consistency in the other direction. (As has been said, there was already an exceptional case in the form of base class names.)
    2. It could foreclose possible extensions (as T.C. reported), but the extensions could have their own disambiguation rather than burdening the common case.

    The paper has strong support and the new rules will probably appear in the working draft in a few months.

    0 讨论(0)
  • 2021-02-01 14:32

    The template argument type T does not, and can not implicitly carry with it its internal components. thus T::type is fundamentally a new type when the compiler looks at the uninstantiated template, hence the need to declare a new typename 'T::type'.

    Unfortunately, I think this issue will remain with us until the standard includes full-fledged Concepts.

    0 讨论(0)
提交回复
热议问题