top | item 4251477

The Functor Pattern in C++

63 points| PopaL | 13 years ago |fpcomplete.com | reply

15 comments

order
[+] evincarofautumn|13 years ago|reply
C++ is a powerful language, but with awful syntax and semantics that can discourage experimentation. Since I started using Haskell just over a year ago, my C++ code is much improved—because I can figure things out quickly in Haskell, then translate them to (somewhat write-only) C++. That I think is a large part of what people mean when they say “Haskell makes me a better programmer”. Not only is it a good language in its own right, but it also helps you prototype software that you need to implement in another language for reasons other than language power.
[+] kombine|13 years ago|reply
"C++ is a powerful language, but with awful syntax and semantics that can discourage experimentation."

Then you should try out D. Bartosz Milewski in fact has been involved in D development for a long time. It certainly makes it easier to apply a lot of the FP techniques.

[+] Oxryly|13 years ago|reply
You had me until "somewhat write-only." Sounds like you are poisoning your code-base with square functional pegs in round C++ holes...
[+] 16s|13 years ago|reply
std::function is really nice. I've started using it everywhere.
[+] evincarofautumn|13 years ago|reply
If only it didn’t use dynamic allocation…ah well. The value is worth the cost.
[+] repsilat|13 years ago|reply
In this case it's probably unnecessary. It's probably better to template these higher-order functions on their function arguments and just return the lambda itself instead of returning it in a function wrapper.