floor.pass.cpp revision 223df2ef0f543f7fef9270b3b34b9c73c869a006
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// UNSUPPORTED: c++03, c++11, c++14 11// <chrono> 12 13// floor 14 15// template <class ToDuration, class Rep, class Period> 16// constexpr 17// ToDuration 18// floor(const duration<Rep, Period>& d); 19 20#include <chrono> 21#include <type_traits> 22#include <cassert> 23 24template <class ToDuration, class FromDuration> 25void 26test(const FromDuration& f, const ToDuration& d) 27{ 28 { 29 typedef decltype(std::chrono::floor<ToDuration>(f)) R; 30 static_assert((std::is_same<R, ToDuration>::value), ""); 31 assert(std::chrono::floor<ToDuration>(f) == d); 32 } 33} 34 35int main() 36{ 37// 7290000ms is 2 hours, 1 minute, and 30 seconds 38 test(std::chrono::milliseconds( 7290000), std::chrono::hours( 2)); 39 test(std::chrono::milliseconds(-7290000), std::chrono::hours(-3)); 40 test(std::chrono::milliseconds( 7290000), std::chrono::minutes( 121)); 41 test(std::chrono::milliseconds(-7290000), std::chrono::minutes(-122)); 42 43 { 44// 9000000ms is 2 hours and 30 minutes 45 constexpr std::chrono::hours h1 = std::chrono::floor<std::chrono::hours>(std::chrono::milliseconds(9000000)); 46 static_assert(h1.count() == 2, ""); 47 constexpr std::chrono::hours h2 = std::chrono::floor<std::chrono::hours>(std::chrono::milliseconds(-9000000)); 48 static_assert(h2.count() == -3, ""); 49 } 50} 51