Topic: Template specialization with template?


Author: "nicolas (n.) chapados" <chapados@bnr.ca>
Date: 1996/02/22
Raw View
It sometimes would be useful to have a template specialization be
itself a template.  For example, to define persistent I/O on all
vectors of type T, one could specialize PersistentIO<T>:

 template <class T>
 class PersistentIO< vector<T> >
 { ... };

I'd like to know whether this is allowed by the current draft.
Given the affirmative, what does the T argument represent inside
the specialization?

An alternative, which is not unfortunately not supported, would be
to define a specialization as a friend inside vector<T>:

 template <class T>
 class Vector<T> {
 public:
  // ...
  friend class PersistentIO< vector<T> >
  { ... };
 };

Could someone enlighten me as to why it is not permitted to define
a friend class inside another class, whereas defining a friend
inline function in a class is perfectly acceptable (and very useful
when used with templates)?

 Nicolas Chapados
 chapados@bnr.ca
---
[ To submit articles: Try just posting with your newsreader.  If that fails,
                      use mailto:std-c++@ncar.ucar.edu
  FAQ:    http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]