Topic: Templates and enums, avoiding code bloat
Author: James Kuyper <kuyper@wizard.net>
Date: 1999/02/15 Raw View
David R Tribble wrote:
>
> Francis Glassborow wrote:
> >
> > James Kuyper <kuyper@wizard.net> writes
> > > Any solution to this problem will need to cope with the
> > > implementation's considerable freedom in choosing the underlying
> > > type of an enum.
> >
> > True, but I do not think that is any more a problem than partial
> > specialisation for pointers.
>
> The only real difference being that pointers are typically the
> same size, while enums come in (at least) three sizes: char, short,
> and int.
>
> Which implies that it might make sense to be able to specialize a
> template class for all of these integer sizes, which could then be
> used to specialize the template class for enum types.
They also can be either signed or unsigned, and may also be
implementation-specific types, such as __int36. All of which makes it
difficult to cover all possiblilities.
[ 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 ]
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
[ 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: David R Tribble <dtribble@technologist.com>
Date: 1999/02/14 Raw View
Francis Glassborow wrote:
>
> James Kuyper <kuyper@wizard.net> writes
> > Any solution to this problem will need to cope with the
> > implementation's considerable freedom in choosing the underlying
> > type of an enum.
>
> True, but I do not think that is any more a problem than partial
> specialisation for pointers.
The only real difference being that pointers are typically the
same size, while enums come in (at least) three sizes: char, short,
and int.
Which implies that it might make sense to be able to specialize a
template class for all of these integer sizes, which could then be
used to specialize the template class for enum types.
-- David R. Tribble, dtribble@technologist.com --
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
Author: Francis Glassborow <francis@robinton.demon.co.uk>
Date: 1999/02/07 Raw View
In article <36B8EE2B.39FDCD8C@wizard.net>, James Kuyper
<kuyper@wizard.net> writes
>Any solution to this problem will need to cope with the implementation's
>considerable freedom in choosing the underlying type of an enum.
True, but I do not think that is any more a problem than partial
specialisation for pointers.
Francis Glassborow Chair of Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
Author: James Kuyper <kuyper@wizard.net>
Date: 1999/02/05 Raw View
Francis Glassborow wrote:
>
> Bjarne Stroustrup gives an example of using partial specialisation to
> avoid code bloat when creating such things as vectors of pointers.
>
> I wonder if anyone has any thoughts on reducing code bloat when the
> template type parameter is an enum. In many cases the kernel code would
> be that of an int but I can think of no way to leverage off this. It
> would seem nice if we could write something such as:
>
> template <typename T> class Something { ... };
>
> template<> class Something<int> { ... };
> template<typename T> class Something<enum T> : private Something<int> {
> ...
> };
Any solution to this problem will need to cope with the implementation's
considerable freedom in choosing the underlying type of an enum.
---
[ 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: Francis Glassborow <francis@robinton.demon.co.uk>
Date: 1999/02/03 Raw View
Bjarne Stroustrup gives an example of using partial specialisation to
avoid code bloat when creating such things as vectors of pointers.
I wonder if anyone has any thoughts on reducing code bloat when the
template type parameter is an enum. In many cases the kernel code would
be that of an int but I can think of no way to leverage off this. It
would seem nice if we could write something such as:
template <typename T> class Something { ... };
template<> class Something<int> { ... };
template<typename T> class Something<enum T> : private Something<int> {
...
};
Francis Glassborow Chair of Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]