MCPcopy Create free account
hub / github.com/Apress/beginning-cpp20 / Array

Class Array

Examples/NoModules/Chapter 21/Ex21_03/Array.h:10–29  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8
9template <typename T> requires std::default_initializable<T> && std::destructible<T>
10class Array
11{
12public:
13 Array();
14 explicit Array(size_t size);
15 ~Array();
16 Array(const Array& array) requires std::copyable<T>;
17 Array& operator=(const Array& rhs) requires std::copyable<T>;
18 Array(Array&& array) noexcept requires std::movable<T>;
19 Array& operator=(Array&& rhs) noexcept requires std::movable<T>;
20 void swap(Array& other) noexcept;
21 T& operator[](size_t index);
22 const T& operator[](size_t index) const;
23 size_t getSize() const { return m_size; }
24 void push_back(T element) requires std::movable<T>;
25
26private:
27 T* m_elements; // Array of type T
28 size_t m_size; // Number of array elements
29};
30
31// Forwarding default constructor template
32template <typename T> requires std::default_initializable<T> && std::destructible<T>

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected