1c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant//===----------------------------------------------------------------------===// 2c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant// 3c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant// The LLVM Compiler Infrastructure 4c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant// 5b64f8b07c104c6cc986570ac8ee0ed16a9f23976Howard Hinnant// This file is dual licensed under the MIT and the University of Illinois Open 6b64f8b07c104c6cc986570ac8ee0ed16a9f23976Howard Hinnant// Source Licenses. See LICENSE.TXT for details. 7c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant// 8c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant//===----------------------------------------------------------------------===// 9c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant 10c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant// <chrono> 11c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant 12c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant// duration 13c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant 14c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant// template <class Rep1, class Period1, class Rep2, class Period2> 15473f838128bcf118ab50d08a65a83433ed1b015aHoward Hinnant// constexpr 16c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant// typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type 17c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant// operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs); 18c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant 19c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant#include <chrono> 20c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant#include <cassert> 21c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant 22c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnantint main() 23c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant{ 24c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant { 25c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant std::chrono::seconds s1(3); 26c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant std::chrono::seconds s2(5); 27c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant std::chrono::seconds r = s1 - s2; 28c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant assert(r.count() == -2); 29c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant } 30c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant { 31c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant std::chrono::seconds s1(3); 32c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant std::chrono::microseconds s2(5); 33c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant std::chrono::microseconds r = s1 - s2; 34c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant assert(r.count() == 2999995); 35c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant } 36c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant { 37c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant std::chrono::duration<int, std::ratio<2, 3> > s1(3); 38c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant std::chrono::duration<int, std::ratio<3, 5> > s2(5); 39c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant std::chrono::duration<int, std::ratio<1, 15> > r = s1 - s2; 40c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant assert(r.count() == -15); 41c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant } 42c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant { 43c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant std::chrono::duration<int, std::ratio<2, 3> > s1(3); 44c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant std::chrono::duration<double, std::ratio<3, 5> > s2(5); 45c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant std::chrono::duration<double, std::ratio<1, 15> > r = s1 - s2; 46c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant assert(r.count() == -15); 47c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant } 48473f838128bcf118ab50d08a65a83433ed1b015aHoward Hinnant#ifndef _LIBCPP_HAS_NO_CONSTEXPR 49473f838128bcf118ab50d08a65a83433ed1b015aHoward Hinnant { 50473f838128bcf118ab50d08a65a83433ed1b015aHoward Hinnant constexpr std::chrono::seconds s1(3); 51473f838128bcf118ab50d08a65a83433ed1b015aHoward Hinnant constexpr std::chrono::seconds s2(5); 52473f838128bcf118ab50d08a65a83433ed1b015aHoward Hinnant constexpr std::chrono::seconds r = s1 - s2; 53473f838128bcf118ab50d08a65a83433ed1b015aHoward Hinnant static_assert(r.count() == -2, ""); 54473f838128bcf118ab50d08a65a83433ed1b015aHoward Hinnant } 55473f838128bcf118ab50d08a65a83433ed1b015aHoward Hinnant { 56473f838128bcf118ab50d08a65a83433ed1b015aHoward Hinnant constexpr std::chrono::seconds s1(3); 57473f838128bcf118ab50d08a65a83433ed1b015aHoward Hinnant constexpr std::chrono::microseconds s2(5); 58473f838128bcf118ab50d08a65a83433ed1b015aHoward Hinnant constexpr std::chrono::microseconds r = s1 - s2; 59473f838128bcf118ab50d08a65a83433ed1b015aHoward Hinnant static_assert(r.count() == 2999995, ""); 60473f838128bcf118ab50d08a65a83433ed1b015aHoward Hinnant } 61473f838128bcf118ab50d08a65a83433ed1b015aHoward Hinnant { 62473f838128bcf118ab50d08a65a83433ed1b015aHoward Hinnant constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(3); 63473f838128bcf118ab50d08a65a83433ed1b015aHoward Hinnant constexpr std::chrono::duration<int, std::ratio<3, 5> > s2(5); 64473f838128bcf118ab50d08a65a83433ed1b015aHoward Hinnant constexpr std::chrono::duration<int, std::ratio<1, 15> > r = s1 - s2; 65473f838128bcf118ab50d08a65a83433ed1b015aHoward Hinnant static_assert(r.count() == -15, ""); 66473f838128bcf118ab50d08a65a83433ed1b015aHoward Hinnant } 67473f838128bcf118ab50d08a65a83433ed1b015aHoward Hinnant { 68473f838128bcf118ab50d08a65a83433ed1b015aHoward Hinnant constexpr std::chrono::duration<int, std::ratio<2, 3> > s1(3); 69473f838128bcf118ab50d08a65a83433ed1b015aHoward Hinnant constexpr std::chrono::duration<double, std::ratio<3, 5> > s2(5); 70473f838128bcf118ab50d08a65a83433ed1b015aHoward Hinnant constexpr std::chrono::duration<double, std::ratio<1, 15> > r = s1 - s2; 71473f838128bcf118ab50d08a65a83433ed1b015aHoward Hinnant static_assert(r.count() == -15, ""); 72473f838128bcf118ab50d08a65a83433ed1b015aHoward Hinnant } 73473f838128bcf118ab50d08a65a83433ed1b015aHoward Hinnant#endif 74c52f43e72dfcea03037729649da84c23b3beb04aHoward Hinnant} 75