2 * Copyright (C) 2024 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
8 #ifndef LTTNG_REFERENCE_H
9 #define LTTNG_REFERENCE_H
16 template <typename ReferencedType, typename CustomDeleter>
17 class non_copyable_reference {
19 using referenced_type = ReferencedType;
20 using deleter = CustomDeleter;
22 non_copyable_reference(non_copyable_reference&& other) noexcept : _value(other._value)
24 _value = other._value;
28 non_copyable_reference() = delete;
29 non_copyable_reference(const non_copyable_reference&) = delete;
30 non_copyable_reference& operator=(non_copyable_reference&& other) noexcept
34 _value = other._value;
41 non_copyable_reference& operator=(const non_copyable_reference&) = delete;
43 ReferencedType& get() const noexcept
48 ReferencedType *operator->() const noexcept
53 ReferencedType& operator*() const noexcept
58 void release() noexcept
63 ~non_copyable_reference()
69 explicit non_copyable_reference(ReferencedType& instance) noexcept : _value(&instance)
79 typename CustomDeleter::deleter del;
84 template <typename FactoryReferencedType, typename FactoryCustomDeleter>
85 friend non_copyable_reference<FactoryReferencedType, FactoryCustomDeleter>
86 make_non_copyable_reference(FactoryReferencedType&);
88 ReferencedType *_value = nullptr;
91 template <typename ReferencedType, typename CustomDeleter>
92 non_copyable_reference<ReferencedType, CustomDeleter>
93 make_non_copyable_reference(ReferencedType& instance)
95 return non_copyable_reference<ReferencedType, CustomDeleter>(instance);
98 } /* namespace lttng */
100 #endif /* LTTNG_REFERENCE_H */