Skip to content

Instantly share code, notes, and snippets.

@hatsusato
Created May 22, 2016 13:11
Show Gist options
  • Save hatsusato/412b754b717a863df7f9954e5e3f91dc to your computer and use it in GitHub Desktop.
Save hatsusato/412b754b717a863df7f9954e5e3f91dc to your computer and use it in GitHub Desktop.
Manipulator in C++11 era
#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