literals.pass.cpp (1946B)
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++98, c++03, c++11 11 // <chrono> 12 13 #include <chrono> 14 #include <type_traits> 15 #include <cassert> 16 17 #include "test_macros.h" 18 19 int main() 20 { 21 using namespace std::literals::chrono_literals; 22 23 // Make sure the types are right 24 static_assert ( std::is_same<decltype( 3h ), std::chrono::hours>::value, "" ); 25 static_assert ( std::is_same<decltype( 3min ), std::chrono::minutes>::value, "" ); 26 static_assert ( std::is_same<decltype( 3s ), std::chrono::seconds>::value, "" ); 27 static_assert ( std::is_same<decltype( 3ms ), std::chrono::milliseconds>::value, "" ); 28 static_assert ( std::is_same<decltype( 3us ), std::chrono::microseconds>::value, "" ); 29 static_assert ( std::is_same<decltype( 3ns ), std::chrono::nanoseconds>::value, "" ); 30 31 std::chrono::hours h = 4h; 32 assert ( h == std::chrono::hours(4)); 33 auto h2 = 4.0h; 34 assert ( h == h2 ); 35 36 std::chrono::minutes min = 36min; 37 assert ( min == std::chrono::minutes(36)); 38 auto min2 = 36.0min; 39 assert ( min == min2 ); 40 41 std::chrono::seconds s = 24s; 42 assert ( s == std::chrono::seconds(24)); 43 auto s2 = 24.0s; 44 assert ( s == s2 ); 45 46 std::chrono::milliseconds ms = 247ms; 47 assert ( ms == std::chrono::milliseconds(247)); 48 auto ms2 = 247.0ms; 49 assert ( ms == ms2 ); 50 51 std::chrono::microseconds us = 867us; 52 assert ( us == std::chrono::microseconds(867)); 53 auto us2 = 867.0us; 54 assert ( us == us2 ); 55 56 std::chrono::nanoseconds ns = 645ns; 57 assert ( ns == std::chrono::nanoseconds(645)); 58 auto ns2 = 645.ns; 59 assert ( ns == ns2 ); 60 61 }