Created
May 22, 2016 13:11
-
-
Save hatsusato/412b754b717a863df7f9954e5e3f91dc to your computer and use it in GitHub Desktop.
Manipulator in C++11 era
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <functional> | |
#include <iostream> | |
class Manipulator { | |
public: | |
using FuncType = std::function<void(std::ostream&)>; | |
Manipulator(const FuncType& f) : f_(f) {} | |
void exec(std::ostream& os) const { f_(os); } | |
private: | |
FuncType f_; | |
}; | |
std::ostream& operator<<(std::ostream& os, const Manipulator& m) { | |
m.exec(os); | |
return os; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment