{"slug": "exotic-crtp-pattern-for-static-polymorphism-using-variadic-mixin-composition-and", "title": "Exotic CRTP pattern for static polymorphism using variadic mixin composition and C++23 explicit object parameters.", "summary": "This article presents a novel C++23 pattern called \"Exotic CRTP\" that combines variadic mixin composition with explicit object parameters to achieve static polymorphism with zero runtime overhead. The pattern introduces a `crtp_access` helper that enables compile-time interface dispatch by using `this auto&& self` in base class methods and casting to the derived type, while hiding implementation methods from external callers. The approach is demonstrated through a simple example where a `Base` class calls `implementation()` on a `Derived` class through static dispatch, with the implementation method only accessible through the CRTP access mechanism.", "body_md": "exotic_crtp.hpp\n\n      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.\n      \nLearn more about bidirectional Unicode characters\n\n \n    Show hidden characters\n\n// Copyright (c) May 2026 Félix-Olivier Dumas. All rights reserved.\n\n// Licensed under the terms described in the LICENSE file\n\n// Reference example of the pattern\n\n// See: https://medium.com/@felixolivierdumas/exotic-crtp-rethinking-static-polymorphism-with-c-23-89f9e75e8ffd\n\n#pragma once\n\n#include <iostream>\n\n#include <type_traits>\n\n#include <utility>\n\nnamespace exotic {\n\n    template<typename... From>\n\n    struct crtp_access : From... {};\n\n    template<typename T>\n\n    constexpr decltype(auto) as_crtp(T&& obj) noexcept {\n\n        using crtp_access_t = crtp_access<std::remove_cvref_t<T>>;\n\n        return static_cast<crtp_access_t&&>(obj);\n\n    }\n\n}\n\nstruct Base {\n\n    void interface(this auto&& self) {\n\n        return exotic::as_crtp(self).implementation();\n\n    }\n\n};\n\nstruct Derived : Base {\n\n    void implementation(this exotic::crtp_access<Derived> self) {\n\n        std::cout << \"Derived implementation\" << std::endl;\n\n    }\n\n};\n\nint main() {\n\n    Derived d;\n\n \n\n    d.interface(); // perfectly works\n\n \n\n    //d.implementation(); -> doesn't work, Derived only shows .interface()\n\n}", "url": "https://wpnews.pro/news/exotic-crtp-pattern-for-static-polymorphism-using-variadic-mixin-composition-and", "canonical_source": "https://gist.github.com/unrays/4eae18cf6a6e46e83c071fdaa1d03205", "published_at": "2026-05-22 20:00:44+00:00", "updated_at": "2026-05-22 20:07:58.898053+00:00", "lang": "en", "topics": ["developer-tools", "research"], "entities": ["Félix-Olivier Dumas", "C++23"], "alternates": {"html": "https://wpnews.pro/news/exotic-crtp-pattern-for-static-polymorphism-using-variadic-mixin-composition-and", "markdown": "https://wpnews.pro/news/exotic-crtp-pattern-for-static-polymorphism-using-variadic-mixin-composition-and.md", "text": "https://wpnews.pro/news/exotic-crtp-pattern-for-static-polymorphism-using-variadic-mixin-composition-and.txt", "jsonld": "https://wpnews.pro/news/exotic-crtp-pattern-for-static-polymorphism-using-variadic-mixin-composition-and.jsonld"}}