Boost logo

Boost Users :

From: Tobias Schwinger (tschwinger_at_[hidden])
Date: 2008-01-24 09:26:41


Ovanes Markarian wrote:
> Hello!
>
> I have a question to this construct:
>
>
> template <typename contractType, typename treeType>
> class TreeImplBase;
>
> Each specialization of these holds a
> static std::map< boost::tuple<int,enum1,enum2,enum3>, const
> TreeImplBase* >;
> which contains the list of the derived template classes.
>
>
> How can you instantiate a pointer to the class temlate? Class template
> is an incomplete type. You will not be able to specify a pointer to it.

The wording is a bit ambiguous: A pointer to an /incomplete type/ is in
fact OK (using standard terminology), but 'TreeImplBase' is a /template
id/ which is not a type at all.

As Ovanes pointed out that construct is illegal, however (except inside
a definition of 'TreeImplBase' where it's the /injected class name/).

/Specializing/ a template with template arguments yields a type. Using
(whatever) member of this type's interface causes the template to be
implicitly (possibly partially) /instantiated/. It's most important to
realize that specializing a template does not cause the template to be
instantiated automatically.

Note that "template specialization" has a context-dependent meaning, as
it can either refer to a type or of a class (template) definition of a
variant implementation of the template:

     // /primary template/
     template< typename T > struct A { ... };

     // definition of the (full) specialization A<int>
     template< > struct A<int> { ... };

     // definition of a partial specialization
     template< typename T > struct A< B<T> >
     {
         typedef A self; // /injected class name/ is a type
     };

     // X and Y are specializations (not instantiations)!
     typedef A< B<int> > X;
     typedef A< long > Y;

     int main()
     {
        X x; // instantiation of the 'B<int>'-specialization of A
        // at this point

     // ...

OK, that's about template terminology in five minutes :-).

Regards,
Tobias


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