cd /news/developer-tools/exotic-crtp-pattern-for-static-polym… · home topics developer-tools article
[ARTICLE · art-9894] src=gist.github.com ↗ pub= topic=developer-tools verified=true sentiment=· neutral

Exotic CRTP pattern for static polymorphism using variadic mixin composition and C++23 explicit object parameters.

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.

read1 min views26 publishedMay 22, 2026

exotic_crtp.hpp

  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.

Learn more about bidirectional Unicode characters

Show hidden characters
// Copyright (c) May 2026 Félix-Olivier Dumas. All rights reserved.

// Licensed under the terms described in the LICENSE file

// Reference example of the pattern

// See: https://medium.com/@felixolivierdumas/exotic-crtp-rethinking-static-polymorphism-with-c-23-89f9e75e8ffd

#pragma once

#include <iostream>

#include <type_traits>

#include <utility>

namespace exotic {

    template<typename... From>

    struct crtp_access : From... {};

    template<typename T>

    constexpr decltype(auto) as_crtp(T&& obj) noexcept {

        using crtp_access_t = crtp_access<std::remove_cvref_t<T>>;

        return static_cast<crtp_access_t&&>(obj);

    }

}

struct Base {

    void interface(this auto&& self) {

        return exotic::as_crtp(self).implementation();

    }

};

struct Derived : Base {

    void implementation(this exotic::crtp_access<Derived> self) {

        std::cout << "Derived implementation" << std::endl;

    }

};

int main() {

    Derived d;

 

    d.interface(); // perfectly works

 

    //d.implementation(); -> doesn't work, Derived only shows .interface()

}
── more in #developer-tools 4 stories · sorted by recency
── more on @félix-olivier dumas 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/exotic-crtp-pattern-…] indexed:0 read:1min 2026-05-22 ·