auto in library functions
Mehrdad
wfunction at hotmail.com
Sun Dec 23 20:16:28 PST 2012
> If a type of a variable changes don't you want to *know* the
> new type of the variable?
Actually, not at all.
Consider this C++ code as an example:
std::vector<int> foo;
template<class T>
void process(T &data) { ... }
int test()
{
auto copy = foo;
process(copy);
if (copy.size() == foo.size())
foo = copy;
return copy.size();
}
The word 'auto' protects against changes to the type of 'foo'
(say, for example, if it was alter changed into std::deque).
No need to explicitly state the type of 'copy' anywhere.
More information about the Digitalmars-d
mailing list