5 ms·
Am I the only one not really bothered by the turbofish? I just think 'declarations, no colons. expressions, colons.' and that rule generally works fine for me.
by Subsentient 6y ago
Am I the only one not really bothered by the turbofish?
I just think 'declarations, no colons. expressions, colons.'
and that rule generally works fine for me.
- scott_s 6y agoIt's a straight-forward rule that (I think) I have mostly internalized. But coming from C++, I was initially mystified.
- vbarrielle 6y agoC++ has a rule similar to the turbofish though: #include <Eigen/Dense> // a library where I know it's required using namespace Eigen; int main() { VectorXd zeros = VectorXd::zeros(5); VectorXf zeros_float = zeros.template cast<float>(); return 0; }
- scott_s 6y agoAnd I have never internalized it! This is me, but for `typename` and `template` in expressions: https://xkcd.com/1168/ https://xkcd.com/1168/
- nzmsv 6y agoI'm sure you know better, but at first glance this seems wrong. Reason: `main` is not itself a template, so `cast` is not a dependent name. C++ compilers used to be liberal about accepting unnecessary instances of the `typename` keyword so lots of people would just sprinkle them everywhere. Modern versions of both Clang and GCC call this out. The actual rule: https://en.cppreference.com/w/cpp/language/dependent_name#The_typename_disambiguator_for_dependent_names https://en.cppreference.com/w/cpp/language/dependent_name#Th...
- vbarrielle 6y agoYou're right, since I'm frequently using templated functions I encounter this issue quite often, but here when I wanted to give an example I forgot I needed to be in a dependent context. I guess I'd better test my example next time I want to give one...
- adkadskhj 6y agoI love it. I'm not here to debate whether it should be there, but i like it nonetheless. Mostly because of the cute name. And i came from being a Python "kill all syntax!" zealot back in the day, hah. Funny how in both Types and Syntax i have migrated from minimalist to explicitness over the years. I was such a zealot on both fronts in those Python days.
- tomjakubowski 6y agoThe syntax gives me a warm feeling, reminding me in the moment that I'm not writing C++.