Boost logo

Boost :

From: Guillaume Melquiond (gmelquio_at_[hidden])
Date: 2003-09-19 01:57:11


On Fri, 19 Sep 2003, Vladimir Prus wrote:

> Robert Ramey wrote:
> > Vladimir Prus wrote:
> > >- if(file_version >= unsigned int(2))
> > >+ if(file_version >= static_cast<unsigned int>(2))
> >
> > Hmm - I just changed it to:
> > if(file_version >= 2)
> >
> > It compiles with VC and gcc 3.2. Does gcc 3.2 complain about that?
>
> This is fine for 3.3.
>
> > >- ar.register_type<bus_stop_corner>();
> > >- ar.register_type<bus_stop_destination>();
> > >+ ar.template register_type<bus_stop_corner>();
> > >+ ar.template register_type<bus_stop_destination>();
> >
> > gosh - I've never seen that syntax before.
> > I don't even know what it means.
>
> This means: "consider register_type to be name of template"
>
> > What was the 3.3 complaint with the original?
>
> The complaint was:
> demo.cpp: In member function `void bus_route::serialize(Archive&, unsigned
> int)
> ':
> demo.cpp:180: error: syntax error before `;' token
>
> The minimal example is:
>
> class C {
> public:
> template<class Archive>
> void serialize(Archive& ar)
> {
> ar.register_type<int>();
> }
> };
>
> I was not able to test with online comeau, since it seems to fail on
> everything, with no error messages. Further, I have failed to find the
> relevant text in the standard. The syntax I've used is allowed by the
> grammar, but I think there is some text about it as well.
>
> - Volodya

This syntax is not only allowed by the grammar, it is obligatory:

14.2-4
"When the name of a member template specialization appears after . or ->
in a postfix expression, of after nested-name-specifier in a qualified-id,
and the postfix-expression or qualified-id depends on a template parameter
(14.6.2), the member template must be prefixed by the keyword template.
Otherwise the name is assumed to name a non-template."

So, if you don't put "template", the compilers believe the "<" means "less
than" (since it is a non-template member) and you get a syntax error with
compliant compilers.

Regards,

Guillaume


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk