unary-function

Passing a function object: Error

What's wrong with the following little program that passes a function object? #include <iostream> #include <functional> void foo(const std::unary_function<const std::string&, void>& fct) { const std::string str = "test"; fct(str); // error } class MyFct : public std::unary_function<const std::string&, void> { public: void operat...

Transform items from iterable with a sequence of unary functions

I frequently find myself needing to apply a sequence of unary functions to a sequence of of the same length. My first thought is to go with map(), however this only takes a single function to be applied to all items in the sequence. In the following code for example, I wish to apply str.upper() to the first item, and int to the second i...