4 ms·
But C++ could take the same route of consistency regardless of the lexer hack. The turbofish is a strict superset of `typename`, and everywhere C++ lets you sk
by Rusky 7y ago
But C++ could take the same route of consistency regardless of the lexer hack.
The turbofish is a strict superset of `typename`, and everywhere C++ lets you skip it it could simply require it instead.
- pcwalton 7y agoI don't think that's true. Consider a modified version of [1]: template<typename T> class X { void foo() { typename T::A* pa; } } The problem here is that C++ can't parse this without knowing whether T::A is a type or not. Otherwise it might be "T::A multiplied by pa". This is the lexer hack in action. Rust, by contrast, has no such limitation [2]: trait SomeTrait { type A; } struct X<T> { f: T, } impl<T> X<T> where T: SomeTrait { fn foo() { let pa: *mut T::A; } } This compiles and runs just fine with no need for a turbofish on T::A, because Rust has no lexer hack. [1]: https://en.cppreference.com/w/cpp/language/dependent_name https://en.cppreference.com/w/cpp/language/dependent_name [2]: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=b62ed773e7243c5352e34dabb5077738 https://play.rust-lang.org/?version=stable&mode=debug&editio...
- Rusky 7y agoThat's true but antiparallel to my point: C++ typename could have the same consistency as Rust's turbofish- its complicated rules are not necessitated by the lexer hack. (In a sense, the complicated rules are what enable the lexer hack.)
- pjmlp 7y agoC++20 has simplified the need for typename use cases. http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0634r3.html http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p063...