Skip to content

Commit b80f036

Browse files
committed
fix clang-tidy warning
disable modernize-use-constraints, google-explicit-constructor for backported std:expected since we don't want diverge from upstream. Signed-off-by: Junwang Zhao <[email protected]>
1 parent 4025343 commit b80f036

File tree

1 file changed

+60
-39
lines changed

1 file changed

+60
-39
lines changed

src/iceberg/expected.h

Lines changed: 60 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
#include "iceberg/iceberg_export.h"
2828

29+
// NOLINTBEGIN(modernize-use-constraints, google-explicit-constructor)
30+
2931
namespace iceberg {
3032

3133
namespace expected_detail {
@@ -196,7 +198,7 @@ class bad_expected_access;
196198
template <>
197199
class ICEBERG_EXPORT bad_expected_access<void> : public std::exception {
198200
public:
199-
virtual const char* what() const noexcept override { return "Bad expected access"; }
201+
const char* what() const noexcept override { return "Bad expected access"; }
200202

201203
protected:
202204
bad_expected_access() = default;
@@ -1020,9 +1022,9 @@ class ICEBERG_EXPORT [[nodiscard]] expected
10201022
using ctor_base = expected_detail::default_ctor_base<T, E>;
10211023

10221024
public:
1023-
typedef T value_type;
1024-
typedef E error_type;
1025-
typedef unexpected<E> unexpected_type;
1025+
using value_type = T;
1026+
using error_type = E;
1027+
using unexpected_type = unexpected<E>;
10261028

10271029
// default constructors
10281030

@@ -1488,10 +1490,12 @@ class ICEBERG_EXPORT [[nodiscard]] expected
14881490
static_assert(std::is_same_v<typename U::error_type, E>,
14891491
"The error type must be the same after calling the F");
14901492

1491-
if (has_value())
1493+
if (has_value()) {
14921494
return std::invoke(std::forward<F>(f), this->m_val);
1493-
else
1495+
1496+
} else {
14941497
return U(unexpect, error());
1498+
}
14951499
}
14961500
template <class F, class GE = E,
14971501
std::enable_if_t<std::is_constructible_v<GE, const GE&>>* = nullptr>
@@ -1502,10 +1506,11 @@ class ICEBERG_EXPORT [[nodiscard]] expected
15021506
static_assert(std::is_same_v<typename U::error_type, E>,
15031507
"The error type must be the same after calling the F");
15041508

1505-
if (has_value())
1509+
if (has_value()) {
15061510
return std::invoke(std::forward<F>(f), this->m_val);
1507-
else
1511+
} else {
15081512
return U(unexpect, error());
1513+
}
15091514
}
15101515

15111516
template <class F, class GE = E,
@@ -1518,10 +1523,11 @@ class ICEBERG_EXPORT [[nodiscard]] expected
15181523
static_assert(std::is_same_v<typename U::error_type, E>,
15191524
"The error type must be the same after calling the F");
15201525

1521-
if (has_value())
1526+
if (has_value()) {
15221527
return std::invoke(std::forward<F>(f), std::move(this->m_val));
1523-
else
1528+
} else {
15241529
return U(unexpect, std::move(error()));
1530+
}
15251531
}
15261532
template <class F, class GE = E,
15271533
std::enable_if_t<std::is_constructible_v<GE, const GE>>* = nullptr>
@@ -1533,10 +1539,11 @@ class ICEBERG_EXPORT [[nodiscard]] expected
15331539
static_assert(std::is_same_v<typename U::error_type, E>,
15341540
"The error type must be the same after calling the F");
15351541

1536-
if (has_value())
1542+
if (has_value()) {
15371543
return std::invoke(std::forward<F>(f), std::move(this->m_val));
1538-
else
1544+
} else {
15391545
return U(unexpect, std::move(error()));
1546+
}
15401547
}
15411548

15421549
template <class F, class UT = T,
@@ -1548,10 +1555,11 @@ class ICEBERG_EXPORT [[nodiscard]] expected
15481555
static_assert(std::is_same_v<typename G::value_type, T>,
15491556
"The value type must be the same after calling the F");
15501557

1551-
if (has_value())
1558+
if (has_value()) {
15521559
return G(std::in_place, this->m_val);
1553-
else
1560+
} else {
15541561
return std::invoke(std::forward<F>(f), error());
1562+
}
15551563
}
15561564
template <class F, class UT = T,
15571565
std::enable_if_t<std::is_constructible_v<UT, const UT&>>* = nullptr>
@@ -1562,10 +1570,11 @@ class ICEBERG_EXPORT [[nodiscard]] expected
15621570
static_assert(std::is_same_v<typename G::value_type, T>,
15631571
"The value type must be the same after calling the F");
15641572

1565-
if (has_value())
1573+
if (has_value()) {
15661574
return G(std::in_place, this->m_val);
1567-
else
1575+
} else {
15681576
return std::invoke(std::forward<F>(f), error());
1577+
}
15691578
}
15701579
template <class F, class UT = T,
15711580
std::enable_if_t<std::is_constructible_v<UT, UT&&>>* = nullptr>
@@ -1576,10 +1585,11 @@ class ICEBERG_EXPORT [[nodiscard]] expected
15761585
static_assert(std::is_same_v<typename G::value_type, T>,
15771586
"The value type must be the same after calling the F");
15781587

1579-
if (has_value())
1588+
if (has_value()) {
15801589
return G(std::in_place, std::move(this->m_val));
1581-
else
1590+
} else {
15821591
return std::invoke(std::forward<F>(f), std::move(error()));
1592+
}
15831593
}
15841594
template <class F, class UT = T,
15851595
std::enable_if_t<std::is_constructible_v<UT, const UT>>* = nullptr>
@@ -1590,10 +1600,11 @@ class ICEBERG_EXPORT [[nodiscard]] expected
15901600
static_assert(std::is_same_v<typename G::value_type, T>,
15911601
"The value type must be the same after calling the F");
15921602

1593-
if (has_value())
1603+
if (has_value()) {
15941604
return G(std::in_place, std::move(this->m_val));
1595-
else
1605+
} else {
15961606
return std::invoke(std::forward<F>(f), std::move(error()));
1607+
}
15971608
}
15981609

15991610
template <class F, class GE = E,
@@ -1801,9 +1812,9 @@ class ICEBERG_EXPORT [[nodiscard]] expected<void, E>
18011812
using ctor_base = expected_detail::default_ctor_base<T, E>;
18021813

18031814
public:
1804-
typedef T value_type;
1805-
typedef E error_type;
1806-
typedef unexpected<E> unexpected_type;
1815+
using value_type = T;
1816+
using error_type = E;
1817+
using unexpected_type = unexpected<E>;
18071818

18081819
constexpr expected() = default;
18091820
constexpr expected(const expected& rhs) = default;
@@ -2068,10 +2079,11 @@ class ICEBERG_EXPORT [[nodiscard]] expected<void, E>
20682079
static_assert(std::is_same_v<typename U::error_type, E>,
20692080
"The error type must be the same after calling the F");
20702081

2071-
if (has_value())
2082+
if (has_value()) {
20722083
return std::invoke(std::forward<F>(f));
2073-
else
2084+
} else {
20742085
return U(unexpect, error());
2086+
}
20752087
}
20762088
template <class F, class GE = E,
20772089
std::enable_if_t<std::is_constructible_v<GE, const GE&>>* = nullptr>
@@ -2082,10 +2094,11 @@ class ICEBERG_EXPORT [[nodiscard]] expected<void, E>
20822094
static_assert(std::is_same_v<typename U::error_type, E>,
20832095
"The error type must be the same after calling the F");
20842096

2085-
if (has_value())
2097+
if (has_value()) {
20862098
return std::invoke(std::forward<F>(f));
2087-
else
2099+
} else {
20882100
return U(unexpect, error());
2101+
}
20892102
}
20902103
template <class F, class GE = E,
20912104
std::enable_if_t<std::is_constructible_v<GE, GE&&>>* = nullptr>
@@ -2096,10 +2109,11 @@ class ICEBERG_EXPORT [[nodiscard]] expected<void, E>
20962109
static_assert(std::is_same_v<typename U::error_type, E>,
20972110
"The error type must be the same after calling the F");
20982111

2099-
if (has_value())
2112+
if (has_value()) {
21002113
return std::invoke(std::forward<F>(f));
2101-
else
2114+
} else {
21022115
return U(unexpect, std::move(error()));
2116+
}
21032117
}
21042118
template <class F, class GE = E,
21052119
std::enable_if_t<std::is_constructible_v<GE, const GE>>* = nullptr>
@@ -2110,10 +2124,11 @@ class ICEBERG_EXPORT [[nodiscard]] expected<void, E>
21102124
static_assert(std::is_same_v<typename U::error_type, E>,
21112125
"The error type must be the same after calling the F");
21122126

2113-
if (has_value())
2127+
if (has_value()) {
21142128
return std::invoke(std::forward<F>(f));
2115-
else
2129+
} else {
21162130
return U(unexpect, std::move(error()));
2131+
}
21172132
}
21182133

21192134
template <class F>
@@ -2124,10 +2139,11 @@ class ICEBERG_EXPORT [[nodiscard]] expected<void, E>
21242139
static_assert(std::is_same_v<typename G::value_type, T>,
21252140
"The value type must be the same after calling the F");
21262141

2127-
if (has_value())
2142+
if (has_value()) {
21282143
return G();
2129-
else
2144+
} else {
21302145
return std::invoke(std::forward<F>(f), error());
2146+
}
21312147
}
21322148
template <class F>
21332149
constexpr auto or_else(F&& f) const& {
@@ -2137,10 +2153,11 @@ class ICEBERG_EXPORT [[nodiscard]] expected<void, E>
21372153
static_assert(std::is_same_v<typename G::value_type, T>,
21382154
"The value type must be the same after calling the F");
21392155

2140-
if (has_value())
2156+
if (has_value()) {
21412157
return G();
2142-
else
2158+
} else {
21432159
return std::invoke(std::forward<F>(f), error());
2160+
}
21442161
}
21452162
template <class F>
21462163
constexpr auto or_else(F&& f) && {
@@ -2150,10 +2167,11 @@ class ICEBERG_EXPORT [[nodiscard]] expected<void, E>
21502167
static_assert(std::is_same_v<typename G::value_type, T>,
21512168
"The value type must be the same after calling the F");
21522169

2153-
if (has_value())
2170+
if (has_value()) {
21542171
return G();
2155-
else
2172+
} else {
21562173
return std::invoke(std::forward<F>(f), std::move(error()));
2174+
}
21572175
}
21582176
template <class F>
21592177
constexpr auto or_else(F&& f) const&& {
@@ -2163,10 +2181,11 @@ class ICEBERG_EXPORT [[nodiscard]] expected<void, E>
21632181
static_assert(std::is_same_v<typename G::value_type, T>,
21642182
"The value type must be the same after calling the F");
21652183

2166-
if (has_value())
2184+
if (has_value()) {
21672185
return G();
2168-
else
2186+
} else {
21692187
return std::invoke(std::forward<F>(f), std::move(error()));
2188+
}
21702189
}
21712190

21722191
template <class F, class GE = E,
@@ -2331,3 +2350,5 @@ ICEBERG_EXPORT constexpr void swap(
23312350
}
23322351

23332352
} // namespace iceberg
2353+
2354+
// NOLINTEND(modernize-use-constraints, google-explicit-constructor)

0 commit comments

Comments
 (0)