News for hackers. Stuff that matters.
Re:Bastion of the Turbofish (2020) by scott_s on Friday February 05, 2021 @08:59AM (#26036361)
It's a straight-forward rule that (I think) I have mostly internalized. But coming from C++, I was initially mystified.
Re:Bastion of the Turbofish (2020) by vbarrielle on Friday February 05, 2021 @10:18AM (#26037207)
C++ 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;
    }
Re:Bastion of the Turbofish (2020) by nzmsv on Saturday February 06, 2021 @11:10AM (#26047452)
I'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#Th...

Re:Bastion of the Turbofish (2020) by vbarrielle on Saturday February 06, 2021 @03:40PM (#26049729)
You'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...
Re:Bastion of the Turbofish (2020) by scott_s on Friday February 05, 2021 @10:18AM (#26037217)
And I have never internalized it! This is me, but for `typename` and `template` in expressions: https://xkcd.com/1168/