Created
October 19, 2020 05:46
-
-
Save Cylix/4d57b2f0894340daf675ef68b2c36ff6 to your computer and use it in GitHub Desktop.
Reflection in C++14 - Member Function #2
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
| //! our function base class, non-templated. | |
| //! it does really nothing, except helping us to store functions in the same container | |
| class function_base { | |
| public: | |
| virtual ~function_base(void) = default; | |
| }; | |
| //! our function class, templated on return and parameters types | |
| template <typename ReturnType, typename... Params> | |
| class function; | |
| template <typename ReturnType, typename... Params> | |
| class function<ReturnType(Params...)> : public function_base { | |
| public: | |
| //! our constructor | |
| //! we simply take an std::function as parameter and store it internally | |
| //! in fact, our function class is just a wrapper of std::function which inherits from function_base, nothing more | |
| function(const std::function<ReturnType(Params...)>& f) : f(f) {} | |
| //! a callable operator to be able to call our function | |
| ReturnType operator()(Params... params) { | |
| return f(params...); | |
| } | |
| private: | |
| std::function<ReturnType(Params...)> f; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment