Boost logo

Boost :

From: Vinícius dos Santos Oliveira (vini.ipsmaker_at_[hidden])
Date: 2020-09-24 21:33:49

Em qui., 24 de set. de 2020 às 12:43, Peter Dimov via Boost
<boost_at_[hidden]> escreveu:
> The purpose of Describe is to establish a standard way of annotating
> (describing) user-defined types (enums, structs and classes), so that types
> can be described once, and then their descriptions can be used from other
> libraries. At the moment, the practice is for each library to invent its own
> ad-hoc annotation/description mechanism.

Hi Peter,

could you consider using "compile-time strings" such as Hana's? I
don't have much use for a const char* in TMP algorithms. I coded a
gperf-like algorithm earlier this year and the only thing that enabled
me to do so were Hana strings:

Another use I've found for Hana-like strings was avoiding allocation
on object keys for json::partial::scanf(). Both algorithms can be
adapted to JSON serialization code that integrates with
serialization/reflection libraries, but only if I have something more
than char*.

You don't need to replace the current `name` member. You could maybe
just add an additional member? Maybe controlled through macros so you
don't force unwanted dependencies on everybody?

OTOH, if you're going to enable Hana integration behind a preprocessor
macro, maybe you could as well just forward on doing a complete
boost::hana::accessors integration. Not sure what is the right approach

Hana is such a great TMP library that you risk turning it into your
default go-to for any complex TMP problem once you get your head
around it.

Honestly, if I can't implement the algorithms described above, I
wouldn't use this library at all (I can already do them on Boost.Hana
and they work today). One usually annotate/describe structs in Hana
using code such as:

namespace ns {
    struct Person {
        explicit Person(std::string const& name, int age)
            : name_(name), age_(age)
        { }
        std::string const& get_name() const { return name_; }
        int get_age() const { return age_; }
        std::string name_;
        int age_;
    (name, [](ns::Person const& p) { return p.get_name(); }),
    (age, [](ns::Person const& p) { return p.get_age(); })

You can see full examples at

Vinícius dos Santos Oliveira

Boost list run by bdawes at, gregod at, cpdaniel at, john at