memesearch
C++ Reflection Validation Nightmare

C++ Reflection Validation Nightmare

Download Find similar pictures
Text on the meme
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}));
What it means

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.

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