Comments (2)
Would it be possible to add a version of REFL_FUNC
that takes a function pointer? That seems like the most efficient way to handle overloads. Usage would look something like:
REFL_FUNC_PTR(MyMethod, static_cast<const char*(*)(int, bool)>(&MyClass::MyMethod))
from refl-cpp.
EDIT: Success! It works with refl::descriptor::get_attribute<func_ptr>
. The code as modified below works.
template <typename Func>
struct func_ptr : refl::attr::usage::member
{
Func func;
constexpr func_ptr(Func func) : func(func) {}
};
REFL_AUTO(type(Foo), func(getPtr, func_ptr(static_cast<char*(foo::*)()>(&getPtr))))
// and in the central handler routine:
constexpr auto type = refl::reflect<tinyxml2::XMLNode>();
constexpr auto members = get_members(type);
for_each_unordered(members, [&](auto member)
{
if constexpr(refl::descriptor::has_attribute<func_ptr>(member))
{
const auto fptr = refl::descriptor::get_attribute<func_ptr>(member).func;
}
else
{
const auto fptr = refl::descriptor::get_pointer(member);
}
});
It also works if you want to use a proxy function instead of the class member. Unfortunately the REFL_FUNC
macro does not appear to be compatible with lambdas or std::function
, but that's a small quibble.
from refl-cpp.
Related Issues (20)
- Another Compiler error on Visual Studio 2019 but not on XCode (GCC) HOT 2
- 100-item limit for REFL_AUTO HOT 2
- cannot compline on my macbook pro HOT 1
- GetDateFormat getter vs. the Win32 API HOT 2
- Use of `get_reader` and `has_writer` produces absurdly long compile times HOT 18
- Q: make REFL_AUTO, REFL_TYPE etc. callable from nested namespace HOT 7
- Port to vcpkg HOT 3
- Fix warnings for strict variadic macro checks (stronger C++20 enforcement)
- refl::util::detail::filter(..) inverts order of member list HOT 2
- Is there a way to reflect private fields? HOT 5
- Q: how to reflect on member functions' parameters and return types? HOT 5
- Is there a possibility of adding features like Boost.PFR? HOT 3
- Ability to break class declarations up HOT 9
- How to implement my case with this library? HOT 1
- Question. a generic getter function for reflected type HOT 1
- Enum reflection HOT 2
- Access member descriptor from pointer-to-member HOT 4
- Field offsetof HOT 4
- Member list empty when using reflect<T>(), but works fine with reflect(const T&) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from refl-cpp.