Skip to content

Instantly share code, notes, and snippets.

@landaire
Created December 7, 2013 05:38
Show Gist options
  • Select an option

  • Save landaire/7837664 to your computer and use it in GitHub Desktop.

Select an option

Save landaire/7837664 to your computer and use it in GitHub Desktop.
#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