-
-
Notifications
You must be signed in to change notification settings - Fork 75
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
Usability/Feature questions: WebAssembly, C++20 concept type-traits, shorten macro for field-only definitions? #49
Comments
@RalphSteinhagen Thank you for enjoying using it!
I'm guessing there is some explanation for that, but unsure what it is.
To answer the question, I am not sure what the utility of checking whether a type is from template <typename T>
constexpr bool isStdType() {
return get_name(refl::reflect<T>()).template substr<0, 5>() == "std::";
} Needless to say, this only works for types that have metadata generated for them. Also:
#define REFL_CUSTOM(TypeName, ...) \
REFL_TYPE(TypeName) \
REFL_DETAIL_FOR_EACH(REFL_DETAIL_EX_1_field, __VA_ARGS__) \
REFL_END Unfortunately, DETAIL_ macros are neither public nor stable. You could replicate the code behind these two (possibly via trial and error) in YaS. About The one you have used is not constexpr, despite the constexpr specifier, because of constexpr auto members = refl::reflect<std::remove_reference_t<decltype(value)>>().members;
constexpr auto index = refl::trait::index_of_v<
refl::trait::remove_qualifiers_t<decltype(member)>, // member is assigned to const auto (remove the const)
refl::trait::remove_qualifiers_t<decltype(members)>>; // members is implicity const, because of constexpr
Hope you can get YaS working on top of refl-cpp! |
@veselink1 I am struck with awe! Thanks for your quick, generous and very thorough reply and suggestions*! 👍
Please feel free to close this issue since the above -- at least for me -- answered all the relevant aspects we initially need to move forward with our YaS. 👍 *P.S. Let me know if there is something I can help you with since you kindly helped me ... |
Glad I could help. |
@veselink1 first: Thanks for making refl-cpp a nice open-source header-only library! 👍
Sorry for the long post, which covers more than one -- albeit overlapping -- aspects.
We are evaluating porting our existing serialiser implementation (YaS - Yet-another-Serialiser) to a more modern C++20 standard using refl-cpp. Having compared several other alternatives, I find your library very neat, efficient, and in the spirit of the upcoming C++(23?) static reflection functionality. Even better: your library works as-is and with minimal requirement already now. Kudos for that! 👍 ⭐ ⭐ ⭐ 👍
While exploring the refl-cpp syntax, I gathered some usability and feature-type questions rather than issues. I was wondering whether you (or someone else reading this) would be willing to comment and/or advise on these.
I made a small example implementing a default streaming operator
operator<<
overload for reflection-annotated classes below to illustrate the MVP use-case which is very similar to our (or for that matter most other) serialisation use-cases.My questions:
I tried to compile the simple serialiser example (which works nicely), but I am getting errors when transpiling to WASM. This probably linked to missing headers in the compiler explorer environment but I was wondering whether somebody else has some successes with this before diving deeper into this myself. Any help/experience related to this would be much appreciated!
REFL_NO_STD_SUPPORT
), for example, via type-traits, concepts, or boolean function? If not -- while I found some workarounds (see below) -- would it be conceivable/useful to incorporate some of the aspects into refl-cpp or should this remain better in the user-code? My worry is that the list of possiblestd::
might get eventually very long and the workaround below is not very maintainable and probably better/less effort being incorporated at the location where these std:: annotations are defined. Just as a thought.REFL_CUSTOM(type, fieldName1, fieldName2, ..., fieldNameN)
? I tried my luck but am not good enough with macros (which seem to be unavoidable and absolutely justified in this case though). Or is this something we should implement ourselves? I found a nice solution using boost -- although that wouldn't probably a suitable dependency to be incorporated into refl-cpp.Any help/experience related to this would be much appreciated!
The example code -- also runnable on compiler-explorer:
The text was updated successfully, but these errors were encountered: