C++ Template That Expires
Playing around with requires clauses to create a C++ template that expires after a specific year. godbolt.org/z/9ocG1Mr9r template <int expirationYear> constexpr bool is_before_year() { const int currentYear = (__DATE__[7] - '0') * 1000 + (__DATE__[8] - '0') * 100 + (__DATE__[9] - '0') * 10 + (__DATE__[10] - '0'); return currentYear < expirationYear; } auto add(auto lhs, auto rhs) -> decltype(lhs + rhs) requires (is_before_year<2026>()) { return lhs + rhs; } int main() { return add(2, 3); }
A screenshot of a social media post shows C++ code defining an addition function that only compiles before the year 2026. The joke is that the template contains an artificial expiration date, making otherwise ordinary legacy code suddenly stop working after a specific year. EN: A screenshot of a social media post shows C++ code defining an addition function that only compiles before the year 2026. The joke is that the template contains an artificial expiration date, making otherwise ordinary legacy code suddenly stop working after a specific year.
social media post / пост в соцсетиprofile photo / фотография профиляverified badge / значок верификацииC++ source code / исходный код C++code editor / редактор кодаdark theme / тёмная темаsyntax highlighting / подсветка синтаксисаtext link / текстовая ссылкаcurly braces / фигурные скобкиparentheses / круглые скобкиnumber 2026 / число 2026
- @ithueti / 15433 2025-03-06
- Type
- image
- Size
- 642×800 · 59.4 KiB
- Mood
- sarcastic
- Language
- en
- Added