Vector<E> -> E __gc[]

  • Thread starter Thread starter ravenous.wolves
  • Start date Start date
R

ravenous.wolves

I'm trying to create a template function to convert from a vector of
Es, to a managed array of Es. I want this to work with std::vector, or
any other type that implements the call requirements of this function.

I get the following error on this code:
error C2143: syntax error : missing ')' before '<'

template<typename T, typename E>
E ToManaged( T<E> const & crUnmanagedVec ) __gc[]
{
int nElements = crUnmanagedVec.size();
E managedArray __gc[] = new E __gc[nElements];

for( int i = 0; i < nElements; ++i )
{
managedArray = crUnmanagedVec;
}

return managedArray;
}
 
I'm trying to create a template function to convert from a vector of
Es, to a managed array of Es. I want this to work with std::vector, or
any other type that implements the call requirements of this function.

I get the following error on this code:
error C2143: syntax error : missing ')' before '<'

template<typename T, typename E>

template<template<class> T, typename E>

-cd
 
Carl said:
template<template<class> T, typename E>

Err...

template<template<typename> class T, typename E>

HOWEVER, that won't work for std::vector. Sadly, the C++ standarization
committee made the regretable decision (IMO) to require template argument
lists for template template parameters to match exactly, rather than
requiring them to be compatible.

The template argument list for std::vector isn't simply <T>, rather, it's at
least <T,std::allocator<T> >. More unfortunately, implementors are allowed
to add additional template parameters with defaults, so in practice it's
impossible to match a standard container such as std::vector to a template
template argument in a portable way.

-cd
 
would this work?

template <typename E, typename Policy = DefPolicy<E> >
class CToManaged
{
public:

E operator () (const typename Policy::ContainerType& crUnmanagedVec)
__gc[];
};

template <typename E>
class DefPolicy
{
public:
typedef std::vector<E> ContainerType;
//...
};


ben
 
Back
Top