Re: New C++ 0x
John Nagle wrote:
RenjithMohan wrote:
I am looking forward to the really cool language extensions and library
enhancements in the new C++ 0x. But at the same time, i see that some
of the new features are already implemented in a preview C# 3.0
edition. I refer specifically to the features like
1) Implicitly typed variables where the compiler automagically guesses
the type of the variable.
where if you say
var i = 10;
This was suggested for C++ years ago, using the keyword "let". That
was considered to break existing code. Then it was proposed with the
keyword "auto", but that generated ambiguities.
The real reason for this was to allow
std::vector<int> tab;
...
for (let p = tab.begin(); p != tab.end(); p++)
{ }
instead of
std::vector<int> tab;
...
for (std::vector<int>::iterator p = tab.begin(); p != tab.end(); p++)
{ }
which is somewhat unwieldy.
But the "can't add keywords" faction won, so it's a dead idea in C++.
The idea is alive enough to be in the current working paper,
N2009, using the keyword auto. 7.1.5.4 includes among its
examples the following:
auto x = 5; // OK: x has type int
const auto *v = &x, u = 6; // OK: v has type const int*,
// u has type const int
showing the new use of "auto". I think this is a great
addition to C++, and I look forward to being able to use
compilers which support it sometime in the future.
-- James
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]