Visual Computing Library  devel
Loading...
Searching...
No Matches
vcl::Cloneable Concept Reference

Concept that is evaluated true if T is a cloneable object. More...

#include <vclib/base/concepts/polymorphism.h>

Concept definition

template<typename T>
concept vcl::Cloneable = requires (T&& obj) {
{ obj.clone() } -> detail::IsSharedPtrOfBaseOf<std::remove_cvref_t<T>>;
}
Concept that is evaluated true if T is a cloneable object.
Definition polymorphism.h:64

Detailed Description

Concept that is evaluated true if T is a cloneable object.

A cloneable object is an object that can be cloned by calling the method clone(), which returns a shared pointer to the cloned object. The type of the shared pointer returned by clone() must be a shared pointer to a base class of T.

Cloneable objects are useful when polymorphism is needed, and the object needs to be copied without knowing the exact type of the object:

std::shared_ptr<Shape> circle = std::make_shared<Circle>();
std::shared_ptr<Shape> clonedCircle = circle->clone();
Template Parameters
TThe type to be checked if it is cloneable.