aboutsummaryrefslogtreecommitdiffstats
path: root/bindings/cxx/include
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-10-31 13:00:47 +0100
committerDavid Robillard <d@drobilla.net>2020-10-31 13:00:47 +0100
commitaf3d564e89ceeda506cbce8ff329ee14c769f9a5 (patch)
tree70f95bdf65f2730c006810e1bb2d98a851d18760 /bindings/cxx/include
parent31e144e667f07eaa6884a2cc2c422569301a76df (diff)
downloadpugl-af3d564e89ceeda506cbce8ff329ee14c769f9a5.tar.gz
pugl-af3d564e89ceeda506cbce8ff329ee14c769f9a5.tar.bz2
pugl-af3d564e89ceeda506cbce8ff329ee14c769f9a5.zip
Remove use of std::unique_ptr
Although it's generally a good idea to use known-solid std classes, in this case the wrapper is very simple so it's not worth including <memory>.
Diffstat (limited to 'bindings/cxx/include')
-rw-r--r--bindings/cxx/include/pugl/pugl.hpp30
1 files changed, 17 insertions, 13 deletions
diff --git a/bindings/cxx/include/pugl/pugl.hpp b/bindings/cxx/include/pugl/pugl.hpp
index 965540d..d5a91fb 100644
--- a/bindings/cxx/include/pugl/pugl.hpp
+++ b/bindings/cxx/include/pugl/pugl.hpp
@@ -27,7 +27,6 @@
#include <cassert>
#include <chrono>
#include <cstdint>
-#include <memory>
#include <stdexcept>
#include <type_traits>
@@ -47,12 +46,6 @@ namespace detail {
template<typename T>
using FreeFunc = void (*)(T*);
-/// Simple overhead-free deleter for a C object
-template<typename T, FreeFunc<T> Free>
-struct Deleter {
- void operator()(T* ptr) { Free(ptr); }
-};
-
/// Generic C++ wrapper for a C object
template<class T, FreeFunc<T> Free>
class Wrapper
@@ -61,19 +54,30 @@ public:
Wrapper(const Wrapper&) = delete;
Wrapper& operator=(const Wrapper&) = delete;
- Wrapper(Wrapper&&) noexcept = default;
- Wrapper& operator=(Wrapper&&) noexcept = default;
+ Wrapper(Wrapper&& wrapper) noexcept
+ : _ptr{wrapper._ptr}
+ {
+ wrapper._ptr = nullptr;
+ }
+
+ Wrapper& operator=(Wrapper&& wrapper) noexcept
+ {
+ _ptr = wrapper._ptr;
+ wrapper._ptr = nullptr;
+ }
+
+ ~Wrapper() noexcept { Free(_ptr); }
- T* cobj() noexcept { return _ptr.get(); }
- const T* cobj() const noexcept { return _ptr.get(); }
+ T* cobj() noexcept { return _ptr; }
+ const T* cobj() const noexcept { return _ptr; }
protected:
explicit Wrapper(T* ptr) noexcept
- : _ptr(ptr, Deleter<T, Free>{})
+ : _ptr{ptr}
{}
private:
- std::unique_ptr<T, Deleter<T, Free>> _ptr;
+ T* _ptr;
};
} // namespace detail