Vector<E> -> E __gc[]

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ravenous.wolves@gmail.com

    Vector<E> -> E __gc[]

    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<typena me 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[i] = crUnmanagedVec[i];
    }

    return managedArray;
    }

  • Carl Daniel [VC++ MVP]

    #2
    Re: Vector&lt;E&gt; -&gt; E __gc[]

    ravenous.wolves @gmail.com wrote:[color=blue]
    > 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<typena me T, typename E>[/color]

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

    -cd



    Comment

    • Carl Daniel [VC++ MVP]

      #3
      Re: Vector&lt;E&gt; -&gt; E __gc[]

      Carl Daniel [VC++ MVP] wrote:[color=blue]
      > ravenous.wolves @gmail.com wrote:[color=green]
      >> 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<typena me T, typename E>[/color]
      >
      > template<templa te<class> T, typename E>[/color]

      Err...

      template<templa te<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::allocat or<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


      Comment

      • ben

        #4
        Re: Vector&lt;E&gt; -&gt; E __gc[]

        would this work?

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

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

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


        ben
        [color=blue]
        > Carl Daniel [VC++ MVP] wrote:[color=green]
        > > ravenous.wolves @gmail.com wrote:[color=darkred]
        > >> 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<typena me T, typename E>[/color]
        > >
        > > template<templa te<class> T, typename E>[/color]
        >
        > Err...
        >
        > template<templa te<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[/color]
        at[color=blue]
        > least <T,std::allocat or<T> >. More unfortunately, implementors are[/color]
        allowed[color=blue]
        > 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
        >
        >[/color]


        Comment

        Working...