tags:

views:

1148

answers:

13

What will day to day C++ development be like in a few years? What C++0x features will change C++ development the most?

In what order should I concentrate learning these new features?

+22  A: 

Lambdas, because they finally introduce reasonable means of harnessing the benefits of functional programming.

Dario
And because they demonstrate the sad result of stuffing fashionable features into 30 years old language.
ima
Switching C++ from "lasting value" category to "trying, but can't keep up"
ima
<irony>Stuffing fashionable features into 80 years old languages has given us Haskell and F#</irony>
Dario
Cheap. What 80 years old language is Haskell backwards-compatible with?
ima
ima
C++0x isn't backwarts compatible either.
Dario
Splitting hairs like this shows you perfectly understand being wrong at the key point.
ima
Maybe it just shows something about the seriousness of this discussion. Admittedly, the C++0x's lambda syntax is weird - as is Python's, Lua's, VB.NET's - , but that has not been questioned. We aren't talking about the motivation of their introduction or the principles of programming language evolution (to which most/all (modern) languages are subject), but their usefulness for future C++ programming. And they **are** useful, mainly because they finally provide us with functionality that lay in the nature of C++ (see how functional the STL is built) but couldn't be replicated sufficiently.
Dario
@ima: so you're saying that because of a slightly quirky syntax (which adds expressiveness by allowing you to choose whether to capture by value or reference), we're all doomed, C++ takes a big step backwards and the world is going to end? Can't say I agree. I fail to see how "C++ with lambdas and a non-ideal syntax" can possibly be *worse* than "C++ without lambdas, but which already had a non-ideal syntax for every other feature in the language"Seriously, complaining about syntax in a discussion of C++? What's the point? C++ wasn't exactly an example of syntactic clarity to begin with
jalf
+13  A: 

Range-based for-loops.

for (int x: numbers) std::cout << x << " ";

Yay!

FredOverflow
what is `numbers`?
Inverse
@Inverse Some range that you can iterator over. For example, an `int[]` or a `std::vector<int>`.
FredOverflow
I assume you can iterate through int[5], but not through int*.But then I also assume you *can't* iterate through C strings. Will C++ strings at least allow iterating?
luiscubal
Why would you ever want to use an `int*` in C++? And of course you can iterate through `string`, it defines a range by its `begin()` and `end()` methods.
FredOverflow
At least `BOOST_FOREACH` supports iterating over zero-terminated char arrays. I don't think there is any technical reason why it couldn't be supported natively, if they have chosen to.
visitor
@visitor: Technical reason, no. But design reason, yes. `char*` is not a string, it is a pointer. Maybe it points to the first character in a null-terminated string, but maybe it points to a single char, like its type suggests.
Dennis Zickefoose
@luiscubal @Fred @visitor @Dennis: To be clear, iterating over c-strings should be fine. They are arrays (of the type `const char[N]`), and ranged-based for-loops are well-defined for arrays.
GMan
@GMan few people store C-style strings in that type, though. Most people store strings as char*s.
luiscubal
@Dennis Zickefoose True, but this is foreach we're talking about. Would it make sense to use foreach on a pointer to a single char? No. But it *would* make sense to apply it to a char* string.
luiscubal
@luiscubal: That's not my problem. I'm talking about a string literal which has the type `const char[N]`. If you want to store a pointer to the first character, that's fine, but my comment isn't intended to apply to that anymore. I mean `for (char c : "asd")`, no more no less. And hell, `char* s = "asd"` is deprecated anyway, *at least* use `const char*`.
GMan
@luiscubal: Like I said, its a design decision. Sure, it makes no sense to pass a pointer to a single character to a range-based for statement. But that doesn't change the fact that the compiler can't tell the difference between the two, and C++ is a strongly typed language. Besides, it makes no sense to *have* a pointer to a null terminated character array in the first place. If you're not dealing with a literal [which GMan is correct in stating the ranged-based for statement will handle appropriately], you should have a container of some sort.
Dennis Zickefoose
@GMan Just curious. Since C strings are null-terminated, "abc" is actually const char[4], right? So that means a foreach applied to it would also be applied to the '\0' char, right?
luiscubal
@luiscubal: Yup. (Which sucks a bit.)
GMan
+6  A: 

auto, lambdas, and smart pointers.

yesraaj
`std::auto_ptr` is in C++03.
Billy ONeal
vector<auto_ptr>, however, is not.
ima
I meant auto key word for type variable compile time detection
yesraaj
@Billy: Right, `std::auto_ptr` is getting deprecated.
visitor
+19  A: 

auto because people will overuse it.

Alexander Gessler
*Exactly* what I'm looking for when I need to declare a loop using iterators.. ahh.. no longer having to constantly type `std::vector<std::basic_string<TCHAR> >::const_iterator` every time I want to loop through a vector of strings.
Billy ONeal
typedef is your friend.
SoapBox
typedef is somewhat less friendly to the next guy who reads your code, though, and has to keep looking up what your typedefs mean...
Jeremy Friesner
how is `typedef std::basic_string<TCHAR> tstring` not friendly to the next guy?
Idan K
@Idan K: The problem is more having to typedef every and each STL container you want to iterate over. And writing generic code to handle this type is tedious. The `auto` keyword will remove all that.
paercebal
“overuse” … well, I don’t know. I certainly intend to use it *extensively*. Don’t know that that’s “over”using it, though.
Konrad Rudolph
@paercebal: Or, you could just typedef the container a few lines before you use it.
rlbond
@paer Absolutely, I prefer `auto x = *it` over `typename std::iterator_traits<Iter>::value_type x = *it` anyday.
FredOverflow
@Idan one typedef isn't so bad. Several hundred typedefs, and it takes the next guy a week of tediously grepping through your header files before he can even begin to understand what is 'really' going on in your code.
Jeremy Friesner
@rlbond : My current code is more than full of `typedef` lines written **only** for loop iterations, and **nothing** else. I contemplated the use of a macro `#define fordef typedef` just for the sake of sick humour. And don't forget the `typename` as correctly commented by FredOverflow. For these reasons (and for metaprograming reasons, but mostly these reasons), I welcome this addition of the `auto` keyword.
paercebal
Overuse how, exactly? That'd imply that there was some kind of cost to it, some kind of disadvantage... Which there isn't. It's no less clear than the ridiculous number of layered typedefs we have today.
jalf
I'm really looking forward to using `auto` instead of those lengthy typedef giants, mostly in STL context. Still I'm sure people will use `auto` even in much more trivial places, where the meaning would be much clearer if the full type was typed out. `auto mynum = 4; auto another = mynum*1.f;`
Alexander Gessler
`auto` also seems like it could make changed to code easier. As in.. want to change from a `map` to a `hash_map`? If your iterators are all auto, it should be a one-line change.
Brendan Long
I already overuse `auto`. Not just for iterators, but in any iterator-like situation where functions return some unspecified type that you just pass around without really caring about, like `size_t` or `a type convertible to bool`. Also, once or twice with function pointers.
Dennis Zickefoose
You can assign lambda functions to `auto` variables only because their type has no name that you could write down :)
FredOverflow
+2  A: 

Regular expressions as a standard library - you know you need them.

ablaeul
Aren't they in boost?
John
they are in new standard also
yesraaj
@John boost is not a standard library.
SoapBox
So what? Moving boost functionality to the standard is not any kind of paradigm shift that will have massive impact, which is what the question was _about_.
John
@John: good point, and I agree. Regardless of how awesome regexes are, putting them in the standard library isn't going to have a huge impact *because we already had them in boost*
jalf
+1  A: 

this is a great article about new features Explicating the new C++ standard (C++0x), and its implementation in VC10

The auto keyword For automatic data-type deduction (at compile time), depending on initialization.

The decltype keyword For deducing data-type from expression, or an auto variable

The nullptr keyword Null pointer is now promoted, and is been awarded a keyword!

The static_assert keyword For compile time assertions. Useful for templates, and validations that cannot be done using #ifdef.

Lambda Expressions Locally defined functions. Inherits features from function-pointers and class objects (functors).

Trailing Return types Mainly useful when templated function's return type cannot be expressed.

R-value references Move semantics - resource utilization before temporary object gets destroyed.

there are also described new features of Microsoft's new compiler

TGadfly
for_each was in C++98 too, but you had to use it with a named function or a function object.
Turnor
So it's not `for_each`, but the usage of `for_each` with a lambda, that you're highlighting?
Mike DeSimone
Just to be a stickler, `auto`'s type is determined by *initialization*, not assignment.
GMan
A: 

what day to day C++ development will be like in a few years

I wonder how much day-to-day C++ development will still be happening in 5 years. It'll still be around of course but on niche platforms of course, compiler support for the new standard could take years to arrive. And as for legacy projects, updating them might never happen. In 5 years, how many new projects on mainstream platforms will be using C++?

Edit: I see the C++ fanboys are out in force. I like C++. But the fact is it's mainly used on legacy projects, or new projects using legacy code-bases, or niche platforms. None of those mean a totally clean upgrade path to a new standard.

John
"Years to arrive" -- that's why the vast majority is already supported in the two most common compilers, MSVC and GCC.
Billy ONeal
@ ONeal - Not to mention the fact that Boost has libraries for most of what's in C++0X.
wash
We've got a huge amount of code written in C++. It works. We see no need to reinvent the wheel. And since our new projects build on the old, we'll still have most of our new development on C++ five years from now. Things don't change fast in huge, complex systems, especially when it comes to things like languages which have zero visibility to the customer.
Mike DeSimone
@Billy, try reading my post. "BUT ON NICHE PLATFORMS..." Like games consoles...
John
@Mike... but are you looking to make sure all those massive projects work on a new standard?
John
C(++) won't die out in the next 5 years, realize that all the fancy platforms you think will replace C/C++ are actually written in those languages under the hood. And what about operating systems such as, you know, Windows, UNIX? How "niche" is that.
wump
-1 because it doesn't really seem to 1) have anything much to do with the real world (where C++ is still heavily used, and certainly will still be heavily used in 5 years), and 2) because it has nothing to do with the question asked.
jalf
@John: I did read your post. You didn't specify only on niche platforms -- you said you think C++ development will continue only on niche platforms. That's got nothing to do with the statement that the standard will take years to arrive. GCC supports almost every platform imaginable and it supports C++0x --- and as a result I'm confused about the years to arrive statement.
Billy ONeal
@John: No, but gcc has a nasty way of not staying put. It's more of a "dragged kicking and screaming" model; I'm not bragging.
Mike DeSimone
John
@John: Actually, it does. PS2 is a MIPS processor, and GCC supports that platform.
Billy ONeal
+13  A: 

Unicode support. No more cobbles and hacks to get correct handling of unicode characters -- now the entire unicode standard is natively supported by the language.

Billy ONeal
yes please! Long overdue.
jalf
indeed very long
Kugel
+4  A: 

Standard facilities for threading and synchronization.

James McNellis
+23  A: 

I personaly think that move semantics (and rvalue references in general) are the most important change, on par with threads/locks/atomics. Everything else is, more or less, simplification of syntax or standardization of common third-party solutions -- we can write functors when we need lambdas and we have numerous regex libraries. Even for the lack of atomic operations there were some solutions, but there were NO move constructors/move assignment operators.

Being able to move objects changes the whole perception of the language to me. Even though we had RVO and the swap-to-temporary trick to emulate some of it already, it's hard to imagine how the life changes when this is part of everyday life. It's not just ofstream("log.txt") << "Hi!";, or the so much faster STL algorithms, it's a whole new way of passing data between functions.

Cubbi
And a whole new generation of programmers having no clue, what they/others are doing and why it doesn't work.
tstenner
+1 - rvalue references allow a whole slew of important constructs and methods that were previously impossible.
Noah Roberts
`unique_ptr` is very nice too - move semantics pointer ownership.
AshleysBrain
You are right that move semantics is a really good feature, but Boost.Move provides a good even if incomplete emulation of C++ move semantics.Note the library is just now under review.
Vicente Botet Escriba
pass-by-value ought to get more popular again. :)
sellibitze
+2  A: 

We switched to 2010 about a month ago. The two most common things we've used are auto and lambda. Rvalue references have allowed me to do many things that were not possible before, but in day-to-day use they are not AS used as lambda and auto.

Noah Roberts
A: 

Concepts. At last, we'll be able to type-check templates before instantiating them, and when we instantiate them incorrectly, we'll get sensible error messages. Whoops! The C++0X committee couldn't agree and eventually tossed them out. Ah well, wait for C++1X...

Norman Ramsey
A: 

auto in the for loops, and lambdas for the algorithm, I'll start a massive using of for_each.

Nicola Leoni