faunus
Type Namespace Reference

Erasure. More...

Detailed Description

Erasure.

Class templates to assist implementing the type erasure pattern. The pairwise composition of concepts is also supported.

Type erasure pattern in general https://www.modernescpp.com/index.php/c-core-guidelines-type-erasure-with-templates This particular implementation was inspired by https://aherrmann.github.io/programming/2014/10/19/type-erasure-with-merged-concepts/

Basic agents are

struct PrintableSpecification {
struct Concept {
virtual ~Concept() = default;
virtual void print() const = 0;
};
template <class Holder>
struct Model : public Holder, public virtual Concept {
using Holder::Holder;
void print() const override {
Holder::get().print();
};
};
template <class Container>
struct Interface : public Container {
using Container::Container;
void print() const {
Container::get().print();
};
};
};
using PrintableType = TypeErasure::TypeErasure<PrintableSpecification>
using PrintableExportableType =
TypeErasure::TypeErasure<TypeErasure::MergeSpecifications<PrintableSpecification,
ExportableSpecification>>

Class templates to assist implementing the type erasure pattern.