|
5 | 5 | // Tests the new functions added as part of P0092R1, "Polishing Chrono" |
6 | 6 | // |
7 | 7 |
|
| 8 | +#include <__msvc_int128.hpp> // an integer-class type should emulate an arithmetic type, see also GH-1909 |
8 | 9 | #include <cassert> |
9 | 10 | #include <chrono> |
10 | 11 | #include <cstdint> |
11 | 12 | #include <ratio> |
| 13 | +#include <type_traits> |
12 | 14 |
|
13 | 15 | using namespace std; |
14 | 16 | using namespace std::chrono; |
@@ -188,6 +190,75 @@ STATIC_ASSERT(floor<seconds>(tp1).time_since_epoch().count() == 1); |
188 | 190 | STATIC_ASSERT(ceil<seconds>(tp1).time_since_epoch().count() == 2); |
189 | 191 | STATIC_ASSERT(round<seconds>(tp1).time_since_epoch().count() == 2); |
190 | 192 |
|
| 193 | +// Test LWG-3090 "What is [time.duration.cons]/4's "no overflow is induced in the conversion" intended to mean?" |
| 194 | +constexpr bool test_lwg_3090() { |
| 195 | + STATIC_ASSERT(is_constructible_v<duration<_Signed128>, seconds>); |
| 196 | + STATIC_ASSERT(is_constructible_v<duration<_Signed128>, const seconds&>); |
| 197 | + STATIC_ASSERT(is_convertible_v<seconds, duration<_Signed128>>); |
| 198 | + STATIC_ASSERT(is_convertible_v<const seconds&, duration<_Signed128>>); |
| 199 | + |
| 200 | + STATIC_ASSERT(!is_constructible_v<seconds, duration<_Signed128>>); |
| 201 | + STATIC_ASSERT(!is_constructible_v<seconds, const duration<_Signed128>&>); |
| 202 | + STATIC_ASSERT(!is_convertible_v<duration<_Signed128>, seconds>); |
| 203 | + STATIC_ASSERT(!is_convertible_v<const duration<_Signed128>&, seconds>); |
| 204 | + |
| 205 | + STATIC_ASSERT(is_constructible_v<duration<_Signed128>, minutes>); |
| 206 | + STATIC_ASSERT(is_constructible_v<duration<_Signed128>, const minutes&>); |
| 207 | + STATIC_ASSERT(is_convertible_v<minutes, duration<_Signed128>>); |
| 208 | + STATIC_ASSERT(is_convertible_v<const minutes&, duration<_Signed128>>); |
| 209 | + |
| 210 | + STATIC_ASSERT(!is_constructible_v<minutes, duration<_Signed128>>); |
| 211 | + STATIC_ASSERT(!is_constructible_v<minutes, const duration<_Signed128>&>); |
| 212 | + STATIC_ASSERT(!is_convertible_v<duration<_Signed128>, minutes>); |
| 213 | + STATIC_ASSERT(!is_convertible_v<const duration<_Signed128>&, minutes>); |
| 214 | + |
| 215 | + STATIC_ASSERT(!is_constructible_v<duration<_Signed128>, milliseconds>); |
| 216 | + STATIC_ASSERT(!is_constructible_v<duration<_Signed128>, const milliseconds&>); |
| 217 | + STATIC_ASSERT(!is_convertible_v<milliseconds, duration<_Signed128>>); |
| 218 | + STATIC_ASSERT(!is_convertible_v<const milliseconds&, duration<_Signed128>>); |
| 219 | + |
| 220 | + STATIC_ASSERT(!is_constructible_v<milliseconds, duration<_Signed128>>); |
| 221 | + STATIC_ASSERT(!is_constructible_v<milliseconds, const duration<_Signed128>&>); |
| 222 | + STATIC_ASSERT(!is_convertible_v<duration<_Signed128>, milliseconds>); |
| 223 | + STATIC_ASSERT(!is_convertible_v<const duration<_Signed128>&, milliseconds>); |
| 224 | + |
| 225 | + STATIC_ASSERT(is_constructible_v<duration<_Unsigned128>, seconds>); |
| 226 | + STATIC_ASSERT(is_constructible_v<duration<_Unsigned128>, const seconds&>); |
| 227 | + STATIC_ASSERT(is_convertible_v<seconds, duration<_Unsigned128>>); |
| 228 | + STATIC_ASSERT(is_convertible_v<const seconds&, duration<_Unsigned128>>); |
| 229 | + |
| 230 | + STATIC_ASSERT(!is_constructible_v<seconds, duration<_Unsigned128>>); |
| 231 | + STATIC_ASSERT(!is_constructible_v<seconds, const duration<_Unsigned128>&>); |
| 232 | + STATIC_ASSERT(!is_convertible_v<duration<_Unsigned128>, seconds>); |
| 233 | + STATIC_ASSERT(!is_convertible_v<const duration<_Unsigned128>&, seconds>); |
| 234 | + |
| 235 | + STATIC_ASSERT(is_constructible_v<duration<_Unsigned128>, minutes>); |
| 236 | + STATIC_ASSERT(is_constructible_v<duration<_Unsigned128>, const minutes&>); |
| 237 | + STATIC_ASSERT(is_convertible_v<minutes, duration<_Unsigned128>>); |
| 238 | + STATIC_ASSERT(is_convertible_v<const minutes&, duration<_Unsigned128>>); |
| 239 | + |
| 240 | + STATIC_ASSERT(!is_constructible_v<minutes, duration<_Unsigned128>>); |
| 241 | + STATIC_ASSERT(!is_constructible_v<minutes, const duration<_Unsigned128>&>); |
| 242 | + STATIC_ASSERT(!is_convertible_v<duration<_Unsigned128>, minutes>); |
| 243 | + STATIC_ASSERT(!is_convertible_v<const duration<_Unsigned128>&, minutes>); |
| 244 | + |
| 245 | + STATIC_ASSERT(!is_constructible_v<duration<_Unsigned128>, milliseconds>); |
| 246 | + STATIC_ASSERT(!is_constructible_v<duration<_Unsigned128>, const milliseconds&>); |
| 247 | + STATIC_ASSERT(!is_convertible_v<milliseconds, duration<_Unsigned128>>); |
| 248 | + STATIC_ASSERT(!is_convertible_v<const milliseconds&, duration<_Unsigned128>>); |
| 249 | + |
| 250 | + STATIC_ASSERT(!is_constructible_v<milliseconds, duration<_Unsigned128>>); |
| 251 | + STATIC_ASSERT(!is_constructible_v<milliseconds, const duration<_Unsigned128>&>); |
| 252 | + STATIC_ASSERT(!is_convertible_v<duration<_Unsigned128>, milliseconds>); |
| 253 | + STATIC_ASSERT(!is_convertible_v<const duration<_Unsigned128>&, milliseconds>); |
| 254 | + |
| 255 | + assert(duration<_Signed128>{seconds{1}}.count() == 1); |
| 256 | + assert(duration<_Signed128>{minutes{12}}.count() == 720); |
| 257 | + assert(duration<_Unsigned128>{seconds{123}}.count() == 123); |
| 258 | + assert(duration<_Unsigned128>{minutes{1234}}.count() == 74040); |
| 259 | + |
| 260 | + return true; |
| 261 | +} |
191 | 262 |
|
192 | 263 | int overloaded(milliseconds) { |
193 | 264 | return 11; |
@@ -222,4 +293,7 @@ int main() { |
222 | 293 | assert(overloaded(40ms) == 11); |
223 | 294 | assert(overloaded(50s) == 22); |
224 | 295 | assert(overloaded(duration<int, exa>(60)) == 33); |
| 296 | + |
| 297 | + STATIC_ASSERT(test_lwg_3090()); |
| 298 | + test_lwg_3090(); |
225 | 299 | } |
0 commit comments