Topic: Template stuff
Author: "cuibo" <cuibo@email.msn.com>
Date: 2000/06/06 Raw View
Yes , you could, but not like that.
Cui Bo
---
[ 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: wmm@fastdial.net
Date: 2000/05/31 Raw View
In article <l3HX4.26493$usz4.16187699@news.xtra.co.nz>,
"Mark Rodgers" <mark.rodgers@cadenza.co.nz> wrote:
> Hyman Rosen <hymie@prolifics.com> wrote in message
> news:t7puq91g72.fsf@calumny.jyacc.com...
> > "Mark Rodgers" <mark.rodgers@cadenza.co.nz> writes:
> >
> > Huh? Why can't a member template be a class template?
>
> Well, my impression from the standard was that a taxonomy of templates
> looked like this
>
> class templates (14.5.1) (A)
> member templates (14.5.2)
> member class templates (B)
> member function templates
> function templates (14.5.5)
I think this is an incorrect taxonomy. According to 14p1,
"A template defines a family of classes or functions" -- that
is, there are only two kinds of templates, class templates and
function templates. (It's true that other things that are not
templates are still declared/defined using template-declarations,
such as static data members of templates and of classes nested
within templates, but that doesn't change the fact that there
are only two kinds of templates.)
14.5.2p1 says, "A template can be declared within a class or
class template; such a template is called a member template."
The fact that it's a member doesn't change the fact that it's
first and foremost a template, and there are only function and
class templates. A member class template is a class template
that is nested within another class or class template.
> It seems pretty clear that member function templates are different
> beasts from function templates, and they cannot be used where a
> function template is expected. I assumed that member class templates
> were equally not class templates. Andrei was trying to use a (B)
> where an (A) was required, and I don't think this is allowed.
The difference between member function templates and non-member
function templates is the same as the difference between member
functions and non-member functions. Aside from that, member
function templates are function templates, just as member
functions are functions.
With respect to the original question, I don't see any reason
that a member class template could not be used as a template
template parameter.
--
William M. Miller, wmm@fastdial.net
OnDisplay, Inc. (www.ondisplay.com)
Sent via Deja.com http://www.deja.com/
Before you buy.
---
[ 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: Ole Reinartz <ole.reinartz@gmx.de>
Date: 2000/05/31 Raw View
>
> Aha, here I gotcha :o). There are some strange beasts in C++ called
> template template parameters. You can have a class temmplate accept
> another template itself by writing:
>
> template <template <typename> class V>
> class Something
> {
> V<int> member1_;
> V<double> member2_;
> ...
> };
>
> If templates are metaprogramming, template templates arguments are
> transcendental programming :o). They are so powerful, nobody exactly
> knows how to use them. But life without template templates is not
> worth living.
Oh! Ah! That is good! Never was forced to need something like this, but...
That really looks powerfull, and its cool , so I'm sure I need that soon
(;-).
Anyway, my compiler (gcc version 2.95 19990728) gives my an internal compiler
error, and I didnt find anything explicit stated in the standard, so I'm
afraid I cannot help you here...
Ole
---
[ 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: 2000/05/31 Raw View
"Mark Rodgers" <mark.rodgers@cadenza.co.nz> writes:
> Well, my impression from the standard was that a taxonomy of templates
> looked like this
> class templates (14.5.1) (A)
> member templates (14.5.2)
> member class templates (B)
> member function templates
> function templates (14.5.5)
I don't see any such hierarchical taxonomy implied by the standard.
14.5.2 mostly just says that member templates are templates declared
inside classes.
> It seems pretty clear that member function templates are different
> beasts from function templates, and they cannot be used where a
> function template is expected. I assumed that member class templates
> were equally not class templates. Andrei was trying to use a (B)
> where an (A) was required, and I don't think this is allowed.
Well, of course member function templates are different from function
templates, in precisely the same way that member functions are
different from functions! But member classes and non-member classes
don't have the same kinds of differences.
Nothing I have seen in the Standard says that a member class template
is not a class template, so I say that it's perfectly legal to use one
as a template template parameter.
---
[ 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: "Andrei Alexandrescu" <andrewalex@hotmail.com>
Date: 2000/05/28 Raw View
Ole Reinartz <ole.reinartz@gmx.de> wrote in message
news:392E66DA.D3817D4@gmx.de...
> Andrei Alexandrescu wrote:
>
> > This might sound whacky but it enables a very powerful idiom.
> >
> > Can I use a member template as template template argument? IOW,
can I
> > do this?
> >
> > template <template <typename> class T>
> > class Wrapper
> > {
> > template <typename U> class Body { ... };
> > };
> >
> > template <template <typename> class V>
> > class Something
> > {
> > ...
> > };
> >
> > Something<Wrapper<int>::Body> isThisPossible;
>
> Hi Andrei,
> I think it wouldnt work exactly as you sent it: the Wrapper template
needs
> another template in its template parameter list, and int is not a
template.
Ah, sorry. You are right. Let me rewrite the example:
template <class T>
class Wrapper
{
template <typename U> class Body { ... };
};
template <template <typename> class V>
class Something
{
...
};
Something<Wrapper<int>::Body> isThisPossible;
> Also, you didnt give Wrapper::Body a type for its template parameter
list; I
> think if you want to instanciate something, you have to fully define
all the
> types needed by involved templates.
Aha, here I gotcha :o). There are some strange beasts in C++ called
template template parameters. You can have a class temmplate accept
another template itself by writing:
template <template <typename> class V>
class Something
{
V<int> member1_;
V<double> member2_;
...
};
If templates are metaprogramming, template templates arguments are
transcendental programming :o). They are so powerful, nobody exactly
knows how to use them. But life without template templates is not
worth living.
> Or I'm just too confused by that all. Could you please explain in
more
> detail what could be the use of this?
The use of template templates or the use of template templates in
conjunction with member templates of template classes, as my example
shows?
Andrei
---
[ 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: "Mark Rodgers" <mark.rodgers@cadenza.co.nz>
Date: 2000/05/29 Raw View
Hyman Rosen <hymie@prolifics.com> wrote in message
news:t7puq91g72.fsf@calumny.jyacc.com...
> "Mark Rodgers" <mark.rodgers@cadenza.co.nz> writes:
>
> Huh? Why can't a member template be a class template?
Well, my impression from the standard was that a taxonomy of templates
looked like this
class templates (14.5.1) (A)
member templates (14.5.2)
member class templates (B)
member function templates
function templates (14.5.5)
It seems pretty clear that member function templates are different
beasts from function templates, and they cannot be used where a
function template is expected. I assumed that member class templates
were equally not class templates. Andrei was trying to use a (B)
where an (A) was required, and I don't think this is allowed.
Perhaps I was mistaken. If so, I'm not sure where it is spelled
out that a member class template ISA class template, and that they
can be used anywhere a class template is expected.
I'm more than happy to be proved wrong, since I agree that it does
make sense for member class templates to be substitutable for class
templates in most (all???) situations.
Mark
---
[ 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: Ole Reinartz <ole.reinartz@gmx.de>
Date: 2000/05/26 Raw View
Andrei Alexandrescu wrote:
> This might sound whacky but it enables a very powerful idiom.
>
> Can I use a member template as template template argument? IOW, can I
> do this?
>
> template <template <typename> class T>
> class Wrapper
> {
> template <typename U> class Body { ... };
> };
>
> template <template <typename> class V>
> class Something
> {
> ...
> };
>
> Something<Wrapper<int>::Body> isThisPossible;
Hi Andrei,
I think it wouldnt work exactly as you sent it: the Wrapper template needs
another template in its template parameter list, and int is not a template.
Also, you didnt give Wrapper::Body a type for its template parameter list; I
think if you want to instanciate something, you have to fully define all the
types needed by involved templates.
Or I'm just too confused by that all. Could you please explain in more
detail what could be the use of this?
Thanks,
Ole
---
[ 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: "Mark Rodgers" <mark.rodgers@cadenza.co.nz>
Date: 2000/05/26 Raw View
Andrei Alexandrescu <andrewalex@hotmail.com> wrote in message
> Can I use a member template as template template argument? IOW, can I
> do this?
I don't think so. The very first words in the section on template template
arguments (14.3.3) are pretty explicit:
"A template-argument for a template template-parameter shall be the
name of a class template, expressed as id-expression."
Since a member template is not a class template, I think you are out of
luck.
Mark
---
[ 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: 2000/05/27 Raw View
"Mark Rodgers" <mark.rodgers@cadenza.co.nz> writes:
> Since a member template is not a class template, I think you are out of
> luck.
Huh? Why can't a member template be a class template?
struct Outer
{
template <typename T> struct Inner { };
};
Outer::Inner sure looks like a class template to me!
---
[ 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: "Andrei Alexandrescu" <andrewalex@hotmail.com>
Date: 2000/05/25 Raw View
This might sound whacky but it enables a very powerful idiom.
Can I use a member template as template template argument? IOW, can I
do this?
template <template <typename> class T>
class Wrapper
{
template <typename U> class Body { ... };
};
template <template <typename> class V>
class Something
{
...
};
Something<Wrapper<int>::Body> isThisPossible;
I think the standard doesn't forbid this, but I think it looks weird
enough to mandate a question. I would appreciate responses. Thanks in
advance.
Andrei
---
[ 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 ]