I am try to create an iterable type which receives a template argument of a specific duration type, say std::seconds
, std::hours
, etc., and I want it to receive as argument 2 values that represent time_points
of the specified duration, and be able to use such a construct in a range based for loop by increasing the current time_point
by a unit of that duration or maybe of a specified duration, something like the following:
DateRange<std::seconds> dr(now() , 50);
for(auto d : dr){
// do something at unit time
}
I have tried to implement it this way
using namespace std::chrono;
template<typename Duration , typename Clock_t = high_resolution_clock,
typename Time_type = time_point<Clock_t, typename Duration> , typename
Time_pointer = Time_type* >
class DateRange {
using Time_type_t = typename Time_type::duration;
public:
DateRange(Time_type_t start, Time_type_t end) :
m_begin(start),
m_end(end)
{
}
DateRange(Time_type_t end):
m_begin(Clock_t::now())
{
}
Time_pointer begin(){
return &m_begin;
}
Time_pointer end() {
return &m_end;
}
Time_pointer operator++(){
present +=Duration(1);
return present_point;
}
Time_type operator*(){
return present;
}
private:
Time_type m_begin;
Time_type m_end;
Time_type present;
Time_pointer present_point = &present;
Clock_t l_clock;
};
int main()
{
DateRange<seconds> dr(40s);
dr.operator++();
std::cout << (*dr).time_since_epoch().count();
}
'std::chrono::time_point::time_point(std::chrono::time_point &&)': cannot convert argument 1 from 'std::chrono::steady_clock::time_point' to 'const _Duration &' DateRange at line 19