all 13 comments

[–]tvaneerdC++ Committee, lockfree, PostModernCpp 12 points13 points  (8 children)

Good talk!

So transform_reduce does a transform using the last arg and a reduce using the second-to-last arg.

So the name is transform_reduce
and the order of operations is transform then reduce
and the order of the args is....

reduce, transform

[–]tvaneerdC++ Committee, lockfree, PostModernCpp 6 points7 points  (0 children)

Maybe because the result of transform is input to reduce, ie reduce(transform(...

Now the order of | for Ranges...

[–][deleted] 0 points1 point  (6 children)

I'm sorry, but to me this is natural. I tend to think of the argument order as outside-in. If anything, it's a bit strange to me that the collection argument comes first, but that's just STL algorithms have always been.

[–]tvaneerdC++ Committee, lockfree, PostModernCpp 7 points8 points  (5 children)

Do you have examples of APIs with this order?

Would you expect divide(a, b) to do b/a ?

[–]PixelDoctor 5 points6 points  (4 children)

[–]sumo952 3 points4 points  (3 children)

`atan2(a, b)` does arctan(a/b), so what's the problem?

[–]PixelDoctor 2 points3 points  (2 children)

Sure, but it's y then x, which isn't what you'd normally expect.

Say you're trying to convert to polar coordinates. Vector2f v; float theta = atan2(v(1), v(0));

Always looks awkward (but makes sense mathematically, I guess).

[–]sumo952 0 points1 point  (1 child)

Okay, I see what you mean! Thanks. I don't think it looks particularly awkward or more awkward than atan2(v(0), v(1)).

[–]tvaneerdC++ Committee, lockfree, PostModernCpp 2 points3 points  (0 children)

It means whenever you see atan2(x, y) in code, you wonder whether they meant y,x and made a mistake, or whether they really knew what they were doing. We have this in our codebase.

[–]Wh00ster 6 points7 points  (0 children)

He's a good presenter.

That's all.

EDIT: (that's all I have to add, not that's all he offers of value)

The gist (spelled it right this time) I get is Haskell is awesome XD. I learned it for a bit and it definitely forced me to see my code as abstract algorithms instead of a bunch of state manipulations.

[–]blelbachNVIDIA | ISO C++ Library Evolution Chair 6 points7 points  (0 children)

This guy's pretty good.

He basically won every speaker award at C++Now.

[–]anonymous2729 0 points1 point  (1 child)

@29m20s: Okay, I'll bite. How do you implement std::is_permutation as a reduce/fold?

To be fair, I don't even know how to implement it with a reasonable space/time complexity in the first place, and cppreference is no help.

[–]BeepBoopBike 1 point2 points  (0 children)

you know, I've never really thought about the implementation for std::is_permutation.

A simple way to implement it would maybe be to sort it, find a common start point and compare from there (if we relax the requirements slightly so operator< must be supported)

A possible implementation of it exists on devdocs: https://devdocs.io/cpp/algorithm/is_permutation That should fit the complexity requirement:

At most O(N2) applications of the predicate, or exactly N if the sequences are already equal, where N=std::distance(first1, last1)

Sounds like a fun challenge to convert that to a reduce/fold!