私はいくつかの C++ コードを (Linux/g++4.8.1 から) Windows に移植する過程にあり、期間のモジュラス演算子の Microsoft の実装が正しくないことに気付きました。
簡単なプログラム
#include <chrono>
#include <iostream>
using namespace std::chrono;
int main(void)
{
std::cout << (milliseconds(1050)%seconds(1)).count() << std::endl;
return 0;
}
Microsoft Visual Studio 2012 でコンパイルすると、コンパイル エラーが発生します。
error C2228: left of '.count' must have class/struct/union
標準 ( http://en.cppreference.com/w/cpp/chrono/duration/operator_arith4 ) の定義は次のとおりです。
template< class Rep1, class Period1, class Rep2, class Period2 >
typename common_type<duration<Rep1,Period1>, duration<Rep2,Period2>>::type
constexpr operator%( const duration<Rep1,Period1>& lhs,
const duration<Rep2,Period2>& rhs );
つまり、モジュラス演算子は共通型の期間を返します。Microsoft の実装 ( http://msdn.microsoft.com/en-us/library/hh874810.aspx ) の定義は次のとおりです。
template<class Rep1, class Period1, class Rep2, class Period2>
constexpr typename common_type<Rep1, Rep2>::type
operator%(
const duration<Rep1, Period1>& Left,
const duration<Rep2, Period2>& Right);
これは、基になる期間ストレージ タイプを誤って返します。これはバグですか、それとも何か不足していますか?