Skip to content

Commit 29a9216

Browse files
authoredDec 2, 2024··
Update code base to pass clang-tidy (#552)
* A few clang-tidy catches. * Buildable checkpoint * Check point. * Checkpoint - building * Final clang-tidy pass. * Removing some explicit `NOLINT`
1 parent 1cd251b commit 29a9216

13 files changed

+105
-97
lines changed
 

‎CMakePresets.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"CMAKE_CXX_STANDARD": "17",
7373
"CMAKE_BUILD_TYPE": "DEBUG",
7474
"BUILD_TESTING": "ON",
75-
"CMAKE_CXX_CLANG_TIDY": "clang-tidy;--fix"
75+
"CMAKE_CXX_CLANG_TIDY": "clang-tidy;--fix;-header-filter=stlab/.*"
7676
}
7777
},
7878
{
@@ -84,7 +84,7 @@
8484
"CMAKE_CXX_STANDARD": "17",
8585
"CMAKE_BUILD_TYPE": "DEBUG",
8686
"BUILD_TESTING": "ON",
87-
"CMAKE_CXX_CLANG_TIDY": "clang-tidy"
87+
"CMAKE_CXX_CLANG_TIDY": "clang-tidy;-header-filter=stlab/.*"
8888
}
8989
}
9090
],

‎stlab/concurrency/channel.hpp

+15-15
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ constexpr process_state_scheduled yield_immediate{process_state::yield,
7171
enum class channel_error_codes : std::uint8_t { // names for channel errors
7272
broken_channel = 1,
7373
process_already_running = 2,
74-
no_state
74+
no_state = 3
7575
};
7676

7777
/**************************************************************************************************/
@@ -761,8 +761,8 @@ struct shared_process
761761
shared_process_sender_helper<Q, T, R, std::make_index_sequence<sizeof...(Args)>, Args...>(
762762
*this),
763763
_executor(std::forward<E>(e)), _process(std::forward<F>(f)) {
764-
_sender_count = std::is_same<result_t, void>::value ? 0 : 1;
765-
_receiver_count = !std::is_same<result_t, void>::value;
764+
_sender_count = std::is_same_v<result_t, void> ? 0 : 1;
765+
_receiver_count = !std::is_same_v<result_t, void>;
766766
}
767767

768768
template <typename E, typename F, typename... U>
@@ -772,16 +772,16 @@ struct shared_process
772772
_executor(std::forward<E>(e)), _process(std::forward<F>(f)),
773773
_upstream(std::forward<U>(u)...) {
774774
_sender_count = sizeof...(Args);
775-
_receiver_count = !std::is_same<result_t, void>::value;
775+
_receiver_count = !std::is_same_v<result_t, void>;
776776
}
777777

778778
void add_receiver() override {
779-
if (std::is_same<result_t, void>::value) return;
779+
if (std::is_same_v<result_t, void>) return;
780780
++_receiver_count;
781781
}
782782

783783
void remove_receiver() override {
784-
if (std::is_same<result_t, void>::value) return;
784+
if (std::is_same_v<result_t, void>) return;
785785
/*
786786
NOTE (sparent) : Decrementing the receiver count can allow this to start running on a
787787
send before we can get to the check - so we need to see if we are already running
@@ -792,7 +792,7 @@ struct shared_process
792792
bool do_run;
793793
{
794794
std::unique_lock<std::mutex> lock(_process_mutex);
795-
do_run = ((!_queue.empty() || std::is_same<first_t<Args...>, void>::value) ||
795+
do_run = ((!_queue.empty() || std::is_same_v<first_t<Args...>, void>) ||
796796
_process_close_queue) &&
797797
!_process_running;
798798
_process_running = _process_running || do_run;
@@ -1313,24 +1313,24 @@ template <typename S, typename F, typename... R>
13131313
/**************************************************************************************************/
13141314

13151315
template <typename M, typename S, typename F, typename... R>
1316-
auto merge_channel(S s, F f, R... upstream_receiver) {
1317-
return detail::channel_combiner::merge_helper<M, S, F, R...>(std::move(s), std::move(f),
1318-
std::move(upstream_receiver)...);
1316+
auto merge_channel(S s, F f, R&&... upstream_receiver) {
1317+
return detail::channel_combiner::merge_helper<M>(std::move(s), std::move(f),
1318+
std::forward<R>(upstream_receiver)...);
13191319
}
13201320

13211321
/**************************************************************************************************/
13221322

13231323
template <typename S, typename F, typename... R>
1324-
auto zip_with(S s, F f, R... upstream_receiver) {
1325-
return detail::channel_combiner::merge_helper<zip_with_t, S, F, R...>(
1326-
std::move(s), std::move(f), std::forward<R>(upstream_receiver)...);
1324+
auto zip_with(S s, F f, const R&... upstream_receiver) {
1325+
return detail::channel_combiner::merge_helper<zip_with_t>(std::move(s), std::move(f),
1326+
upstream_receiver...);
13271327
}
13281328

13291329
/**************************************************************************************************/
13301330

13311331
template <typename S, typename... R>
1332-
auto zip(S s, R... r) {
1333-
return zip_with(std::move(s), detail::zip_helper{}, std::move(r)...);
1332+
auto zip(S s, const R&... r) {
1333+
return zip_with(std::move(s), detail::zip_helper{}, r...);
13341334
}
13351335

13361336
// template <typename S, typename F, typename... R>

‎stlab/concurrency/future.hpp

+23-22
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ auto package(E executor, F&& f)
993993
try {
994994
std::move(r).detach([_p = std::move(promise)](auto&& f) mutable noexcept {
995995
if (auto e = f.exception()) {
996-
std::move(_p).set_exception(std::move(e));
996+
std::move(_p).set_exception(e);
997997
} else {
998998
std::move(_p).set_value(invoke_void_to_monostate_result(
999999
[&] { return std::forward<decltype(f)>(f).get_ready(); }));
@@ -1044,7 +1044,7 @@ namespace detail {
10441044
template <typename F>
10451045
struct assign_ready_future {
10461046
template <typename T>
1047-
static void assign(T& x, F f) {
1047+
static void assign(T& x, F&& f) {
10481048
x = std::move(*(std::move(f).get_try()));
10491049
}
10501050
};
@@ -1067,13 +1067,14 @@ struct when_all_shared {
10671067
std::exception_ptr _exception;
10681068
packaged_task<> _f;
10691069

1070+
// require f is sink.
10701071
template <std::size_t index, typename FF>
1071-
void done(FF&& f) {
1072+
auto done(FF&& f) -> std::enable_if_t<!std::is_lvalue_reference_v<FF>> {
10721073
auto run{false};
10731074
{
10741075
std::unique_lock<std::mutex> lock{_guard};
10751076
if (!_exception) {
1076-
assign_ready_future<FF>::assign(std::get<index>(_args), std::forward<FF>(f));
1077+
assign_ready_future<FF>::assign(std::get<index>(_args), std::move(f));
10771078
if (--_remaining == 0) run = true;
10781079
}
10791080
}
@@ -1181,7 +1182,7 @@ struct when_any_shared<S, void> {
11811182
}
11821183
};
11831184

1184-
inline void rethrow_if_false(bool x, std::exception_ptr& p) {
1185+
inline void rethrow_if_false(bool x, const std::exception_ptr& p) {
11851186
if (!x) std::rethrow_exception(p);
11861187
}
11871188

@@ -1212,12 +1213,12 @@ auto apply_when_any_arg(F& f, P& p) {
12121213
template <std::size_t i, typename E, typename P, typename T>
12131214
void attach_when_arg_(E&& executor, std::shared_ptr<P>& shared, T a) {
12141215
auto holds =
1215-
std::move(a).recover(std::forward<E>(executor), [_w = std::weak_ptr<P>(shared)](auto x) {
1216+
std::move(a).recover(std::forward<E>(executor), [_w = std::weak_ptr<P>(shared)](auto&& x) {
12161217
auto p = _w.lock();
12171218
if (!p) return;
12181219

12191220
if (auto ex = x.exception()) {
1220-
p->failure(ex);
1221+
p->failure(std::move(ex));
12211222
} else {
12221223
p->template done<i>(std::move(x));
12231224
}
@@ -1243,7 +1244,7 @@ void attach_when_args(E&& executor, std::shared_ptr<P>& p, Ts... a) {
12431244
/**************************************************************************************************/
12441245

12451246
template <typename E, typename F, typename... Ts>
1246-
auto when_all(E executor, F f, future<Ts>... args) {
1247+
auto when_all(const E& executor, F f, future<Ts>... args) {
12471248
using vt_t = voidless_tuple<Ts...>;
12481249
using opt_t = optional_placeholder_tuple<Ts...>;
12491250
using result_t = decltype(apply_ignore_placeholders(std::declval<F>(), std::declval<vt_t>()));
@@ -1263,7 +1264,7 @@ auto when_all(E executor, F f, future<Ts>... args) {
12631264
template <typename T>
12641265
struct make_when_any {
12651266
template <typename E, typename F, typename... Ts>
1266-
static auto make(E executor, F f, future<T> arg, future<Ts>... args) {
1267+
static auto make(const E& executor, F f, future<T> arg, future<Ts>... args) {
12671268
using result_t = detail::result_t<F, T, size_t>;
12681269

12691270
auto shared = std::make_shared<detail::when_any_shared<sizeof...(Ts) + 1, T>>();
@@ -1283,7 +1284,7 @@ struct make_when_any {
12831284
template <>
12841285
struct make_when_any<void> {
12851286
template <typename E, typename F, typename... Ts>
1286-
static auto make(E executor, F&& f, future<Ts>... args) {
1287+
static auto make(E&& executor, F&& f, future<Ts>... args) {
12871288
using result_t = detail::result_t<F, size_t>;
12881289

12891290
auto shared = std::make_shared<detail::when_any_shared<sizeof...(Ts), void>>();
@@ -1292,7 +1293,7 @@ struct make_when_any<void> {
12921293
});
12931294
shared->_f = std::move(p.first);
12941295

1295-
detail::attach_when_args(executor, shared, std::move(args)...);
1296+
detail::attach_when_args(std::forward<E>(executor), shared, std::move(args)...);
12961297

12971298
return std::move(p.second);
12981299
}
@@ -1301,8 +1302,8 @@ struct make_when_any<void> {
13011302
/**************************************************************************************************/
13021303

13031304
template <typename E, typename F, typename T, typename... Ts>
1304-
auto when_any(E executor, F&& f, future<T> arg, future<Ts>... args) {
1305-
return make_when_any<T>::make(std::move(executor), std::forward<F>(f), std::move(arg),
1305+
auto when_any(E&& executor, F&& f, future<T>&& arg, future<Ts>&&... args) {
1306+
return make_when_any<T>::make(std::forward<E>(executor), std::forward<F>(f), std::move(arg),
13061307
std::move(args)...);
13071308
}
13081309

@@ -1497,13 +1498,13 @@ struct common_context : CR {
14971498
/**************************************************************************************************/
14981499

14991500
template <typename C, typename E, typename T>
1500-
void attach_tasks(size_t index, E executor, const std::shared_ptr<C>& context, T&& a) {
1501+
void attach_tasks(size_t index, E&& executor, const std::shared_ptr<C>& context, T&& a) {
15011502
auto&& hold = std::forward<T>(a).recover(
1502-
std::move(executor), [_context = make_weak_ptr(context), _i = index](auto x) {
1503+
std::forward<E>(executor), [_context = make_weak_ptr(context), _i = index](const auto& x) {
15031504
auto p = _context.lock();
15041505
if (!p) return;
15051506
if (auto ex = x.exception()) {
1506-
p->failure(ex, _i);
1507+
p->failure(std::move(ex), _i);
15071508
} else {
15081509
p->done(std::move(x), _i);
15091510
}
@@ -1519,7 +1520,7 @@ struct create_range_of_futures;
15191520
template <typename R, typename T, typename C>
15201521
struct create_range_of_futures<R, T, C, enable_if_copyable<T>> {
15211522
template <typename E, typename F, typename I>
1522-
static auto do_it(E executor, F&& f, I first, I last) {
1523+
static auto do_it(const E& executor, F&& f, I first, I last) {
15231524
assert(first != last);
15241525

15251526
auto context = std::make_shared<C>(std::forward<F>(f), std::distance(first, last));
@@ -1539,7 +1540,7 @@ struct create_range_of_futures<R, T, C, enable_if_copyable<T>> {
15391540
template <typename R, typename T, typename C>
15401541
struct create_range_of_futures<R, T, C, enable_if_not_copyable<T>> {
15411542
template <typename E, typename F, typename I>
1542-
static auto do_it(E executor, F&& f, I first, I last) {
1543+
static auto do_it(const E& executor, F&& f, I first, I last) {
15431544
assert(first != last);
15441545

15451546
auto context = std::make_shared<C>(std::forward<F>(f), std::distance(first, last));
@@ -1566,7 +1567,7 @@ template <typename E, // models task executor
15661567
typename F, // models functional object
15671568
typename I> // models ForwardIterator that reference to a range of futures of the same
15681569
// type
1569-
auto when_all(E executor, F f, std::pair<I, I> range) {
1570+
auto when_all(const E& executor, F f, std::pair<I, I> range) {
15701571
using param_t = typename std::iterator_traits<I>::value_type::result_type;
15711572
using result_t = typename detail::result_of_when_all_t<F, param_t>::result_type;
15721573
using context_result_t =
@@ -1591,7 +1592,7 @@ template <typename E, // models task executor
15911592
typename F, // models functional object
15921593
typename I> // models ForwardIterator that reference to a range of futures of the same
15931594
// type
1594-
auto when_any(E executor, F&& f, std::pair<I, I> range) {
1595+
auto when_any(const E& executor, F&& f, std::pair<I, I> range) {
15951596
using param_t = typename std::iterator_traits<I>::value_type::result_type;
15961597
using result_t = typename detail::result_of_when_any_t<F, param_t>::result_type;
15971598
using context_result_t = std::conditional_t<std::is_same_v<void, param_t>, void, param_t>;
@@ -1618,14 +1619,14 @@ auto when_any(E executor, F&& f, std::pair<I, I> range) {
16181619
#endif
16191620

16201621
template <typename E, typename F, typename... Args>
1621-
auto async(E executor, F&& f, Args&&... args)
1622+
auto async(const E& executor, F&& f, Args&&... args)
16221623
-> detail::reduced_t<detail::result_t<std::decay_t<F>, std::decay_t<Args>...>> {
16231624
using result_type = detail::result_t<std::decay_t<F>, std::decay_t<Args>...>;
16241625

16251626
auto [pro, fut] = package<result_type()>(
16261627
executor,
16271628
[f = std::forward<F>(f), args = std::make_tuple(std::forward<Args>(args)...)]() mutable
1628-
-> result_type { return std::apply(std::move(f), std::move(args)); });
1629+
-> result_type { return std::apply(std::move(f), std::move(args)); });
16291630

16301631
executor(std::move(pro));
16311632

‎stlab/concurrency/ready_future.hpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -44,29 +44,29 @@ namespace detail {
4444
template <class T>
4545
struct _make_exceptional_future {
4646
template <typename E>
47-
auto operator()(std::exception_ptr error, E executor) const -> future<T> {
47+
auto operator()(const std::exception_ptr& error, E executor) const -> future<T> {
4848
auto p = package<T(T)>(std::move(executor),
4949
[](auto&& a) { return std::forward<decltype(a)>(a); });
50-
p.first.set_exception(std::move(error));
50+
p.first.set_exception(error);
5151
return std::move(p.second);
5252
}
5353
};
5454

5555
template <>
5656
struct _make_exceptional_future<void> {
5757
template <typename E>
58-
auto operator()(std::exception_ptr error, E executor) const -> future<void> {
58+
auto operator()(const std::exception_ptr& error, E executor) const -> future<void> {
5959
auto p = package<void()>(std::move(executor), []() {});
60-
p.first.set_exception(std::move(error));
60+
p.first.set_exception(error);
6161
return std::move(p.second);
6262
}
6363
};
6464

6565
} // namespace detail
6666

6767
template <typename T, typename E>
68-
auto make_exceptional_future(std::exception_ptr error, E executor) -> future<T> {
69-
return detail::_make_exceptional_future<T>{}(std::move(error), std::move(executor));
68+
auto make_exceptional_future(const std::exception_ptr& error, E executor) -> future<T> {
69+
return detail::_make_exceptional_future<T>{}(error, std::move(executor));
7070
}
7171

7272
/**************************************************************************************************/

‎stlab/concurrency/task.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ class task_ {
8282
signature to the actual captured model.
8383
*/
8484

85+
// NOLINTNEXTLINE(performance-unnecessary-value-param)
8586
static auto invoke(void* self, Args... args) noexcept(NoExcept) -> R {
8687
return (static_cast<model*>(self)->_f)(std::forward<Args>(args)...);
8788
}
@@ -145,6 +146,7 @@ class task_ {
145146
// empty (default) vtable
146147
static void dtor(void*) noexcept {}
147148
static void move_ctor(void*, void*) noexcept {}
149+
// NOLINTNEXTLINE(performance-unnecessary-value-param)
148150
static auto invoke(void*, Args...) noexcept(NoExcept) -> R {
149151
if constexpr (NoExcept) {
150152
try {

‎stlab/forest.hpp

+23-19
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ struct child_iterator {
106106
using iterator_category = typename std::iterator_traits<I>::iterator_category;
107107

108108
child_iterator() = default;
109-
explicit child_iterator(I x) : _x(std::move(x)) {}
109+
explicit child_iterator(const I& x) : _x(std::move(x)) {}
110110
template <class U>
111111
child_iterator(const child_iterator<U>& u) : _x(u.base()) {}
112112

@@ -182,7 +182,7 @@ struct edge_iterator {
182182
using iterator_category = typename std::iterator_traits<I>::iterator_category;
183183

184184
edge_iterator() = default;
185-
explicit edge_iterator(I x) : _x(find_edge(x, Edge)) {}
185+
explicit edge_iterator(const I& x) : _x(find_edge(x, Edge)) {}
186186
template <class U>
187187
edge_iterator(const edge_iterator<U, Edge>& u) : _x(u.base()) {}
188188

@@ -882,17 +882,18 @@ class forest {
882882
erase(--end());
883883
}
884884

885-
auto insert(iterator position, const_child_iterator first, const_child_iterator last)
886-
-> iterator;
885+
auto insert(iterator position,
886+
const const_child_iterator& first,
887+
const const_child_iterator& last) -> iterator;
887888

888-
auto splice(iterator position, forest<T>& x) -> iterator;
889-
auto splice(iterator position, forest<T>& x, iterator i) -> iterator;
890-
auto splice(iterator position, forest<T>& x, child_iterator first, child_iterator last)
889+
auto splice(const iterator& position, forest<T>& x) -> iterator;
890+
auto splice(const iterator& position, forest<T>& x, iterator i) -> iterator;
891+
auto splice(const iterator& position, forest<T>& x, child_iterator first, child_iterator last)
891892
-> iterator;
892-
auto splice(iterator position,
893+
auto splice(const iterator& position,
893894
forest<T>& x,
894-
child_iterator first,
895-
child_iterator last,
895+
const child_iterator& first,
896+
const child_iterator& last,
896897
size_type count) -> iterator;
897898

898899
auto insert_parent(child_iterator front, child_iterator back, const T& x) -> iterator;
@@ -937,7 +938,7 @@ namespace unsafe {
937938

938939
template <class I> // I models a FullorderIterator
939940
struct set_next_fn<child_iterator<I>> {
940-
void operator()(child_iterator<I> x, child_iterator<I> y) {
941+
void operator()(const child_iterator<I>& x, const child_iterator<I>& y) {
941942
unsafe::set_next(pivot_of(x.base()), y.base());
942943
}
943944
};
@@ -1014,15 +1015,15 @@ auto forest<T>::erase(const iterator& position) -> iterator {
10141015
/**************************************************************************************************/
10151016

10161017
template <class T>
1017-
auto forest<T>::splice(iterator position, forest<T>& x) -> iterator {
1018+
auto forest<T>::splice(const iterator& position, forest<T>& x) -> iterator {
10181019
return splice(position, x, child_iterator(x.begin()), child_iterator(x.end()),
10191020
x.size_valid() ? x.size() : 0);
10201021
}
10211022

10221023
/**************************************************************************************************/
10231024

10241025
template <class T>
1025-
auto forest<T>::splice(iterator position, forest<T>& x, iterator i) ->
1026+
auto forest<T>::splice(const iterator& position, forest<T>& x, iterator i) ->
10261027
typename forest<T>::iterator {
10271028
i.edge() = forest_edge::leading;
10281029
return splice(position, x, child_iterator(i), ++child_iterator(i), has_children(i) ? 0 : 1);
@@ -1031,7 +1032,8 @@ auto forest<T>::splice(iterator position, forest<T>& x, iterator i) ->
10311032
/**************************************************************************************************/
10321033

10331034
template <class T>
1034-
auto forest<T>::insert(iterator pos, const_child_iterator f, const_child_iterator l) -> iterator {
1035+
auto forest<T>::insert(iterator pos, const const_child_iterator& f, const const_child_iterator& l)
1036+
-> iterator {
10351037
for (const_iterator first(f.base()), last(l.base()); first != last; ++first, ++pos) {
10361038
if (is_leading(first)) pos = insert(pos, *first);
10371039
}
@@ -1042,9 +1044,11 @@ auto forest<T>::insert(iterator pos, const_child_iterator f, const_child_iterato
10421044
/**************************************************************************************************/
10431045

10441046
template <class T>
1045-
auto forest<T>::splice(
1046-
iterator pos, forest<T>& x, child_iterator first, child_iterator last, size_type count)
1047-
-> iterator {
1047+
auto forest<T>::splice(const iterator& pos,
1048+
forest<T>& x,
1049+
const child_iterator& first,
1050+
const child_iterator& last,
1051+
size_type count) -> iterator {
10481052
if (first == last || first.base() == pos) return pos;
10491053

10501054
if (&x != this) {
@@ -1070,8 +1074,8 @@ auto forest<T>::splice(
10701074
/**************************************************************************************************/
10711075

10721076
template <class T>
1073-
auto forest<T>::splice(iterator pos, forest<T>& x, child_iterator first, child_iterator last) ->
1074-
typename forest<T>::iterator {
1077+
auto forest<T>::splice(const iterator& pos, forest<T>& x, child_iterator first, child_iterator last)
1078+
-> typename forest<T>::iterator {
10751079
return splice(pos, x, first, last, 0);
10761080
}
10771081

‎stlab/forest_algorithms.hpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ struct transcribe_iterator {
4040
using reference = void;
4141
using container_type = Container;
4242

43-
transcribe_iterator(Container& c, typename Container::iterator i) : _c{&c}, _i{std::move(i)} {}
43+
transcribe_iterator(Container& c, const typename Container::iterator& i) : _c{&c}, _i{i} {}
4444

4545
constexpr auto operator*() -> auto& { return *this; }
4646
constexpr auto operator++() -> auto& {
@@ -78,7 +78,7 @@ auto transcriber(Container& c) {
7878
/**************************************************************************************************/
7979

8080
template <class I, class O, class P, class UP>
81-
auto transcribe(I first, I last, O out, P proj, UP pred) {
81+
auto transcribe(I first, const I& last, O out, P proj, UP pred) {
8282
for (; first != last; ++first, ++out) {
8383
if (pred(first)) {
8484
out = proj(*first);
@@ -96,8 +96,8 @@ auto transcribe(const R& range, O out, P proj, UP pred) {
9696
}
9797

9898
template <class I, class O, class P>
99-
auto transcribe(I first, I last, O out, P proj) {
100-
return transcribe(std::move(first), std::move(last), std::move(out), std::move(proj),
99+
auto transcribe(const I& first, const I& last, O out, P proj) {
100+
return transcribe(first, last, std::move(out), std::move(proj),
101101
[](const auto& p) { return is_leading(p); });
102102
}
103103

@@ -110,7 +110,7 @@ auto transcribe(const R& range, O out, P proj) {
110110

111111
template <class I, // models ForestFullorderIterator
112112
class O> // models OutputIterator
113-
auto flatten(I first, I last, O out) {
113+
auto flatten(I first, const I& last, O out) {
114114
for (; first != last; ++first) {
115115
if (is_leading(first)) {
116116
*out++ = *first;

‎stlab/iterator/set_next.hpp

+2-7
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@
99
#define STLAB_ITERATOR_SET_NEXT_HPP
1010

1111
#include <iterator>
12-
13-
/**************************************************************************************************/
14-
15-
12+
#include <utility>
1613

1714
/**************************************************************************************************/
1815

@@ -26,7 +23,7 @@ struct set_next_fn; // Must be specialized
2623
/**************************************************************************************************/
2724

2825
template <typename I> // I models NodeIterator
29-
inline void set_next(I x, I y) {
26+
inline void set_next(const I& x, const I& y) {
3027
set_next_fn<I>()(x, y);
3128
}
3229

@@ -55,8 +52,6 @@ inline void skip_node(I location) {
5552

5653
/**************************************************************************************************/
5754

58-
59-
6055
/**************************************************************************************************/
6156

6257
#endif // STLAB_ITERATOR_SET_NEXT_HPP

‎test/forest_test.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**************************************************************************************************/
22

33
// stdc++
4-
#include <cstddef>
54
#include <cassert>
5+
#include <cstddef>
66
#include <iostream>
77
#include <iterator>
88
#include <optional>
@@ -158,7 +158,7 @@ auto to_string(const R& r) {
158158
}
159159

160160
template <typename I>
161-
auto to_string(I first, I last) {
161+
auto to_string(I first, const I& last) {
162162
std::string result;
163163
while (first != last) {
164164
result += *first++;
@@ -169,14 +169,16 @@ auto to_string(I first, I last) {
169169
/**************************************************************************************************/
170170

171171
template <typename Iterator>
172-
void test_fullorder_traversal(Iterator first, Iterator last, const std::string& expected) {
172+
void test_fullorder_traversal(const Iterator& first,
173+
const Iterator& last,
174+
const std::string& expected) {
173175
BOOST_CHECK(to_string(first, last) == expected);
174176
}
175177

176178
/**************************************************************************************************/
177179

178180
template <typename Iterator, forest_edge Edge, typename Forest>
179-
auto test_edge_traversal(Forest& f, Iterator fi, Iterator li) {
181+
auto test_edge_traversal(Forest& f, const Iterator& fi, const Iterator& li) {
180182
std::string expected;
181183

182184
{

‎test/future_recover_tests.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ BOOST_AUTO_TEST_CASE(future_recover_failure_during_when_all_on_lvalue) {
430430

431431
sut = when_all(
432432
make_executor<0>(), [](int x, int y) { return x + y; }, f1, f2)
433-
.recover([](auto error) {
433+
.recover([](const auto& error) {
434434
if (error.exception()) {
435435
return 815;
436436
}
@@ -449,7 +449,7 @@ BOOST_AUTO_TEST_CASE(future_recover_failure_during_when_all_on_lvalue) {
449449

450450
sut = (when_all(
451451
make_executor<0>(), [](int x, int y) { return x + y; }, f1, f2) ^
452-
[](auto error) {
452+
[](const auto& error) {
453453
if (error.exception()) {
454454
return 815;
455455
}
@@ -1140,7 +1140,7 @@ BOOST_AUTO_TEST_CASE(future_recover_move_only_with_broken_promise) {
11401140
sut = [&check]() {
11411141
auto p{
11421142
package<move_only(move_only)>(immediate_executor, [](move_only x) { return x; })};
1143-
return std::move(p.second).recover([&check](auto f) {
1143+
return std::move(p.second).recover([&check](const auto& f) {
11441144
check = true;
11451145
try {
11461146
return *std::move(f.get_try());
@@ -1158,7 +1158,7 @@ BOOST_AUTO_TEST_CASE(future_recover_move_only_with_broken_promise) {
11581158
sut = [&check]() {
11591159
auto p{
11601160
package<move_only(move_only)>(immediate_executor, [](move_only x) { return x; })};
1161-
return std::move(p.second) ^ [&check](auto f) {
1161+
return std::move(p.second) ^ [&check](const auto& f) {
11621162
check = true;
11631163
try {
11641164
return *std::move(f.get_try());

‎test/future_when_any_arguments_tests.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ BOOST_AUTO_TEST_CASE(future_when_any_int_void_range_with_one_argument) {
3838
_i = index;
3939
_r = x;
4040
},
41-
a1);
41+
std::move(a1));
4242

4343
check_valid_future(sut);
4444
wait_until_future_completed(std::move(sut));
@@ -81,7 +81,7 @@ BOOST_AUTO_TEST_CASE(future_when_any_int_void_range_with_many_arguments_first_su
8181
++_counter;
8282
_r = x;
8383
},
84-
a1, a2, a3, a4);
84+
std::move(a1), std::move(a2), std::move(a3), std::move(a4));
8585

8686
check_valid_future(sut);
8787
wait_until_future_completed(std::move(sut));
@@ -131,7 +131,7 @@ BOOST_AUTO_TEST_CASE(future_when_any_int_void_argument_with_many_arguments_middl
131131
++_counter;
132132
_r = x;
133133
},
134-
a1, a2, a3, a4);
134+
std::move(a1), std::move(a2), std::move(a3), std::move(a4));
135135

136136
check_valid_future(sut);
137137
wait_until_future_completed(std::move(sut));
@@ -180,7 +180,7 @@ BOOST_AUTO_TEST_CASE(future_when_any_int_void_argument_with_many_arguments_last_
180180
++_counter;
181181
_r = x;
182182
},
183-
a1, a2, a3, a4);
183+
std::move(a1), std::move(a2), std::move(a3), std::move(a4));
184184

185185
check_valid_future(sut);
186186
wait_until_future_completed(std::move(sut));
@@ -219,7 +219,7 @@ BOOST_AUTO_TEST_CASE(
219219
_i = index;
220220
_result = x;
221221
},
222-
a1, a2, a3, a4);
222+
std::move(a1), std::move(a2), std::move(a3), std::move(a4));
223223

224224
check_valid_future(sut);
225225
wait_until_future_completed(std::move(sut));
@@ -249,7 +249,7 @@ BOOST_AUTO_TEST_CASE(future_when_any_int_void_arguments_with_many_arguments_all_
249249
_i = index;
250250
_r = x;
251251
},
252-
a1, a2, a3, a4);
252+
std::move(a1), std::move(a2), std::move(a3), std::move(a4));
253253

254254
wait_until_all_tasks_completed();
255255
wait_until_future_fails<test_exception>(std::move(sut));
@@ -275,7 +275,7 @@ BOOST_AUTO_TEST_CASE(future_when_any_int_int_argument_with_one_argument) {
275275
_i = index;
276276
return x;
277277
},
278-
a1);
278+
std::move(a1));
279279
check_valid_future(sut);
280280

281281
auto result = await(std::move(sut));
@@ -318,7 +318,7 @@ BOOST_AUTO_TEST_CASE(future_when_any_int_int_arguments_with_many_arguments_last_
318318
++_counter;
319319
return x;
320320
},
321-
a1, a2, a3, a4);
321+
std::move(a1), std::move(a2), std::move(a3), std::move(a4));
322322
check_valid_future(sut);
323323
wait_until_future_completed(copy(sut));
324324
block_context._go = true;
@@ -367,7 +367,7 @@ BOOST_AUTO_TEST_CASE(
367367
_index = index;
368368
return x;
369369
},
370-
a1, a2, a3, a4);
370+
std::move(a1), std::move(a2), std::move(a3), std::move(a4));
371371
check_valid_future(sut);
372372

373373
auto result = await(std::move(sut));
@@ -419,7 +419,7 @@ BOOST_AUTO_TEST_CASE(future_when_any_int_arguments_with_diamond_formation_argume
419419
_i = index;
420420
return x;
421421
},
422-
a1, a2, a3, a4);
422+
std::move(a1), std::move(a2), std::move(a3), std::move(a4));
423423

424424
check_valid_future(sut);
425425
wait_until_future_completed(copy(sut));

‎test/tuple_test.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ BOOST_AUTO_TEST_CASE(add_placeholder_test) {
8888
/**************************************************************************************************/
8989

9090
template <typename F, typename... Ts>
91-
void when_all_typecheck(F, future<Ts>...) {
91+
void when_all_typecheck(F, const future<Ts>&...) {
9292
using pt_t = placeholder_tuple<Ts...>;
9393
using opt_t = optional_placeholder_tuple<Ts...>;
9494
using vt_t = voidless_tuple<Ts...>;
@@ -186,8 +186,10 @@ BOOST_AUTO_TEST_CASE(future_when_all_int_void_string_void_bool_void) {
186186

187187
auto f = when_all(
188188
stlab::default_executor,
189-
[](auto... args) { for_each_argument([](auto x) { cout << x << "\n"; }, args...); }, fi(),
190-
fv(), fs(), fv(), fb(), fv());
189+
[](const auto&... args) {
190+
for_each_argument([](const auto& x) { cout << x << "\n"; }, args...);
191+
},
192+
fi(), fv(), fs(), fv(), fb(), fv());
191193

192194
await(std::move(f));
193195
}

‎test/utility_test.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
#include <stlab/utility.hpp>
1010

1111
#include <type_traits>
12+
#include <utility>
1213

1314
// boost
1415
#include <boost/test/unit_test.hpp>
16+
1517
#include <stlab/test/model.hpp>
1618

1719
/**************************************************************************************************/

0 commit comments

Comments
 (0)
Please sign in to comment.