boostorg / describe

A C++14 reflection library
https://boost.org/libs/describe
67 stars 24 forks source link

Add support for custom class/struct member names #19

Open phprus opened 2 years ago

phprus commented 2 years ago

I suggest adding support for custom class/struct member names to the library. Like this example:

#include <boost/describe.hpp>
#include <iostream>

struct my_struct
{
    int   a;
    float b;
    char  c;
};

BOOST_DESCRIBE_STRUCT(
    my_struct, (), (
        (a, "a_name"),
        (b, "b_name"),
        (c)
    )
)

int main()
{
    boost::mp11::mp_for_each<
        boost::describe::describe_members<my_struct,
        boost::describe::mod_any_access>
    >([&](auto D){
        std::cout << D.name << std::endl;
    }); 

    // Output:
    //    a_name
    //    b_name
    //    c

    return 0;
}