Skip to content
DevMeme
4489 of 7590
Languages Post #4928 · source on Telegram

Modern C++ readability claims shattered by a wall of template sorcery

Description

The meme has a black background with white caption text at the top reading "C++ programmers: modern C++ is really nice and readable" followed by a line break and "Also C++ programmers:". Below the caption is a rounded-corner screenshot of a C++ source file displayed in a rainbow-colored syntax-highlighting theme. The visible code shows extremely dense template metaprogramming with almost every modern C++ feature crammed into one snippet: "template <typename... T> requires std::is_same_v<int, T...[0]> && requires(T...[0]) { (T...[0])() -> std::same_as<T...[0]>; } struct S : T...[1] { [[no_unique_address]] T...[1] base = {}; using foo = T...[1]; S() // : T...[1]() {} static_assert(std::is_same_v<int, T...[0]>); const T...[0] f(T...[0] && p) noexcept((T...[0])0) { T...[0] (*test)(const volatile T...[0]**); thread_local T...[0] d; [[maybe_unused]] T...[0] a = p; return a; auto ptr = new T...[0](); using Int = int; (*ptr).~T...[0](); return T...[0]()(); typename T...[1]::foo b = 0; T...[1]::i = 0; return (T...[0])(a); new T...[0]; new ((T...[0]& )a) T...[0]; auto l = [T...[0](T...[0][1]) -> T...[0]{return static_cast<T...[0]>(0);}]; [[maybe_unused]] auto _ = l.template operator()<T...[0]>()({0}); } operator T...[0]() const; }; struct base { using foo = int; static inline int i = 42; }; int main() { S<int, base>()(f()); //////////// }" The chaotic rainbow highlight underscores how unreadable and intimidating the supposedly "nice" modern C++ can become, poking fun at the disconnect between claims of elegance and real-world template monstrosities

Comments

6
Anonymous ★ Top Pick Modern C++: proving int is int with a 3-line requires clause, shaving one byte with [[no_unique_address]], and still waiting five minutes for the linker to veto the whole idea
  1. Anonymous ★ Top Pick

    Modern C++: proving int is int with a 3-line requires clause, shaving one byte with [[no_unique_address]], and still waiting five minutes for the linker to veto the whole idea

  2. Anonymous

    The same engineers who spent three sprints perfecting this template metaprogramming masterpiece will reject a PR for using a ternary operator because it "hurts readability."

  3. Anonymous

    Ah yes, modern C++ - where 'readable' means you only need three PhD dissertations, a working knowledge of category theory, and a compiler error message that spans 47 terminal screens to understand a simple function signature. The real kicker? This code probably compiles to the same assembly as 'int x = 42;' but now your junior devs need a sabbatical to understand the PR. Remember when we thought C++ templates were just 'fancy generics'? Those were simpler times, before concepts made us question our career choices and fold expressions made us fold our laptops shut

  4. Anonymous

    Modern C++ is readable - if your reviewers can evaluate requires clauses, pack expansions, and noexcept expressions in their head while tracking placement-new lifetimes

  5. Anonymous

    Modern C++ is “readable” once you accept you’re not writing a function - you’re writing a proof that T...[0] may legally be {}, with concepts, static_asserts, and ADL acting as the judge

  6. Anonymous

    Modern C++ templates: where readability yields to the compiler's infinite wisdom, leaving mortals to divine intent from error spew

Use J and K for navigation