Changed code to avoid advancing iterator beyond end since some compilers

complain about this (and it's technically not allowed in C++).
This commit is contained in:
Davis King 2016-07-28 19:09:07 -04:00
parent edb2790bcc
commit 3a096469ef

View File

@ -2189,10 +2189,15 @@ namespace dlib
{ {
std::vector<label_type> results(std::distance(data.begin(), data.end())); std::vector<label_type> results(std::distance(data.begin(), data.end()));
auto o = results.begin(); auto o = results.begin();
for (auto i = data.begin(); i < data.end(); i+=batch_size, o+=batch_size) auto i = data.begin();
auto num_remaining = results.size();
while(num_remaining != 0)
{ {
auto end = std::min(i+batch_size, data.end()); auto inc = std::min(batch_size, num_remaining);
(*this)(i, end, o); (*this)(i, i+inc, o);
i += inc;
o += inc;
num_remaining -= inc;
} }
return results; return results;
} }