swapped old-school new -> delete to fancy std::unique_ptr

This commit is contained in:
Kjistóf 2016-11-27 14:15:10 +01:00
parent 1ae511542c
commit 087f3d45bd
1 changed files with 7 additions and 4 deletions

View File

@ -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; }
}; };