![]() |
|
Time to start using C++0x? |
Karadoc ~~
Member #2,749
September 2002
![]() |
I'm curious about how many people are already making use of the new features in c++0x. I've kind of been avoiding it, because of concerns about stability, portability, and efficiency. But I think it's probably reached the stage where portability is the only problem left, and it's just a matter of time before that gets cured too. So, I'm tempted to go through some of my code and replace this: boost::ptr_map<PlayerID, Player>::iterator it; for (it = player_table.begin(); it != player_table.end(); ++it) { ... } with this: for(auto it : player_table) { ... } It certainly looks a lot cleaner, and is easier to write. So what do you think? Is it time to take the plunge? ----------- |
Arthur Kalliokoski
Second in Command
February 2005
![]() |
It kind of reminds me of this: They all watch too much MSNBC... they get ideas. |
Oscar Giner
Member #2,207
April 2002
![]() |
It depends. For code that you don't care if others are able to compile or not, just use all C++0x features your chosen compiler implements. For projects where you do care about that, use a minimum common denominator. So if you are ok by requiring gcc 4.5 and MSVC10 you can use most major c++0x features. But a lot of minor ones, mostly syntactic sugar ones (like your example, since MSVC10 doesn't support range-based for-loop yet Append: And you need at least gcc 4.6 it seems, and the lastest mingw version is still 4.5.2), won't be there for some compiler or the other. Myself I can't live without auto anymore. It makes working with iterators so much cleaner. -- |
bamccaig
Member #7,536
July 2006
![]() |
Oscar Giner said: Myself I can't live without auto anymore. It makes working with iterators so much cleaner.
I can certainly understand this. -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
Karadoc ~~
Member #2,749
September 2002
![]() |
Oscar Giner said: Append: And you need at least gcc 4.6 it seems, and the lastest mingw version is still 4.5.2), won't be there for some compiler or the other. I'm using MinGW 4.6. I got it from here. Unfortunately, Qt Creator (the IDE I'm using) apparently doesn't know the syntax highlighting for range for. ----------- |
orz
Member #565
August 2000
|
I'm a bit nervous about C++0x. I was still regularly finding bugs in MSVC & gcc support of vanilla C++ until just the last 5 years or so, and I don't really want to have to go through that again. Though auto does sound pretty swell. |
AMCerasoli
Member #11,955
May 2010
![]() |
Karadoc ~~ said: rtunately, Qt Creator (the IDE I'm using) apparently doesn't know the syntax highlighting for range for. It doesn't allow you to customize it? This is an IDE: {"name":"604139","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/e\/de2250ecdb1918f2a6f79cb3983c9a42.png","w":564,"h":832,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/d\/e\/de2250ecdb1918f2a6f79cb3983c9a42"}
|
Karadoc ~~
Member #2,749
September 2002
![]() |
AMCerasoli said: It doesn't allow you to customize it? As I understand it, there are two types of syntax highlighting built into Qt Creator. One is just the bare basics: it highlights keywords a particular colour, strings another colour, number, comments, and so on. The other type is a bit more complex - it actually checks that the code is well formed. It will highlight code that tries to use an undeclared variable, or tries to include a file that the IDE can't find, and so on. For just the colour stuff, you can download different definition files for different languages and edited them as you like them. But I don't think the other stuff is customisable. In other news, I was a bit disappointed to find that std::bind doesn't work as well as boost::bind. At least, it isn't a drop-in replacement. std::bind apparently couldn't work out which function I was trying to bind arguments to because the function was overloaded. boost::bind had no problem with the same function. ----------- |
SiegeLord
Member #7,827
October 2006
![]() |
I'll start using it when it becomes the default on GCC. I use D 90% of the time, so I've had many of the C++0x features for years now... "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
AMCerasoli
Member #11,955
May 2010
![]() |
What web pages are you using to see the new features? I downloaded a PDF file from the official web page (I think) but it has 1300 pages Quote:
This document is not an ISO International Standard. It is distributed for review and comment. It is subject I would like to check out the official documents, but ISO.org is way too big... Who has the Bjarne Stroustrup's phone number?
|
Surt
Member #273
April 2000
![]() |
AMCerasoli said: What web pages are you using to see the new features? I find this to be handy: http://www2.research.att.com/~bs/C++0xFAQ.html --- |
Karadoc ~~
Member #2,749
September 2002
![]() |
The page Surt linked to is my main source of information about C++0x. Anyway. I've started using c++0x features, and they are mostly good. I started with auto and range for, which make iterating through container elements much neater and easier. I then decided that since I'm using c++0x anyway, I might as well replace NULL with nullptr - not really a big deal. Then I remembered enums. I've posted on a.cc a couple of times to talk about how I'd like to use enums if they weren't broken... And now in c++0x they are fixed! I'm also using constexpr, which allows me to initialize static class constants in a sane looking way. So yeah, things are going well. The only thing I'm kind of disappointed about is that the c++0x standard library isn't living up to my expectations. As I mentioned earlier std::bind doesn't work as well as boost::bind, and the threads stuff, including std::mutex etc., doesn't work at all on my version of MinGW. So far, the new standard library just seems to be a weak and incomplete version of boost. But I expect that to improve in later version of MinGW. ----------- |
|