Git Product home page Git Product logo

Comments (4)

veselink1 avatar veselink1 commented on June 12, 2024

Hey there 👋,

There is currently no provision for a field descriptor lookup given a pointer to a member, however, one can be added if it's going to be useful, which it seems to be 👍.

from refl-cpp.

W4RH4WK avatar W4RH4WK commented on June 12, 2024

To provide some background: I am trying to build a serialization framework where types can be automatically serialized via reflection (as fallback), but the user can still customize the serialization of a specific type by using template specialization.

It would be nice if attributes (or more generally the descriptor) can still be accessed from this customized serialization function.
For my use-case, the attributes will contain information that is helpful for the serialization process (e.g. upper/lower bounds on a numeric member).

My first idea for implementing this would be by using filter on the members of the type's descriptor, comparing the pointer-to-member. Yet, I am unsure how to reduce from the type list to single (optional) element.

Note that there is absolutely no hurry. I am just toying around with a pet project.

from refl-cpp.

veselink1 avatar veselink1 commented on June 12, 2024

Ah, that makes sense. Have you considered refl::util::find_one, which returns the matching descriptor and fails if the list doesn't contain a match?

Something like

template <typename T, typename C, T C::*P>
auto find_field_impl() {
    return refl::util::find_one(field_descriptors_of<C>{}, [](auto m) { return m.pointer == P; });
}

https://godbolt.org/z/je3oxc6Wc

from refl-cpp.

W4RH4WK avatar W4RH4WK commented on June 12, 2024

Sorry for the late reply. I missed find_one.

The example looks good! Just noticed a typo in line 11, reflect should take C as template parameter not T; unless I misunderstood something.

A bit sad that the additional type traits are necessary, but I guess there are already a lot of custom type traits in the library.
Do you have any plans for adding this functionality for fields and functions / properties in a future release?

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.