Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 2 [3]

Author Topic: Starting out in C++  (Read 4093 times)

Thief^

  • Bay Watcher
  • Official crazy person
    • View Profile
Re: Starting out in C++
« Reply #30 on: August 17, 2012, 08:42:43 am »

Oh and Theif^, VC++10 also supported autos. I use them greatly when iterating through containers. Typing out a 40+ letter iterator class gets old really quick. Especially when you have something insane like:
Code: [Select]
std::map<std::string, std::vector<math::vector3D>> StupidContainerClass();

//Iteration would be something like
for(std::map<std::string, std::vector<math::vector3D>>::iterator i = StupidContainerClass.begin() ; i  != StupidContainerClass.end() ; i ++){
}
//This is where auto makes life MUCH easier
for(auto i = StupidContainerClass.begin() ; i  != StupidContainerClass.end() ; i ++){
}

IIRC you can now do something like:

Code: [Select]
std::map<std::string, std::vector<math::vector3D>> StupidContainerClass;

for (auto i : StupidContainerClass)
{
}
(i.e. using foreach and auto together)
« Last Edit: August 17, 2012, 08:56:44 am by Thief^ »
Logged
Dwarven blood types are not A, B, AB, O but Ale, Wine, Beer, Rum, Whisky and so forth.
It's not an embark so much as seven dwarves having a simultaneous strange mood and going off to build an artifact fortress that menaces with spikes of awesome and hanging rings of death.

malloc

  • Bay Watcher
    • View Profile
Re: Starting out in C++
« Reply #31 on: August 17, 2012, 08:46:55 am »


IIRC you can now do something like:

Code: [Select]
std::map<std::string, std::vector<math::vector3D>> StupidContainerClass();

for (auto i : StupidContainerClass)
{
}
(i.e. using foreach and auto together)

Yes, but that only works in 2012 and it's lovely. I really love the foreach functionality.
But I still use VC++2010, so I will have to do with my method, as the c++11 support is more limited.
Logged

Eduan

  • Bay Watcher
  • A genius born genius
    • View Profile
    • EduanTech
Re: Starting out in C++
« Reply #32 on: August 18, 2012, 09:29:38 am »

Just now I learned what you guys are talking about. lol

I really do think auto is a nice addition, not that I would use it that much, but when I do, I will appreciate it.
Pages: 1 2 [3]