Skip to content

Commit a821b32

Browse files
committed
refactor(*): applying deducing this language feature
1 parent f6747f2 commit a821b32

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+785
-1132
lines changed

.clang-format

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ AlignOperands: DontAlign
1010
AlignTrailingComments: false
1111
AllowAllArgumentsOnNextLine: false
1212
AllowAllParametersOfDeclarationOnNextLine: false
13+
AllowBreakBeforeNoexceptSpecifier: OnlyWithParen
1314
AllowShortBlocksOnASingleLine: Always
15+
AllowShortCompoundRequirementOnASingleLine: true
1416
AllowShortCaseLabelsOnASingleLine: true
1517
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
1618
AllowShortLoopsOnASingleLine: true

.clang-tidy

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ Checks: # enabled
3535
-*-rvalue-reference-param-not-moved,
3636
-*-include-cleaner,
3737
-*-swappable-parameters,
38-
-*-reserved-identifier'
38+
-*-reserved-identifier,
39+
-cert-dcl58-cpp,
40+
-*-avoid-nested-conditional-operator,
41+
-*-inc-dec-in-conditions'
3942
# disabled alias
4043
- '-bugprone-narrowing-conversions,
4144
-cert-con36-c,
@@ -90,6 +93,7 @@ Checks: # enabled
9093
-clang-analyzer-nullability.NullableDereferenced,
9194
-clang-analyzer-nullability.NullablePassedToNonnull,
9295
-clang-analyzer-nullability.NullableReturnedFromNonnull,
96+
-clang-analyzer-optin.core.EnumCastOutOfRange,
9397
-clang-analyzer-optin.cplusplus.UninitializedObject,
9498
-clang-analyzer-optin.cplusplus.VirtualCall,
9599
-clang-analyzer-optin.mpi.MPI-Checker,
@@ -129,6 +133,7 @@ Checks: # enabled
129133
-clang-analyzer-osx.coreFoundation.containers.OutOfBounds,
130134
-clang-analyzer-osx.coreFoundation.containers.PointerSizedValues,
131135
-clang-analyzer-security.FloatLoopCounter,
136+
-clang-analyzer-security.cert.env.InvalidPtr,
132137
-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,
133138
-clang-analyzer-security.insecureAPI.UncheckedReturn,
134139
-clang-analyzer-security.insecureAPI.bcmp,
@@ -143,9 +148,11 @@ Checks: # enabled
143148
-clang-analyzer-security.insecureAPI.strcpy,
144149
-clang-analyzer-security.insecureAPI.vfork,
145150
-clang-analyzer-unix.API,
151+
-clang-analyzer-unix.Errno,
146152
-clang-analyzer-unix.Malloc,
147153
-clang-analyzer-unix.MallocSizeof,
148154
-clang-analyzer-unix.MismatchedDeallocator,
155+
-clang-analyzer-unix.StdCLibraryFunctions,
149156
-clang-analyzer-unix.Vfork,
150157
-clang-analyzer-unix.cstring.BadSizeArg,
151158
-clang-analyzer-unix.cstring.NullArg,

include/stdsharp/algorithm/algorithm.h

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,56 +7,59 @@
77

88
namespace stdsharp
99
{
10-
inline constexpr auto set_if = []<typename T, typename U, std::predicate<U, T> Comp>
11-
requires std::assignable_from<T&, U> // clang-format off
12-
(T& left, U&& right, Comp comp = {})
13-
noexcept(nothrow_predicate<Comp, U, T> && nothrow_assignable_from<T&, U>)
14-
-> T& // clang-format on
10+
inline constexpr struct set_if_fn
1511
{
16-
if(invoke(cpp_move(comp), right, left)) left = cpp_forward(right);
17-
return left;
18-
};
19-
20-
using set_if_fn = decltype(set_if);
21-
22-
inline constexpr auto set_if_greater = []<typename T, typename U>
23-
requires std::invocable<set_if_fn, T&, U, std::ranges::greater> // clang-format off
24-
(T & left, U && right)
25-
noexcept(nothrow_invocable<set_if_fn, T&, U, std::ranges::greater>) -> T& // clang-format on
26-
{ return set_if(left, cpp_forward(right), greater_v); };
27-
28-
using set_if_greater_fn = decltype(set_if_greater);
12+
template<typename T, typename U, std::predicate<U, T> Comp>
13+
requires std::assignable_from<T&, U>
14+
constexpr T& operator()(T& left, U&& right, Comp comp = {}) const
15+
noexcept(nothrow_predicate<Comp, U, T> && nothrow_assignable_from<T&, U>)
16+
{
17+
if(invoke(cpp_move(comp), right, left)) left = cpp_forward(right);
18+
return left;
19+
}
20+
} set_if{};
2921

30-
inline constexpr auto set_if_less = []<typename T, typename U>
31-
requires std::invocable<set_if_fn, T&, U, std::ranges::less> // clang-format off
32-
(T& left, U&& right)
33-
noexcept(nothrow_invocable<set_if_fn, T&, U, std::ranges::less>) -> T& // clang-format on
34-
{ return set_if(left, cpp_forward(right), less_v); };
22+
inline constexpr struct set_if_greater_fn
23+
{
24+
template<typename T, typename U>
25+
requires std::invocable<set_if_fn, T&, U, std::ranges::greater>
26+
constexpr T& operator()(T& left, U&& right) const
27+
noexcept(nothrow_invocable<set_if_fn, T&, U, std::ranges::greater>)
28+
{
29+
return set_if(left, cpp_forward(right), greater_v);
30+
}
31+
} set_if_greater{};
3532

36-
using set_if_less_fn = decltype(set_if_less);
33+
inline constexpr struct set_if_less_fn
34+
{
35+
template<typename T, typename U>
36+
requires std::invocable<set_if_fn, T&, U, std::ranges::less>
37+
constexpr T& operator()(T& left, U&& right) const
38+
noexcept(nothrow_invocable<set_if_fn, T&, U, std::ranges::less>)
39+
{
40+
return set_if(left, cpp_forward(right), less_v);
41+
}
42+
} set_if_less{};
3743

3844
inline constexpr struct is_between_fn
3945
{
4046
template<
4147
typename T,
4248
typename Proj = std::identity,
4349
std::indirect_strict_weak_order<std::projected<const T*, Proj>> Compare =
44-
std::ranges::less // clang-format off
45-
> // clang-format on
46-
[[nodiscard]] constexpr auto operator()( // NOLINTBEGIN(*-easily-swappable-parameters)
50+
std::ranges::less>
51+
[[nodiscard]] constexpr auto operator()(
4752
const T& t,
48-
const T& min,
49-
const T& max,
53+
decltype(t) min,
54+
decltype(t) max,
5055
Compare cmp = {},
5156
Proj proj = {}
52-
) const // NOLINTEND(*-easily-swappable-parameters)
53-
noexcept( //
54-
nothrow_predicate<
55-
Compare,
56-
std::projected<const T*, Proj>,
57-
std::projected<const T*, Proj> // clang-format off
58-
> // clang-format on
59-
)
57+
) const noexcept( //
58+
nothrow_predicate<
59+
Compare,
60+
std::projected<const T*, Proj>,
61+
std::projected<const T*, Proj>> //
62+
)
6063
{
6164
const auto& proj_max = invoke(proj, max);
6265
const auto& proj_min = invoke(proj, min);

include/stdsharp/array/array.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ namespace stdsharp
1919
std::array<value_type, N> arr{};
2020

2121
std::ranges::copy(
22-
cpp_forward(rng) | //
23-
std::views::transform(proj) | //
24-
std::views::take(N),
22+
cpp_forward(rng) | std::views::transform(proj) | std::views::take(N),
2523
arr.begin()
2624
);
2725

include/stdsharp/cassert/cassert.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,4 @@ namespace stdsharp
3838

3939
inline constexpr auto assert_not_null = //
4040
[](const nullable_pointer auto& ptr) noexcept { assert_not_equal(ptr, nullptr); };
41-
4241
}

include/stdsharp/compilation_config_in.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717

1818
#ifdef _MSC_VER
1919
#define STDSHARP_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
20-
#define STDSHARP_INTRINSIC [[msvc::intrinsic]]
20+
#define STDSHARP_INTRINSIC [[msvc::intrinsic]]
2121
#else
2222
#define STDSHARP_NO_UNIQUE_ADDRESS [[no_unique_address]]
23-
#define STDSHARP_INTRINSIC STDSHARP_ALWAYS_INLINE
23+
#define STDSHARP_INTRINSIC STDSHARP_ALWAYS_INLINE
2424
#endif
2525

2626
#if defined(_MSC_VER) || (defined(_WIN32) && defined(__clang__))

0 commit comments

Comments
 (0)