-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GIve away the details of get_name
#150
Comments
You need to pass the field in a template function. Then you use a demangle function inside the current template function. To demangle, use the special feature from the preprocessor: pfr/include/boost/pfr/detail/core_name20_static.hpp Lines 88 to 96 in c695aa0
Then you need to extract the template parameter of the current template function. But the output of the demangle function is not standardized, it's compiler dependent. See pfr/include/boost/pfr/config.hpp Lines 115 to 126 in c695aa0
You may have a look at https://bitwizeshift.github.io/posts/2021/03/09/getting-an-unmangled-type-name-at-compile-time/ And after writing it, I noticed it returns only the type, not the member.... I hope it will help you a little... I also spend an hour without understand how the name of the field is demangled by |
#90 |
Thanks. |
(There are no pointer-to-member in this method (I tried to get here but constexpr time will not work).) The simplified strategy is the following:
template<class T>
extern const T non_exists;
template<class T>
constexpr auto get_members() {
// this example works only with 3 member
auto& [m1, m2, m3] = non_exists<T>;
return std::tuple{&m1, &m2, &m3};
}
template<class T, std::size_t I, auto* member = std::get<I>(get_members<T>())>
auto get_name()
{
__PRETTY_FUNCTION__ // this contains:
// member = &non_exists<the_type>.member_name
} So we "get" the name from the non-existent object's member address. The library uses some workaround, but basically, this is under the hood |
I still don't get this part. This code only returns pointers (rather than pointers-to-members). |
You right, only references in this code. And it's more than enough to obtain the name. |
Oh. Thank you. This is brilliant. |
Sure, article in the docs will be created later |
https://godbolt.org/z/Kj9MKosz9 constexpr auto first = sv.find_last_of(":.>", last); than constexpr auto first = sv.find_last_not_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789", last); |
Would it be possible to describe in "How it works" how obtaining the name is implemented?
I tried to study the library for a couple of hours, and still cannot understand it. Apparently, you must be creating a pointer-to-member somewhere, no? But how is it done?
The text was updated successfully, but these errors were encountered: