Thread View: comp.std.c++
2 messages
2 total messages
Started by nicolas (n.) chapados
Thu, 22 Feb 1996 17:13
Template specialization with template?
Author: nicolas (n.) chapados
Date: Thu, 22 Feb 1996 17:13
Date: Thu, 22 Feb 1996 17:13
37 lines
2057 bytes
2057 bytes
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
]
Re: Template specialization with template?
Author: Matt Austern
Date: Thu, 22 Feb 1996 20:29
Date: Thu, 22 Feb 1996 20:29
33 lines
1950 bytes
1950 bytes
In article <312BF6A1.5BBE@bnr.ca> "nicolas (n.) chapados" <chapados@bnr.ca> writes:
> 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?
Yes, this is allowed. (So long as an unspecialized version of
PersistentIO<X> has been declared first.) This is known as partial
specialization, and it is described in section 14.6 [temp.class.spec]
of the draft standard. Partial specialization is used in the standard
class library.
Unfortunately, I don't know of any released compilers that have
actually implemented partial specialization.
--
Matt Austern
SGI: MTI Compilers Group
austern@isolde.mti.sgi.com
[ 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
]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads