op_-duration.pass.cpp revision 832b304076afcd832a5ffe95281b46a7abdaf869
1//===----------------------------------------------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is dual licensed under the MIT and the University of Illinois Open 6// Source Licenses. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10// <chrono> 11 12// time_point 13 14// template <class Clock, class Duration1, class Rep2, class Period2> 15// time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type> 16// operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs); 17 18#include <chrono> 19#include <cassert> 20 21int main() 22{ 23 typedef std::chrono::system_clock Clock; 24 typedef std::chrono::milliseconds Duration1; 25 typedef std::chrono::microseconds Duration2; 26 { 27 std::chrono::time_point<Clock, Duration1> t1(Duration1(3)); 28 std::chrono::time_point<Clock, Duration2> t2 = t1 - Duration2(5); 29 assert(t2.time_since_epoch() == Duration2(2995)); 30 } 31#if _LIBCPP_STD_VER > 11 32 { 33 constexpr std::chrono::time_point<Clock, Duration1> t1(Duration1(3)); 34 constexpr std::chrono::time_point<Clock, Duration2> t2 = t1 - Duration2(5); 35 static_assert(t2.time_since_epoch() == Duration2(2995), ""); 36 } 37#endif 38} 39