C++ Logo

sg7

Advanced search

Re: [SG7] From TMP to value-based reflection

From: Matus Chochlik <chochlik_at_[hidden]>
Date: Tue, 21 Dec 2021 06:47:38 +0100
On Tue, Dec 14, 2021 at 6:57 PM Jean-Baptiste Vallon Hoarau via SG7 <
sg7_at_[hidden]> wrote:

> So IIUC the difference that we're talking about is the following:
>>
> ...
>
> consteval string_view my_algo(meta::info mo) {
>> return classify(type_identity<do_t<something_t<here_t<[: mo :]>>>>{});
>> }
>
>
> This code is incorrect : "mo" here is not an instantiation-time value and
> so cannot be spliced.
>
> As for the rest of your concerns, I'd like to emphasize that, since it's
> easy to transform one style of API into the other at a library level, there
> are no fundamental differences between the two, except that the TMP-based
> reflection will take more of the compiler resources.
>
> I've spent the last week playing with the value-based implementation (and
also with meta::info a little) and I think my confusion came from having
heard and read that the consteval API tries to replace template-based API.
IIUC that is not true in many cases and instantiation is required to some
parts of meta::info to work.

>
> I might implement the reflection TS as a library using clang-meta, to
> illustrate the point.
>
I see now how that might be doable with the splicing operators working
differently in templates than in plain consteval functions.

Also I have started working on a library of utilities and examples using
the functional/template-based API:
https://github.com/matus-chochlik/mirror

I hope I'll be useful to gather the use-cases that we need to cover with
the standardized API, find common patterns, identify potantial higher-level
utilities, etc.
PRs with new examples and feedback is welcome.

--Matus

Received on 2021-12-20 23:47:51