On Sep 20, 11:08 am, James Kanze <james.ka...@gmail.comwrote:
On Sep 19, 5:17 pm, Vladislav.Lazare...@gmail.com wrote:
On Sep 19, 4:42 pm, Erik Wikström <Erik-wikst...@telia.comwrote:
It is a defect in the language, you must put a space between
the two or the compiler will interpret it as the >>
operator, i.e.
It is not a defect!
The standards committee disagrees with you. In the next version
of the standard, the space will not be necessary; if a >token
occurs in a context where a which closes a template argument
list (but not a which means greater than) is legal, it is
broken down into two '>' tokens. Note that this change will
break code like:
template< int I class T ;
T< x >3 t ;
But such code is probably not very frequent, and there is a
simple work-around:
T< (x >3) t ;
Now if there were only such a simple fix for the most
embarassing parse problem (where what you thought defined a
variable in fact declares a function).
--
James Kanze (GABI Software) email:james.ka...@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Hi to all,
you can try a little metaprogramming to avoid nested typedefs. Try if
something like this works.
Bye,
Francesco :-)
#include <iostream>
#include <vector>
#include <string>
template< template< typename class TContainer, typename T, int KSize
>
struct CMultiDimContainer
{
typedef TContainer< typename CMultiDimContainer< TContainer, T,
KSize - 1 >::CType CType;
};
template< template< typename class TContainer, typename T >
struct CMultiDimContainer< TContainer, T, 1 >
{
typedef TContainer< T CType;
};
//
template< int KInt >
struct CTypeFromInt
{
enum { kResult = KInt };
};
//
template< typename T, template< typename class TTemplClass >
struct CIsInstanceOf
{
enum { kResult = false };
};
template< typename T, template< typename class TTemplClass >
struct CIsInstanceOf< TTemplClass< T >, TTemplClass >
{
enum { kResult = true };
};
//
template< template< typename T class TContainer, typename T >
void MultiDimResize( TContainer< T & inContainer, int inSize );
template< typename TContainer >
void MultiDimResize ( TContainer & inContainer, int inSize,
CTypeFromInt< true )
{
for( typename TContainer::iterator theIter = inContainer.begin();
theIter != inContainer.end(); ++theIter )
MultiDimResize( *theIter, inSize );
}
template< typename TContainer >
void MultiDimResize( TContainer & inContainer, int inSize,
CTypeFromInt< false )
{}
template< template< typename T class TContainer, typename T >
void MultiDimResize( TContainer< T & inContainer, int inSize )
{
inContainer.resize( inSize );
MultiDimResize( inContainer, inSize, CTypeFromInt< CIsInstanceOf<
T, TContainer >::kResult >() );
}
//
int main( void )
{
CMultiDimContainer< std::vector, int, 3 >::CType theMultiVec;
MultiDimResize( theMultiVec, 10 );
std::cout << theMultiVec.size() << std::endl;
std::cout << theMultiVec[ 4 ].size() << std::endl;
std::cout << theMultiVec[ 5 ][ 3 ].size() << std::endl;
std::cout << theMultiVec[ 2 ][ 7 ][ 4 ] << std::endl;
std::string str; // just to block this *#$^&$
std::cin >str;
}