time_point模数持续时间不编译

时间:2015-07-30 19:41:42

标签: c++11 visual-studio-2013 modulo chrono

环境:win7,visual 2013 x64

鉴于std::chrono::system_clock::time_point tpstd::chrono::system_clock::duration dur,如何找到下一个std::chrono::system_clock::time_point tp2

 tp2 = tp - tp % dur + dur

这表示考虑时钟和心跳的下一个时间点,例如dur=10s

我做了很多...我最好的猜测是这样的:

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;      
} 

我总是遇到相同的编译错误:

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>          ]

我的问题:如何在c ++ 11 std :: chrono中使用modulo运算符?

0 个答案:

没有答案