Boost logo

Boost Users :

From: dizzy (dizzy_at_[hidden])
Date: 2008-02-13 12:19:14


On Wednesday 13 February 2008 19:05:16 Kobi Cohen-Arazi wrote:
> > > I'm taking a wild guess here not knowing what you're running this on
> > > (and I really haven't looked into your code much), but try:
> > >
> > > t.template get<0>();
> > > t.template get<1>();
> > >
> > > Was that it?
> > >
> > > Stjepan
> >
> > It compiles w/o error. Thanks!
> >
> > _______________________________________________
>
> Is it possible for the boost/template gurus to explain why it is needed
> here?
>
> Any help would be appreciated,

I'm no template guru but (the same as typename), template may be used in such
contexts to tell the compiler that the following _dependent_ name (ie "get")
is to be treated as a template and not (as it assumes by default) as say a
data member. Because if it was a data member then get<0 actually means
operator<(get, 0) and not part of the syntax to instantiate the
template "get". So then you must tell the compiler "get" is a template.

Notice I underlined "dependent", it means this is needed in contexts where the
name depends on a template parameter, so if "t" is of a template parameter
type (or dependent on such a parameter) then the compiler cannot know
in "t.name", if "name" is suposed to be a member, a nested non-template type
or a template (class or function, doesn't matter). It will require additional
specification from you (otherwise assumes to be a member, except some
contexts in which it assumes to be a non-template type), in our case it
requires that we tell it that "get" is a template for all "t"s possible in
that context.

I hope I got it right...

-- 
Mihai RUSU					Email: dizzy_at_[hidden]
			"Linux is obsolete" -- AST

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net