$darkmode
maybe_own.hpp File Reference
#include <memory>
Include dependency graph for maybe_own.hpp:

Go to the source code of this file.

Classes

class  cloe::utility::Deleter< T >
 

Typedefs

template<typename T >
using cloe::utility::maybe_own = std::unique_ptr< T, Deleter< T > >
 

Typedef Documentation

◆ maybe_own

template<typename T >
using cloe::utility::maybe_own = typedef std::unique_ptr<T, Deleter<T> >

maybe_own is a unique_ptr that sometimes has a no-op deleter, depending on how the Deleter class is defined.

The best way to use this class is by using the C++11 initializer lists:

maybe_own<MyClass> mp;
MyClass c;
mp = {&c, false}; // not-owned
MyClass* cp = new MyClass();
mp = {cp, true}; // owned, c not deleted
mp = {new MyClass(), true}; // owned, cp now deleted