1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
#include <iostream>
#include <type_traits>
#include <vector>
template <typename T, typename Allocator = std::allocator<T>>
class Vec : public std::vector<T> {
using std::vector<T>::vector;
public:
Vec( std::initializer_list<T> init, Allocator const& alloc = Allocator() );
T& operator[](int i)
{
return std::vector<T>::at(i);
}
const T& operator[](int i) const
{
return std::vector<T>::at(i);
}
};
template <typename T, typename Allocator>
Vec<T, Allocator>::Vec( std::initializer_list<T> init, Allocator const& alloc )
: std::vector<T, Allocator>(init, alloc)
{
}
void useVec()
{
std::vector<int> lst { 2, 7, 12, 35 };
std::vector<int> vec( 10, 5 );
std::vector vvec { 1, 3, 5, 7, 9, 11, 13 };
std::vector vlist { lst.begin(), lst.end() };
std::vector vcopy { vvec };
Vec<int> v( 10, 5 );
Vec vvec2 { 1, 3, 5, 7, 9, 11, 13 };
Vec vvlist { lst.begin(), lst.end() };
v[3] = 5;
std::cout << v[3];
}
int main()
{
useVec();
}
|