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