25 #ifndef ARM_COMPUTE_MISC_ITERABLE_H
26 #define ARM_COMPUTE_MISC_ITERABLE_H
40 template <
typename Base,
typename Derived>
41 Base *default_polymorphic_copy(
const Base *ptr)
43 static_assert(std::is_base_of<Base, Derived>::value,
"Derived is not a specialization of Base");
48 return new Derived(*
static_cast<const Derived *
>(ptr));
58 template <
typename Base>
62 using CopyFunc = std::function<Base *(
const Base *)>;
67 template <
typename Derived,
typename CopyFuncDerived>
70 static_assert(std::is_base_of<Base, Derived>::value,
"Derived is not a specialization of Base");
71 static_assert(std::is_constructible<CopyFunc, CopyFuncDerived>::value,
72 "CopyFuncDerived is not valid for a copy functor");
91 swap(ptr0._val, ptr1._val);
92 swap(ptr0._copy, ptr1._copy);
106 return _val.operator->();
111 return _val.operator->();
118 const Base *
get() const noexcept
123 explicit operator bool() const noexcept
125 return static_cast<bool>(_val);
130 if (rhs.
get() ==
nullptr && _val ==
nullptr)
134 else if (rhs.
get() ==
nullptr || _val ==
nullptr)
140 return (*_val == *rhs);
147 return {_copy(_val.get()),
CopyFunc(_copy)};
149 std::unique_ptr<Base> _val{
nullptr};
162 template <
typename Base,
typename Derived,
typename CopyFunc>
165 return {
new Derived(std::move(temp)), CopyFunc{std::move(
copy)}};
168 template <
typename Base,
typename Derived>
171 static_assert(std::is_base_of<Base, Derived>::value,
"Derived is not a specialization of Base");
173 return make_deep_unique<Base, Derived>(std::move(temp), default_polymorphic_copy<Base, Derived>);
176 template <
typename Base,
typename Derived,
typename... Args>
179 static_assert(std::is_constructible<Derived, Args...>::value,
"Cannot instantiate Derived from arguments");
181 return make_deep_unique<Base, Derived>(std::move(Derived{std::forward<Args>(
args)...}));
187 #endif // ARM_COMPUTE_MISC_ITERABLE_H