Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- old_operation(stream, format, varArgs);
- stream << operation(format, varArgs);
- template<typename ...T>
- decltype(auto) storage(T&& ...t) {
- return [&](auto&& f) ->decltype(auto) {
- return std::forward<decltype(f)>(f)(t...);
- };
- }
- template<typename ...T>
- class Operation
- {
- using Storage = decltype(storage(std::declval<T>()...));
- public:
- template<typename ...Args>
- explicit Operation(Args&& ...args) :
- mArgs(storage(std::forward<Args>(args)...)) {};
- template<class StreamType>
- StreamType& Apply(StreamType& stream)
- {
- auto f = [&](auto&& ...xs)
- {
- old_operation(stream, std::forward<decltype(xs)>(xs)...);
- }
- mArgs(f);
- return stream;
- }
- private:
- Storage mArgs;
- };
- template<typename ...Args>
- Operation<Args...> MakeOperation(Args&&... args)
- {
- return Operation<Args...>(std::forward<Args>(args)...);
- }
- template<class StreamType, typename ...Args>
- StreamType& operator<<(StreamType& stream, Operation<Args...>&& operation)
- {
- return operation.Apply(stream);
- }
- namespace X {namespace Y { namespace Z { int formater(double x) { return std::round(x); }}}
- #define OPERATION(...)
- [&]() {
- using namespace ::X:Y:Z;
- return Operation("" __VA_ARGS__); }()
- stream << OPERATION(format, formater(2.3));
Add Comment
Please, Sign In to add comment