https://github.com/unrays/exotic-crtp
https://github.com/unrays/exotic-crtp
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/unrays/exotic-crtp
- Owner: unrays
- License: bsl-1.0
- Created: 2026-03-15T23:25:12.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2026-03-22T14:08:44.000Z (4 months ago)
- Last Synced: 2026-03-23T05:35:13.332Z (4 months ago)
- Size: 4.88 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# exotic-crtp
**Article :** [Rethinking Static Polymorphism with C++23](https://medium.com/@felixolivierdumas/exotic-crtp-rethinking-static-polymorphism-with-c-23-89f9e75e8ffd)
## The pattern
```cpp
namespace exotic {
template
struct crtp_access : From... {};
template
constexpr decltype(auto) as_crtp(T&& obj) noexcept {
using crtp_access_t = crtp_access>;
return static_cast(obj);
}
}
struct Base {
void interface(this auto&& self) {
return as_crtp(self).implementation();
}
};
struct Derived : Base {
void implementation(this crtp_access self) {
std::cout << "Derived implementation" << std::endl;
}
};
```