Date: Fri, 23 May 2025 13:30:39 +0000
Hi all,
Is std::chrono::sys_days sufficiently "like an integer" for iota to work with it?
I understand that the current standard would not allow it (concept weakly_incrementable I guess stops it), but should it allow it?
It would be good to be able to do something like:
const auto value = std::chrono::sys_days{ /*some date*/ };
const auto bound = std::chrono::sys_days{ /*some later date*/ };
auto s =
std::views::iota(value, bound) |
std::views::filter(my::is_business_day);
To generate business days, etc between 2 calendar dates.
Or is iota really, really just integers? We can of course in this case (sticking with iota), do something like:
const auto value = std::chrono::sys_days{ /*some date*/ }.time_since_epoch().count();
const auto bound = std::chrono::sys_days{ /*some later date*/ }.time_since_epoch().count();
const auto to_sd = [](const int i)
{
return std::chrono::sys_days{} + std::chrono::days{ i };
};
auto s =
std::views::iota(value, bound) |
std::views::transform(to_sd) |
std::views::filter(my::is_business_day);
It feels to me that the current standard is unnecessarily too restrictive in this case and could be relaxed.
Thank you for your time,
Gorby
Is std::chrono::sys_days sufficiently "like an integer" for iota to work with it?
I understand that the current standard would not allow it (concept weakly_incrementable I guess stops it), but should it allow it?
It would be good to be able to do something like:
const auto value = std::chrono::sys_days{ /*some date*/ };
const auto bound = std::chrono::sys_days{ /*some later date*/ };
auto s =
std::views::iota(value, bound) |
std::views::filter(my::is_business_day);
To generate business days, etc between 2 calendar dates.
Or is iota really, really just integers? We can of course in this case (sticking with iota), do something like:
const auto value = std::chrono::sys_days{ /*some date*/ }.time_since_epoch().count();
const auto bound = std::chrono::sys_days{ /*some later date*/ }.time_since_epoch().count();
const auto to_sd = [](const int i)
{
return std::chrono::sys_days{} + std::chrono::days{ i };
};
auto s =
std::views::iota(value, bound) |
std::views::transform(to_sd) |
std::views::filter(my::is_business_day);
It feels to me that the current standard is unnecessarily too restrictive in this case and could be relaxed.
Thank you for your time,
Gorby
Received on 2025-05-23 13:30:44