cpp_prac/vector/vec.h

46 lines
1.2 KiB
C
Raw Permalink Normal View History

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();
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;
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;