diff --git a/include/opaque.hh b/include/opaque.hh index 1925892..5c868fe 100644 --- a/include/opaque.hh +++ b/include/opaque.hh @@ -210,7 +210,7 @@ concept OpaqueHandleFunc = std::is_invocable_v template HandleF> // Note: This should be a lambda, or a free-function. it's lifetime must not end before the `opaque_handle` returned from this function does. constexpr inline opaque_handle make_opaque_handle(T* data, const HandleF& handler) noexcept { - constexpr bool is_nothrow = std::is_nothrow_invocable_v; + constexpr const bool is_nothrow = std::is_nothrow_invocable_v; struct object_handler { @@ -242,8 +242,8 @@ constexpr inline opaque_handle make_opaque_handle(T* data, const HandleF& handle template HandleF> constexpr inline opaque_handle make_opaque_handle(T* data, HandleF&& handler) noexcept(std::is_nothrow_move_constructible_v) { - constexpr bool is_nothrow = std::is_nothrow_invocable_v; - constexpr bool is_nothrow_ctor = std::is_nothrow_move_constructible_v; + constexpr const bool is_nothrow = std::is_nothrow_invocable_v; + constexpr const bool is_nothrow_ctor = std::is_nothrow_move_constructible_v; struct object_handler { diff --git a/src/main.cpp b/src/main.cpp index 43e03be..ba07755 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,9 +27,25 @@ static inline void print(const std::string& string) return print_view(sv); } +void use_moh() +{ + std::string str{"Hello from 2!"}; + opaque_handle v{make_opaque_handle(&str, [](std::string* ptr, auto op) noexcept { + if(ptr) { + switch(op) { + case opaque_handle_operation::Clone: return new std::string(*ptr); + case opaque_handle_operation::Delete: delete ptr; break; + } + } + return static_cast(nullptr); + })}; + print(*v); +} + int main() { const opaque_handle v{make_opaque_object_handle(std::string{"Hello world"})}; print(*v); //XXX: Why does converting it to string_view here break it? + use_moh(); return 0; }