1 #ifndef CASM_cloneable_ptr_HH
2 #define CASM_cloneable_ptr_HH
13 template<
typename T,
typename ...Args>
15 return std::unique_ptr<T>(
new T(std::forward<Args>(args)...));
20 std::unique_ptr<Cloneable>
clone()
const {
21 return std::unique_ptr<Cloneable>(this->
_clone());
27 template<
typename Type>
31 template<
typename T,
typename ...Args>
37 template <
typename T,
typename =
void>
52 return std::unique_ptr<T>(
new T(obj));
65 template<
typename Type>
133 unique() = std::move(other.unique());
153 unique() = std::move(other);
177 const std::unique_ptr<Type> &
unique()
const {
182 explicit operator bool()
const {
192 template<
typename Type>
194 A.unique().swap(B.unique());
197 template<
typename Type>
199 return A.
unique() < B.unique();
202 template<
typename Type>
204 return A.unique() == B.unique();
207 template<
typename Type>
209 return A.unique() != B.unique();
void swap(cloneable_ptr< Type > &A, cloneable_ptr< Type > &B)
cloneable_ptr(const Type &obj)
Construct by cloning obj.
std::unique_ptr< T > make_unique(Args &&...args)
c++11 does not include 'make_unique'
virtual Cloneable * _clone() const =0
cloneable_ptr & operator=(cloneable_ptr other)
Assignment via copy-swap.
cloneable_ptr(pointer ptr)
Construct by taking ownership of ptr.
reference operator*() const
cloneable_ptr(cloneable_ptr< U > &&other)
Construct by moving other.
cloneable_ptr(const std::unique_ptr< U > &other)
Construct by cloning other.
cloneable_ptr()
Default constructor.
typename make_void< Ts...>::type void_t
Alias for void, to help SFINAE work.
Base type inherits from std::false_type if T does not have clone method.
cloneable_ptr & operator=(cloneable_ptr< U > &&other)
Assignment via move.
bool operator!=(const cloneable_ptr< Type > &A, const cloneable_ptr< Type > &B)
cloneable_ptr(std::unique_ptr< U > &&other)
Construct by moving.
pointer operator->() const
cloneable_ptr< T > make_cloneable(Args &&...args)
make a cloneable_ptr via T(Args... args)
const std::unique_ptr< Type > & unique() const
const Access contained unique_ptr
void reset()
Reset contained unique_ptr.
std::unique_ptr< T > clone(const T &obj, typename std::enable_if< has_clone< T >::value, T >::type *=nullptr)
bool operator==(const cloneable_ptr< Type > &A, const cloneable_ptr< Type > &B)
Non-std smart pointer classes and functions.
std::unique_ptr< Type > m_unique
cloneable_ptr & operator=(std::unique_ptr< U > &&other)
Assignment via move.
std::unique_ptr< Type > & unique()
Access contained unique_ptr.
cloneable_ptr & operator=(const std::unique_ptr< U > &other)
Assignment via clone.
A 'cloneable_ptr' can be used in place of 'unique_ptr'.
std::unique_ptr< Cloneable > clone() const
cloneable_ptr(const cloneable_ptr< U > &other)
Construct by cloning other.
cloneable_ptr(const cloneable_ptr &other)
Construct by cloning other.