Skip to content

Commit 5dc8be6

Browse files
committed
use simple std::views, use simple std::format
Signed-off-by: Martijn Govers <Martijn.Govers@Alliander.com>
1 parent 955f2d4 commit 5dc8be6

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

power_grid_model_c/power_grid_model/include/power_grid_model/common/exception.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "enum.hpp"
99

1010
#include <exception>
11+
#include <format>
1112
#include <sstream>
1213
#include <string>
1314

@@ -23,7 +24,7 @@ inline auto to_string(std::integral auto x) { return std::to_string(x); }
2324

2425
class PowerGridError : public std::exception {
2526
public:
26-
void append_msg(std::string_view msg) { msg_ += msg; }
27+
void append_msg(std::string_view msg) { msg_ = std::format("{}{}", msg_, msg); }
2728
char const* what() const noexcept final { return msg_.c_str(); }
2829

2930
private:

power_grid_model_c/power_grid_model/include/power_grid_model/topology.hpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -296,20 +296,17 @@ class Topology {
296296
}
297297

298298
// copy all the far-end non-cyclic node, in reverse order
299-
// NOLINTNEXTLINE(modernize-use-ranges) // waiting for std::views
300-
std::copy_if(dfs_node_copy.crbegin(), dfs_node_copy.crend(), std::back_inserter(dfs_node),
301-
[this](Idx x) { return node_status_[x] == -1; });
299+
std::ranges::copy_if(std::views::reverse(dfs_node_copy), std::back_inserter(dfs_node),
300+
[this](Idx x) { return node_status_[x] == -1; });
302301

303302
// copy all cyclic node
304303
std::vector<Idx> cyclic_node;
305-
// NOLINTNEXTLINE(modernize-use-ranges) // waiting for std::views
306-
std::copy_if(dfs_node_copy.cbegin(), dfs_node_copy.cend(), std::back_inserter(cyclic_node),
307-
[this](Idx x) { return node_status_[x] == -2; });
304+
std::ranges::copy_if(dfs_node_copy, std::back_inserter(cyclic_node),
305+
[this](Idx x) { return node_status_[x] == -2; });
308306

309307
// reorder does not make sense if number of cyclic nodes in a sub graph is smaller than 4
310308
if (cyclic_node.size() < 4) {
311-
// NOLINTNEXTLINE(modernize-use-ranges) // waiting for std::views
312-
std::copy(cyclic_node.crbegin(), cyclic_node.crend(), std::back_inserter(dfs_node));
309+
std::ranges::copy(std::views::reverse(cyclic_node), std::back_inserter(dfs_node));
313310
return fill_in;
314311
}
315312

0 commit comments

Comments
 (0)