Zapis nr.1:
std::string strNumbers = "1,2"; //arg funkcji
std::vector<int> vOfNumbers;
for (const auto& it : strNumbers) {
if (isdigit(it))
vOfNumbers.push_back(it - '0');
}
return std::accumulate(std::begin(vOfNumbers), std::end(vOfNumbers), 0);
Zapis nr.2:
std::string strNumbers = "1,2"; //arg funkcji
std::vector<int> vOfNumbers;
for_each(std::begin(strNumbers), std::end(strNumbers),
[&vOfNumbers](const auto& it) {
if (isdigit(it))
vOfNumbers.push_back(it - '0');
});
return std::accumulate(std::begin(vOfNumbers), std::end(vOfNumbers), 0);
Cześć, mam takie pytanie: Wolicie czytać coś "prostego" jak zapis nr.1 czy to bez znaczenia dla was i zapis nr. 2 wygląda tak samo? Jeśli załóżmy rozwijamy algorytm, który jest dość nieczytelny przez stl, to lepiej napisać to w prostszy sposób czy zostawić takiego krzaka?
tbh wiem, że głupi wątek, ale nie znam nikogo, kto by zrobił mi code review, albo przynajmniej powiedział, że coś rozumie z kodu, a więc polegam na tym forum.
Pozdro!