Wednesday, January 21, 2015

Comment on GotW #94 Solution: AAA Style (Almost Always Auto) by thila

 
 

Comment on Reader Q&A: auto and for loop index variables by Matthew Fioravante

I usually just do this:
  for(int i = 0; i < int(container.size()); ++i) {  }  
It’s not perfect, but the majority of the time my array will never have anything close to 2 billion elements. Having a habit of using signed ints also prevents writing infinite loops when you traverse the array from back to front using indices. Using ssize_t could be another option if you’re concerned about sizeof(int).
I like to use ints everywhere unless a more specific integral type is needed. If you make your loop variable unsigned then when you use it within the loop you’re likely to be doing math and comparisons between signed and unsigned.
Fancy ranges and meta programming are nice but a lot of times we just have 2 arrays and want to iterate over them both with a simple index. No reason to over think things.

Read More »

Comment on Reader Q&A: auto and for loop index variables by Brian M

Wow some really scary answers! If not a generic template, then leave as is, if a template then rewrite using the appropriate iteration style. Life can be simple sometimes…..even in c++!

Read More »

Comment on Reader Q&A: auto and for loop index variables by Martin


{auto i = 0; for(auto e: container) {
...
++i;
}}


Read More »

Comment on GotW #94 Solution: AAA Style (Almost Always Auto) by thila

@herb: Perhaps this may be irrelevant here (Sorry!), I couldn’t find any other relevant place to comment on this. When will the GotWs 8 – 88 be available? I read this article series with in the past few days and learned a lot about C++ !! Hope the other GotWs will be available soon. Thanks for your great work.

Read More »
 
 

No comments:

Post a Comment