#ifndef NALL_METHOD_HPP #define NALL_METHOD_HPP //provides extension-method and chaining-method support to classes //extension: class(function, params...); //chaining: class[function](params...)[function](params...); //usage: //struct object : method { // using method::operator[]; //if object::operator[] defined // using method::operator(); //if object::operator() defined //}; //note: extension-methods would be obsolete if C++17 introduces unified function call syntax //currently proposed as N4165 and N4174 namespace nall { template struct method { template struct chain { chain(T& self, const F& f) : self(self), f(f) {} template auto operator()(P&&... p) -> T& { return f(self, std::forward

(p)...), self; } private: T& self; const F& f; }; template struct const_chain { const_chain(const T& self, const F& f) : self(self), f(f) {} template auto operator()(P&&... p) const -> const T& { return f(self, std::forward

(p)...), self; } private: const T& self; const F& f; }; template>> auto operator[](const F& f) -> chain { return chain((T&)*this, f); } template>> auto operator[](const F& f) const -> const_chain { return const_chain((const T&)*this, f); } template>> auto operator()(const F& f, P&&... p) -> decltype(f((T&)*this, std::forward

(p)...)) { return f((T&)*this, std::forward

(p)...); } template>> auto operator()(const F& f, P&&... p) const -> decltype(f((const T&)*this, std::forward

(p)...)) { return f((const T&)*this, std::forward

(p)...); } }; } #endif