so... c++0x ?

A place for Ogre users to discuss non-Ogre subjects with friends from the community.
User avatar
JaJDoo
Gnome
Posts: 343
Joined: Wed Feb 04, 2009 9:15 pm
x 5

so... c++0x ?

Post by JaJDoo »

I'm rather excited about c++0x, but confused about its status and compilers actually supporting the new syntax or contain the new std libs...
vc++2010 exp seem to have some knowledge of 0x here and there, but it seem rather work in progress

can anyone supply some order ?
Last edited by JaJDoo on Sat Aug 06, 2011 7:03 am, edited 1 time in total.
some post from somewhere:
"So you basically want to make a car without a steering wheel because you don't know how to drive. I'd say learn how to use pointers"
User avatar
aguru
Goblin
Posts: 236
Joined: Tue Feb 26, 2008 5:48 pm
x 3

Re: so... c++0x ?

Post by aguru »

You need to compile adding the -std=gnu++0x flag.

We have this in our cmake script for compatibility between VC and gcc:

Code: Select all

# allow for C++0x extensions
if(UNIX)
    add_definitions(-std=gnu++0x)
endif(UNIX)
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179

Re: so... c++0x ?

Post by jacmoe »

I just learned that it was approved 13th of August. :wink:

GCC has strong support already, and we will probably see both GCC and VC have full support sometime next year.
So I think we can start using it already.

http://wiki.apache.org/stdcxx/C++0xCompilerSupport

C++ is going to get so much better now. :)
C++11 I hope it's called.
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
Klaim
Old One
Posts: 2565
Joined: Sun Sep 11, 2005 1:04 am
Location: Paris, France
x 56

Re: so... c++0x ?

Post by Klaim »

I use if already even at work (well just 3 features actually but it helps a lot!). However it's not a good idea for any project yet. I guess it's a good idea for a new project.
When Visual Studio "vNext" will be out, we'll have a good idea of what C++11 features we will be able to use "immediately" in a cross-platform way for at least linux and windows. Then we'll have to wait for clang to be up to date on MAcOS.

...


lots of waiting... But I guess having GCC on all platforms is a better solution for now.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179

Re: so... c++0x ?

Post by jacmoe »

Have you noticed that the compilers already supports a lot of the features of the new standard, even before it was approved?
That's really different from c++03 and c++98.
So I expect all major compilers to be fully compliant by summer 2012. :)
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
CABAListic
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 2903
Joined: Thu Jan 18, 2007 2:48 pm
x 58

Re: so... c++0x ?

Post by CABAListic »

Yeah, but not everyone upgrades to the latest compiler version right away. VS2005 is still in use ;)
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179

Re: so... c++0x ?

Post by jacmoe »

I would be surprised if they didn't.
Because C++ has just gotten so much better.
It's the biggest overhaul since.. since the STL. :)

That must mean that companies, teams, people will want to upgrade because it's simply silly not to.
IMO. An easier to use C++ and less error prone must mean time/money saved.
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
CABAListic
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 2903
Joined: Thu Jan 18, 2007 2:48 pm
x 58

Re: so... c++0x ?

Post by CABAListic »

It's not always about that. When you have a working platform (complete with compiled supporting libraries etc.), there is a cost to upgrading that platform. Companies probably will avoid to do that while working on a project, so older versions will be around for a while. It's always been that way, it won't be any different this time.
User avatar
Klaim
Old One
Posts: 2565
Joined: Sun Sep 11, 2005 1:04 am
Location: Paris, France
x 56

Re: so... c++0x ?

Post by Klaim »

Yeah and if you don't have a specific need to upgrade, there is no good reason. Even maintenance isn't one because the code is already written, so you have to have a reason to use the new features in new or refactored code to make upgrading a good idea.


I'm glad I can use experimental features in my current C++ projects, I know contexts where I couldn't. I will use C++0x as much as needed, I'm just limited to VS2010 features so far as I need to work on crossplatform code.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179

Re: so... c++0x ?

Post by jacmoe »

Can't we agree that the compiler vendors/teams seems to be tripping over each others toes to implement the standard?
That's not how it used to be.
I think that's a good sign. :wink:

New projects can actually start using it in less than a year. :)

That established projects are not switching is to be expected.
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
Klaim
Old One
Posts: 2565
Joined: Sun Sep 11, 2005 1:04 am
Location: Paris, France
x 56

Re: so... c++0x ?

Post by Klaim »

Yes yes we agree, there is no disagreement here.

It's just that even if implementation is faster, upgrading isn't a good idea for all projects.

For new projects independent (with informed developers) it would be a good idea.
User avatar
JaJDoo
Gnome
Posts: 343
Joined: Wed Feb 04, 2009 9:15 pm
x 5

Re: so... c++0x ?

Post by JaJDoo »

well, i found some time to squeeze in a Google search in my busy schedule being annoying, failing exams, playing lute and working on my doomed shaders ide;

two articles i really liked regarding 0x:
one is a summary for inpatient readers like myself : "The Biggest Changes in C++11 (and Why You Should Care)"
http://www.softwarequalityconnection.co ... ould-care/

second is a good place for people who want to learn multithreading with the new c++ :
http://www.justsoftwaresolutions.co.uk/ ... reads.html

and they said c++ was going COBOL
some post from somewhere:
"So you basically want to make a car without a steering wheel because you don't know how to drive. I'd say learn how to use pointers"
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179

Re: so... c++0x ?

Post by jacmoe »

What's wrong with COBOL? :)
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
Klaim
Old One
Posts: 2565
Joined: Sun Sep 11, 2005 1:04 am
Location: Paris, France
x 56

Re: so... c++0x ?

Post by Klaim »

Well first, it's a bit like COBOL. :mrgreen:
Arkiruthis
Gremlin
Posts: 178
Joined: Fri Dec 24, 2010 7:55 pm
x 10

Re: so... c++0x ?

Post by Arkiruthis »

I think the introduction of the 'auto' keyword is my favourite c++0x thingy so far.

Changing from:

Code: Select all

boost::filter_iterator<std::const_mem_fun<bool, Agent*>, vector<Agent*>::iterator> filterIt;
to

Code: Select all

auto filterIt;
makes me happy and stops my head exploding like something out of that 80s film "Scanners". :D (alas, the XCode 4 gcc doesn't support c++0x yet... at least, I don't think it does?)
User avatar
JaJDoo
Gnome
Posts: 343
Joined: Wed Feb 04, 2009 9:15 pm
x 5

Re: so... c++0x ?

Post by JaJDoo »

auto drew me into looking up whats new in 0x...
its like the naked lady on the cover of crossword puzzle books

nothing wrong with COBOL, but its just kind of dead outside of the large businesses sector, and that's mainly because its legacy code. old programming languages usually depend on momentum, and most die in cases of "too little too late" ; 5 more years of endless debating and c++ will have been there ( its already started becoming a argument on the anti c++ side 3-4 years ago )

heres the new COBOL propaganda -
http://www.youtube.com/watch?v=mUrdX9xJ ... r_embedded
Last edited by JaJDoo on Fri Oct 21, 2011 5:30 pm, edited 2 times in total.
some post from somewhere:
"So you basically want to make a car without a steering wheel because you don't know how to drive. I'd say learn how to use pointers"
User avatar
Klaim
Old One
Posts: 2565
Joined: Sun Sep 11, 2005 1:04 am
Location: Paris, France
x 56

Re: so... c++0x ?

Post by Klaim »

CaptainFlaps wrote:I think the introduction of the 'auto' keyword is my favourite c++0x thingy so far.

Changing from:

Code: Select all

boost::filter_iterator<std::const_mem_fun<bool, Agent*>, vector<Agent*>::iterator> filterIt;
to

Code: Select all

auto filterIt;
makes me happy and stops my head exploding like something out of that 80s film "Scanners". :D (alas, the XCode 4 gcc doesn't support c++0x yet... at least, I don't think it does?)

I guess your example isn't complete because you cannot do that :twisted:

The assignation is missing!
User avatar
JaJDoo
Gnome
Posts: 343
Joined: Wed Feb 04, 2009 9:15 pm
x 5

Re: so... c++0x ?

Post by JaJDoo »

oh yes, one other nice touch - an actual foreach loop.. wait, no its not a foreach like those java weaklings, we got a
Range-based for-loop

Code: Select all

int my_array[5] = {1, 2, 3, 4, 5};
for (int &x : my_array) 
{
    x *= 2;
}
some post from somewhere:
"So you basically want to make a car without a steering wheel because you don't know how to drive. I'd say learn how to use pointers"
Arkiruthis
Gremlin
Posts: 178
Joined: Fri Dec 24, 2010 7:55 pm
x 10

Re: so... c++0x ?

Post by Arkiruthis »

Klaim: Well, yes, but it's the principal of the thing... :mrgreen: (and in practice saves a LOT of space to the left of the assignation)

In practice:

Code: Select all

auto fighters_begin	= boost::make_filter_iterator(not1(mem_fun(&Agent::IsRetreating)), enemyArmy->begin(), enemyArmy->end());
auto fighters_end	= boost::make_filter_iterator(not1(mem_fun(&Agent::IsRetreating)), enemyArmy->end(), enemyArmy->end());
auto f_it = min_element(fighters_begin, fighters_end, MinDistanceBGE<BaseGameEntity*>(a->GetPosition()));
I won't write the non C++0x version! :lol:
User avatar
Klaim
Old One
Posts: 2565
Joined: Sun Sep 11, 2005 1:04 am
Location: Paris, France
x 56

Re: so... c++0x ?

Post by Klaim »

What I love is mixing auto, lambda and algorithms :shock:

But I hate the fact that we can't have yet polymorphic lambdas. It feels so wrong!
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 538

Re: so... c++0x ?

Post by Kojack »

User avatar
JaJDoo
Gnome
Posts: 343
Joined: Wed Feb 04, 2009 9:15 pm
x 5

Re: so... c++0x ?

Post by JaJDoo »

Kojack wrote:
What's wrong with COBOL?
http://99-bottles-of-beer.net/language-cobol-1766.html
:)
off topic : my favorite language
http://www.99-bottles-of-beer.net/langu ... -1544.html
>> Ian said on 03/01/08 18:09:42

YOU'RE DOING IT WRONG!!!

neither LOLCODE program handlez pluralz correctly

>> Baba said on 05/20/08 03:27:59

Ian, what do you expect from cats?
some post from somewhere:
"So you basically want to make a car without a steering wheel because you don't know how to drive. I'd say learn how to use pointers"
JDX_John
Gnome
Posts: 397
Joined: Sat Nov 08, 2008 1:59 pm
x 2

Re: so... c++0x ?

Post by JDX_John »

I wonder what the thoughts are about Ogre and the new standards... for a start is it backwards compatible enough that Ogre will work on 0x? And secondly would Ogre soon/ever allow developers to use 0x in the code, or is support for VS2003/5/8/10 too entrenched?
CABAListic
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 2903
Joined: Thu Jan 18, 2007 2:48 pm
x 58

Re: so... c++0x ?

Post by CABAListic »

I do aim to make C++0x the default thread provider in the future (when available), but other than that you will probably not see those features in (mandatory) Ogre code. Simply for the reason you stated: So long as non-conforming compilers are still in wide use, it would be suicide to do so.
User avatar
zarlox
Halfling
Posts: 70
Joined: Tue Apr 19, 2011 12:32 am
Location: Canada
x 2

Re: so... c++0x ?

Post by zarlox »

I also have been using the subset of C++0x feature available on VC10.

Feature that i like the most is the auto type that i solely use tio replace annoying iterator declaration/assignation. Especially in a being/end for loop.

Also i intensively use the R-value reference for my string class. Having move constructor, move assignation and using it on operator like '+' does make some marvels. Being able to do something like this:

Code: Select all

MyStr result = "str1" + strVar1 + "str2" + strVar2 + "\n";
R-value reference can be used to prevent so many allocation and free of temporary variables.

For example, a string class move constructor would be defined like this:

Code: Select all

MyStr::MyStr(MyStr&& str)
{
}
When the compiler choose this constructor, it means the MyStr variable passed to the constructor is for sure a R-value temporary variable that will be discarded right after. So the move constructor for the string class would just use first, my his own heap string pointer point to the argument string internal allocated memory. Then it would NULL the argument pointer so the argument object destructor would not try to free the heap memory that has been passed to this object. So at the end, you avoid 1 new and 1 delete operation.

Supposedly, all the std container can use this in VC10. For example, all the push_back() implementation would use the

Code: Select all

MyStr::operator=(MyStr&& str)
But i never really checked if its the case.

The other thing that i really would have liked to see in VC10 is the strong typed enumeration. They said that they implemented it but it does not work. Strong typed enumeration is supposed to strictly prevent you from comparing or assigning integer whole value to an enum variable.
Last edited by zarlox on Thu Nov 03, 2011 7:34 pm, edited 1 time in total.