Medusa  1.1
Coordinate Free Mehless Method implementation
mm::deep_copy_unique_ptr< T > Class Template Reference

#include <memutils.hpp>

Detailed Description

template<typename T>
class mm::deep_copy_unique_ptr< T >

Unique pointer with polymorphic deep copy semantics.

It is copy constructible and copy assignable. Copy construction creates a new pointer, containing a clone of the object, the original pointer pointed to.

Template Parameters
TValue type. Must be polymorphically cloneable, i.e. have a virtual clone method as example below.

Usage example:

class A {
int a;
public:
A(int a) : a(a) {}
virtual ~A() = default;
virtual int f() { return a; }
virtual A* clone() const { return new A(*this); }
};
class B : public A {
int b;
public:
B(int a, int b) : A(a), b(b) {}
int f() override { return b; }
B* clone() const override { return new B(*this); }
};
deep_copy_unique_ptr<A> pa(new A(3));
deep_copy_unique_ptr<A> pb(new B(1, 2));
EXPECT_EQ(3, pa->f());
EXPECT_EQ(2, pb->f());
deep_copy_unique_ptr<A> pc = pb;
EXPECT_EQ(2, pc->f());
pb.reset(nullptr);
EXPECT_EQ(2, pc->f());
pa = deep_copy_unique_ptr<A>(*pc);
EXPECT_EQ(2, pa->f());
pa = deep_copy_unique_ptr<A>(static_cast<A>(*pc));
EXPECT_EQ(1, pa->f());
pb = pc;
EXPECT_EQ(2, pb->f());
pb = B(7, 5);
EXPECT_EQ(5, pb->f());
pb = std::move(pc);
EXPECT_EQ(2, pb->f());
deep_copy_unique_ptr<A> pd(std::move(pb));
EXPECT_EQ(2, pd->f());

Definition at line 22 of file DomainShape_fwd.hpp.

Public Member Functions

 deep_copy_unique_ptr (const T &v)
 Construct by polymorphically cloning a given value. More...
 
 deep_copy_unique_ptr (const deep_copy_unique_ptr &o)
 Copy by cloning the value of o. More...
 
 deep_copy_unique_ptr (deep_copy_unique_ptr &&o) noexcept
 Move construct as unique_ptr. More...
 
deep_copy_unique_ptroperator= (const T &v)
 Copy assign by cloning a given value. More...
 
deep_copy_unique_ptroperator= (const deep_copy_unique_ptr &o)
 Copy assign by cloning the value of o. More...
 
deep_copy_unique_ptroperator= (deep_copy_unique_ptr &&o) noexcept
 Move assign as unique_ptr More...
 

Constructor & Destructor Documentation

◆ deep_copy_unique_ptr() [1/3]

template<typename T >
mm::deep_copy_unique_ptr< T >::deep_copy_unique_ptr ( const T &  v)
inlineexplicit

Construct by polymorphically cloning a given value.

Definition at line 37 of file memutils.hpp.

◆ deep_copy_unique_ptr() [2/3]

template<typename T >
mm::deep_copy_unique_ptr< T >::deep_copy_unique_ptr ( const deep_copy_unique_ptr< T > &  o)
inline

Copy by cloning the value of o.

Definition at line 41 of file memutils.hpp.

◆ deep_copy_unique_ptr() [3/3]

template<typename T >
mm::deep_copy_unique_ptr< T >::deep_copy_unique_ptr ( deep_copy_unique_ptr< T > &&  o)
inlinenoexcept

Move construct as unique_ptr.

Definition at line 47 of file memutils.hpp.

Member Function Documentation

◆ operator=() [1/3]

template<typename T >
deep_copy_unique_ptr& mm::deep_copy_unique_ptr< T >::operator= ( const deep_copy_unique_ptr< T > &  o)
inline

Copy assign by cloning the value of o.

Definition at line 57 of file memutils.hpp.

◆ operator=() [2/3]

template<typename T >
deep_copy_unique_ptr& mm::deep_copy_unique_ptr< T >::operator= ( const T &  v)
inline

Copy assign by cloning a given value.

Definition at line 51 of file memutils.hpp.

◆ operator=() [3/3]

template<typename T >
deep_copy_unique_ptr& mm::deep_copy_unique_ptr< T >::operator= ( deep_copy_unique_ptr< T > &&  o)
inlinenoexcept

Move assign as unique_ptr

Definition at line 63 of file memutils.hpp.


The documentation for this class was generated from the following files: