Skip to content

Commit ae5f97c

Browse files
committed
resolve forward iterator by value instead of const&
Signed-off-by: Martijn Govers <Martijn.Govers@Alliander.com>
1 parent 383a51c commit ae5f97c

File tree

5 files changed

+13
-8
lines changed

5 files changed

+13
-8
lines changed

.clang-tidy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,8 @@ WarningsAsErrors: '*'
6767
HeaderFilterRegex: '.*'
6868

6969
FormatStyle: file
70+
71+
CheckOptions:
72+
- key: performance-unnecessary-value-param.AllowedTypes
73+
- value: 'ForwardIterator'
7074
...

power_grid_model_c/power_grid_model/include/power_grid_model/main_core/input.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ constexpr std::array<Branch3Side, 3> const branch3_sides = {Branch3Side::side_1,
2323
template <std::derived_from<Base> Component, class ComponentContainer,
2424
forward_iterator_like<typename Component::InputType> ForwardIterator>
2525
requires model_component_state_c<MainModelState, ComponentContainer, Component>
26-
inline void add_component(MainModelState<ComponentContainer>& state, ForwardIterator const& begin,
27-
ForwardIterator const& end, double system_frequency) {
26+
inline void add_component(MainModelState<ComponentContainer>& state, ForwardIterator begin, ForwardIterator end,
27+
double system_frequency) {
2828
using ComponentView = std::conditional_t<std::same_as<decltype(*begin), typename Component::InputType const&>,
2929
typename Component::InputType const&, typename Component::InputType>;
3030

power_grid_model_c/power_grid_model/include/power_grid_model/main_core/update.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace power_grid_model::main_core::update {
1818
namespace detail {
1919
template <component_c Component, forward_iterator_like<typename Component::UpdateType> ForwardIterator, typename Func>
2020
requires std::invocable<std::remove_cvref_t<Func>, typename Component::UpdateType, Idx2D const&>
21-
inline void iterate_component_sequence(Func func, ForwardIterator const& begin, ForwardIterator const& end,
21+
inline void iterate_component_sequence(Func func, ForwardIterator begin, ForwardIterator end,
2222
std::span<Idx2D const> sequence_idx) {
2323
assert(std::distance(begin, end) >= static_cast<ptrdiff_t>(sequence_idx.size()));
2424

@@ -246,8 +246,8 @@ template <component_c Component, class ComponentContainer,
246246
forward_iterator_like<typename Component::UpdateType> ForwardIterator,
247247
std::output_iterator<Idx2D> OutputIterator>
248248
requires model_component_state_c<MainModelState, ComponentContainer, Component>
249-
inline UpdateChange update_component(MainModelState<ComponentContainer>& state, ForwardIterator const& begin,
250-
ForwardIterator const& end, OutputIterator changed_it,
249+
inline UpdateChange update_component(MainModelState<ComponentContainer>& state, ForwardIterator begin,
250+
ForwardIterator end, OutputIterator changed_it,
251251
std::span<Idx2D const> sequence_idx) {
252252
using UpdateType = typename Component::UpdateType;
253253

power_grid_model_c/power_grid_model/include/power_grid_model/main_model_impl.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,7 @@ class MainModelImpl<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentLis
226226
// if sequence_idx is given, it will be used to load the object instead of using IDs via hash map.
227227
template <class CompType, cache_type_c CacheType,
228228
forward_iterator_like<typename CompType::UpdateType> ForwardIterator>
229-
void update_component(ForwardIterator const& begin, ForwardIterator const& end,
230-
std::span<Idx2D const> sequence_idx) {
229+
void update_component(ForwardIterator begin, ForwardIterator end, std::span<Idx2D const> sequence_idx) {
231230
constexpr auto comp_index = main_core::utils::index_of_component<CompType, ComponentType...>;
232231

233232
assert(construction_complete_);

tests/cpp_unit_tests/test_tap_position_optimizer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1531,17 +1531,18 @@ TEST_CASE("Test RankIterator") {
15311531
tap_changed = rank_iterator.iterate_ranks(regulator_order, mock_lambda, tap_changed);
15321532
iterations_per_rank = rank_iterator.iterations_per_rank();
15331533
rank_index = rank_iterator.rank_index();
1534+
CHECK_FALSE(tap_changed);
15341535
CHECK(iterations_per_rank[0] == 2);
15351536
CHECK(iterations_per_rank[1] == 4);
15361537
CHECK(iterations_per_rank[2] == 6);
15371538
CHECK(rank_index == 2);
1538-
CHECK(tap_changed == false);
15391539
}
15401540
SUBCASE("Test tap changed") {
15411541
update = true;
15421542
tap_changed = rank_iterator.iterate_ranks(regulator_order, mock_lambda, tap_changed);
15431543
iterations_per_rank = rank_iterator.iterations_per_rank();
15441544
rank_index = rank_iterator.rank_index();
1545+
CHECK(tap_changed);
15451546
CHECK(iterations_per_rank[0] == 3);
15461547
CHECK(iterations_per_rank[1] == 0);
15471548
CHECK(iterations_per_rank[2] == 0);
@@ -1553,6 +1554,7 @@ TEST_CASE("Test RankIterator") {
15531554
tap_changed = rank_iterator.iterate_ranks(regulator_order, mock_lambda, tap_changed);
15541555
iterations_per_rank = rank_iterator.iterations_per_rank();
15551556
rank_index = rank_iterator.rank_index();
1557+
CHECK(tap_changed);
15561558
CHECK(iterations_per_rank[0] == 2);
15571559
CHECK(iterations_per_rank[1] == 4);
15581560
CHECK(iterations_per_rank[2] == 7);

0 commit comments

Comments
 (0)