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
|
template <typename T>
struct CompleteVector{
T value;
CompleteVector(const T &value = {}) : value(value){}
CompleteVector(T &&value) : value(std::move(value)){}
CompleteVector(const CompleteVector &) = default;
};
template <typename T>
CompleteVector<T> complete(const T &x){
return CompleteVector<T>(x);
}
template <typename T>
struct VectorMultiArray{
std::vector<size_t> dimensions;
VectorMultiArray() = default;
template <typename T2>
VectorMultiArray(const VectorMultiArray<T2> &x) : dimensions(x.dimensions){}
template <typename T2>
VectorMultiArray(VectorMultiArray<T2> &&x){
this->dimensions = std::move(x.dimensions);
}
VectorMultiArray<std::vector<T>> operator<<(size_t n) const{
VectorMultiArray<std::vector<T>> copy = *this;
copy.dimensions.push_back(n);
return copy;
}
template <typename T2>
T operator<<(const CompleteVector<T2> &n) const{
T ret;
initialize(ret, n.value, &this->dimensions[0], this->dimensions.size());
return ret;
}
private:
template <typename V, typename T2>
static void initialize(V &dst, const T2 &value, const size_t *sizes, size_t n){
dst.resize(sizes[0]);
for (auto &i : dst)
initialize(i, value, sizes + 1, n - 1);
}
template <typename T2>
static void initialize(std::vector<T2> &dst, const T2 &value, const size_t *sizes, size_t n){
dst.resize(sizes[0], value);
}
};
template <typename T>
std::vector<std::vector<T>> operator<<(const std::vector<T> &x, size_t n){
return std::vector<std::vector<T>>(n, x);
}
|