Created
December 7, 2013 05:38
-
-
Save landaire/7837664 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #ifndef DYNAMICARRAY_H | |
| #define DYNAMICARRAY_H | |
| #include <iostream> | |
| #include <vector> | |
| #include <algorithm> | |
| #include <utility> | |
| using namespace std; | |
| template<typename T> | |
| class DynamicArray | |
| { | |
| private: | |
| vector<T> v; | |
| public: | |
| /** | |
| * Optionally, instead of doing resizing here, you can do the following | |
| * DynamicArray(initializer_list<T> a) : v(a) {} | |
| * @brief DynamicArray | |
| * @param a | |
| */ | |
| DynamicArray(initializer_list<T> a) | |
| { | |
| v.resize(a.size()); | |
| std::uninitialized_copy(a.begin(), a.end(), v.begin()); | |
| } | |
| void print() | |
| { | |
| for (auto p : v) | |
| { | |
| cout << p; | |
| } | |
| } | |
| T& operator[](int i) | |
| { | |
| return v[i]; | |
| } | |
| void swap(T& a, T& b) | |
| { | |
| auto tmp = move(a); | |
| a = move(b); | |
| b = move(tmp); | |
| } | |
| DynamicArray(const DynamicArray &rhs) = delete; | |
| }; | |
| #endif // DYNAMICARRAY_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment