qxLib
smart_ptr_ref_adapter.h
Go to the documentation of this file.
1 /**
2 
3  @file smart_ptr_ref_adapter.h
4  @author Khrapov
5  @date 25.05.2025
6  @copyright © Nick Khrapov, 2025. All right reserved.
7 
8 **/
9 #pragma once
10 
11 #include <memory>
12 
13 namespace qx::details
14 {
15 
16 template<template<class, class...> class pointer_t, class T, class... args_t>
17 class base_smart_ptr_ref_adapter : public pointer_t<T, args_t...>
18 {
19 public:
20  using original_pointer_type = pointer_t<T, args_t...>;
21  using super = original_pointer_type;
22  using element_type = T;
23  using pointer = T*;
24  using reference = T&;
25 
26  base_smart_ptr_ref_adapter() = delete;
27  base_smart_ptr_ref_adapter(std::nullptr_t) = delete;
28 
29  operator T&() noexcept;
30  operator const T&() const noexcept;
31 
32 protected:
34  base_smart_ptr_ref_adapter& operator=(base_smart_ptr_ref_adapter&&) noexcept = default;
35  base_smart_ptr_ref_adapter(const base_smart_ptr_ref_adapter&) noexcept = default;
36  base_smart_ptr_ref_adapter& operator=(const base_smart_ptr_ref_adapter&) noexcept = default;
37 
38  template<class... constructor_args_t>
39  base_smart_ptr_ref_adapter(constructor_args_t&&... args);
40 
41 private:
42  using original_pointer_type::get;
43  using original_pointer_type::reset;
44  using original_pointer_type::operator bool;
45  using original_pointer_type::operator=;
46 };
47 
48 template<template<class, class...> class pointer_t, class T, class... args_t>
50 {
51 public:
52  using super = base_smart_ptr_ref_adapter<pointer_t, T, args_t...>;
53  using original_pointer_type = typename super::original_pointer_type;
54  using element_type = typename super::element_type;
55  using pointer = typename super::pointer;
56  using reference = typename super::reference;
57 
58  typename super::reference get() const noexcept;
59 
60 protected:
65  default;
66 
67  template<class... constructor_args_t>
68  overload_functions_smart_ptr_ref_adapter(constructor_args_t&&... args);
69 };
70 
71 template<template<class> class pointer_t, class T, class... args_t>
73 
74 } // namespace qx::details
75 
76 namespace std
77 {
78 
79 template<template<class, class...> class pointer_t, class T, class... args_t>
80 struct hash<qx::details::smart_ptr_ref_adapter<pointer_t, T, args_t...>>
81 {
82  size_t operator()(const qx::details::smart_ptr_ref_adapter<pointer_t, T, args_t...>& adaper) const noexcept
83  {
84  return hash<pointer_t<T, args_t...>>()(adaper);
85  }
86 };
87 
88 template<template<class, class...> class pointer_t, class T, class... args_t>
89 void swap(
92 {
93  lhs.swap(rhs);
94 }
95 
96 } // namespace std
97