|
| 1 | +/* |
| 2 | + * Copyright (c) 2026 Morwenn |
| 3 | + * SPDX-License-Identifier: MIT |
| 4 | + */ |
| 5 | +#ifndef CPPSORT_TESTSUITE_COMPARATORS_H_ |
| 6 | +#define CPPSORT_TESTSUITE_COMPARATORS_H_ |
| 7 | + |
| 8 | +//////////////////////////////////////////////////////////// |
| 9 | +// Headers |
| 10 | +//////////////////////////////////////////////////////////// |
| 11 | +#include <functional> |
| 12 | +#include <cpp-sort/utility/as_function.h> |
| 13 | +#include <cpp-sort/utility/functional.h> |
| 14 | + |
| 15 | +namespace helpers |
| 16 | +{ |
| 17 | + // Identify the function that was called |
| 18 | + enum struct compare_result |
| 19 | + { |
| 20 | + total_less, |
| 21 | + total_greater, |
| 22 | + weak_less, |
| 23 | + weak_greater, |
| 24 | + partial_less, |
| 25 | + partial_greater, |
| 26 | + }; |
| 27 | + |
| 28 | + // Collection of empty classes and empty comparison overloads used |
| 29 | + // to identify what overload was selected during resolution |
| 30 | + |
| 31 | + struct totally_comparable |
| 32 | + { |
| 33 | + friend constexpr auto total_less(const totally_comparable&, |
| 34 | + const totally_comparable&) |
| 35 | + -> compare_result |
| 36 | + { |
| 37 | + return compare_result::total_less; |
| 38 | + } |
| 39 | + }; |
| 40 | + |
| 41 | + constexpr auto total_greater(const totally_comparable&, |
| 42 | + const totally_comparable&) |
| 43 | + -> compare_result |
| 44 | + { |
| 45 | + return compare_result::total_greater; |
| 46 | + } |
| 47 | + |
| 48 | + struct weakly_comparable |
| 49 | + { |
| 50 | + friend constexpr auto weak_less(const weakly_comparable&, |
| 51 | + const weakly_comparable&) |
| 52 | + -> compare_result |
| 53 | + { |
| 54 | + return compare_result::weak_less; |
| 55 | + } |
| 56 | + }; |
| 57 | + |
| 58 | + constexpr auto weak_greater(const weakly_comparable&, |
| 59 | + const weakly_comparable&) |
| 60 | + -> compare_result |
| 61 | + { |
| 62 | + return compare_result::weak_greater; |
| 63 | + } |
| 64 | + |
| 65 | + struct partially_comparable |
| 66 | + { |
| 67 | + friend constexpr auto partial_less(const partially_comparable&, |
| 68 | + const partially_comparable&) |
| 69 | + -> compare_result |
| 70 | + { |
| 71 | + return compare_result::partial_less; |
| 72 | + } |
| 73 | + }; |
| 74 | + |
| 75 | + constexpr auto partial_greater(const partially_comparable&, |
| 76 | + const partially_comparable&) |
| 77 | + -> compare_result |
| 78 | + { |
| 79 | + return compare_result::partial_greater; |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +#endif // CPPSORT_TESTSUITE_COMPARATORS_H_ |
0 commit comments