1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // UNSUPPORTED: c++03, c++11, c++14, c++17 9 // <chrono> 10 11 // constexpr hours make12(const hours& h) noexcept; 12 // Returns: The 12-hour equivalent of h in the range [1h, 12h]. 13 // If h is not in the range [0h, 23h], the value returned is unspecified. 14 15 #include <chrono> 16 #include <cassert> 17 #include <utility> 18 19 #include "test_macros.h" 20 21 int main(int, char**) 22 { 23 using hours = std::chrono::hours; 24 ASSERT_SAME_TYPE(hours, decltype(std::chrono::make12(std::declval<hours>()))); 25 ASSERT_NOEXCEPT( std::chrono::make12(std::declval<hours>())); 26 27 static_assert( std::chrono::make12(hours( 0)) == hours(12), ""); 28 static_assert( std::chrono::make12(hours(11)) == hours(11), ""); 29 static_assert( std::chrono::make12(hours(12)) == hours(12), ""); 30 static_assert( std::chrono::make12(hours(23)) == hours(11), ""); 31 32 assert( std::chrono::make12(hours(0)) == hours(12)); 33 for (int i = 1; i < 13; ++i) 34 assert( std::chrono::make12(hours(i)) == hours(i)); 35 for (int i = 13; i < 24; ++i) 36 assert( std::chrono::make12(hours(i)) == hours(i-12)); 37 38 return 0; 39 } 40