C++ Logo

sg7

Advanced search

Re: [SG7] TS Reflection experimental implementation in Clang available

From: Matus Chochlik <chochlik_at_[hidden]>
Date: Tue, 7 Dec 2021 10:13:44 +0100
Hi David,

On Sun, Dec 5, 2021 at 6:40 PM David Rector <davrec_at_[hidden]> wrote:

> Matus,
>
> For run time reflection needs there is a lot to like in your
> implementation. My main interest is using reflected info in injection
> statements at compile time, i.e. within consteval functions that generate
> code. It would be nice to play around with this reflection implementation
> in that context as well.
>
> To that end I cleaned up and updated my old string-injection*
> implementation:
> https://github.com/drec357/llvm-project/tree/stringinjection
> (Example usages here:
> https://github.com/drec357/llvm-project/blob/stringinjection/_stringinj/inj01.cpp
> )
>
> And I merged it with your project, into here:
> https://github.com/drec357/llvm-project/tree/main
>
Nice!


>
> Referring to your mirror01.cpp example, it would be nice to be able to use
> the combination of reflection and injection to do something like the
> following:
> ```
> consteval void inject_name_and_nextdayval(std::string_view n) {
> auto d = string_to_enum<weekdays>(n);
> __injf("static const weekdays {} = {};", "dummy", 3);
> }
>
> struct next_day_of {
> consteval {
> using namespace std::experimental::mirror;
> for_each(get_enumerators(mirror(weekdays)), [](auto mo) {
> inject_name_and_nextdayval(get_name(mo));
> });
> }
> };
>
I think we'll get to code-splicing eventually, but to do it properly we
need to gather some usage experience.


> ```
> (By the way, how does one put this merged project onto a separate
> compiler-explorer instance? Can anyone assist with that?)
>

I recently learned that it is just a matter of creating a ticket on github
and providing the necessary info :)

>
> However the above fails due to the usual inability to constant evaluate
> the necessary expressions. It might yet be possible with other TMP
> iteration techniques, though a simpler iteration interface will be nice. I
> suspect `template for` may still be needed for using refections in
> injection statements and for other compile-time tasks, I will try to add
> that feature to the above repositories in the next few days to see what
> that adds.
>
> But let me know if you try it out and find a nicer way to do this.
>

The first thing that I want to try out with code injection is to implement
some form of identifier splicing from metaobjects, but I want to finish the
TS implementation first.

--Matus

Received on 2021-12-07 03:13:56