Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<typename T> class faux_vector {
- std::vector<T> storage;
- std::size_t actual_size;
- public:
- faux_vector() : actual_size(0) {}
- void push_back(T& t) {
- if (actual_size == storage.capacity()) {
- std::vector<T> new_buffer;
- new_buffer.resize(storage.size() * 1.5 + 1);
- for(int i = 0; i < storage.size(); i++) {
- storage[i].swap(new_buffer[i]);
- }
- std::swap(storage, new_buffer);
- }
- storage[actual_size++].swap(t);
- }
- void pop_back() {
- T t;
- storage[actual_size--].swap(t);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement