bwidgets/inc/basic_widgets/core/type/opaque_struct.hpp
Andrea Blankenstijn 7c5277dabd They say members defined in header are implicitly inline.
Also remove the static from static inline (is that C specific?)
2021-08-14 09:17:51 +02:00

49 lines
982 B
C++

#ifndef BWIDGETS_OPAQUE_STRUCT_HPP
#define BWIDGETS_OPAQUE_STRUCT_HPP
#include <functional>
namespace bwidgets
{
template<typename T>
class OpaqueStruct
{
using Deleter = std::function<void(T*)>;
const Deleter _deleter;
T* _c_pod;
public:
OpaqueStruct(T* ptr, const Deleter& d) : _deleter(d), _c_pod(ptr) {}
OpaqueStruct(const OpaqueStruct&) = delete;
OpaqueStruct(OpaqueStruct&&) = delete;
virtual ~OpaqueStruct() noexcept
{
try {
_deleter(_c_pod);
} catch (...) {
}
};
[[nodiscard]] auto* operator()() const
{
return _c_pod;
}
auto operator=(const OpaqueStruct&) = delete;
auto operator=(OpaqueStruct&&) = delete;
struct Wrapper
{
OpaqueStruct _data;
Wrapper(T* ptr, const Deleter& d) : _data(ptr, d) {}
};
};
}
#endif