News for hackers. Stuff that matters.
Re:C++: Associative map containers with compile-time lookup by jstimpfle on Tuesday October 23, 2018 @07:45AM (#18282518)
Re: 3), here's a clean and technically humble way that I typically use.

    enum {
        KEY_FOO,
        KEY_BAR,
        KEY_BLAH,
        NUM_KEYS,
    };

    struct KeyInfo {
        const char *name;
        int info1;
        float info2;
    };

    const static struct KeyInfo keyInfo[NUM_KEYS] = {
    #define MAKE(x, y, z) [x] = { #x, y, z }
        MAKE( KEY_FOO,   1,   1.0 ),
        MAKE( KEY_BAR,   7,   3.5 ),
        MAKE( KEY_BLAH, 42, 127.2 ),
    #undef MAKE
    };

    void print_key(int key)
    {
        printf("%d's name is %s\n", key, keyInfo[key].name);
    }
It's both low-tech and maintainable. It compiles super quick. If one doesn't like that one has to type KEY_FOO twice (in the enum and in the array definition), one can use X-macros or code generation. But personally I don't care.
Re:C++: Associative map containers with compile-time lookup by hogliux on Tuesday October 23, 2018 @08:10AM (#18282646)
Yes, that's a nice approach. However, this approach requires you to list all your keys in advance (in the enum).

The `semi::static_map` does not require this.This is especially useful if you are writing library code: imagine you are programming a `getFont` method - you don't know with which constexpr keys your method will be called, so there is no way for you to list all these keys in an enum.

Re:C++: Associative map containers with compile-time lookup by kazinator on Tuesday October 23, 2018 @02:25PM (#18286032)
If you don't like pointlessly repeating occurrences of identifiers, you should hardly be favoring C++.

   class foo {
   public:
     foo();
     ~foo();
   };
 
   foo::foo() { }

   foo::~foo() { }
Ad nauseum.

Oh, but C++ can eliminate redundancy in this one cool case I'm thinking of!

Re:C++: Associative map containers with compile-time lookup by IshKebab on Tuesday October 23, 2018 @08:27AM (#18282743)
C++ doesn't support designated initialisers.