|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace sr::detail |
|
|
namespace sr::detail |
|
|
{ |
|
|
{ |
|
|
|
|
|
struct NoopGuard |
|
|
|
|
|
{ |
|
|
|
|
|
constexpr void release() const |
|
|
|
|
|
{ |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T> |
|
|
template<class T> |
|
|
class Wrapper |
|
|
class Wrapper |
|
|
{ |
|
|
{ |
|
|
public: |
|
|
public: |
|
|
|
|
|
|
|
|
template<class TT, class G, std::enable_if_t<std::is_constructible_v<T, TT>, int> = 0> |
|
|
|
|
|
Wrapper(TT&& v, G&& g) noexcept(std::is_nothrow_constructible_v<T, TT>) : value(std::forward<TT>(v)) |
|
|
|
|
|
|
|
|
template<class TT, class G = NoopGuard, std::enable_if_t<std::is_constructible_v<T, TT>, int> = 0> |
|
|
|
|
|
Wrapper(TT&& v, G&& g = G{}) noexcept(std::is_nothrow_constructible_v<T, TT>) : value(std::forward<TT>(v)) |
|
|
{ |
|
|
{ |
|
|
g.release(); |
|
|
g.release(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
{ |
|
|
{ |
|
|
public: |
|
|
public: |
|
|
|
|
|
|
|
|
template<class TT, class G, std::enable_if_t<std::is_convertible_v<TT, T&>, int> = 0> |
|
|
|
|
|
Wrapper(TT&& v, G&& g) noexcept(std::is_nothrow_constructible_v<TT, T&>) : value(static_cast<T&>(v)) |
|
|
|
|
|
|
|
|
template<class TT, class G = NoopGuard, std::enable_if_t<std::is_convertible_v<TT, T&>, int> = 0> |
|
|
|
|
|
Wrapper(TT&& v, G&& g = G{}) noexcept(std::is_nothrow_constructible_v<TT, T&>) : value(static_cast<T&>(v)) |
|
|
{ |
|
|
{ |
|
|
g.release(); |
|
|
g.release(); |
|
|
} |
|
|
} |