this post was submitted on 30 Jun 2024
11 points (100.0% liked)

C++

1773 readers
8 users here now

The center for all discussion and news regarding C++.

Rules

founded 1 year ago
MODERATORS
top 3 comments
sorted by: hot top controversial new old
[–] 0x0@programming.dev 3 points 4 months ago

C++ feature creep continues...

[–] riodoro1@lemmy.world 2 points 4 months ago* (last edited 4 months ago) (1 children)

“Simple” enum to string

template <typename E>
  requires std::is_enum_v<E>
constexpr std::string enum_to_string(E value) {
  template for (constexpr auto e : std::meta::enumerators_of(^E)) {
    if (value == [:e:]) {
      return std::string(std::meta::name_of(e));
    }
  }

  return "<unnamed>";
}

They have taken us for absolute fools.

[–] lambalicious@lemmy.sdf.org 1 points 4 months ago

No requires(requires(...

No decltype((auto))

No noexcept(noexcept(...

To be fair, it's quite an advancement considering what I was expecting.

Just about my only question is why the return is a string and not a `string_view``.