🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2932

Re: Class template specialization ?

#2932
From: Mia Lahteenmaki
Date: Thu, 14 Dec 1995 20:21
81 lines
3744 bytes
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. ]
Technical Details
Message-ID: <4ap7td$n1n@hydra.cs.Helsinki.FI>
Path: arc1-ca.pugleaf.net!howland.reston.ans.net!agate!agate!matt
References: <49ssga$2eu@hydra.cs.Helsinki.FI> <4a4hc2$1qb@oznet03.ozemail.com.au>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!howland.reston.ans.net!agate!agate!matt
From: mlahteen@cs.Helsinki.FI (Mia Lahteenmaki)
Newsgroups: comp.std.c++
Subject: Re: Class template specialization ?
Date: 14 Dec 1995 20:21:51 GMT
Organization: University of Helsinki, Department of Computer Science
Approved: matt@Austern (Matt Austern)
Message-ID: <4ap7td$n1n@hydra.cs.Helsinki.FI>
References: <49ssga$2eu@hydra.cs.Helsinki.FI> <4a4hc2$1qb@oznet03.ozemail.com.au>
NNTP-Posting-Host: austern.hip.berkeley.edu