Re: "Concepts" were removed from C++0x
"Stephen Horne" <sh006d3592@blueyonder.co.uk>
std::vector<size_t> blah;
blah.resize(20);
for(size_t i = 0; i < 50; i++) {
size_t& ref = blah[10];
ref += std::rand();
ref += std::rand();
}
That's not an alias - at least, not in the sense I'm using the word.
An alias is purely a new name - not a mechanism for precalculating a
subscripting operation, pointer dereferences, member selection or
whatever.
Obviously using a reference is a good thing in your example - and yes,
I use references like that from time to time.
Similarly, I might alias a constant by declaring a new constant. That
may have a run-time impact in terms of initialising that constant and
memory used to store it - as always, depending on the optimiser.
A reference is not an object. It is an alias (in its other meaning) to an
existing object. Normally it doesn't need storage, just the compiler keep
track what it refers. (Sometimes it prolongs life of temporary objects a
little, but that is another story).
You
could argue that the constant may be a faster and more readable than
repeating a constant expression over and over, but if your constant
expression does anything more than identify an existing constant, it
isn't an alias. An alias is a new name for something that already
exists and already has a name.
Interesting distinction, the meaning I know does not have the last
requirement -- it is a name introduced to an existing object, period. Who
cares what names it already has or not.
suppose you know to have one of the following:
int i1; int & i2 = i1;
or
int i2; int & i1 = i2;
can you write code that figures out which is the situation? Does i1 and i2
behave differently? Which is alias of which? IMO they are simmetric, two
names for a single object.
You can add int& i3 = i2; now would be i3 alias of what? ;-)