]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/std/time/traits/is_clock.cc
1d936a53629698a639713c321ad8a1fa8a3701e7
1 // Copyright (C) 2020-2023 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-do compile { target c++20 } }
21 #include <slow_clock.h>
23 namespace chrono
= std::chrono
;
25 static_assert( chrono::is_clock
<chrono::system_clock
>::value
);
26 static_assert( chrono::is_clock_v
<chrono::system_clock
> );
28 static_assert( chrono::is_clock
<chrono::high_resolution_clock
>::value
);
29 static_assert( chrono::is_clock_v
<chrono::high_resolution_clock
> );
31 static_assert( chrono::is_clock
<chrono::steady_clock
>::value
);
32 static_assert( chrono::is_clock_v
<chrono::steady_clock
> );
34 static_assert(chrono::is_clock
<chrono::file_clock
>::value
);
35 static_assert(chrono::is_clock_v
<chrono::file_clock
>);
37 // Clock<xxx_clock> will not use the specialization of is_clock<xxx_clock>
38 template<typename C
> struct Clock
: C
{ };
40 static_assert( chrono::is_clock
<Clock
<chrono::system_clock
>>::value
);
41 static_assert( chrono::is_clock_v
<Clock
<chrono::system_clock
>> );
43 static_assert( chrono::is_clock
<Clock
<chrono::high_resolution_clock
>>::value
);
44 static_assert( chrono::is_clock_v
<Clock
<chrono::high_resolution_clock
>> );
46 static_assert( chrono::is_clock
<Clock
<chrono::steady_clock
>>::value
);
47 static_assert( chrono::is_clock_v
<Clock
<chrono::steady_clock
>> );
49 static_assert(chrono::is_clock
<Clock
<chrono::file_clock
>>::value
);
50 static_assert(chrono::is_clock_v
<Clock
<chrono::file_clock
>>);
52 static_assert( chrono::is_clock
<__gnu_test::slow_clock
>::value
);
53 static_assert( chrono::is_clock_v
<__gnu_test::slow_clock
> );
57 static_assert( ! chrono::is_clock
<int>::value
);
58 static_assert( ! chrono::is_clock_v
<int> );
60 static_assert( ! chrono::is_clock
<void>::value
);
61 static_assert( ! chrono::is_clock_v
<void> );
66 using period
= std::ratio
<4, 2>;
67 using duration
= chrono::duration
<long, period
>; // different rep
68 using time_point
= chrono::time_point
<not_a_clock_1
>;
69 static constexpr bool is_steady
= false;
70 static time_point
now();
73 static_assert( ! chrono::is_clock
<not_a_clock_1
>::value
);
74 static_assert( ! chrono::is_clock_v
<not_a_clock_1
> );
79 using period
= int; // not a std::ratio
80 using duration
= chrono::duration
<rep
>;
81 using time_point
= chrono::time_point
<not_a_clock_2
>;
82 static constexpr bool is_steady
= false;
83 static time_point
now();
86 static_assert( ! chrono::is_clock
<not_a_clock_2
>::value
);
87 static_assert( ! chrono::is_clock_v
<not_a_clock_2
> );
92 using period
= std::ratio
<1>;
93 using duration
= chrono::duration
<rep
>;
95 using time_point
= chrono::time_point
<not_a_clock_3
, chrono::duration
<long>>;
96 static constexpr bool is_steady
= false;
97 static time_point
now();
100 static_assert( ! chrono::is_clock
<not_a_clock_3
>::value
);
101 static_assert( ! chrono::is_clock_v
<not_a_clock_3
> );
106 using period
= std::ratio
<1>;
107 using duration
= chrono::duration
<rep
>;
108 using time_point
= chrono::time_point
<not_a_clock_4
>;
109 static constexpr int is_steady
= 0; // not a const bool
110 static time_point
now();
113 static_assert( ! chrono::is_clock
<not_a_clock_4
>::value
);
114 static_assert( ! chrono::is_clock_v
<not_a_clock_4
> );
119 using period
= std::ratio
<1>;
120 using duration
= chrono::duration
<rep
>;
121 using time_point
= chrono::time_point
<not_a_clock_5
>;
122 static constexpr bool is_steady
= false;
123 static int now(); // wrong return type
126 static_assert( ! chrono::is_clock
<not_a_clock_5
>::value
);
127 static_assert( ! chrono::is_clock_v
<not_a_clock_5
> );
132 using period
= std::ratio
<1>;
133 using duration
= chrono::duration
<rep
>;
134 using time_point
= chrono::time_point
<not_a_clock_6
>;
135 const bool is_steady
= false; // not static
136 static time_point
now();
139 static_assert( ! chrono::is_clock
<not_a_clock_6
>::value
);
140 static_assert( ! chrono::is_clock_v
<not_a_clock_6
> );