Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cctype>
- #include <array>
- #include <algorithm>
- using namespace std;
- class Myexeption{};
- template <typename T>
- class SimpleVector
- {
- public:
- T* data;
- size_t Size;
- size_t capacity;
- explicit SimpleVector(size_t size)
- {
- data = new T[size];
- Size = size;
- capacity = 0;
- }
- ~SimpleVector()
- {
- delete[](data);
- }
- T& operator[](size_t index)
- {
- return data[index];
- }
- T* begin()
- {
- return data;
- }
- T* end()
- {
- return data + Size;
- }
- [[nodiscard]] size_t Sizev() const
- {
- return Size;
- }
- void PushBack(const T& value)
- {
- try
- {
- if (capacity >= Size) throw Myexeption();
- data[capacity] = value;
- capacity++;
- }
- catch (Myexeption)
- {
- cout << "This action is impossimble" << endl;
- }
- }
- };
- template <typename T>
- ostream& operator<< (ostream& os, SimpleVector<T> &vec)
- {
- for (auto &el : vec)
- os << el << " ";
- return os << endl;
- }
- int main()
- {
- SimpleVector<int> vec(10);
- for (int i = 0; i < 10; i++)
- vec.PushBack(i);
- cout << vec.Sizev() << endl;
- cout << vec[9] << endl;
- cout << vec;
- vec.PushBack(69);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement