mutable
A Database System for Research and Fast Prototyping
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Member Functions | Private Attributes
m::crtp< ConcreteType, CRTPBaseType, TParams > Struct Template Reference

A helper class to define CRTP class hierarchies. More...

#include <crtp.hpp>

Inheritance diagram for m::crtp< ConcreteType, CRTPBaseType, TParams >:
[legend]
Collaboration diagram for m::crtp< ConcreteType, CRTPBaseType, TParams >:
[legend]

Public Types

using actual_type = ConcreteType
 

Public Member Functions

actual_typeactual ()
 
const actual_typeactual () const
 

Private Member Functions

 crtp ()
 

Private Attributes

friend CRTPBaseType< actual_type, TParams... >
 

Detailed Description

template<typename ConcreteType, template< typename... > typename CRTPBaseType, typename... TParams>
struct m::crtp< ConcreteType, CRTPBaseType, TParams >

A helper class to define CRTP class hierarchies.

Taken from An Implementation Helper For The Curiously Recurring Template Pattern - Fluent C++.

This CRTP helper ensures that the

Template Parameters
ConcreteTypeactually inherits from
CRTPBaseType.The helper defines a method actual() that allows for safely casting the CRTP base type
CRTPBaseTypeto the
ConcreteType,properlyconst-quanified.

A class that wants to make use of CRTP should inherit from this helper. The following example demonstrates this:

template<typename ConcreteType>
struct CRTPBase : crtp<ConcreteType, CRTPBase>
{
using crtp<ConcreteType, CRTPBase>::actual;
};
A helper class to define CRTP class hierarchies.
Definition: crtp.hpp:50

It is also possible for the class implementing CRTP to take additional template parameters:

template<typename ConcreteType, typename T1, typename T2>
struct CRTPBase : crtp<ConcreteType, CRTPBase, T1, T2>
{
using crtp<ConcreteType, CRTPBase, T1, T2>::actual;
};

This should also work with variadic templates:

template<typename ConcreteType, typename... Args>
struct CRTPBase : crtp<ConcreteType, CRTPBase, Args...>
{
using crtp<ConcreteType, CRTPBase, Args...>::actual;
};

Definition at line 49 of file crtp.hpp.

Member Typedef Documentation

◆ actual_type

template<typename ConcreteType , template< typename... > typename CRTPBaseType, typename... TParams>
using m::crtp< ConcreteType, CRTPBaseType, TParams >::actual_type = ConcreteType

Definition at line 51 of file crtp.hpp.

Constructor & Destructor Documentation

◆ crtp()

template<typename ConcreteType , template< typename... > typename CRTPBaseType, typename... TParams>
m::crtp< ConcreteType, CRTPBaseType, TParams >::crtp ( )
inlineprivate

Definition at line 56 of file crtp.hpp.

Member Function Documentation

◆ actual() [1/2]

template<typename ConcreteType , template< typename... > typename CRTPBaseType, typename... TParams>
actual_type & m::crtp< ConcreteType, CRTPBaseType, TParams >::actual ( )
inline

◆ actual() [2/2]

template<typename ConcreteType , template< typename... > typename CRTPBaseType, typename... TParams>
const actual_type & m::crtp< ConcreteType, CRTPBaseType, TParams >::actual ( ) const
inline

Definition at line 53 of file crtp.hpp.

Field Documentation

◆ CRTPBaseType< actual_type, TParams... >

template<typename ConcreteType , template< typename... > typename CRTPBaseType, typename... TParams>
friend m::crtp< ConcreteType, CRTPBaseType, TParams >::CRTPBaseType< actual_type, TParams... >
private

Definition at line 57 of file crtp.hpp.


The documentation for this struct was generated from the following file: