
Robert Jones wrote:
On Fri, Dec 12, 2008 at 5:52 PM, Noah Roberts <roberts.noah@gmail.com>wrote:
Noah Roberts wrote:
Neil, Noah, Kim - Thanks all for your input. Although no perfect solution has emerged it is always good to see a few good minds looking at it.
Don't recall if it was said already but you can also explicitly say which type you're using: int main( ) { Block< int, 16 > :: type a; const Block< int, 16 > :: type b = { }; assign<int[16]>( a, b ); } Then you'll need to establish template metaprograms to remove one array level from a type and get the type beneath in order to write your recursive template call so that it can cast the next level: template < typename T > struct next_level { typedef T type; }; template < typename T, size_t sz > struct next_level<T[sz]> { typedef T type; }; template < typename T > void assign( T & assignee, const T & value ) { assignee = value; } template < typename T, std :: size_t sz > void assign( T ( & assignee )[ sz ], const T ( & value )[ sz ] ) { for (size_t i = 0; i < sz; ++i) assign<typename next_level<T>::type>(assignee[i], value[i]); } Tested and works in msvc: int main( ) { typedef Block<int,3>::type type_t; type_t a; type_t const b = { { 1,2,3}, {4,5,6}, {7,8,9} }; assign<int[3]>( a, b ); for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) std::cout << a[i][j] << " "; std::cout << std::endl; } std::cin.get(); }