Page 1 of 1

C++0x

Posted: Thu Aug 16, 2012 2:49 pm
by GroundUpEngine
Does anybody use the new version of C++, I found myself inclined while I was recently learning some Java for the coming first year in uni. The reason I tried this new version of C++ was because of some of the features that are supported in Java that I remembered/realized were recently added to C++ in this late update.

"Range-based for-loop" from http://en.wikipedia.org/wiki/C%2B%2B11

Code: Select all

int my_array[5] = {1, 2, 3, 4, 5};
for (int &x : my_array) {
    x *= 2;
}

Re: C++0x

Posted: Thu Aug 16, 2012 3:41 pm
by Nokurn
I use C++11 extensively.

Re: C++0x

Posted: Thu Aug 16, 2012 3:52 pm
by bbguimaraes
The only reason I wouldn't use it would be on code that should run on other platforms. It might take a while for those compilers to catch up with the new features. That aside, I use it constantly. I even compiled gcc when the version installed on Ubuntu didn't support it. Some of the features I remember using (I'll surely forget some):

Code: Select all

vector<int> f() {
    // User-types list initialization.
    vector<int> v = { 1, 2, 3, 4, 5 };
    return v;
}

// ...

// Move copy-constructor =).
vector v = f();

// Auto type and constant begin/end.
auto it = v.cbegin();

// Lambda functions, rarely (though I always have to google the damn syntax).
sort(v.begin(), v.end(), [](int x, int y) { return y < x; });

// The freaking string constructor for fstream.
ifstream reader(someStringThatCanFinallyBeUsedToWithoutCUnderlineStr);
I still have to take a look at the new things in the standard library.