|
1 | 1 | // Copyright (c) Microsoft Corporation. |
2 | 2 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
3 | 3 |
|
4 | | -// Covers: |
5 | | -// * spaceship for containers |
6 | | - |
7 | 4 | #include <array> |
8 | 5 | #include <cassert> |
9 | 6 | #include <compare> |
|
21 | 18 | #include <set> |
22 | 19 | #include <stack> |
23 | 20 | #include <string> |
| 21 | +#include <string_view> |
24 | 22 | #include <system_error> |
25 | 23 | #include <thread> |
26 | 24 | #include <type_traits> |
@@ -434,27 +432,148 @@ void ordering_test_cases() { |
434 | 432 | std::ssub_match sm3 = m3[0]; |
435 | 433 | std::ssub_match sm4 = m4[0]; |
436 | 434 |
|
437 | | - // TRANSITION, std::char_traits<char> doesn't define comparison_category |
438 | | - spaceship_test<std::weak_ordering>(sm1, sm1_equal, sm2); |
439 | | - spaceship_test<std::weak_ordering>(sm1, s1, s2); |
440 | | - spaceship_test<std::weak_ordering>(sm1, s1.c_str(), s2.c_str()); |
441 | | - spaceship_test<std::weak_ordering>(sm3, 'c', 'm'); |
442 | | - spaceship_test<std::weak_ordering>(s1, sm1, sm2); |
443 | | - spaceship_test<std::weak_ordering>(s1.c_str(), sm1, sm2); |
444 | | - spaceship_test<std::weak_ordering>('c', sm3, sm4); |
| 435 | + spaceship_test<std::strong_ordering>(sm1, sm1_equal, sm2); |
| 436 | + spaceship_test<std::strong_ordering>(sm1, s1, s2); |
| 437 | + spaceship_test<std::strong_ordering>(sm1, s1.c_str(), s2.c_str()); |
| 438 | + spaceship_test<std::strong_ordering>(sm3, 'c', 'm'); |
| 439 | + spaceship_test<std::strong_ordering>(s1, sm1, sm2); |
| 440 | + spaceship_test<std::strong_ordering>(s1.c_str(), sm1, sm2); |
| 441 | + spaceship_test<std::strong_ordering>('c', sm3, sm4); |
445 | 442 |
|
446 | 443 | using StronglyOrderedMatch = std::ssub_match; |
447 | 444 | using WeaklyOrderedMatch = std::sub_match<std::basic_string<WeaklyOrderedChar>::const_iterator>; |
448 | 445 | using WeaklyOrderdByOmissionMatch = |
449 | 446 | std::sub_match<std::basic_string<WeaklyOrderedByOmissionChar>::const_iterator>; |
450 | 447 | using PartiallyOrderedMatch = std::sub_match<std::basic_string<PartiallyOrderedChar>::const_iterator>; |
451 | 448 |
|
452 | | - // TRANSITION, std::char_traits<char> doesn't define comparison_category |
453 | | - static_assert(std::is_same_v<SpaceshipType<StronglyOrderedMatch>, std::weak_ordering>); |
| 449 | + static_assert(std::is_same_v<SpaceshipType<StronglyOrderedMatch>, std::strong_ordering>); |
454 | 450 | static_assert(std::is_same_v<SpaceshipType<WeaklyOrderedMatch>, std::weak_ordering>); |
455 | 451 | static_assert(std::is_same_v<SpaceshipType<WeaklyOrderdByOmissionMatch>, std::weak_ordering>); |
456 | 452 | static_assert(std::is_same_v<SpaceshipType<PartiallyOrderedMatch>, std::partial_ordering>); |
457 | 453 | } |
| 454 | + { // char_traits |
| 455 | + static_assert(std::is_same_v<std::char_traits<char>::comparison_category, std::strong_ordering>); |
| 456 | +#ifdef __cpp_char8_t |
| 457 | + static_assert(std::is_same_v<std::char_traits<char8_t>::comparison_category, std::strong_ordering>); |
| 458 | +#endif // __cpp_char8_t |
| 459 | + static_assert(std::is_same_v<std::char_traits<char16_t>::comparison_category, std::strong_ordering>); |
| 460 | + static_assert(std::is_same_v<std::char_traits<char32_t>::comparison_category, std::strong_ordering>); |
| 461 | + static_assert(std::is_same_v<std::char_traits<wchar_t>::comparison_category, std::strong_ordering>); |
| 462 | + } |
| 463 | + { // Strings library |
| 464 | + const std::string a1 = "abcdef"; |
| 465 | + const std::string a2 = "abcdef"; |
| 466 | + const std::string a3 = "abcdefg"; |
| 467 | + const std::string a4 = "abcde"; |
| 468 | + const std::string a5 = "abddef"; |
| 469 | + const std::string a6 = "abbdef"; |
| 470 | + |
| 471 | + assert((a1 <=> a2) == std::strong_ordering::equivalent); |
| 472 | + assert((a1 <=> a3) == std::strong_ordering::less); |
| 473 | + assert((a1 <=> a4) == std::strong_ordering::greater); |
| 474 | + assert((a1 <=> a5) == std::strong_ordering::less); |
| 475 | + assert((a1 <=> a6) == std::strong_ordering::greater); |
| 476 | + |
| 477 | + assert(a1 == a2); |
| 478 | + assert(a1 >= a2); |
| 479 | + assert(a1 <= a2); |
| 480 | + assert(a1 < a3); |
| 481 | + assert(a1 <= a3); |
| 482 | + assert(a1 != a3); |
| 483 | + assert(a1 > a4); |
| 484 | + assert(a1 >= a4); |
| 485 | + assert(a1 != a4); |
| 486 | + assert(a1 < a5); |
| 487 | + assert(a1 <= a5); |
| 488 | + assert(a1 != a5); |
| 489 | + assert(a1 > a6); |
| 490 | + assert(a1 >= a6); |
| 491 | + assert(a1 != a6); |
| 492 | + |
| 493 | + assert((a1 <=> "aardvark") == std::strong_ordering::greater); |
| 494 | + assert((a1 <=> "abcdef") == std::strong_ordering::equivalent); |
| 495 | + assert((a1 <=> "zebra") == std::strong_ordering::less); |
| 496 | + |
| 497 | + assert(("aardvark" <=> a1) == std::strong_ordering::less); |
| 498 | + assert(("abcdef" <=> a1) == std::strong_ordering::equivalent); |
| 499 | + assert(("zebra" <=> a1) == std::strong_ordering::greater); |
| 500 | + } |
| 501 | + { // string_view |
| 502 | + const std::string_view a1 = "abcdef"; |
| 503 | + const std::string_view a2 = "abcdef"; |
| 504 | + const std::string_view a3 = "abcdefg"; |
| 505 | + const std::string_view a4 = "abcde"; |
| 506 | + const std::string_view a5 = "abddef"; |
| 507 | + const std::string_view a6 = "abbdef"; |
| 508 | + |
| 509 | + assert((a1 <=> a2) == std::strong_ordering::equivalent); |
| 510 | + assert((a1 <=> a3) == std::strong_ordering::less); |
| 511 | + assert((a1 <=> a4) == std::strong_ordering::greater); |
| 512 | + assert((a1 <=> a5) == std::strong_ordering::less); |
| 513 | + assert((a1 <=> a6) == std::strong_ordering::greater); |
| 514 | + |
| 515 | + assert(a1 == a2); |
| 516 | + assert(a1 >= a2); |
| 517 | + assert(a1 <= a2); |
| 518 | + assert(a1 < a3); |
| 519 | + assert(a1 <= a3); |
| 520 | + assert(a1 != a3); |
| 521 | + assert(a1 > a4); |
| 522 | + assert(a1 >= a4); |
| 523 | + assert(a1 != a4); |
| 524 | + assert(a1 < a5); |
| 525 | + assert(a1 <= a5); |
| 526 | + assert(a1 != a5); |
| 527 | + assert(a1 > a6); |
| 528 | + assert(a1 >= a6); |
| 529 | + assert(a1 != a6); |
| 530 | + |
| 531 | + assert((a1 <=> "aardvark") == std::strong_ordering::greater); |
| 532 | + assert((a1 <=> "abcdef") == std::strong_ordering::equivalent); |
| 533 | + assert((a1 <=> "zebra") == std::strong_ordering::less); |
| 534 | + |
| 535 | + assert(("aardvark" <=> a1) == std::strong_ordering::less); |
| 536 | + assert(("abcdef" <=> a1) == std::strong_ordering::equivalent); |
| 537 | + assert(("zebra" <=> a1) == std::strong_ordering::greater); |
| 538 | + } |
| 539 | + { // constexpr string_view |
| 540 | + constexpr std::string_view a1 = "abcdef"; |
| 541 | + constexpr std::string_view a2 = "abcdef"; |
| 542 | + constexpr std::string_view a3 = "abcdefg"; |
| 543 | + constexpr std::string_view a4 = "abcde"; |
| 544 | + constexpr std::string_view a5 = "abddef"; |
| 545 | + constexpr std::string_view a6 = "abbdef"; |
| 546 | + |
| 547 | + static_assert((a1 <=> a2) == std::strong_ordering::equivalent); |
| 548 | + static_assert((a1 <=> a3) == std::strong_ordering::less); |
| 549 | + static_assert((a1 <=> a4) == std::strong_ordering::greater); |
| 550 | + static_assert((a1 <=> a5) == std::strong_ordering::less); |
| 551 | + static_assert((a1 <=> a6) == std::strong_ordering::greater); |
| 552 | + |
| 553 | + static_assert(a1 == a2); |
| 554 | + static_assert(a1 >= a2); |
| 555 | + static_assert(a1 <= a2); |
| 556 | + static_assert(a1 < a3); |
| 557 | + static_assert(a1 <= a3); |
| 558 | + static_assert(a1 != a3); |
| 559 | + static_assert(a1 > a4); |
| 560 | + static_assert(a1 >= a4); |
| 561 | + static_assert(a1 != a4); |
| 562 | + static_assert(a1 < a5); |
| 563 | + static_assert(a1 <= a5); |
| 564 | + static_assert(a1 != a5); |
| 565 | + static_assert(a1 > a6); |
| 566 | + static_assert(a1 >= a6); |
| 567 | + static_assert(a1 != a6); |
| 568 | + |
| 569 | + static_assert((a1 <=> "aardvark") == std::strong_ordering::greater); |
| 570 | + static_assert((a1 <=> "abcdef") == std::strong_ordering::equivalent); |
| 571 | + static_assert((a1 <=> "zebra") == std::strong_ordering::less); |
| 572 | + |
| 573 | + static_assert(("aardvark" <=> a1) == std::strong_ordering::less); |
| 574 | + static_assert(("abcdef" <=> a1) == std::strong_ordering::equivalent); |
| 575 | + static_assert(("zebra" <=> a1) == std::strong_ordering::greater); |
| 576 | + } |
458 | 577 | { // Diagnostics Library |
459 | 578 | diagnostics_test<std::error_code>(); |
460 | 579 | diagnostics_test<std::error_condition>(); |
|
0 commit comments