Import CStringView from the Babeltrace tree
[lttng-tools.git] / src / common / make-unique-wrapper.hpp
index 50d1916f20239624525c5226a926f5e76f58e3af..a0a4b541a2fd64bc7c01da8babd6b5c01bb54d5c 100644 (file)
@@ -34,14 +34,13 @@ namespace lttng {
  *                    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
+ * If you need to return this unique_ptr instance, you should consider writing
  * a proper, idiomatic, wrapper.
  */
 
-namespace details
-{
+namespace memory {
 template <typename WrappedType, void (*DeleterFunction)(WrappedType *)>
-struct create_unique_class {
+struct create_deleter_class {
        struct deleter {
                void operator()(WrappedType *instance) const
                {
@@ -54,7 +53,6 @@ struct create_unique_class {
                return std::unique_ptr<WrappedType, deleter>(instance);
        }
 };
-} /* namespace details */
 
 /*
  * 'free' is a utility function for use with make_unique_wrapper. It makes it easier to
@@ -67,12 +65,14 @@ void free(Type *ptr)
 {
        std::free(ptr);
 }
+} /* namespace memory */
 
 template <typename WrappedType, void (*DeleterFunc)(WrappedType *)>
-std::unique_ptr<WrappedType, typename details::create_unique_class<WrappedType, DeleterFunc>::deleter>
-make_unique_wrapper(WrappedType *instance)
+std::unique_ptr<WrappedType,
+               typename memory::create_deleter_class<WrappedType, DeleterFunc>::deleter>
+make_unique_wrapper(WrappedType *instance = nullptr)
 {
-       const details::create_unique_class<WrappedType, DeleterFunc> unique_deleter;
+       const memory::create_deleter_class<WrappedType, DeleterFunc> unique_deleter;
 
        return unique_deleter(instance);
 }
This page took 0.023749 seconds and 4 git commands to generate.