Modernizing Legacy C++ Code

Play Modernizing Legacy C++ Code

The Discussion

  • User profile image
    Craig Gidney

    It looks like the "new, better function implementation" at 21:36 secretly modifies the variable you give to it to be lower case, instead of only returning the lower case version. The input type should be const char&.

  • User profile image

    Craig, the macro itself also assigns to the variable passed in, so char& would be a faithful port to a function in that case. Of course, the question stands why one would want such a macro or function, but that's something probably better left to another refactoring step, I guess.

  • User profile image

    Couldn't you just write &(pfd.get()) at 25:20 to get the address of the raw pointer?

  • User profile image

    @Michael: It wouldn't work. The pfd.get() call result is a temporary value, not a reference to the underlying pointer.

  • User profile image

    One massive reason that the STL algorithms are underused is that their interface sucks.
    Where "sucks" means "requires odious use of being+end pairs, insead of the infinitely more sensible use of the container itself".
    auto the_max = std::max_element(v);  // <- this is what the library should offer.  underutilization is an absolutely direct result of this failure.

  • User profile image

    @Mordachai: There's a Ranges study group that is working on your first point. As for the second, an extra star is really not much to ask for the ability to know where the maximum is.

Add Your 2 Cents