Last active
August 8, 2016 15:14
-
-
Save qgp9/e7fbd3d9b15e15b12499 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
template < class T, int n > struct mvector_tool{ | |
typedef vector< typename mvector_tool<T,n-1>::type > type; | |
static type gen_vector( std::array<unsigned int, n> index, T initvalue ){ | |
std::array<unsigned int,n-1> index_next; | |
std::copy_n( index.begin()+1, n-1, index_next.begin() ); | |
return type( index.front(), mvector_tool<T,n-1>::gen_vector( index_next, initvalue )); | |
} | |
}; | |
template < class T > struct mvector_tool<T,0>{ | |
typedef T type; | |
static type gen_vector( std::array<unsigned int,0> index, T &initvalue ){ | |
return initvalue; | |
} | |
}; | |
template <class T, int n> using mvec = typename mvector_tool<T,n>::type; | |
struct mvector_tool_g { | |
template < class T > static void PrintVector( T v ){ | |
std::cout<< v << std::endl;; | |
} | |
template < class T > static void PrintVector( vector<T> &v ){ | |
for ( auto i : v ) { PrintVector( i );} | |
} | |
}; | |
void test_multivector(){ | |
mvec<int, 5> mv1 = mvector_tool<int, 5>::gen_vector( {2, 3, 4, 5, 6}, 1 ); | |
mvector_tool_g::PrintVector( mv1 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment