Topic: Can anyone explain me 14.3.3/1?


Author: Biju Thomas <b.thomas@attglobal.net>
Date: 2000/04/20
Raw View
Andrei Alexandrescu wrote:
>
> I wonder what the following quote of 14.3.3/1 means:
>
> "partial specializations are not considered even if their paramaeter lists
> match that of the template template parameter."
>
> Below, 14.3.3/2 continues with:
>
> "Any partial specializations [...] are considered when a specialization
> based on the template template-parameter is instantiated."
>
> I don't get the meaning of all this. Could someone enlighten me? Thanks.
>

You snipped the relevant part of the first quote. The first quote was
about template argument deduction for a template template-parameter when
the compiler tries to match it with a given template template-argument;
partial specializations don't have any effect on that. The second quote
is regarding instantiation/specialization of a template using the
template template-parameter.

For example:

  template < class T1, class T2 >
  struct Foo {};

  template < class T >
  struct Foo<T,T> {};

  template < class T,
             template < class A > class X >
  struct Bar1 {};

  template < class T1, class T2,
             template < class A, class B > class X >
  struct Bar2 {
    X<T1,T2> m;
  };

  Bar1<int,Foo> x1;
    // Illegal, since Foo has two template
    // parameters, although there is a
    // matching partial specialization.

  Bar2<int,int,Foo> x2;
    // x2.m uses the partial sepecialization
    // for Foo behind the covers.

--
Biju Thomas

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: "Andrei Alexandrescu" <andrewalex@hotmail.com>
Date: 2000/04/20
Raw View
Awesome. The example made it crystal-clear. Thanks Biju.

I haven't found any use of template template parameters for a long while.
Now I think a good use of them is for specifying policies.

For instance: you develop a smart pointer class. In general, smart pointers
are typically chock-full of policies: ownership policy, copying policy,
checking policy, array policy (does the pointer point to an array or to a
single element?), locking policy (behavior in a multithreaded environment).

If you make the smart pointer essentially policy-free, and distribute
policies as its template parameters (some of which can be templates
themselves), you end up having a highly reusable smart pointer class. You
just have to specify an acceptably general interface for each policy, and
define a number of usual policies (refcounting etc.). Then users can develop
their own policies and use them with your smart pointer and your other
policies, without having to start from scratch.



Andrei


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: "Andrei Alexandrescu" <andrewalex@hotmail.com>
Date: 2000/04/16
Raw View
Hi,


I wonder what the following quote of 14.3.3/1 means:

"partial specializations are not considered even if their paramaeter lists
match that of the template template parameter."

Below, 14.3.3/2 continues with:

"Any partial specializations [...] are considered when a specialization
based on the template template-parameter is instantiated."

I don't get the meaning of all this. Could someone enlighten me? Thanks.


Andrei


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]