# Tuesday, 09 May 2006

The ISO C++ committee is working on the next standard for C++. At their April meeting, a number of items were added to the working draft, which means they will almost certainly end up in the standard -- it's just a matter of final agreement on some of the subtle details of the item, rather than whether it should be there or not. As Herb Sutter reports, the items that were added are:

  • TR1, a pile of library changes (as opposed to the language itself) including various new kinds of smart pointers
  • declaring variables but letting the compiler deduce their type instead of doing it yourself (auto type deduction).
  • delegating constructors
  • the > > vs >> subtlety that Brandon referred to in his recent Channel 9 interview. Visual C++ takes care of this already, but now it's being added to the standard.
  • extern template

Now why should an ordinary programmer care about the machinations of the standards committee, and something that may or may not get approved this decade? Well for one thing, the compiler vendors don't wait for the standard before they implement the new keyword or the new functionality. And for another, it can give you a hint about what's headed your way. Let me tell you what I mean.

Here are Herb's examples of auto type deduction:

auto x = 3.1415926535;
auto i = container.begin();

In this case, x has type double, and i has type map<string,unordered_map<int,tuple<float,string,const int> > >::const_iterator or whatever the right type happens to be, without having to spell it out.
Now in and of itself this is a cool feature, especially for C++ with heavy STL use. Another thing Brandon talked about in his Channel 9 spot was how foreach saves us from having to declare those iterators, set things to begin() and so on, and there's no doubt that figuring out the types is part of that pain. But go beyond that for a moment. I have seen plenty of auto-type deduction examples in C# over the last year or so, and they were all LINQ examples. Does this mean C++ will get getting LINQ too? At least one language barrier to LINQ will be going. Let's see what else happens.
 
Kate

Tuesday, 09 May 2006 07:21:11 (Eastern Daylight Time, UTC-04:00)  #