C++ Logo


Advanced search

Re: [SG7] Update: P1240R2 — Scalable Reflection

From: Peter Dimov <pdimov_at_[hidden]>
Date: Sun, 16 Jan 2022 00:34:06 +0200
David Rector wrote:
> There is also the matter of a) iteration,

>From my perspective (which is trying to get something
working without being able to patch my own compiler),
one interesting property of using info<__id> is that one
can obtain iteration without having `template for`.

Range-returning functions can just return list<__i1, __i2,
..., __in>, which can then be iterated using fold
expressions (or mp_for_each).

I understand that this is quite contrary to the value-based
"ideology", but it's often more usable. Consider, for
instance, the use case of taking a struct and making a
tuple out of it.


template<class S> auto struct_to_tuple( S const& s )
    return struct_to_tuple_impl(s, members_of(^S));

template<class S, template<auto...> class L, auto... R>
auto struct_to_tuple_impl( S const& s, L<R...> )
    return std::make_tuple( s.*pointer_to( R{} )... );

Of course, it might be possible to implement this with
ease using P1240/P2320 range splicing; if so, it will make
a good example.

Received on 2022-01-15 22:34:07