26 #ifndef LBANN_UTILS_CLONEABLE_HPP_INCLUDED 27 #define LBANN_UTILS_CLONEABLE_HPP_INCLUDED 29 #include <h2/meta/core/SFINAE.hpp> 31 #include <type_traits> 54 template <
typename Base>
93 template <
typename T,
typename... Base>
98 std::unique_ptr<T>
clone()
const 100 return std::unique_ptr<T>{
static_cast<T*
>(this->do_clone_())};
107 return new T(static_cast<T const&>(*
this));
111 template <
typename T,
typename Base>
118 return std::unique_ptr<T>{
static_cast<T*
>(this->do_clone_())};
128 return new T(static_cast<T const&>(*
this));
133 template <
typename T>
141 return std::unique_ptr<T>{
static_cast<T*
>(this->do_clone_())};
158 template <
typename T,
typename... Base>
164 return std::unique_ptr<T>{
static_cast<T*
>(this->do_clone_())};
168 virtual Cloneable* do_clone_()
const = 0;
171 template <
typename T,
typename Base>
177 return std::unique_ptr<T>{
static_cast<T*
>(this->do_clone_())};
184 virtual Cloneable* do_clone_()
const = 0;
188 template <
typename T>
196 return std::unique_ptr<T>{
static_cast<T*
>(this->do_clone_())};
200 virtual Cloneable* do_clone_()
const = 0;
218 template <
typename T>
221 #ifndef DOXYGEN_SHOULD_SKIP_THIS 223 template <
typename... Ts>
230 struct definitely_not_a_unique_ptr;
232 template <
typename T>
233 auto has_right_clone(T
const& x) -> decltype(x.clone());
235 definitely_not_a_unique_ptr has_right_clone(...);
239 template <
typename T>
241 : std::is_same<decltype(details::has_right_clone(std::declval<T>())),
245 #endif // DOXYGEN_SHOULD_SKIP_THIS 247 template <
typename T>
253 template <
typename T>
256 template <
typename T>
261 template <
typename T>
266 template <
typename T>
271 template <
typename T,
typename DeleterT>
277 template <
typename T>
283 template <
typename T>
289 template <
typename T,
typename... Bases>
292 template <
typename CloneablePtrT,
293 h2::meta::EnableWhen<IsCloneablePtr<CloneablePtrT>,
int> = 1>
294 auto clone_all(std::vector<CloneablePtrT>
const& things)
296 std::vector<CloneablePtrT> cloned_things;
297 cloned_things.reserve(things.size());
298 for (
auto const& t : things) {
300 cloned_things.emplace_back(t->clone());
302 cloned_things.emplace_back(
nullptr);
304 return cloned_things;
308 #endif // LBANN_UTILS_CLONEABLE_HPP_INCLUDED Inject polymorphic clone functions into hierarchies.
std::unique_ptr< T > clone() const
constexpr bool IsCloneablePtr_v()
std::unique_ptr< T > clone() const
Cloneable * do_clone_() const
std::unique_ptr< T > clone() const
Return an exception-safe, memory-safe copy of this object.
Declare that T has unimplemented virtual functions.
Declare Base to be a virtual base.
auto clone_all(std::vector< CloneablePtrT > const &things)
constexpr bool IsCloneable
constexpr bool IsCloneablePtr
std::unique_ptr< T > clone() const
virtual Cloneable * do_clone_() const override
Implement the covariant raw-pointer-based clone operation.
virtual Cloneable * do_clone_() const override
Implement the covariant raw-pointer-based clone operation.
std::unique_ptr< T > clone() const
Return an exception-safe, memory-safe copy of this object.
std::unique_ptr< T > clone() const
constexpr bool IsCloneable_v()
Predicate testing for Cloneable interface.