Class Scine::Utils::CloneInterface

template<class Derived, class ...Bases>
class CloneInterface : public Bases

Class serving the purpose of a generic clone interface.

This class provides the clone method for any interface in core needing it. It uses the curiously recurrent template pattern (CRTP) to acquire infos at compile time about both the interface and the derived class. This allows for the one-time-only generation of code for the clone method, avoiding unnecessary code duplication. Basically, a derived class must just inherit from the CloneInterface with template parameters Derived = derived class and Base = interface class to have a functioning clone method. See https://www.fluentcpp.com/2017/09/12/how-to-return-a-smart-pointer-and-use-covariance/ for further details.

Note that classes deriving from CloneInterface<Derived, Base> do implicitly derive from Base, hence they do not need an additional ‘public Base’ statement.

Public Functions

std::unique_ptr<Derived> clone() const

Templetized clone method, it hides the interface clone method.

Return

A unique_ptr to the derived class. This function allows for working directly with the derived class if the type is known. It hides the Base class’ clone() method (does not override it!). This is achieved with templetized Derived and Base classes.

Template Parameters
  • Derived: The type of the derived class.