Comments (3)
@RalphSteinhagen Thank you for enjoying using it!
I will try to answer as fully as possible, apologies if I miss some detail.
- I have never attempted to compile refl-cpp to WASM.
Attempting to include any one of the following fails in Godbolt. (The includes are from refl-cpp.) https://godbolt.org/z/K597qx989
#include <cstring>
#include <array>
#include <utility> // std::move, std::forward
#include <optional>
#include <tuple>
#include <type_traits>
#include <ostream>
#include <sstream>
#include <iomanip> // std::quoted
I'm guessing there is some explanation for that, but unsure what it is.
- I understand why this might be concerning. I have no plans to include metadata for
std::*
. In fact, at this time, I have no plans to continue adding any other types in there, as this will be a breaking change and might lead to clashes with user-defined metadata. The general idea behind the provided ones was to allow for the simplest and most common of data structures to be inspected and printed usingrefl::runtime::debug
. This includes exceptions (which I am regretting now), strings, tuples, pairs, smart pointers, complex numbers, as these have fairly standard representations. Coupled with the support for std:: containers inruntime::debug
, this should allow users to provide debug messages about composite types (containing lists, maps, etc). This is the primary reason why these exist. Anything else should be provided externally. Of course, this does not mean that no additional types will be added in the future!
To answer the question, I am not sure what the utility of checking whether a type is from std::
or not is, but have you considered just checking the prefix of the type name? https://godbolt.org/z/EYd51Tb6E
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:
refl::trait::is_instance_of_v<std::basic_string, T> === unique::is_instance<T, std::basic_string>::value
- I believe this accomplishes what you're asking for: https://godbolt.org/z/f84carnfs
#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 if (index > 0) { // how to make this constexpr??
: Argument expressions cannot participate in core constant expressions, which is what the condition for if constexpr
is. The compiler will optimise that away anyway, in constexpr lambdas.
The one you have used is not constexpr, despite the constexpr specifier, because of os <<
.
If you really want to, you can get a the index at compile time, with a little bit more difficulty. https://godbolt.org/z/K6fPhzY6h
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
- The example code does not really present a solution to a problem, but is more in the realm of exploring what is possible. I don't think it will be directly useful to users, but thanks for the suggestion.
Hope you can get YaS working on top of refl-cpp!
from refl-cpp.
@veselink1 I am struck with awe! Thanks for your quick, generous and very thorough reply and suggestions*! π
-
Regarding WASM: I do not expect any troubles since the header compiles fine with clang (one of the WASM work horses) and I did not see any obvious other reasons why not. This was more to explore, my guess is that the bug I saw is rather related to the specific compiler-explorer setup and that I have to do my own homework and do an actual proof of concept for myself. ;-)
I will let you know if I find anything to the contrary but you could consider this sub-issue/question as closed for now. -
This includes exceptions (which I am regretting now), [..]
I fully understand your reasoning behind this. We have both use-cases -- those where this additional info of the std type is
quite helpful and those where we do not want to dive into the std containers because we need to handle them differently to our annotated types.have you considered just checking the prefix of the type name?
Thanks for the hint and for pointing/reminding me of this simpler solution! I am usually hesitant regarding checking for literal class names (because of potentially breaking when refactoring) but for the 'std::*' context this should be pretty safe. π
-
I believe this accomplishes what you're asking for [..]
Yes, exactly! Thanks for helping out. As mentioned, I am not familiar enough with modern C++ macros but this does the trick. I also understand and respect your disclaimer ... no worries, we will fix it on our side in case it breaks. But for now, this is sufficient. π
-
The example code does not really present a solution to a problem [..]
OK. That's why I asked. I saw that you already implemented some other debug mechanism and found '<<' for our debugging style useful. Although, overloading the '<<' operator is also quite basic and can be easily rediscovered/implemented by others without having an explicit example. 'Document as much and only as much as absolutely needed' ... I think your docs/example style meets this criterion which is probably sufficient for most users.
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 ...
from refl-cpp.
Glad I could help.
from refl-cpp.
Related Issues (20)
- 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
- How to resolve the non-const signature of a class method. HOT 2
- Q: Implementing a member attribute for "Default value" to use in ctors
- (unknown)**Β that is all i get for typename HOT 1
- Deleted 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.