Env: win7, visual 2013 x64
Given a std::chrono::system_clock::time_point tp
, and a std::chrono::system_clock::duration dur
, how to find the next std::chrono::system_clock::time_point tp2
following :
tp2 = tp - tp % dur + dur
This represents the next time point considering a clock and a heartbeat, for example dur=10s
.
I tryied a lot ... my best I guess was this:
using namespace std; // for better readability
template < class duration_t >
system_clock::time_point next_time_aligned_on(const system_clock::time_point & tp, const duration_t & step)
{
const system_clock::duration d = tp.time_since_epoch();
const auto step2 = duration_cast<system_clock::duration>(step);
const auto elapsed_since_last = d % step2;
return tp - elapsed_since_last + step;
}
I got always the same compilation error:
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC
\include\type_traits(1446): error C2446: ':' : no conversion from
'std::chrono::duration<std::chrono::system_clock::rep,std::chrono::system_clock::period>'
to 'std::chrono::system_clock::rep'
1> No user-defined-conversion operator available that can perform
this conversion, or the operator cannot be called
1> C:\trading\tepp\src\tepp/tools/strings.h(49) : see reference
to class template instantiation std::common_type<std::chrono::system_clock::rep,std::chrono::duration<std::chrono::system_clock::rep,std::chrono::system_clock::period>>'
being compiled
1> st_gammalong.cpp(30) : see reference to function template
instantiation 'std::chrono::system_clock::time_point
tepp::next_time_aligned_on<std::chrono::seconds>(const std::chrono::system_clock::time_point &,const duration_t &)'
being compiled
1> with
1> [
1> duration_t=std::chrono::seconds
1> ]
My question: how to use modulo operator in c++11 std::chrono ?
Aucun commentaire:
Enregistrer un commentaire