2025-01-10 08:15:31 +01:00
|
|
|
#include <initializer_list>
|
|
|
|
#include <iterator>
|
|
|
|
|
|
|
|
typedef int T;
|
|
|
|
constexpr int INITIAL_LEN = 10;
|
|
|
|
|
|
|
|
class Vec {
|
|
|
|
std::size_t cap;
|
|
|
|
std::size_t w_idx;
|
|
|
|
T *arr = nullptr;
|
|
|
|
|
|
|
|
void resize(std::size_t newsize);
|
|
|
|
|
|
|
|
public:
|
|
|
|
Vec();
|
2025-01-11 17:13:50 +01:00
|
|
|
explicit Vec(std::size_t);
|
2025-01-10 08:15:31 +01:00
|
|
|
Vec(std::initializer_list<T>);
|
|
|
|
Vec(const Vec &other); // Copy
|
|
|
|
Vec(Vec &&other) noexcept; // Move
|
|
|
|
Vec &operator=(const Vec &other); // CopyAssign
|
|
|
|
Vec &operator=(Vec &&other) noexcept; // MoveAssign
|
|
|
|
~Vec(); // Destructor
|
|
|
|
|
|
|
|
T &operator[](std::size_t) const noexcept;
|
|
|
|
|
|
|
|
std::size_t size() const;
|
|
|
|
std::size_t capacity() const noexcept;
|
|
|
|
|
2025-01-11 17:13:50 +01:00
|
|
|
void push_back(const T &value); // May except
|
|
|
|
void push_back(T &&value);
|
2025-01-10 08:15:31 +01:00
|
|
|
void pop_back() noexcept;
|
|
|
|
void clear() noexcept;
|
|
|
|
|
|
|
|
using iterator = T *;
|
|
|
|
using const_iterator = const T *;
|
|
|
|
|
|
|
|
iterator begin() noexcept { return arr; }
|
|
|
|
iterator end() noexcept { return arr + w_idx; }
|
|
|
|
|
|
|
|
const_iterator begin() const noexcept { return arr; }
|
|
|
|
const_iterator end() const noexcept { return arr + w_idx; }
|
|
|
|
};
|
|
|
|
|
|
|
|
// std::iterator<Vec> end() const noexcept;
|
|
|
|
// std::iterator begin() const noexcept;
|