Topic: Class template specialization ?
Author: mlahteen@cs.Helsinki.FI (Mia Lahteenmaki)
Date: 1995/12/14 Raw View
In <4a4hc2$1qb@oznet03.ozemail.com.au> John Max Skaller
<maxtal@suphys.physics.su.oz.au> writes:
>mlahteen@cs.Helsinki.FI (Mia Lahteenmaki) (almost) wrote:
>>template<class T> class Ref {...};
>>template<class T1> class Collection {...};
>> // primary template
>>template<class T1> class Collection<Ref<T> > {...};
>> // specialisation
> ---> is correct as you wrote it.
I'm sorry, I do not agree with you here (anymore).
After the answers from David Vandevoorde and Timo Holkeri and some
rethinking I agree with them that the correct form must be
template<class T> class Collection<Ref<T> > {...};
In <4a4hc2$1qb@oznet03.ozemail.com.au> John Max Skaller
<maxtal@suphys.physics.su.oz.au> continues:
>... However, I wouldn't
>advise doing this particular specialisation!
>It isn't necessary, your "Ref<T>" class(es) should do
>all the work. You could consider a container adaptor
>instead.
>BTW: you CAN'T specialise standard library templates;
>if you do you release your compiler from any obligation
>to operate correctly.
>--
>John Max Skaller voice: 61-2-566-2189
>81 Glebe Point Rd fax: 61-2-660-0850
>GLEBE NSW 2037 email: maxtal@suphys.physics.oz.au
>AUSTRALIA email: skaller@maxtal.com.au
And right you are !
I should have changed the type names or explain further why I'm doing
these odd things.
Here comes the explanation: I am not using STL or implementing collections
from the scratch. I am using commercial library having persistent-capable
collections that only accept pointer element types. I want to build
an interface on top of this library to allow ODMG-93 standard compatible
use. In the ODMG-93 standard compatible use, the element types user
defines may be smart pointers (Ref<T>) in which case I must change the
element type to Ref<T>*. In addition, I must take care that the smart
pointer instance to be stored is persistent, if the collection is meant
to be persistent. After I add the pointer to the element type, it is not
taken care automatically.
There has been some other suggestions of using template parameters
in this case. I thank you for reminding me this option. However, I
consider class template specialization a more intuitive and suitable
solution in this case. A collection type that has smart pointers as
its element type is one special type of collections.
BTW, does anyone know a compiler which implements class template
specialization already ?
- Mia
---------------------------------------------------------------------
Mia Lahteenmaki University of Helsinki
e-mail: mia.lahteenmaki@helsinki.fi Department of Computer Science
Tel : +358 0 7084 4246 P.O. Box 26
Fax : +358 0 7084 4441 FIN-00014 UNIVERSITY OF HELSINKI
FINLAND
---------------------------------------------------------------------
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Author: akv@cacs.usl.edu (Anil Vijendran)
Date: 1995/12/06 Raw View
>>>>> On 4 Dec 1995 16:30:04 GMT, mlahteen@cs.Helsinki.FI (Mia
Lahteenmaki) said:
Mia> The WP draft (28 April,1995) describes class template
Mia> specializations in 14.6 [temp.class.spec]. I would like to
Mia> specialize collection class to use smart pointer (Ref)
Mia> element type. The typical template instantiation is
Mia> 'Collection<Ref<C>>' where C is some class.
Mia> template<class T> class Ref {...}; //primary template
Mia> template<class T1> class Collection {...};
Mia> // How should I declare now the specialization ? Like this?
Mia> template<class T1> class Collection<Ref<T> > {...};
Check out 14.7 (temp.param). It might be of use to you.
AFAIK (don't take my word for granted and pl correct me if I I'm
wrong), you could do it like this:
template <class T> class Ref { ... };
template <class T, template <class T> class RefType = Ref> class Collection { ... };
There is an example out there that does stuff like the above.
None of the compilers I have access to understand this baroque syntax.
--
Peace.... +<:-)
Anil
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Author: John Max Skaller <maxtal@suphys.physics.su.oz.au>
Date: 1995/12/06 Raw View
mlahteen@cs.Helsinki.FI (Mia Lahteenmaki) (almost) wrote:
template<class T> class Ref {...};
template<class T1> class Collection {...};
// primary template
template<class T1> class Collection<Ref<T> > {...};
// specialisation
---> is correct as you wrote it. However, I wouldn't
advise doing this particular specialisation!
It isn't necessary, your "Ref<T>" class(es) should do
all the work. You could consider a container adaptor
instead.
BTW: you CAN'T specialise standard library templates;
if you do you release your compiler from any obligation
to operate correctly.
--
John Max Skaller voice: 61-2-566-2189
81 Glebe Point Rd fax: 61-2-660-0850
GLEBE NSW 2037 email: maxtal@suphys.physics.oz.au
AUSTRALIA email: skaller@maxtal.com.au
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]