🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

5 total messages Started by Mia Lahteenmaki Mon, 04 Dec 1995 16:30
Class template specialization ?
#2828
Author: Mia Lahteenmaki
Date: Mon, 04 Dec 1995 16:30
41 lines
2427 bytes
The WP draft (28 April,1995) describes class template specializations 
in 14.6 [temp.class.spec]. I would like to specialize 
collection class to use smart pointer (Ref) element type. 
The typical template instantiation is 'Collection<Ref<C>>' 
where C is some class.

template<class T> class Ref {...};
//primary template
template<class T1> class Collection {...};

// How should I declare now the specialization ? Like this?
template<class T1> class Collection<Ref<T> > {...};  

Would the above declaration be correct ?
I understand that the standard clause 7, first point:
"- A specialized nontype argument expression shall not involve a
   template parameter of the specialization "
is now met.

My current compiler (MS Visual C++ 2.0) does not understand the 
above declaration, but that does not say me much about
whether the declaration is standard compliant or not, of course.

Regards,
  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                
---------------------------------------------------------------------
--
--------------------------------------------------------------------
Mia L{hteenm{ki                      Helsingin yliopisto 
e-mail: mia.lahteenmaki@helsinki.fi  Tietojenk{sittelytieteen laitos
Tel   : (90) 7084 4246               PL 26 (Teollisuuskatu 23)

[ 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. ]
Re: Class template specialization ?
#2842
Author: David Vandevoorde
Date: Mon, 04 Dec 1995 22:55
22 lines
1315 bytes
>>>>> "ML" == Mia Lahteenmaki <mlahteen@cs.Helsinki.FI> writes:
[...]
ML> template<class T> class Ref {...};
ML> //primary template
ML> template<class T1> class Collection {...};

ML> // How should I declare now the specialization ? Like this?
ML> template<class T1> class Collection<Ref<T> > {...};  

I think it should be:

	template<class T>
	class Collection<Ref<T> > // ...

Very few (if any) compilers support this form of partial
specialization yet.

	Daveed

[ 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. ]
Re: Class template specialization ?
#2861
Author: Anil Vijendran
Date: Wed, 06 Dec 1995 00:34
39 lines
1816 bytes
>>>>> 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. ]
Re: Class template specialization ?
#2870
Author: John Max Skaller
Date: Wed, 06 Dec 1995 16:53
32 lines
1752 bytes
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. ]
Re: Class template specialization ?
#2932
Author: 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. ]
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