Skip to content

Instantly share code, notes, and snippets.

@hjroh0315
Created January 2, 2022 06:18
Show Gist options
  • Save hjroh0315/cfa8070bb045d918869f32dc443e605c to your computer and use it in GitHub Desktop.
Save hjroh0315/cfa8070bb045d918869f32dc443e605c to your computer and use it in GitHub Desktop.
변태같은 다차원벡터
#include <iostream>
#include <vector>
using namespace std;
template<int>
struct multivector;
template<>
struct multivector<1>
{
vector<int> vec;
int& operator[](int n)
{
return vec[n];
}
};
template<int d>
struct multivector
{
vector<multivector<d-1>> vec;
void add_row(int n)
{
if(n==0)return;
vec.push_back(multivector<d-1>());
add_row(n-1);
}
multivector<d-1>& operator[](int n)
{
return vec[n];
}
};
int main()
{
multivector<2> mvec;
mvec.add_row(2);
mvec[1].vec.push_back(3);
cout << mvec[1][0] << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment