Created
October 19, 2020 05:52
-
-
Save Cylix/5081764fb21c5b42f42262281211a1df to your computer and use it in GitHub Desktop.
Reflection in C++14 - Member Function #5
This file contains 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
//! register specific member function | |
template <typename ReturnType, typename... Params> | |
void register_function(const std::pair<std::string, ReturnType (Type::*)(Params...)>& f) { | |
//! wrap the instanciation of a new object of type Type and the call to the function f in a C++11 lambda | |
auto f_wrapper = [f](Params... params) -> ReturnType { | |
return (Type().*f.second)(params...); | |
}; | |
//! store function information | |
functions.push_back({ | |
f.first, //! function name | |
std::make_shared<function<ReturnType(Params...)>>(f_wrapper) //! function object | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment