←back to thread

196 points svlasov | 8 comments | | HN request time: 1.468s | source | bottom
1. TillE ◴[] No.40851335[source]
Finally. I think there have been proposals since C++17 at least, and all I really wanted is for them to solve the common problem of basic static reflection for enums (without hacks like magic_enum uses).
replies(1): >>40851454 #
2. jjmarr ◴[] No.40851454[source]
magic_enum is killing my build time with endless template instantiations. Is this going to be faster?
replies(3): >>40851746 #>>40853037 #>>40871158 #
3. leni536 ◴[] No.40851746[source]
magic_enum works by walking all possible enumeration values from one-by-one in a wide range at compile time, instantiating a function template for each one so it can extract the __PRETTY_FUNCTION__ name, which is very slow. The C++26 feature just directly returns the vector of the named enumerators in one go, so it should be way faster.

They have a reference implementation on godbolt under clang, so you can play around with that. I did not try it yet.

replies(1): >>40852230 #
4. jjmarr ◴[] No.40852230{3}[source]
Wow. I'm trying to make some of these template instantiations explicit on a large project I'm on as magic_enum is one of the largest contributors to our build-time.

It's nice to know I can just transition to C++26 to fix this.

5. mehrdadn ◴[] No.40853037[source]
Do you think you could try my library [1] and let me know how it performs in comparison? I've been curious about its compile-time performance, but I've never tried to compare its performance against that of magic_enum.

[1] https://news.ycombinator.com/item?id=32236447

6. dakka1 ◴[] No.40871158[source]
If you're using C++20 or above, you could try conjure_enum (https://github.com/fix8mt/conjure_enum) It's based on magic_enum but optimized for C++20. Not sure about compile times although in our testing and with our test users it hasn't been reported as an issue.

Yes, there is magic_enum already - and we based this implementation on the core of magic_enum, but refocused for C++20, using some of the key features of this language version such constexpr algorithms, std::source_location and concepts; we also improved on and expanded the API.

replies(1): >>40908829 #
7. jjmarr ◴[] No.40908829{3}[source]
I'm trying it, and this library doesn't work on clang 14. Do you have any insight as to why?
replies(1): >>40910641 #
8. dakka1 ◴[] No.40910641{4}[source]
Not supported. Minimum 15. See "8. Compiler support"