Topic: Templatized typedef
Author: Thierry Grellier <t.grellier@arexsys.com>
Date: 1999/12/28 Raw View
Hello,
is it possible to define aliases of templates ?
I'd like to do something like :
template <int N> struct S;
template <int N> typedef S<N> Alias;
so that I can use either Alias<N> or S<N>.
I'm aware that a better design would be to do
template <int N> struct Alias { S<N> proxied; };
But this is far longer to code, and while prototyping
I prefer the quickest solution.
---
[ 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: 1999/12/29 Raw View
Thierry Grellier wrote:
>
> Hello,
>
> is it possible to define aliases of templates ?
>
> I'd like to do something like :
> template <int N> struct S;
>
> template <int N> typedef S<N> Alias;
>
> so that I can use either Alias<N> or S<N>.
>
> I'm aware that a better design would be to do
> template <int N> struct Alias { S<N> proxied; };
> But this is far longer to code, and while prototyping
> I prefer the quickest solution.
A solution that requires far less code is:
template <int N> struct Alias : public S<N> {};
One other alternative is:
template <int N> class name1
{
typedef S<N> name2;
};
Then name1<T>::name2 would be an alias for S<N>. A little lumsy, but
pretty much foolproof.
---
[ 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: Hyman Rosen <hymie@prolifics.com>
Date: 1999/12/29 Raw View
Thierry Grellier <t.grellier@arexsys.com> writes:
> is it possible to define aliases of templates ?
> I'd like to do something like :
> template <int N> struct S;
> template <int N> typedef S<N> Alias;
> so that I can use either Alias<N> or S<N>.
No. The best you can do with C++ is
template <int N> struct Alias { typedef S<N> t; };
and then use Alias<N>::t instead of S<N>.
---
[ 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: Hyman Rosen <hymie@prolifics.com>
Date: 1999/12/30 Raw View
James Kuyper <kuyper@wizard.net> writes:
> A solution that requires far less code is:
> template <int N> struct Alias : public S<N> {};
This would force all the constructors of S to be repeated in Alias.
---
[ 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: Thierry Grellier <t.grellier@arexsys.com>
Date: 1999/12/30 Raw View
Hyman Rosen wrote:
>
> Thierry Grellier <t.grellier@arexsys.com> writes:
> > is it possible to define aliases of templates ?
> > I'd like to do something like :
> > template <int N> struct S;
> > template <int N> typedef S<N> Alias;
> > so that I can use either Alias<N> or S<N>.
>
> No. The best you can do with C++ is
>
> template <int N> struct Alias { typedef S<N> t; };
>
> and then use Alias<N>::t instead of S<N>.
Thanks for the idea. I'll try to fing a meaningful t name. I couldn't go
for inheritence because I've got overloaded operators.
Thierry
---
[ 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 ]