An open API service indexing awesome lists of open source software.

https://github.com/unrays/exotic-crtp


https://github.com/unrays/exotic-crtp

Last synced: 2 months ago
JSON representation

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;
}
};
```