News for hackers. Stuff that matters.
Re:Fun with C++26 reflection: Keyword Arguments by NL807 on Tuesday February 11, 2025 @12:24AM (#43009287)
Honestly, all I ever want is to be enumerate a struct data member or an enum at compile time, and be able to get the name, type and value of each iterated member. That's it. That's all I want.
Re:Fun with C++26 reflection: Keyword Arguments by Gibbon1 on Tuesday February 11, 2025 @01:16AM (#43009572)
Would be happy with a enum that's a named key value.

    key_enum one_two_three 
    {
       FIRST = { .name = "first"},
       SECOND = { .name = "second"},
       THIRD = { .name = "third"},
       LAST = { .value = 255, .name = "last"},
    };
Re:Fun with C++26 reflection: Keyword Arguments by uecker on Tuesday February 11, 2025 @04:02AM (#43010575)
What is wrong with the following? Do you want type more type safety, e.g. linking the enumeration constants to the array?

  enum { FIRST, SECOND, THIRD };
  struct { char *name; int value; } table[] = {
    [FIRST] = { .name = "FIRST", .value = 0 },
    [SECOND] = { .name = "SECOND", .value = 1 },
    [THIRD] = { .name = "THIRD", .value = 3 },
  };
Re:Fun with C++26 reflection: Keyword Arguments by gpderetta on Tuesday February 11, 2025 @06:18AM (#43011518)
You still need generic code to link the enum type to its format string, for example for use in std::format or std::ostream.

Nothing really difficult, normally all of this is done by hand, which is tedious and error prone, or incorporated in a macro. It would just be nice if there was a standard provided turn-key solution to the problem.

Re:Fun with C++26 reflection: Keyword Arguments by jcelerier on Tuesday February 11, 2025 @11:04AM (#43014454)
I have yet to see a project where there have never been bugs due to someone forgetting to update the metadata attached with the enum when there's a change
Re:Fun with C++26 reflection: Keyword Arguments by jjmarr on Tuesday February 11, 2025 @08:44AM (#43012643)
magic_enum addresses your issue but will absolutely kill compile time on a large project due to recursive template instantiation.