CASM  1.1.0
A Clusters Approach to Statistical Mechanics
cloneable_ptr.hh File Reference
#include <iostream>
#include <memory>
#include <utility>
#include "casm/misc/type_traits.hh"

Go to the source code of this file.

Classes

class  notstd::Cloneable
 Base class for cloning. More...
 
struct  notstd::has_clone< T, typename >
 Base type inherits from std::false_type if T does not have clone method. More...
 
struct  notstd::has_clone< T, void_t< decltype(&T::clone)> >
 Specialized case inherits from std::true_type if T does have clone method. More...
 
struct  notstd::has_move< T, typename >
 Base type inherits from std::false_type if T does not have move method. More...
 
struct  notstd::has_move< T, void_t< decltype(&T::move)> >
 Specialized case inherits from std::true_type if T does have move method. More...
 
class  notstd::cloneable_ptr< Type >
 A 'cloneable_ptr' can be used in place of 'unique_ptr'. More...
 

Namespaces

 notstd
 Non-std smart pointer classes and functions.
 

Macros

#define ABSTRACT_CLONEABLE(T)
 
#define ABSTRACT_CLONEABLE_DERIVED(T)
 
#define CLONEABLE(T)
 
#define CLONEABLE_NEEDS_DESTRUCTOR_DEF(T)
 

Functions

template<typename T , typename... Args>
std::unique_ptr< T > notstd::make_unique (Args &&... args)
 c++17 does not include 'make_unique' More...
 
template<typename T , typename... Args>
cloneable_ptr< T > notstd::make_cloneable (Args &&... args)
 make a cloneable_ptr<T> via T(Args... args) More...
 
template<typename T , typename std::enable_if<!has_clone< T >::value, void >::type * = nullptr>
std::unique_ptr< T > notstd::clone (const T &obj)
 
template<typename T , typename std::enable_if<!has_move< T >::value, void >::type * = nullptr>
std::unique_ptr< T > notstd::clone_move (T &&obj)
 Construct std::unique_ptr<T> from rvalue reference. More...
 
template<typename Type >
void notstd::swap (cloneable_ptr< Type > &A, cloneable_ptr< Type > &B)
 
template<typename Type >
bool notstd::operator< (const cloneable_ptr< Type > &A, const cloneable_ptr< Type > &B)
 
template<typename Type >
bool notstd::operator== (const cloneable_ptr< Type > &A, const cloneable_ptr< Type > &B)
 
template<typename Type >
bool notstd::operator!= (const cloneable_ptr< Type > &A, const cloneable_ptr< Type > &B)
 
template<typename Type >
bool notstd::operator== (std::nullptr_t, const cloneable_ptr< Type > &B)
 
template<typename Type >
bool notstd::operator!= (std::nullptr_t, const cloneable_ptr< Type > &B)
 
template<typename Type >
bool notstd::operator== (const cloneable_ptr< Type > &A, std::nullptr_t)
 
template<typename Type >
bool notstd::operator!= (const cloneable_ptr< Type > &A, std::nullptr_t)
 

Macro Definition Documentation

◆ ABSTRACT_CLONEABLE

#define ABSTRACT_CLONEABLE (   T)
Value:
public: \
virtual ~T() {} \
\
std::unique_ptr<T> clone() const { \
return std::unique_ptr<T>(this->_clone()); \
} \
std::unique_ptr<T> move() { return std::unique_ptr<T>(this->_move()); } \
\
private: \
virtual T *_clone() const = 0; \
virtual T *_move() = 0; \
\
public:
std::unique_ptr< T > clone(const T &obj)

Include in a class/struct definition that inherits from Cloneable to make it also cloneable

Definition at line 12 of file cloneable_ptr.hh.

◆ ABSTRACT_CLONEABLE_DERIVED

#define ABSTRACT_CLONEABLE_DERIVED (   T)
Value:
public: \
virtual ~T() {} \
\
std::unique_ptr<T> clone() const { \
return std::unique_ptr<T>(this->_clone()); \
} \
std::unique_ptr<T> move() { return std::unique_ptr<T>(this->_move()); } \
\
private: \
virtual T *_clone() const override = 0; \
virtual T *_move() override = 0; \
\
public:

Include in a class/struct definition that inherits from Cloneable to make it also cloneable

Definition at line 29 of file cloneable_ptr.hh.

◆ CLONEABLE

#define CLONEABLE (   T)
Value:
public: \
virtual ~T() {} \
\
std::unique_ptr<T> clone() const { \
return std::unique_ptr<T>(this->_clone()); \
} \
std::unique_ptr<T> move() { return std::unique_ptr<T>(this->_move()); } \
\
private: \
virtual T *_clone() const override { return new T(*this); } \
virtual T *_move() override { return new T(std::move(*this)); } \
\
public:

Include in a class/struct definition that inherits from Cloneable to make it also cloneable

Definition at line 46 of file cloneable_ptr.hh.

◆ CLONEABLE_NEEDS_DESTRUCTOR_DEF

#define CLONEABLE_NEEDS_DESTRUCTOR_DEF (   T)
Value:
public: \
virtual ~T(); \
\
std::unique_ptr<T> clone() const { \
return std::unique_ptr<T>(this->_clone()); \
} \
std::unique_ptr<T> move() { return std::unique_ptr<T>(this->_move()); } \
\
private: \
virtual T *_clone() const override { return new T(*this); } \
virtual T *_move() override { return new T(std::move(*this)); } \
\
public:

Include in a class/struct definition that inherits from Cloneable to make it also cloneable, but do not include destructor defintion

Definition at line 63 of file cloneable_ptr.hh.