[libc++][NFC] Simplify the implementation of string and string_views operator== ...
[llvm-project.git] / libcxx / test / std / time / time.clock / time.clock.local / ostream.verify.cpp
blobaa348b06947aadb557f005fd4db1d988608da672
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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
10 // UNSUPPORTED: no-localization
11 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
13 // TODO FMT This test should not require std::to_chars(floating-point)
14 // XFAIL: availability-fp_to_chars-missing
16 // <chrono>
18 // class system_clock;
20 // template<class charT, class traits, class Duration>
21 // basic_ostream<charT, traits>&
22 // operator<<(basic_ostream<charT, traits>& os, const local_time<Duration>& tp);
24 // The function uses the system_clock which has two overloads
26 // template<class charT, class traits, class Duration>
27 // basic_ostream<charT, traits>&
28 // operator<<(basic_ostream<charT, traits>& os, const sys_time<Duration>& tp);
29 // Constraints: treat_as_floating_point_v<typename Duration::rep> is false, and Duration{1} < days{1} is true.
31 // template<class charT, class traits>
32 // basic_ostream<charT, traits>&
33 // operator<<(basic_ostream<charT, traits>& os, const sys_days& dp);
35 // Note local_time's operator<< is specified a
36 // Effects: os << sys_time<Duration>{lt.time_since_epoch()};
37 // since it uses Effects and not Effects: Equivalent to the constrains of
38 // sys_time do not apply to this operator. This means it's not possible to use
39 // a SFINAE test.
41 #include <chrono>
42 #include <ratio>
43 #include <sstream>
44 #include <type_traits>
46 void test() {
47 std::stringstream sstr;
49 // floating-point values
51 sstr << // expected-error@*:* {{invalid operands to binary expression}}
52 std::chrono::local_time<std::chrono::duration<float, std::ratio<1, 1>>>{
53 std::chrono::duration<float, std::ratio<1, 1>>{0}};
55 sstr << // expected-error@*:* {{invalid operands to binary expression}}
56 std::chrono::local_time<std::chrono::duration<double, std::ratio<1, 1>>>{
57 std::chrono::duration<double, std::ratio<1, 1>>{0}};
59 sstr << // expected-error@*:* {{invalid operands to binary expression}}
60 std::chrono::local_time<std::chrono::duration<long double, std::ratio<1, 1>>>{
61 std::chrono::duration<long double, std::ratio<1, 1>>{0}};
63 // duration >= day
65 sstr << // valid since day has its own formatter
66 std::chrono::local_days{std::chrono::days{0}};
68 using rep = std::conditional_t<std::is_same_v<std::chrono::days::rep, int>, long, int>;
69 sstr << // a different rep does not matter,
70 std::chrono::local_time<std::chrono::duration<rep, std::ratio<86400>>>{
71 std::chrono::duration<rep, std::ratio<86400>>{0}};
73 sstr << // expected-error@*:* {{invalid operands to binary expression}}
74 std::chrono::local_time<std::chrono::duration<typename std::chrono::days::rep, std::ratio<86401>>>{
75 std::chrono::duration<typename std::chrono::days::rep, std::ratio<86401>>{0}};
77 sstr << // These are considered days.
78 std::chrono::local_time<std::chrono::weeks>{std::chrono::weeks{3}};
80 sstr << // These too.
81 std::chrono::local_time<std::chrono::duration<rep, std::ratio<20 * 86400>>>{
82 std::chrono::duration<rep, std::ratio<20 * 86400>>{0}};
84 sstr << // expected-error@*:* {{invalid operands to binary expression}}
85 std::chrono::local_time<std::chrono::months>{std::chrono::months{0}};
87 sstr << // expected-error@*:* {{invalid operands to binary expression}}
88 std::chrono::local_time<std::chrono::years>{std::chrono::years{0}};