15 #ifndef HEXT_CLONEABLE_H_INCLUDED
16 #define HEXT_CLONEABLE_H_INCLUDED
24 #include <type_traits>
35 template<
typename Derived,
typename Base>
45 virtual std::unique_ptr<Base>
clone()
const override
47 static_assert(std::is_base_of<Base, Derived>::value,
48 "template argument <Base> is not a base of "
49 "template argument <Derived>");
50 static_assert(std::is_copy_constructible<Derived>::value,
51 "template argument <Derived> is not copy constructible");
54 return std::make_unique<Derived>(
static_cast<const Derived&
>(*
this));
Defines HEXT_PUBLIC and HEXT_PRIVATE.
Curiously recurring template pattern that extends a base class to provide a virtual method Cloneable:...
virtual std::unique_ptr< Base > clone() const override
Clones objects of template type Derived and returns an owning pointer to the newly allocated Base.