C++ Reflection Validation Nightmare
struct Range { int lo, hi; }; struct Config { [[=Range{ lo: 1, hi: 65535}]] int port; [[=Range{ lo: 1, hi: 256}]] int max_threads; [[=Range{ lo: 100, hi: 30000}]] int timeout_ms; }; template <typename T> constexpr bool validate(const T& obj) { constexpr auto context = std::meta::access_context::current(); template for (constexpr auto member : define_static_array( r: nonstatic_data_members_of(^T, context))) { template for (constexpr auto annotation : define_static_array( annotations_of_with_type(member, ^Range))) { auto [lo, hi] = extract<Range>(annotation); if (obj[:member:] < lo || obj[:member:] > hi) return false; } } return true; } static_assert(validate(Config{.port: 1000, .max_threads: 50, .timeout_ms: 20000})); static_assert(!validate(Config{.port: 0, .max_threads: 0, .timeout_ms: 0}));
A screenshot shows dense C++ code using proposed reflection syntax to annotate configuration fields with valid ranges and validate them at compile time. The joke is that C++26 reflection makes a simple validation task look extremely complicated and visually unpleasant, so it is shared as a sarcastic reaction to the new syntax. EN: A screenshot shows dense C++ code using proposed reflection syntax to annotate configuration fields with valid ranges and validate them at compile time. The joke is that C++26 reflection makes a simple validation task look extremely complicated and visually unpleasant, so it is shared as a sarcastic reaction to the new syntax.
code editor screenshot / скриншот редактора кодаC++ source code / исходный код C++struct definition / определение структурыconfiguration object / объект конфигурацииinteger fields / целочисленные поляrange annotations / аннотации диапазонаvalidation function / функция валидацииcompile-time assertion / проверка на этапе компиляцииmonospace text / моноширинный текстwhite background / белый фон
#c++#reflection#programming#программирование#template metaprogramming#метапрограммирование шаблонов#syntax#синтаксис#code#код#developer#разработчик#compile time#время компиляции#validation#валидация#range checking#проверка диапазона#ugly syntax#уродливый синтаксис#reaction#реакция#sarcasm#сарказм#screenshot#скриншот#programmer meme#мем программиста
- @gentoomemes / 21912 2026-09-08
- Type
- image
- Size
- 800×593 · 87.4 KiB
- Mood
- саркастичный
- Language
- en
- Added