Skip to content

Commit 1c4aed7

Browse files
committed
fix clang-tidy warning
Signed-off-by: Junwang Zhao <[email protected]>
1 parent 4bd3010 commit 1c4aed7

File tree

1 file changed

+77
-52
lines changed

1 file changed

+77
-52
lines changed

src/iceberg/expected.h

Lines changed: 77 additions & 52 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)
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;
@@ -352,7 +354,7 @@ struct storage_base {
352354
storage_base& operator=(storage_base&&) = default;
353355

354356
constexpr storage_base() noexcept(noexcept(T{})) : m_val(T{}), m_has_val(true) {}
355-
constexpr storage_base(no_init_t) noexcept : m_no_init(), m_has_val(false) {}
357+
constexpr explicit storage_base(no_init_t) noexcept : m_no_init(), m_has_val(false) {}
356358

357359
template <class... Args,
358360
std::enable_if_t<std::is_constructible_v<T, Args&&...>>* = nullptr>
@@ -418,7 +420,7 @@ struct storage_base<T, E, false> {
418420
storage_base& operator=(storage_base&&) = default;
419421

420422
constexpr storage_base() noexcept(noexcept(T{})) : m_val(T{}), m_has_val(true) {}
421-
constexpr storage_base(no_init_t) noexcept : m_no_init(), m_has_val(false) {}
423+
constexpr explicit storage_base(no_init_t) noexcept : m_no_init(), m_has_val(false) {}
422424

423425
template <class... Args,
424426
std::enable_if_t<std::is_constructible_v<T, Args&&...>>* = nullptr>
@@ -496,7 +498,7 @@ struct storage_base<void, E, true> {
496498

497499
constexpr storage_base() noexcept : m_has_val(true) {}
498500

499-
constexpr storage_base(no_init_t) noexcept : m_val(), m_has_val(false) {}
501+
constexpr explicit storage_base(no_init_t) noexcept : m_val(), m_has_val(false) {}
500502

501503
constexpr explicit storage_base(std::in_place_t) noexcept : m_has_val(true) {}
502504

@@ -542,7 +544,7 @@ struct storage_base<void, E, false> {
542544

543545
constexpr storage_base() noexcept : m_has_val(true) {}
544546

545-
constexpr storage_base(no_init_t) noexcept : m_val(), m_has_val(false) {}
547+
constexpr explicit storage_base(no_init_t) noexcept : m_val(), m_has_val(false) {}
546548

547549
constexpr explicit storage_base(std::in_place_t) noexcept : m_has_val(true) {}
548550

@@ -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

@@ -1038,7 +1040,7 @@ class ICEBERG_EXPORT [[nodiscard]] expected
10381040
std::is_convertible_v<const G&, E>>* = nullptr,
10391041
expected_detail::enable_from_other_expected_t<T, E, U, G, const U&,
10401042
const G&>* = nullptr>
1041-
constexpr expected(const expected<U, G>& rhs) //
1043+
constexpr explicit expected(const expected<U, G>& rhs) //
10421044
noexcept(std::is_nothrow_constructible_v<T, const U&> &&
10431045
std::is_nothrow_constructible_v<E, const G&>)
10441046
: ctor_base(expected_detail::default_constructor_tag{}) {
@@ -1071,7 +1073,7 @@ class ICEBERG_EXPORT [[nodiscard]] expected
10711073
std::enable_if_t<std::is_convertible_v<U, T> &&
10721074
std::is_convertible_v<G, E>>* = nullptr,
10731075
expected_detail::enable_from_other_expected_t<T, E, U, G, U, G>* = nullptr>
1074-
constexpr expected(expected<U, G>&& rhs) //
1076+
constexpr explicit expected(expected<U, G>&& rhs) //
10751077
noexcept(std::is_nothrow_constructible_v<T, U> &&
10761078
std::is_nothrow_constructible_v<E, G>)
10771079
: ctor_base(expected_detail::default_constructor_tag{}) {
@@ -1105,7 +1107,7 @@ class ICEBERG_EXPORT [[nodiscard]] expected
11051107
// implicit
11061108
template <class U = T, std::enable_if_t<std::is_convertible_v<U, T>>* = nullptr,
11071109
expected_detail::enable_forward_t<T, E, U>* = nullptr>
1108-
constexpr expected(U&& v) noexcept(std::is_nothrow_constructible_v<T, U>)
1110+
constexpr explicit expected(U&& v) noexcept(std::is_nothrow_constructible_v<T, U>)
11091111
: expected(std::in_place, std::forward<U>(v)) {}
11101112

11111113
// explicit
@@ -1129,7 +1131,7 @@ class ICEBERG_EXPORT [[nodiscard]] expected
11291131
template <class G, //
11301132
std::enable_if_t<std::is_convertible_v<const G&, E>>* = nullptr, //
11311133
std::enable_if_t<std::is_constructible_v<E, const G&>>* = nullptr>
1132-
constexpr expected(unexpected<G> const& e) noexcept(
1134+
constexpr explicit expected(unexpected<G> const& e) noexcept(
11331135
std::is_nothrow_constructible_v<E, const G&>)
11341136
: impl_base(unexpect, e.error()),
11351137
ctor_base(expected_detail::default_constructor_tag{}) {}
@@ -1147,7 +1149,8 @@ class ICEBERG_EXPORT [[nodiscard]] expected
11471149
template <class G, //
11481150
std::enable_if_t<std::is_convertible_v<G, E>>* = nullptr, //
11491151
std::enable_if_t<std::is_constructible_v<E, G>>* = nullptr>
1150-
constexpr expected(unexpected<G>&& e) noexcept(std::is_nothrow_constructible_v<E, G>)
1152+
constexpr explicit expected(unexpected<G>&& e) noexcept(
1153+
std::is_nothrow_constructible_v<E, G>)
11511154
: impl_base(unexpect, std::move(e.error())),
11521155
ctor_base(expected_detail::default_constructor_tag{}) {}
11531156

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

1491-
if (has_value())
1494+
if (has_value()) {
14921495
return std::invoke(std::forward<F>(f), this->m_val);
1493-
else
1496+
1497+
} else {
14941498
return U(unexpect, error());
1499+
}
14951500
}
14961501
template <class F, class GE = E,
14971502
std::enable_if_t<std::is_constructible_v<GE, const GE&>>* = nullptr>
@@ -1502,10 +1507,11 @@ class ICEBERG_EXPORT [[nodiscard]] expected
15021507
static_assert(std::is_same_v<typename U::error_type, E>,
15031508
"The error type must be the same after calling the F");
15041509

1505-
if (has_value())
1510+
if (has_value()) {
15061511
return std::invoke(std::forward<F>(f), this->m_val);
1507-
else
1512+
} else {
15081513
return U(unexpect, error());
1514+
}
15091515
}
15101516

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

1521-
if (has_value())
1527+
if (has_value()) {
15221528
return std::invoke(std::forward<F>(f), std::move(this->m_val));
1523-
else
1529+
} else {
15241530
return U(unexpect, std::move(error()));
1531+
}
15251532
}
15261533
template <class F, class GE = E,
15271534
std::enable_if_t<std::is_constructible_v<GE, const GE>>* = nullptr>
@@ -1533,10 +1540,11 @@ class ICEBERG_EXPORT [[nodiscard]] expected
15331540
static_assert(std::is_same_v<typename U::error_type, E>,
15341541
"The error type must be the same after calling the F");
15351542

1536-
if (has_value())
1543+
if (has_value()) {
15371544
return std::invoke(std::forward<F>(f), std::move(this->m_val));
1538-
else
1545+
} else {
15391546
return U(unexpect, std::move(error()));
1547+
}
15401548
}
15411549

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

1551-
if (has_value())
1559+
if (has_value()) {
15521560
return G(std::in_place, this->m_val);
1553-
else
1561+
} else {
15541562
return std::invoke(std::forward<F>(f), error());
1563+
}
15551564
}
15561565
template <class F, class UT = T,
15571566
std::enable_if_t<std::is_constructible_v<UT, const UT&>>* = nullptr>
@@ -1562,10 +1571,12 @@ class ICEBERG_EXPORT [[nodiscard]] expected
15621571
static_assert(std::is_same_v<typename G::value_type, T>,
15631572
"The value type must be the same after calling the F");
15641573

1565-
if (has_value())
1574+
if (has_value()) {
15661575
return G(std::in_place, this->m_val);
1567-
else
1576+
1577+
} else {
15681578
return std::invoke(std::forward<F>(f), error());
1579+
}
15691580
}
15701581
template <class F, class UT = T,
15711582
std::enable_if_t<std::is_constructible_v<UT, UT&&>>* = nullptr>
@@ -1576,10 +1587,11 @@ class ICEBERG_EXPORT [[nodiscard]] expected
15761587
static_assert(std::is_same_v<typename G::value_type, T>,
15771588
"The value type must be the same after calling the F");
15781589

1579-
if (has_value())
1590+
if (has_value()) {
15801591
return G(std::in_place, std::move(this->m_val));
1581-
else
1592+
} else {
15821593
return std::invoke(std::forward<F>(f), std::move(error()));
1594+
}
15831595
}
15841596
template <class F, class UT = T,
15851597
std::enable_if_t<std::is_constructible_v<UT, const UT>>* = nullptr>
@@ -1590,10 +1602,11 @@ class ICEBERG_EXPORT [[nodiscard]] expected
15901602
static_assert(std::is_same_v<typename G::value_type, T>,
15911603
"The value type must be the same after calling the F");
15921604

1593-
if (has_value())
1605+
if (has_value()) {
15941606
return G(std::in_place, std::move(this->m_val));
1595-
else
1607+
} else {
15961608
return std::invoke(std::forward<F>(f), std::move(error()));
1609+
}
15971610
}
15981611

15991612
template <class F, class GE = E,
@@ -1801,9 +1814,9 @@ class ICEBERG_EXPORT [[nodiscard]] expected<void, E>
18011814
using ctor_base = expected_detail::default_ctor_base<T, E>;
18021815

18031816
public:
1804-
typedef T value_type;
1805-
typedef E error_type;
1806-
typedef unexpected<E> unexpected_type;
1817+
using value_type = T;
1818+
using error_type = E;
1819+
using unexpected_type = unexpected<E>;
18071820

18081821
constexpr expected() = default;
18091822
constexpr expected(const expected& rhs) = default;
@@ -1814,7 +1827,7 @@ class ICEBERG_EXPORT [[nodiscard]] expected<void, E>
18141827
class G, //
18151828
std::enable_if_t<std::is_convertible_v<const G&, E>>* = nullptr, //
18161829
expected_detail::enable_from_other_void_expected_t<E, U, G, const G&>* = nullptr>
1817-
constexpr expected(const expected<U, G>& rhs) noexcept(
1830+
constexpr explicit expected(const expected<U, G>& rhs) noexcept(
18181831
std::is_nothrow_constructible_v<E, const G&>)
18191832
: ctor_base(expected_detail::default_constructor_tag{}) {
18201833
if (rhs.has_value()) {
@@ -1843,7 +1856,8 @@ class ICEBERG_EXPORT [[nodiscard]] expected<void, E>
18431856
class G, //
18441857
std::enable_if_t<std::is_convertible_v<G, E>>* = nullptr, //
18451858
expected_detail::enable_from_other_void_expected_t<E, U, G, G>* = nullptr>
1846-
constexpr expected(expected<U, G>&& rhs) noexcept(std::is_nothrow_constructible_v<E, G>)
1859+
constexpr explicit expected(expected<U, G>&& rhs) noexcept(
1860+
std::is_nothrow_constructible_v<E, G>)
18471861
: ctor_base(expected_detail::default_constructor_tag{}) {
18481862
if (rhs.has_value()) {
18491863
this->construct();
@@ -1881,7 +1895,7 @@ class ICEBERG_EXPORT [[nodiscard]] expected<void, E>
18811895
template <class G, //
18821896
std::enable_if_t<std::is_convertible_v<const G&, E>>* = nullptr, //
18831897
std::enable_if_t<std::is_constructible_v<E, const G&>>* = nullptr>
1884-
constexpr expected(unexpected<G> const& e) noexcept(
1898+
constexpr explicit expected(unexpected<G> const& e) noexcept(
18851899
std::is_nothrow_constructible_v<E, const G&>)
18861900
: impl_base(unexpect, e.error()),
18871901
ctor_base(expected_detail::default_constructor_tag{}) {}
@@ -1899,7 +1913,8 @@ class ICEBERG_EXPORT [[nodiscard]] expected<void, E>
18991913
template <class G, //
19001914
std::enable_if_t<std::is_convertible_v<G, E>>* = nullptr, //
19011915
std::enable_if_t<std::is_constructible_v<E, G>>* = nullptr>
1902-
constexpr expected(unexpected<G>&& e) noexcept(std::is_nothrow_constructible_v<E, G>)
1916+
constexpr explicit expected(unexpected<G>&& e) noexcept(
1917+
std::is_nothrow_constructible_v<E, G>)
19031918
: impl_base(unexpect, std::move(e.error())),
19041919
ctor_base(expected_detail::default_constructor_tag{}) {}
19051920

@@ -2068,10 +2083,11 @@ class ICEBERG_EXPORT [[nodiscard]] expected<void, E>
20682083
static_assert(std::is_same_v<typename U::error_type, E>,
20692084
"The error type must be the same after calling the F");
20702085

2071-
if (has_value())
2086+
if (has_value()) {
20722087
return std::invoke(std::forward<F>(f));
2073-
else
2088+
} else {
20742089
return U(unexpect, error());
2090+
}
20752091
}
20762092
template <class F, class GE = E,
20772093
std::enable_if_t<std::is_constructible_v<GE, const GE&>>* = nullptr>
@@ -2082,10 +2098,11 @@ class ICEBERG_EXPORT [[nodiscard]] expected<void, E>
20822098
static_assert(std::is_same_v<typename U::error_type, E>,
20832099
"The error type must be the same after calling the F");
20842100

2085-
if (has_value())
2101+
if (has_value()) {
20862102
return std::invoke(std::forward<F>(f));
2087-
else
2103+
} else {
20882104
return U(unexpect, error());
2105+
}
20892106
}
20902107
template <class F, class GE = E,
20912108
std::enable_if_t<std::is_constructible_v<GE, GE&&>>* = nullptr>
@@ -2096,10 +2113,11 @@ class ICEBERG_EXPORT [[nodiscard]] expected<void, E>
20962113
static_assert(std::is_same_v<typename U::error_type, E>,
20972114
"The error type must be the same after calling the F");
20982115

2099-
if (has_value())
2116+
if (has_value()) {
21002117
return std::invoke(std::forward<F>(f));
2101-
else
2118+
} else {
21022119
return U(unexpect, std::move(error()));
2120+
}
21032121
}
21042122
template <class F, class GE = E,
21052123
std::enable_if_t<std::is_constructible_v<GE, const GE>>* = nullptr>
@@ -2110,10 +2128,11 @@ class ICEBERG_EXPORT [[nodiscard]] expected<void, E>
21102128
static_assert(std::is_same_v<typename U::error_type, E>,
21112129
"The error type must be the same after calling the F");
21122130

2113-
if (has_value())
2131+
if (has_value()) {
21142132
return std::invoke(std::forward<F>(f));
2115-
else
2133+
} else {
21162134
return U(unexpect, std::move(error()));
2135+
}
21172136
}
21182137

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

2127-
if (has_value())
2146+
if (has_value()) {
21282147
return G();
2129-
else
2148+
} else {
21302149
return std::invoke(std::forward<F>(f), error());
2150+
}
21312151
}
21322152
template <class F>
21332153
constexpr auto or_else(F&& f) const& {
@@ -2137,10 +2157,11 @@ class ICEBERG_EXPORT [[nodiscard]] expected<void, E>
21372157
static_assert(std::is_same_v<typename G::value_type, T>,
21382158
"The value type must be the same after calling the F");
21392159

2140-
if (has_value())
2160+
if (has_value()) {
21412161
return G();
2142-
else
2162+
} else {
21432163
return std::invoke(std::forward<F>(f), error());
2164+
}
21442165
}
21452166
template <class F>
21462167
constexpr auto or_else(F&& f) && {
@@ -2150,10 +2171,11 @@ class ICEBERG_EXPORT [[nodiscard]] expected<void, E>
21502171
static_assert(std::is_same_v<typename G::value_type, T>,
21512172
"The value type must be the same after calling the F");
21522173

2153-
if (has_value())
2174+
if (has_value()) {
21542175
return G();
2155-
else
2176+
} else {
21562177
return std::invoke(std::forward<F>(f), std::move(error()));
2178+
}
21572179
}
21582180
template <class F>
21592181
constexpr auto or_else(F&& f) const&& {
@@ -2163,10 +2185,11 @@ class ICEBERG_EXPORT [[nodiscard]] expected<void, E>
21632185
static_assert(std::is_same_v<typename G::value_type, T>,
21642186
"The value type must be the same after calling the F");
21652187

2166-
if (has_value())
2188+
if (has_value()) {
21672189
return G();
2168-
else
2190+
} else {
21692191
return std::invoke(std::forward<F>(f), std::move(error()));
2192+
}
21702193
}
21712194

21722195
template <class F, class GE = E,
@@ -2331,3 +2354,5 @@ ICEBERG_EXPORT constexpr void swap(
23312354
}
23322355

23332356
} // namespace iceberg
2357+
2358+
// NOLINTEND(modernize-use-constraints)

0 commit comments

Comments
 (0)