Add make_unique_wrapper()
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 28 Apr 2022 15:28:15 +0000 (11:28 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 13 Jun 2022 20:34:46 +0000 (16:34 -0400)
commit8802d23ba9c07d32d0da22213d8e76ed102d553f
tree8ca6e59589752d30b38efbcbef757dea1bcc1b19
parent9dc3671c8a9647690d5c6e22e97840954a6c18fe
Add make_unique_wrapper()

make_unique_wrapper is intended to facilitate the use of std::unique_ptr
to wrap C-style APIs that don't provide RAII resource management facilities.

Usage example:

   // API
   struct my_c_struct {
           // ...
   };

   struct my_c_struct *create_my_c_struct(void);
   void destroy_my_c_struct(struct my_c_struct *value);

   // Creating a unique_ptr to my_c_struct.
   auto safe_c_struct =
           lttng::make_unique_wrapper<my_c_struct, destroy_my_c_struct>(
                   create_my_c_struct());

Note that this facility is intended for use in the scope of a function.
If you need to return this unique_ptr instance, you should consider writting
a proper, idiomatic, wrapper.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I429fc6f62896efb04af95fc26143096043206265
src/common/Makefile.am
src/common/make-unique-wrapper.hpp [new file with mode: 0644]
This page took 0.028277 seconds and 5 git commands to generate.