boostorg / describe

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

Add support for class template #17

Closed sdebionne closed 2 years ago

sdebionne commented 3 years ago

Would support for class template description be implementable (eventually with a different macro)?

namespace app {
    template <typename T>
    struct point
    {
        T x;
        T y;
    };

    BOOST_DESCRIBE_STRUCT(point, (), (x, y))      // Not supported
    BOOST_DESCRIBE_STRUCT(point<int>, (), (x, y)) // OK
} //namespace app
pdimov commented 3 years ago

Class templates already work with BOOST_DESCRIBE_CLASS. (But MSVC can't compile it due to compiler bugs.)

sdebionne commented 3 years ago

Awesome, I was unlucky then. Just to be sure, BOOST_DESCRIBE_CLASS works with class templates but not BOOST_DESCRIBE_STRUCT or am I reading too much between the lines? It's just that BOOST_DESCRIBE_CLASS is slightly more intrusive, being defined inside the class...

pdimov commented 3 years ago

That's correct, BOOST_DESCRIBE_CLASS works, BOOST_DESCRIBE_STRUCT doesn't (work for templates).

However I notice I don't actually have a test for it. I probably intended to add one and got distracted with other things.

pdimov commented 3 years ago

Oh it works with VS 16.10. Cool.

sdebionne commented 3 years ago

Thanks for clarifying. Making BOOST_DESCRIBE_STRUCT work for templates, would that be possible? If not, I'll just close the issue.

pdimov commented 3 years ago

No, it can't work as is. It might be possible to have another macro BOOST_DESCRIBE_TEMPLATE_STRUCT but the syntax in the general case will be awful, I think.

pdimov commented 3 years ago

It turns out it only works with VS2019 with /std:c++latest. :-)

pdimov commented 3 years ago

https://github.com/boostorg/describe/commit/7e9f1f0eb9759a0b75f0ba8097764c9146c0cf49

sdebionne commented 2 years ago

It might be possible to have another macro BOOST_DESCRIBE_TEMPLATE_STRUCT but the syntax in the general case will be awful, I think.

Any chance that you got new ideas how to implement a non-intrusive description of class template ? Just checking before giving it a try...

pdimov commented 2 years ago

No, I haven't been considering it.