CsPointer  2.0.0
cs_unique_array_pointer.h
1 
19 #ifndef LIB_CS_UNIQUE_ARRAY_POINTER_H
20 #define LIB_CS_UNIQUE_ARRAY_POINTER_H
21 
22 #include <cs_pointer_traits.h>
23 #include <cs_unique_pointer.h>
24 
25 #include <memory>
26 
27 namespace CsPointer {
28 
29 template <typename T, typename Deleter = std::default_delete<cs_add_missing_extent_t<T>>>
30 class CsUniqueArrayPointer : public CsUniquePointer<cs_add_missing_extent_t<T>, Deleter>
31 {
32  public:
33  using pointer = typename std::unique_ptr<cs_add_missing_extent_t<T>, Deleter>::pointer;
34  using element_type = typename std::unique_ptr<cs_add_missing_extent_t<T>, Deleter>::element_type;
35  using deleter_type = typename std::unique_ptr<cs_add_missing_extent_t<T>, Deleter>::deleter_type;
36 
37  using Pointer = pointer;
38  using ElementType = element_type;
39  using DeleterType = deleter_type;
40 
42 
44  : CsUniquePointer<cs_add_missing_extent_t<T>, Deleter>(std::move(other.m_ptr))
45  {
46  }
47 
49  {
50  this->m_ptr = std::move(other.m_ptr);
51  return *this;
52  }
53 
54  CsUniqueArrayPointer(CsUniqueArrayPointer<ElementType[]> &&other) noexcept
55  : CsUniquePointer<cs_add_missing_extent_t<T>, Deleter>(std::move(other.m_ptr))
56  {
57  }
58 
59  CsUniqueArrayPointer &operator=(CsUniqueArrayPointer<ElementType[]> &&other) noexcept {
60  this->m_ptr = std::move(other.m_ptr);
61  return *this;
62  }
63 
64  ElementType &operator*() const noexcept(noexcept(* std::declval<pointer>())) {
65  return this->get()[0];
66  }
67 
68  ElementType &operator[](std::size_t index) const noexcept {
69  return this->get()[index];
70  }
71 };
72 
73 template <typename T, typename = typename std::enable_if_t<std::is_array_v<T>>>
75 {
76  return std::make_unique<T>(size);
77 }
78 
79 } // end namespace
80 
81 #endif
CsUniqueArrayPointer< T > make_unique(std::size_t size)
Definition: cs_unique_array_pointer.h:74
ElementType & operator[](std::size_t index) const noexcept
Definition: cs_unique_array_pointer.h:68
CsUniqueArrayPointer & operator=(CsUniqueArrayPointer< ElementType[]> &&other) noexcept
Definition: cs_unique_array_pointer.h:59
CsUniqueArrayPointer(CsUniqueArrayPointer< ElementType[]> &&other) noexcept
Definition: cs_unique_array_pointer.h:54
CsUniqueArrayPointer & operator=(CsUniqueArrayPointer< ElementType > &&other) noexcept
Definition: cs_unique_array_pointer.h:48
CsUniqueArrayPointer(CsUniqueArrayPointer< ElementType > &&other) noexcept
Definition: cs_unique_array_pointer.h:43
CsUniquePointer(Pointer p=nullptr) noexcept
Definition: cs_unique_pointer.h:43
typename cs_add_missing_extent< T >::type cs_add_missing_extent_t
Definition: cs_pointer_traits.h:35
deleter_type DeleterType
Definition: cs_unique_pointer.h:37
Pointer get() const noexcept
Definition: cs_unique_pointer.h:91
typename std::unique_ptr< cs_add_missing_extent_t< T >, Deleter >::deleter_type deleter_type
Definition: cs_unique_pointer.h:33
Contains a pointer to an object and takes exclusive ownership.
Definition: cs_shared_pointer.h:28
typename std::unique_ptr< cs_add_missing_extent_t< T >, Deleter >::pointer pointer
Definition: cs_unique_pointer.h:31
Contains a pointer to a dynamically allocated array.
Definition: cs_unique_array_pointer.h:30
Namespace for the CsPointer library.