Hacker News new | ask | show | jobs
by forrestthewoods 270 days ago
I skimmed the post. I have absolutely no idea what std::flip is supposed to do. All the sample code looks awful and undesirable. And that’s coming from someone who writes C++ every day. Yes I read the plot twist at the end, made me lol.
2 comments

You write C++ every day, and you didn’t understand the is_descendant_of/is_ancestor_of example? Or how you can use it to reverse a relation like std::less?
I don’t understand why I should care about this. It doesn’t appear to solve real problems. The examples are all dumb toys and simply writing a wrapper by hand is perfectly fine and easier to read.
It's as useful (or not) as you find this:

https://cppreference.com/w/cpp/utility/functional/not_fn.htm...

If you don't see any value in that, you wouldn't see any value in the similar `flip` function or other combinators.

So not useful. Got it.
> I have absolutely no idea what std::flip is supposed to do.

Just reverse parameter order. It seems very silly.

  void f(int, double);

  void main() {
    flip(f)(3.14, 1);
  }
You do realize it's not meant for silly situations like that, right?
I cannot imagine a not-silly situation where it would be used.
If I have a library that let me curry trailing arguments for a function, then I can see how something like std::flip() could be useful in letting me curry different arguments without costing extra lines of code. The library I had in mind is Google's RPC callbacks:

https://github.com/protocolbuffers/protobuf/blob/main/src/go...

This library was written in the C++98 era. It might seem silly now because with C++11, we could use std::bind or lambda expressions instead.

I am insufficiently clever to imagine a non-silly situation in which it is useful. If authors only present silly use cases then I am inclined to suspect their creations are only useful in silly cases. If it were useful in solving real problems they should show that as an example!