Files
dusklight/include/dusk/scope.hpp
T
PJB3005 824263fa6e Config system v1
Roughly inspired by what I've learned from my work on Space Station 14, without some of the unnecessary cruft and complexity.

Implementation is relatively simple once I figured out all the template order shenanigans.
2026-04-04 22:47:48 +02:00

30 lines
679 B
C++

#ifndef DUSK_SCOPE_HPP
#define DUSK_SCOPE_HPP
namespace dusk {
/**
* A simple value wrapper that will destroy the value at the end of its scope.
* @tparam T The type of value contained.
* @tparam Destructor The type of function used to destroy the value.
*/
template <typename T, typename Destructor>
struct ScopeValue {
T value;
Destructor destructor;
explicit ScopeValue(T value, Destructor destructor) : value(value), destructor(destructor) {
}
~ScopeValue() {
destructor(value);
}
constexpr operator T&() const noexcept {
return value;
}
};
}
#endif // DUSK_SCOPE_HPP