Giter Club home page Giter Club logo

Comments (3)

veselink1 avatar veselink1 commented on May 20, 2024

@RalphSteinhagen Thank you for enjoying using it!
I will try to answer as fully as possible, apologies if I miss some detail.

  1. 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.

  1. 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 using refl::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 in runtime::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

  1. 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
  1. 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.

RalphSteinhagen avatar RalphSteinhagen commented on May 20, 2024

@veselink1 I am struck with awe! Thanks for your quick, generous and very thorough reply and suggestions*! πŸ‘

  1. 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.

  2. 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. πŸ‘

  3. 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. πŸ‘

  4. 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.

veselink1 avatar veselink1 commented on May 20, 2024

Glad I could help.

from refl-cpp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.