Re: Is this valid ISO C++?

From: Victor Bazarov (v.Abazarov_at_comAcast.net)
Date: 03/30/05


Date: Tue, 29 Mar 2005 20:08:28 -0500


"Ioannis Vranos" <ivr@remove.this.grad.com> wrote...
> This compiles with MINGW GCC 3.4.2 but not with my other compilers. Is it
> valid ISO C++?
>
>
> #include <vector>
>
>
> template< template<class> class ContainerTemplate, class ValueType>
> inline void test(const ValueType &val)
> {
> ContainerTemplate<ValueType> container(val);
> }
>
>
>
> int main()
> {
> using namespace std;
>
> test<vector>(10);
> }

No, this is not valid for a simple reason that std::vector is a template
that has more than one argument. Your 'ContainerTemplate' template
template argument has only one argument itself.

Until we have template typedefs you're probably out of luck. You could
try declaring your own template deriving form 'vector<T>', but you'd
have to duplicate all functionality.

V



Relevant Pages

  • Re: Template instantiation issue
    ... I was hoping someone could help, I have some code that compiles on GCC but throws a warning with VS2005. ... TY polFit(const TX&,const int, ... confused about that (the const is redundant for the declaration in any case). ... template double polFit(const double&,const int, ...
    (microsoft.public.vc.language)
  • Re: Member template internal compiler error
    ... I'm fairly sure it is well-formed (g++ 3.4.2 compiles it fine). ... template <int N> ... static void Test() ... function template. ...
    (microsoft.public.vc.language)
  • Possible g++ bug in template parsing
    ... The attached code compiles and works properly when I comment out the ... declaration, definition, and invocations of the method 'eck'. ... Note that 'gak' (a template function in a template class) works, ...
    (comp.lang.cpp)
  • Re: EDG possible sozeof BUG
    ... Which version of MSVC did you use? ... Yes it compiles, but produces incorrect results, when the type being ... tested has a template operator T, but works for non template operator's ... Yep, not sure its that similar though, this isn't a full conversion test. ...
    (comp.lang.cpp)
  • Re: EDG possible sozeof BUG
    ... Which version of MSVC did you use? ... > tested has a template operator T, but works for non template operator's ... >> compiles fine with Comeau. ... > Yep, not sure its that similar though, this isn't a full conversion test. ...
    (comp.lang.cpp)