Functional Programming in C++
The main thing missing in C++ to do functional programming, as mentioned by John Carmack in http://gamasutra.com/view/news/169296/Indepth_Functional_pro... is lack of a 'pure' keyword to enforce it.
Experience with the 'pure' keyword in D has been overwhelmingly positive.
I like the idea of functional programming in C++, but unfortunately, you would have to write an entirely different (non-standard) library for that to work. For example, from the article:
...I like the pass-by-value syntax here, but it just won't work with the standard library, at least not the one in C++14. If you pass a vector into this function, you'll be creating a copy of the vector (!), then operating on the copy of the vector (!!). Then there is the question of what for_each does if it isn't manipulating state or performing I/O. In either case, you would not want an 'unop', you would want some sort of monad.template <typename Collection,typename unop> void for_each(Collection col, unop op){ std::for_each(col.begin(),col.end(),op); }For a more complete perspective on this sort of thing, I recommend Eric Neibler's blog and Bartosz Milewski's blog. Here's somewhere to start. You'll find Neibler's blog linked from there:
http://bartoszmilewski.com/2014/10/17/c-ranges-are-pure-mona...
> With modern C++ you can use value semantics with move semantics to get same performance as pass by reference.
That's overly simplistic. To enjoy the benefits of move semantics you need something to move from. If you call for_each from the article with an lvalue, you will end up making a copy (and it'll be up to the compiler to do something about that).
> Also you can use smart pointers to do automatic garbage collection.
Not quite. Smart pointers do automatic reference counting, which doesn't use a garbage collector.
Oh god, why.