lundi 2 février 2015

Is there a more elegant way to do the following in C++11?

I want to avoid warnings about a comparison between unsigned int and signed int.


I use loops such as:



for (int i =0 ; i < vec.size(); i++) {
// do something
}


which gives these warnings (which by itself is fine, I want high-level of warnings).


I thought of changing it to the following:



for (auto i = vec.size()*0; i < vec.size(); i++) {
// do something
}


in which case I don't get the warnings. But I am wondering if there is something more elegant than that, that would automatically deduce the type required for the iterator.


Aucun commentaire:

Enregistrer un commentaire