Date: Sat, 23 Sep 2023 00:43:02 -0600
This is keeping me awake now.
`template< typename T >
requires( 1 == sizeof...(T) )
T &&thinglonger( T &&one_thing ) noexcept
{ return ( static_cast< T &&>( one_thing ) ); }
template< typename T >
requires( sizeof...(T) > 1 )
auto thinglonger( T &&bag_of_things )
{ return { bag_of_things... }; }
template< typename ...Ts >
auto thinglonger( Ts &&...many_things )
{ return thinglonger( thinglonger( many_things )... ); }
struct Thing
{
struct
{
int you;
int got;
int me;
};
union
{
int oh;
int now;
int what;
int hot_shot; //?
};
};
void Fn()
{
auto boop = thinglonger( Thing{}, Thing{} );
auto &gotClone = boop<1>;
}
// Effective result (I think):
struct LongerThing
{
int you;
int got;
int me;
union
{
int its;
int the_same;
int value;
int and_we_dont_need_the_name;
};
int ouch;
int its_crowded;
int and_flat;
union
{
int what;
int could_be;
int my_name;
int though;
};
};`
On Fri, Sep 22, 2023 at 11:04 PM Chris Gary <cgary512_at_[hidden]> wrote:
> On that note, something like a "nameof" operator that just returns an
> ASCIIz as some "const char (&name)[N]" would "print an enum" or "make a
> config form with these things on it, specialized templates determine the
> widget types" etc... very easy, and the programmer has the choice of
> looping over arrays into which such data is unpacked, or employing template
> metaprogramming in some way.
>
> On Fri, Sep 22, 2023 at 10:50 PM Chris Gary <cgary512_at_[hidden]> wrote:
>
>> :D
>> It ought to be, IMO.
>> What else is there left to do?
>>
>> When it comes to reflection, do I really need to do anything else but
>> "walk" public members in the same way?
>>
>> Something like "OrdinaryStruct ...clone;" then "clone<5>;" is easy to
>> verify, eliminates the need for special accessors, and resembles the other
>> use-cases mentioned.
>>
>> Private members are none of anything else's business, functions can be
>> inspected using concepts, and most use-cases for what's left for reflection
>> that I've encountered are really just serialization/marshalling of structs
>> with no private members (e.g. RPC parameter packs or handling form data for
>> a UI).
>>
>> On Fri, Sep 22, 2023 at 10:10 PM Thiago Macieira via Std-Proposals <
>> std-proposals_at_[hidden]> wrote:
>>
>>> On Friday, 22 September 2023 11:50:35 PDT Chris Gary via Std-Proposals
>>> wrote:
>>> > // Unpack public type members of MiscData in declaration order.
>>> > // Unpack public value members of a MiscData instance in the same
>>> order.
>>> > Mirror< MiscData... > clone{ data... };
>>>
>>> This looks like reflection.
>>>
>>> --
>>> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
>>> Software Architect - Intel DCAI Cloud Engineering
>>>
>>>
>>>
>>> --
>>> Std-Proposals mailing list
>>> Std-Proposals_at_[hidden]
>>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>>>
>>
`template< typename T >
requires( 1 == sizeof...(T) )
T &&thinglonger( T &&one_thing ) noexcept
{ return ( static_cast< T &&>( one_thing ) ); }
template< typename T >
requires( sizeof...(T) > 1 )
auto thinglonger( T &&bag_of_things )
{ return { bag_of_things... }; }
template< typename ...Ts >
auto thinglonger( Ts &&...many_things )
{ return thinglonger( thinglonger( many_things )... ); }
struct Thing
{
struct
{
int you;
int got;
int me;
};
union
{
int oh;
int now;
int what;
int hot_shot; //?
};
};
void Fn()
{
auto boop = thinglonger( Thing{}, Thing{} );
auto &gotClone = boop<1>;
}
// Effective result (I think):
struct LongerThing
{
int you;
int got;
int me;
union
{
int its;
int the_same;
int value;
int and_we_dont_need_the_name;
};
int ouch;
int its_crowded;
int and_flat;
union
{
int what;
int could_be;
int my_name;
int though;
};
};`
On Fri, Sep 22, 2023 at 11:04 PM Chris Gary <cgary512_at_[hidden]> wrote:
> On that note, something like a "nameof" operator that just returns an
> ASCIIz as some "const char (&name)[N]" would "print an enum" or "make a
> config form with these things on it, specialized templates determine the
> widget types" etc... very easy, and the programmer has the choice of
> looping over arrays into which such data is unpacked, or employing template
> metaprogramming in some way.
>
> On Fri, Sep 22, 2023 at 10:50 PM Chris Gary <cgary512_at_[hidden]> wrote:
>
>> :D
>> It ought to be, IMO.
>> What else is there left to do?
>>
>> When it comes to reflection, do I really need to do anything else but
>> "walk" public members in the same way?
>>
>> Something like "OrdinaryStruct ...clone;" then "clone<5>;" is easy to
>> verify, eliminates the need for special accessors, and resembles the other
>> use-cases mentioned.
>>
>> Private members are none of anything else's business, functions can be
>> inspected using concepts, and most use-cases for what's left for reflection
>> that I've encountered are really just serialization/marshalling of structs
>> with no private members (e.g. RPC parameter packs or handling form data for
>> a UI).
>>
>> On Fri, Sep 22, 2023 at 10:10 PM Thiago Macieira via Std-Proposals <
>> std-proposals_at_[hidden]> wrote:
>>
>>> On Friday, 22 September 2023 11:50:35 PDT Chris Gary via Std-Proposals
>>> wrote:
>>> > // Unpack public type members of MiscData in declaration order.
>>> > // Unpack public value members of a MiscData instance in the same
>>> order.
>>> > Mirror< MiscData... > clone{ data... };
>>>
>>> This looks like reflection.
>>>
>>> --
>>> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
>>> Software Architect - Intel DCAI Cloud Engineering
>>>
>>>
>>>
>>> --
>>> Std-Proposals mailing list
>>> Std-Proposals_at_[hidden]
>>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>>>
>>
Received on 2023-09-23 06:43:14