In another forum we where talking about multidimensional vectors specifically 2D vector, i got bored and thought i wonder if we can have a std::vector of 100th dimension and i came-up with this meta-template program, see if you can understand it and if your compiler can handle this:
#include <cstddef>
#include <vector>
template < typename T, size_t N, template < typename U, typename W > class con, template < typename G > class Alloc = std::allocator >
struct gen_multi {
typedef con< T, Alloc<T> > simple;
typedef typename gen_multi< simple, N - 1, con, Alloc >::simple n_container;
};
template < typename T, template < typename U, typename W > class con, template < typename G > class Alloc >
struct gen_multi< T, 0, con, Alloc > {
typedef con<T, Alloc<T> > simple;
typedef simple n_container;
};
int main() {
gen_multi< int, 100, std::vector >::n_container foo;
return 0;
}
after about 10 mins i get this output from GCC 3.4.2:
cc1plus.exe: out of memory allocating 297795646 bytes
LOL
so i kept on changing the size and managed to get it to compile at N == 20 so a 20D vector lol:
int main() {
gen_multi< int, 20, std::vector >::n_container foo;
return 0;
}
See if you can get it any higher!
[Edited by - snk_kid on September 30, 2004 7:43:27 PM]