Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Feature Requests
 Convert for loops to range-based for loops

You must be registered to post a reply.
Click here to register.

Screensize:
UserName:
Password:
Format: BoldItalicizeUnderlineStrikethrough Align leftCenterAlign right Insert horizontal ruleUpload and insert imageInsert hyperlinkInsert email addressInsert codeInsert quoted textInsert listInsert Emoji
   
Message:

Forum code is on.
Html is off.

 
Check to subscribe to this topic.
   

T O P I C    R E V I E W
jay.carlton Posted - Oct 31 2013 : 10:48:32 PM
Hi,

So one of the very nice things in C++11 is range-based for loops.
http://www.cprogramming.com/c 11/c 11-ranged-for-loop.html

Since it's so much clearer without being less expressive than the old-fashioned kind, it would be really nice to have a tool that could find eligible for loops and replace the for statement with an equivalent range statement.

So instead of

for (auto itElem = vec.begin(); itElem != vec.end(); ++itElem) {}


we would have
for (auto& elem : vec) {}


I guess the main trick is distinguishing the reference case from the copy case for the iterator, and making sure you don't change the semantics of any of the loops.

Thanks,
Jay
1   L A T E S T    R E P L I E S    (Newest First)
feline Posted - Nov 01 2013 : 10:27:31 PM
This is an interesting idea, and this new syntax is a lot more compact and clean. I have put in a feature request to see what our developers make of it:

case=78175

I am not sure about updating all loops in your solution, but a refactoring to update specific loops, on a loop by loop basis, makes sense.

© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000