Topic: partial explicit instantiation
Author: David R Tribble <david.tribble@noSPAM.central.beasys.com>
Date: 1998/08/18 Raw View
Geoff Fortytwo wrote:
>> Is it legal to do partial explicit instantiation?
>> [...]
>>
>> typedef StandardCreator<Column, TheProduct>
>> StandardColumnCreator<TheProduct>;
Christopher Eltschka wrote:
>> You cannot make a template typedef - a typedef *must* denote
>> a single type.
James Kuyper wrote:
> However, you can achieve much the same effect as a template typedef,
> by defining a typedef member of a templated class:
>
> template<TheProduct> class StandardColumn {
> typedef StandardCreator<Column, TheProduct> Creator;
> };
>
> Then you use StandardColumn<T>::Creator instead of
> StandardColumnCreator<T>.
Here's a question for the committee:
Why are template typedefs not allowed (simply an oversite)?
Another related question: Does the method above work in all cases,
i.e., is it a general substitute for all template typedefs?
(If so, then that probably answers my first question.)
-- David R. Tribble, dtribble@technologist.com --
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Christopher Eltschka <celtschk@physik.tu-muenchen.de>
Date: 1998/08/12 Raw View
Geoff Fortytwo wrote:
>
> Is it legal to do partial explicit instantiation? And if so, am I doing
> it correctly? MSVC++ 5.0 doesn't like the last 2 lines of the following
> code (I'm trying to implement a generic Factory Method pattern):
>
[...]
> typedef StandardCreator<Column,TheProduct>
> StandardColumnCreator<TheProduct>;
You cannot make a template typedef - a typedef *must* denote
a single type.
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: James Kuyper <kuyper@wizard.net>
Date: 1998/08/12 Raw View
Christopher Eltschka wrote:
>
> Geoff Fortytwo wrote:
> >
> > Is it legal to do partial explicit instantiation? And if so, am I doing
> > it correctly? MSVC++ 5.0 doesn't like the last 2 lines of the following
> > code (I'm trying to implement a generic Factory Method pattern):
> >
>
> [...]
>
> > typedef StandardCreator<Column,TheProduct>
> > StandardColumnCreator<TheProduct>;
>
> You cannot make a template typedef - a typedef *must* denote
> a single type.
However, you can achieve much the same effect as a template typedef, by
definine a typedef member of a templated class:
template<TheProduct> class StandardColumn{
typedef StandardCreator<Column,TheProduct> Creator;
};
Then you use StandardColumn<T>::Creator instead of
StandardColumnCreator<T>.
(I chose class and member names to maximize similarity; other names
might be more appropriate.)
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: James Kuyper <kuyper@wizard.net>
Date: 1998/08/12 Raw View
Christopher Eltschka wrote:
>
> Geoff Fortytwo wrote:
> >
> > Is it legal to do partial explicit instantiation? And if so, am I doing
> > it correctly? MSVC++ 5.0 doesn't like the last 2 lines of the following
> > code (I'm trying to implement a generic Factory Method pattern):
> >
>
> [...]
>
> > typedef StandardCreator<Column,TheProduct>
> > StandardColumnCreator<TheProduct>;
>
> You cannot make a template typedef - a typedef *must* denote
> a single type.
However, you can achieve much the same effect as a template typedef, by
definine a typedef member of a templated class:
template<TheProduct> class StandardColumn{
typedef StandardCreator<Column,TheProduct> Creator;
};
Then you use StandardColumn<T>::Creator instead of
StandardColumnCreator<T>.
(I chose class and member names to maximize similarity; other names
might be more appropriate.)
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern/std-c++/faq.html ]
Author: Geoff Fortytwo <geoff.d.fortytwo@intel.com>
Date: 1998/08/11 Raw View
Is it legal to do partial explicit instantiation? And if so, am I doing
it correctly? MSVC++ 5.0 doesn't like the last 2 lines of the following
code (I'm trying to implement a generic Factory Method pattern):
template<typename ProductTypeBase>
class Creator
{
public:
virtual ProductTypeBase* Create() = 0;
};
template<typename ProductTypeBase, typename TheProduct>
class StandardCreator : public Creator<ProductTypeBase>
{
public:
virtual ProductTypeBase* Create() {return new TheProduct;}
};
// This explicit instantiation and typedef compiles fine.
template<> Creator<Column>;
typedef Creator<Column> ColumnCreator;
// But this partial explicit instantiation and typedef don't work.
template<typename TheProduct> StandardCreator<Column,TheProduct>;
typedef StandardCreator<Column,TheProduct>
StandardColumnCreator<TheProduct>;
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Alberto Barbati" <albbarb@tin.it>
Date: 1998/08/12 Raw View
Geoff Fortytwo wrote in message <6qp8hc$9p4$1@scnews.sc.intel.com>...
>
>Is it legal to do partial explicit instantiation? And if so, am I doing
>it correctly? MSVC++ 5.0 doesn't like the last 2 lines of the following
>code (I'm trying to implement a generic Factory Method pattern):
It's legal in C++, but MSVC++ 5.0 (and 6.0) does not support such a feature.
Sorry.
--
Alberto Barbati
albbarb@tin.it
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]