common: Add a default nullptr argument to make_unique_wrapper
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Sat, 4 Feb 2023 00:24:54 +0000 (19:24 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 15 Jun 2023 15:50:28 +0000 (11:50 -0400)
When wrapping C libraries that return unmanaged pointers,
lttng::make_unique_wrapper makes it easier to locally "wrap" returned
pointers.

  auto val = lttng::make_unique_ptr<struct foo *,
                                    lttng::free>(some_func());

However, in its current form, a nullptr must be passed to define an
alias:

  using my_type_uptr =
    decltype(lttng::make_unique_wrapper<lttng_session,
                                        lttng::free>(nullptr));

Adding a default nullptr argument cuts down a bit of boiler plate.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I9d05d8162d28cc156b1e9ec6fe623f1cc02e9c8e

src/common/make-unique-wrapper.hpp

index e49e5ced779e5bc8343b32c8e4f402625555da9a..ebec2ca45d29a908a648d398a5a8dfba516afa9f 100644 (file)
@@ -70,7 +70,7 @@ void free(Type *ptr)
 template <typename WrappedType, void (*DeleterFunc)(WrappedType *)>
 std::unique_ptr<WrappedType,
                typename memory::create_deleter_class<WrappedType, DeleterFunc>::deleter>
-make_unique_wrapper(WrappedType *instance)
+make_unique_wrapper(WrappedType *instance = nullptr)
 {
        const memory::create_deleter_class<WrappedType, DeleterFunc> unique_deleter;
 
This page took 0.026432 seconds and 4 git commands to generate.