Skip to content

Commit 5c6966c

Browse files
authored
Merge pull request #280 from elbeno/fix-wnrvo
🚨 Fix warnings arising from `-Wnrvo`
2 parents ebb98cf + e0bf3ec commit 5c6966c

File tree

4 files changed

+44
-31
lines changed

4 files changed

+44
-31
lines changed

include/stdx/bit.hpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,13 @@ template <typename To, typename From> constexpr auto bit_unpack(From arg) {
334334
"bit_unpack is undefined for those types");
335335

336336
constexpr auto sz = sized<From>{1}.template in<To>();
337-
auto r = bit_cast<std::array<To, sz>>(to_be(arg));
338-
for (auto &elem : r) {
339-
elem = from_be(elem);
340-
}
341-
return r;
337+
return [&]() -> std::array<To, sz> {
338+
auto r = bit_cast<std::array<To, sz>>(to_be(arg));
339+
for (auto &elem : r) {
340+
elem = from_be(elem);
341+
}
342+
return r;
343+
}();
342344
}
343345

344346
namespace detail {
@@ -436,14 +438,16 @@ template <std::size_t N> using smallest_uint_t = decltype(smallest_uint<N>());
436438

437439
namespace bit_detail {
438440
template <std::size_t... Offsets>
439-
constexpr auto shifts = [] {
441+
constexpr auto shifts =
442+
[]() -> std::array<std::size_t, sizeof...(Offsets) + 1> {
440443
constexpr auto offsets = std::array{std::size_t{}, Offsets...};
441444
auto s = std::array<std::size_t, sizeof...(Offsets) + 1>{};
442445
for (auto i = std::size_t{}; i < sizeof...(Offsets); ++i) {
443446
s[i + 1] = offsets[i + 1] - offsets[i];
444447
}
445448
return s;
446-
}();
449+
}
450+
();
447451

448452
template <std::size_t Shift, std::size_t Msb, typename T>
449453
constexpr auto shift_extract(T &t) -> T {

include/stdx/ct_format.hpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ CONSTEVAL auto count_specifiers(std::string_view fmt) -> std::size_t {
106106
return count;
107107
}
108108

109-
template <std::size_t N> CONSTEVAL auto split_specifiers(std::string_view fmt) {
109+
template <std::size_t N>
110+
CONSTEVAL auto split_specifiers(std::string_view fmt)
111+
-> std::array<std::string_view, N> {
110112
auto splits = std::array<std::string_view, N>{};
111113
auto count = std::size_t{};
112114

@@ -196,24 +198,26 @@ CONSTEVAL auto convert_output() {
196198
}
197199
}
198200

201+
template <std::size_t N>
202+
CONSTEVAL auto perform_format(auto s, auto v) -> ct_string<N + 1> {
203+
ct_string<N + 1> cts{};
204+
fmt::format_to(cts.begin(), s, v);
205+
return cts;
206+
}
207+
199208
template <ct_string Fmt, typename Arg> constexpr auto format1(Arg arg) {
200209
if constexpr (requires { arg_value(arg); }) {
201210
constexpr auto fmtstr = FMT_COMPILE(std::string_view{Fmt});
202211
constexpr auto a = arg_value(arg);
203-
auto const f = []<std::size_t N>(auto s, auto v) {
204-
ct_string<N + 1> cts{};
205-
fmt::format_to(cts.begin(), s, v);
206-
return cts;
207-
};
208212
if constexpr (is_specialization_of_v<std::remove_cv_t<decltype(a)>,
209213
format_result>) {
210214
constexpr auto s = convert_input(a.str);
211215
constexpr auto sz = fmt::formatted_size(fmtstr, s);
212-
constexpr auto cts = f.template operator()<sz>(fmtstr, s);
216+
constexpr auto cts = perform_format<sz>(fmtstr, s);
213217
return format_result{cts_t<cts>{}, a.args};
214218
} else {
215219
constexpr auto sz = fmt::formatted_size(fmtstr, a);
216-
constexpr auto cts = f.template operator()<sz>(fmtstr, a);
220+
constexpr auto cts = perform_format<sz>(fmtstr, a);
217221
return format_result{cts_t<cts>{}};
218222
}
219223
} else if constexpr (is_specialization_of_v<Arg, format_result>) {

include/stdx/tuple.hpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -369,14 +369,16 @@ struct tuple_impl<std::index_sequence<Is...>, index_function_list<Fs...>, Ts...>
369369
using C =
370370
std::common_comparison_category_t<decltype(lhs[index<Is>] <=>
371371
rhs[index<Is>])...>;
372-
C result = lhs[index<0>] <=> rhs[index<0>];
373-
auto const compare_at = [&]<std::size_t I>() {
374-
result = lhs[index<I>] <=> rhs[index<I>];
375-
return result != 0;
376-
};
377-
[[maybe_unused]] auto b =
378-
(compare_at.template operator()<Is>() or ...);
379-
return result;
372+
return [&]() -> C {
373+
C result = lhs[index<0>] <=> rhs[index<0>];
374+
auto const compare_at = [&]<std::size_t I>() {
375+
result = lhs[index<I>] <=> rhs[index<I>];
376+
return result != 0;
377+
};
378+
[[maybe_unused]] auto b =
379+
(compare_at.template operator()<Is>() or ...);
380+
return result;
381+
}();
380382
}
381383
}
382384
};

include/stdx/tuple_algorithms.hpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ template <typename F, tuplelike... Ts> constexpr auto apply(F &&f, Ts &&...ts) {
2020
constexpr auto total_num_elements =
2121
(std::size_t{} + ... + stdx::tuple_size_v<std::remove_cvref_t<Ts>>);
2222

23-
[[maybe_unused]] constexpr auto element_indices = [&] {
23+
[[maybe_unused]] constexpr auto element_indices =
24+
[&]() -> std::array<detail::index_pair, total_num_elements> {
2425
std::array<detail::index_pair, total_num_elements> indices{};
2526
[[maybe_unused]] auto p = indices.data();
2627
((p = std::remove_cvref_t<Ts>::fill_inner_indices(p)), ...);
@@ -48,7 +49,8 @@ template <tuplelike... Ts> [[nodiscard]] constexpr auto tuple_cat(Ts &&...ts) {
4849
constexpr auto total_num_elements =
4950
(std::size_t{} + ... + stdx::tuple_size_v<std::remove_cvref_t<Ts>>);
5051

51-
[[maybe_unused]] constexpr auto element_indices = [&] {
52+
[[maybe_unused]] constexpr auto element_indices =
53+
[&]() -> std::array<detail::index_pair, total_num_elements> {
5254
std::array<detail::index_pair, total_num_elements> indices{};
5355
auto p = indices.data();
5456
((p = std::remove_cvref_t<Ts>::fill_inner_indices(p)), ...);
@@ -112,7 +114,7 @@ template <template <typename T> typename Pred, tuplelike T>
112114
(std::size_t{} + ... +
113115
(Pred<stdx::tuple_element_t<Is, tuple_t>>::value ? std::size_t{1}
114116
: std::size_t{}));
115-
constexpr auto indices = [] {
117+
constexpr auto indices = []() -> std::array<std::size_t, num_matches> {
116118
auto a = std::array<std::size_t, num_matches>{};
117119
[[maybe_unused]] auto it = a.begin();
118120
[[maybe_unused]] auto copy_index =
@@ -286,7 +288,8 @@ struct chunk {
286288

287289
template <tuplelike T, template <typename> typename Proj = std::type_identity_t>
288290
requires(tuple_size_v<T> > 1)
289-
[[nodiscard]] constexpr auto create_chunks() {
291+
[[nodiscard]] constexpr auto create_chunks()
292+
-> std::array<chunk, count_chunks<T, Proj>()> {
290293
auto index = std::size_t{};
291294
std::array<chunk, count_chunks<T, Proj>()> chunks{};
292295
++chunks[index].size;
@@ -410,11 +413,11 @@ template <template <typename> typename Proj = std::type_identity_t,
410413
sorted_idxs[Is], sorted_idxs[Is + 1]>...};
411414
}(std::make_index_sequence<stdx::tuple_size_v<tuple_t> - 1>{});
412415

413-
constexpr auto chunks = [&] {
414-
constexpr auto chunk_count =
415-
std::count(std::begin(tests), std::end(tests), false) + 1;
416+
constexpr auto chunk_count =
417+
std::count(std::begin(tests), std::end(tests), false) + 1;
418+
constexpr auto chunks =
419+
[&]() -> std::array<detail::chunk, chunk_count> {
416420
std::array<detail::chunk, chunk_count> cs{};
417-
418421
auto index = std::size_t{};
419422
++cs[index].size;
420423
for (auto i = std::size_t{}; i < std::size(tests); ++i) {

0 commit comments

Comments
 (0)