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
|
#include <iostream>
template < int X, int Y > struct outer
{
template < typename T > struct inner
{
T matrix[X][Y] ;
static constexpr int bytes = X*Y * sizeof(T) ;
template < typename U > using rebind = typename outer<X,Y>::template inner<U> ;
template < int XX, int YY > using redim = typename outer<XX,YY>::template inner<T> ;
};
};
template < int X, int Y, typename T > using inner_t = typename outer<X,Y>::template inner<T> ;
int main()
{
outer<2,3>::inner<int> var { { { 0, 1, 2 }, { 3, 4, 5 } } } ;
inner_t<2,3,int> cpy = var ;
decltype(cpy)::rebind<char> another {};
decltype(cpy)::redim<4,6> yet_another {};
decltype(cpy)::redim<10,20>::rebind<char> a_third {};
std::cout << var.bytes << ' ' << another.bytes << ' ' << yet_another.bytes << ' ' << a_third.bytes << '\n' ;
static_assert( outer<1,1>::inner<char>::rebind<int>::redim<2,3>::bytes == sizeof(var), "must be equal" ) ;
}
|