C++ Logo

std-proposals

Advanced search

[std-proposals] Simplified reflection with tuples

From: <yang.franklin9_at_[hidden]>
Date: Tue, 2 Jan 2024 18:52:41 -0800
Hello all,
 
I am not sure if discussion about reflection is still in order. Regardless,
I believe the usage is too complicated and the syntax somewhat messy.
 
Instead of a dedicated language feature that creates yet another usage for
`using`, I propose simply using the existing std::tuple type to hold member
information. This not only reduces potential language clutter, but also
provides programmers with a more familiar and "C++-like" interface to
reflection.

`reflexpr` will return a tuple containing `std::reflect::var`,
`std::reflect::lambda`, `std::reflect::func`, `std::reflect::class`, among
others, which represent objects. These "meta-types" will each contain their
own specific members (e.g. `std::reflect::func` but not `std::reflect::var`
may contain `get_parameters()`), and types for variables and classes could
be provided through a type alias.
 
I do not see a need to alter the contents of the current reflection
extensions, just how it is organized and presented. With my proposal, all
existing meta-object operations shall simply be converted to members of the
std::reflect types, except for those which are impractical.
 
Any feedback or criticism is appreciated.
 
Thanks,
Franklin Yang

Received on 2024-01-03 02:52:47