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 protected:
31  base_smart_ptr_ref_adapter& operator=(base_smart_ptr_ref_adapter&&) noexcept = default;
32 
33  template<class... constructor_args_t>
34  base_smart_ptr_ref_adapter(constructor_args_t&&... args);
35 
36 private:
37  using original_pointer_type::get;
38  using original_pointer_type::reset;
39  using original_pointer_type::operator bool;
40  using original_pointer_type::operator=;
41 };
42 
43 template<template<class, class...> class pointer_t, class T, class... args_t>
45 {
46 public:
47  using super = base_smart_ptr_ref_adapter<pointer_t, T, args_t...>;
48  using original_pointer_type = typename super::original_pointer_type;
49  using element_type = typename super::element_type;
50  using pointer = typename super::pointer;
51  using reference = typename super::reference;
52 
53  super::reference get() const noexcept;
54 
55 protected:
58 
59  template<class... constructor_args_t>
60  overload_functions_smart_ptr_ref_adapter(constructor_args_t&&... args);
61 };
62 
63 template<template<class> class pointer_t, class T, class... args_t>
65 
66 } // namespace qx::details
67 
68 namespace std
69 {
70 
71 template<template<class, class...> class pointer_t, class T, class... args_t>
72 struct hash<qx::details::smart_ptr_ref_adapter<pointer_t, T, args_t...>>
73 {
74  size_t operator()(const qx::details::smart_ptr_ref_adapter<pointer_t, T, args_t...>& adaper) const noexcept
75  {
76  return hash<pointer_t<T, args_t...>>()(adaper);
77  }
78 };
79 
80 template<template<class, class...> class pointer_t, class T, class... args_t>
81 void swap(
84 {
85  lhs.swap(rhs);
86 }
87 
88 } // namespace std
89