I need iterate all months in a code:
for (auto m = std::chrono::January; m <= std::chrono::December; m++)
std::cout << std::format(std::locale { "pt_BR.UTF-8" }, "{:L%B}\n", m);
But it happens it's a infinity loop, because the std::chrono::month
increment has a modulo 12 + 1 behavior. So when the loop m
variable reaches December
(12), it wraps around to January
(1).
I tried with std::views::iota
:
for (auto m : std::views::iota(std::chrono::January) | std::views::take(12))
std::cout << std::format(std::locale { "pt_BR.UTF-8" }, "{:L%B}\n", m);
But fails to compile as std::chrono::month
don't satisfies the concept std::weakly_incrementable
.
Aucun commentaire:
Enregistrer un commentaire