memesearch
Дикий enum to string

Дикий enum to string

Download Find similar pictures
Text on the meme
template <typename E> requires std::is_enum_v<E> constexpr std::string enum_to_string(E value) { template for (constexpr auto e : std::meta::members_of('E')) { if (value == e::value) { return std::string(std::meta::name_of(e)); } } return "<unnamed>"; } enum Color { red, green, blue }; static_assert(enum_to_string(Color::red) == "red"); static_assert(enum_to_string(Color(42)) == "<unnamed>");
What it means

На изображении показан фрагмент современного C++-кода, который преобразует значение enum в строку через метапрограммирование. Для обычных значений Color функция возвращает имя элемента, а для Color(42) — «<unnamed>», что высмеивает чрезмерно сложный способ решения простой задачи. EN: The image shows a snippet of modern C++ code that converts an enum value to a string using metaprogramming. For ordinary Color values the function returns the enumerator name, while Color(42) produces “<unnamed>”, poking fun at an overly elaborate solution to a simple problem.

Objects
Tags
Source
Type
image
Size
800×245 · 23.6 KiB
Mood
саркастичный
Language
en
Added