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

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

#include <vclib/concepts/polymorphism.h>

Concept definition

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

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.

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.