Files CCore/inc/gadget/NoCopy.h CCore/src/gadget/NoCopy.cpp
NoCopy classes are Property Types and used to disable the implicit copy constructor and the implicit assign operator (and move also). Unlucky, in the C++ a compiler generates these two class members by default, despite they are goodless in most cases.
First of them is the typedef NoCopy.
/* struct NoCopyType */
struct NoCopyType
{
NoCopyType() = default ;
NoCopyType(const NoCopyType &) = delete ;
void operator = (const NoCopyType &) = delete ;
};
/* type NoCopy */
using NoCopy = NoCopyType ;
Use it as a base class in a class definition to make a class non-copyable:
class C : NoCopy { };
Second is the template typedef NoCopyBase.
/* struct ImpNoCopyBase<TT> */
template <class ... TT>
struct ImpNoCopyBase : TT ...
{
ImpNoCopyBase() = default ;
ImpNoCopyBase(const ImpNoCopyBase &) = delete ;
void operator = (const ImpNoCopyBase &) = delete ;
};
/* type NoCopyBase<TT> */
template <class ... TT>
using NoCopyBase = ImpNoCopyBase<TT...> ;
Use it as a base class in a class definition to inherit a group of classes and make a class non-copyable:
class D : NoCopyBase<A,B,C> { };
Why do we need typedefs here? To deal with the following case:
class C : NoCopy { }; class D : C { class E : NoCopy // without typedef NoCopy is inaccessible here { }; };