Skip to content

Commit a07ffe8

Browse files
committed
feat all: use three way comparison unconditionally
Tests: протестировано CI commit_hash:7cb58f6943c80f38b31626b2cadecb3af31b214a
1 parent ceb559a commit a07ffe8

12 files changed

Lines changed: 9 additions & 105 deletions

File tree

.mapping.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5365,7 +5365,6 @@
53655365
"universal/include/userver/compiler/impl/asan.hpp":"taxi/uservices/userver/universal/include/userver/compiler/impl/asan.hpp",
53665366
"universal/include/userver/compiler/impl/lifetime.hpp":"taxi/uservices/userver/universal/include/userver/compiler/impl/lifetime.hpp",
53675367
"universal/include/userver/compiler/impl/lsan.hpp":"taxi/uservices/userver/universal/include/userver/compiler/impl/lsan.hpp",
5368-
"universal/include/userver/compiler/impl/three_way_comparison.hpp":"taxi/uservices/userver/universal/include/userver/compiler/impl/three_way_comparison.hpp",
53695368
"universal/include/userver/compiler/impl/tls.hpp":"taxi/uservices/userver/universal/include/userver/compiler/impl/tls.hpp",
53705369
"universal/include/userver/compiler/impl/tsan.hpp":"taxi/uservices/userver/universal/include/userver/compiler/impl/tsan.hpp",
53715370
"universal/include/userver/compiler/select.hpp":"taxi/uservices/userver/universal/include/userver/compiler/select.hpp",

redis/include/userver/storages/redis/command_control.hpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
#include <atomic>
77
#include <chrono>
8+
#include <compare>
89
#include <cstdint>
910
#include <optional>
1011
#include <string>
1112

12-
#include <userver/compiler/impl/three_way_comparison.hpp>
1313
#include <userver/storages/redis/fwd.hpp>
1414

1515
USERVER_NAMESPACE_BEGIN
@@ -32,14 +32,7 @@ class ServerId {
3232

3333
bool IsAny() const { return id_ == -1; }
3434

35-
#ifdef USERVER_IMPL_HAS_THREE_WAY_COMPARISON
3635
auto operator<=>(const ServerId&) const = default;
37-
#else
38-
bool operator==(const ServerId& other) const { return other.id_ == id_; }
39-
bool operator!=(const ServerId& other) const { return !(other == *this); }
40-
41-
bool operator<(const ServerId& other) const { return id_ < other.id_; }
42-
#endif
4336

4437
static ServerId Generate() {
4538
ServerId sid;
@@ -147,9 +140,7 @@ struct CommandControl {
147140
) noexcept
148141
: timeout_single(timeout_single), timeout_all(timeout_all), max_retries(max_retries) {}
149142

150-
#ifdef USERVER_IMPL_HAS_THREE_WAY_COMPARISON
151143
auto operator<=>(const CommandControl&) const = default;
152-
#endif
153144

154145
CommandControl MergeWith(const CommandControl& b) const;
155146
CommandControl MergeWith(const testsuite::RedisControl&) const;

redis/src/storages/redis/command_control_test.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
USERVER_NAMESPACE_BEGIN
66

7-
#ifdef USERVER_IMPL_HAS_THREE_WAY_COMPARISON
87
TEST(CommandControl, Comparison) {
98
const storages::redis::CommandControl cc1{std::chrono::milliseconds(500), std::chrono::milliseconds(500), 1};
109
const storages::redis::CommandControl cc2{std::chrono::milliseconds(500), std::chrono::milliseconds(500), 2};
@@ -17,6 +16,5 @@ TEST(CommandControl, Comparison) {
1716
EXPECT_EQ(cc2, cc2);
1817
EXPECT_EQ(cc3, cc3);
1918
}
20-
#endif
2119

2220
USERVER_NAMESPACE_END

scripts/docs/doxygen.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2576,7 +2576,6 @@ INCLUDE_FILE_PATTERNS =
25762576

25772577
PREDEFINED = __attribute__(x)= \
25782578
DOXYGEN \
2579-
USERVER_IMPL_HAS_THREE_WAY_COMPARISON \
25802579
"USERVER_NAMESPACE=" \
25812580
"USERVER_NAMESPACE_BEGIN=" \
25822581
"USERVER_NAMESPACE_END="

universal/include/userver/compiler/impl/three_way_comparison.hpp

Lines changed: 0 additions & 13 deletions
This file was deleted.

universal/include/userver/decimal64/decimal64.hpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include <array>
2222
#include <cassert>
23+
#include <compare>
2324
#include <cstdint>
2425
#include <ios>
2526
#include <iosfwd>
@@ -35,7 +36,6 @@
3536
#include <fmt/compile.h>
3637
#include <fmt/format.h>
3738

38-
#include <userver/compiler/impl/three_way_comparison.hpp>
3939
#include <userver/decimal64/format_options.hpp>
4040
#include <userver/formats/common/meta.hpp>
4141
#include <userver/utils/assert.hpp>
@@ -573,21 +573,7 @@ class Decimal {
573573
return *this;
574574
}
575575

576-
#ifdef USERVER_IMPL_HAS_THREE_WAY_COMPARISON
577576
constexpr auto operator<=>(const Decimal& rhs) const = default;
578-
#else
579-
constexpr bool operator==(Decimal rhs) const { return value_ == rhs.value_; }
580-
581-
constexpr bool operator!=(Decimal rhs) const { return value_ != rhs.value_; }
582-
583-
constexpr bool operator<(Decimal rhs) const { return value_ < rhs.value_; }
584-
585-
constexpr bool operator<=(Decimal rhs) const { return value_ <= rhs.value_; }
586-
587-
constexpr bool operator>(Decimal rhs) const { return value_ > rhs.value_; }
588-
589-
constexpr bool operator>=(Decimal rhs) const { return value_ >= rhs.value_; }
590-
#endif
591577

592578
constexpr Decimal operator+() const { return *this; }
593579

universal/include/userver/utils/datetime/date.hpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
/// @brief @copybrief utils::datetime::Date
55

66
#include <chrono>
7+
#include <compare>
78
#include <iosfwd>
89
#include <stdexcept>
910
#include <string>
1011

11-
#include <userver/compiler/impl/three_way_comparison.hpp>
1212
#include <userver/formats/common/meta.hpp>
1313

1414
USERVER_NAMESPACE_BEGIN
@@ -50,16 +50,7 @@ class Date final {
5050
/// @copydoc GetSysDays()
5151
constexpr explicit operator SysDays() const { return sys_days_; }
5252

53-
#ifdef USERVER_IMPL_HAS_THREE_WAY_COMPARISON
5453
constexpr auto operator<=>(const Date&) const = default;
55-
#else
56-
constexpr bool operator==(Date other) const { return sys_days_ == other.sys_days_; }
57-
constexpr bool operator!=(Date other) const { return !(*this == other); }
58-
constexpr bool operator<(Date other) const { return sys_days_ < other.sys_days_; }
59-
constexpr bool operator<=(Date other) const { return sys_days_ <= other.sys_days_; }
60-
constexpr bool operator>(Date other) const { return sys_days_ > other.sys_days_; }
61-
constexpr bool operator>=(Date other) const { return sys_days_ >= other.sys_days_; }
62-
#endif
6354

6455
private:
6556
SysDays sys_days_{};

universal/include/userver/utils/strong_typedef.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/// @file userver/utils/strong_typedef.hpp
44
/// @brief @copybrief utils::StrongTypedef
55

6+
#include <compare>
67
#include <functional>
78
#include <iosfwd>
89
#include <string>
@@ -15,7 +16,6 @@
1516
#include <boost/functional/hash_fwd.hpp>
1617

1718
#include <userver/compiler/impl/lifetime.hpp>
18-
#include <userver/compiler/impl/three_way_comparison.hpp>
1919
#include <userver/formats/common/meta.hpp>
2020
#include <userver/utils/meta.hpp>
2121
#include <userver/utils/strong_typedef_fwd.hpp>
@@ -296,10 +296,7 @@ UTILS_STRONG_TYPEDEF_REL_OP(<)
296296
UTILS_STRONG_TYPEDEF_REL_OP(>)
297297
UTILS_STRONG_TYPEDEF_REL_OP(<=)
298298
UTILS_STRONG_TYPEDEF_REL_OP(>=)
299-
300-
#ifdef USERVER_IMPL_HAS_THREE_WAY_COMPARISON
301299
UTILS_STRONG_TYPEDEF_REL_OP(<=>)
302-
#endif
303300

304301
#undef UTILS_STRONG_TYPEDEF_REL_OP
305302

universal/include/userver/utils/time_of_day.hpp

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
#include <algorithm>
77
#include <array>
88
#include <chrono>
9+
#include <compare>
910
#include <string_view>
1011
#include <type_traits>
1112
#include <vector>
1213

1314
#include <fmt/format.h>
1415

15-
#include <userver/compiler/impl/three_way_comparison.hpp>
1616
#include <userver/utils/fmt_compat.hpp>
1717

1818
USERVER_NAMESPACE_BEGIN
@@ -86,17 +86,7 @@ class TimeOfDay<std::chrono::duration<Rep, Period>> {
8686

8787
//@{
8888
/** @name Comparison operators */
89-
90-
#ifdef USERVER_IMPL_HAS_THREE_WAY_COMPARISON
9189
constexpr auto operator<=>(const TimeOfDay&) const = default;
92-
#else
93-
constexpr bool operator==(const TimeOfDay&) const;
94-
constexpr bool operator!=(const TimeOfDay&) const;
95-
constexpr bool operator<(const TimeOfDay&) const;
96-
constexpr bool operator<=(const TimeOfDay&) const;
97-
constexpr bool operator>(const TimeOfDay&) const;
98-
constexpr bool operator>=(const TimeOfDay&) const;
99-
#endif
10090
//@}
10191

10292
//@{
@@ -422,38 +412,6 @@ constexpr TimeOfDay<std::chrono::duration<Rep, Period>>::TimeOfDay(std::string_v
422412
: since_midnight_{detail::TimeOfDayParser<Rep, Period>{}(str)}
423413
{}
424414

425-
#ifndef USERVER_IMPL_HAS_THREE_WAY_COMPARISON
426-
template <typename Rep, typename Period>
427-
constexpr bool TimeOfDay<std::chrono::duration<Rep, Period>>::operator==(const TimeOfDay& rhs) const {
428-
return since_midnight_ == rhs.since_midnight_;
429-
}
430-
431-
template <typename Rep, typename Period>
432-
constexpr bool TimeOfDay<std::chrono::duration<Rep, Period>>::operator!=(const TimeOfDay& rhs) const {
433-
return !(*this == rhs);
434-
}
435-
436-
template <typename Rep, typename Period>
437-
constexpr bool TimeOfDay<std::chrono::duration<Rep, Period>>::operator<(const TimeOfDay& rhs) const {
438-
return since_midnight_ < rhs.since_midnight_;
439-
}
440-
441-
template <typename Rep, typename Period>
442-
constexpr bool TimeOfDay<std::chrono::duration<Rep, Period>>::operator<=(const TimeOfDay& rhs) const {
443-
return since_midnight_ <= rhs.since_midnight_;
444-
}
445-
446-
template <typename Rep, typename Period>
447-
constexpr bool TimeOfDay<std::chrono::duration<Rep, Period>>::operator>(const TimeOfDay& rhs) const {
448-
return since_midnight_ > rhs.since_midnight_;
449-
}
450-
451-
template <typename Rep, typename Period>
452-
constexpr bool TimeOfDay<std::chrono::duration<Rep, Period>>::operator>=(const TimeOfDay& rhs) const {
453-
return since_midnight_ >= rhs.since_midnight_;
454-
}
455-
#endif
456-
457415
template <typename Rep, typename Period>
458416
constexpr std::chrono::minutes TimeOfDay<std::chrono::duration<Rep, Period>>::Minutes() const noexcept {
459417
if constexpr (detail::kHasMinutes<Period>) {

universal/src/decimal64/decimal64_test.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <userver/decimal64/decimal64.hpp>
22

3+
#include <compare>
34
#include <limits>
45
#include <unordered_map>
56

@@ -217,12 +218,10 @@ TEST(Decimal64, DivisionByZero) {
217218
EXPECT_THROW(Dec4{1} / 0, decimal64::DivisionByZeroError);
218219
}
219220

220-
#ifdef USERVER_IMPL_HAS_THREE_WAY_COMPARISON
221221
TEST(Decimal64, ThreeWayComparison) {
222222
EXPECT_EQ(Dec4{1} <=> Dec4{1}, 1 <=> 1);
223223
EXPECT_EQ(Dec4{1} <=> Dec4{2}, 1 <=> 2);
224224
}
225-
#endif
226225

227226
TEST(Decimal64, RoundToMultipleOf) {
228227
const auto dec = Dec4{"12.346"};

0 commit comments

Comments
 (0)