swapped old-school new -> delete to fancy std::unique_ptr
This commit is contained in:
parent
1ae511542c
commit
087f3d45bd
11
Function.hpp
11
Function.hpp
@ -1,3 +1,7 @@
|
|||||||
|
#include <memory>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template <typename Fun>
|
template <typename Fun>
|
||||||
class Function;
|
class Function;
|
||||||
|
|
||||||
@ -28,14 +32,15 @@ private:
|
|||||||
virtual ~callable() override {}
|
virtual ~callable() override {}
|
||||||
};
|
};
|
||||||
|
|
||||||
callable_base* _fun;
|
std::unique_ptr _fun;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Function() {}
|
Function() {}
|
||||||
|
|
||||||
template <typename Fun>
|
template <typename Fun>
|
||||||
Function& operator=(Fun fun)
|
Function& operator=(Fun fun)
|
||||||
{
|
{
|
||||||
_fun = new callable<Fun>(fun);
|
_fun = std::make_unique<callable<Fun>>(fun);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,6 +49,4 @@ public:
|
|||||||
|
|
||||||
operator bool() const
|
operator bool() const
|
||||||
{ return static_cast<bool>(_fun); }
|
{ return static_cast<bool>(_fun); }
|
||||||
|
|
||||||
~Function() { delete _fun; }
|
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user