veselink1 / refl-cpp

Static reflection for C++17 (compile-time enumeration, attributes, proxies, overloads, template functions, metaprogramming).
https://veselink1.github.io/refl-cpp/md__introduction.html
MIT License
1.06k stars 77 forks source link

Use case question involving func() declared members #6

Closed Undertoe closed 4 years ago

Undertoe commented 4 years ago

Hello, I have a usecase for this library and I'm not sure if its implemented and I'm trying to implement it wrong or if its still in the works. I am trying to get a key/value structure with reference to a structure and have it dynamically generated. I have the following code:

refl_CPP

on line 44 i'd like to be able to get the reference to the function in a std::function<> type. I'm not sure if this a feature currently in the library, but it would be an incredibly helpful usecase on my end.

veselink1 commented 4 years ago

Hello! Since you have posted a screenshot I cannot test your code, but it appears that you want to get a function pointer to a reflected function? You can just use the member.pointer member, which is available, seeing that the function in question is not overloaded. So that would be functionMap[name] = member.pointer;

Undertoe commented 4 years ago

Yeah, ideally i'd like to get it in this case to a declared: std::function<int(const std::string&)>, or at least in a way so that i can reference that . Still new to some of the TMP navigation so i'm not 100% sure on how to arrive there.

However, I have arrived at a partially working (but not quite to where i'd like it just yet) solution. I'll try to post when i can get the code off of the system that has it, it may be a nice example case for you.

The use-case for what I am doing is building a "Shell" for a RT Simulation that allows my group to modify and retrieve values from an object, as well as call an object's functions, and I'm trying to set it up so that we don't have to map a function for every variable. This reflection library pretty much solved all of that with only a few functions / objects to tie everything together so now things are automatically referenced by the member / function name.