Skip to content

Commit 81e44ca

Browse files
authored
Merge branch 'feature/main-model-refactor-clean-templates-experiment' into feature/dependent-component-types-check
Signed-off-by: Nitish Bharambe <[email protected]>
2 parents 806bf71 + a0c44fb commit 81e44ca

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

power_grid_model_c/power_grid_model/include/power_grid_model/main_core/core_utils.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#pragma once
66

7-
#include "../all_components.hpp"
87
#include "../container.hpp"
98
#include "state.hpp"
109

@@ -15,8 +14,8 @@ namespace power_grid_model::main_core::utils {
1514
namespace detail {
1615

1716
template <typename Tuple, class Functor, std::size_t... Indices>
18-
constexpr void run_functor_with_tuple_index_return_void(Functor functor, std::index_sequence<Indices...> /*unused*/) {
19-
(functor.template operator()<std::tuple_element_t<Indices, Tuple>>(), ...);
17+
constexpr void run_functor_with_tuple_index_return_void(Functor&& functor, std::index_sequence<Indices...> /*unused*/) {
18+
(std::forward<Functor>(functor).template operator()<std::tuple_element_t<Indices, Tuple>>(), ...);
2019
}
2120

2221
} // namespace detail
@@ -41,8 +40,8 @@ template <class... Types, class Functor> constexpr auto run_functor_with_all_typ
4140
}
4241
/////////////////// To remove ///////////////////
4342

44-
template <typename Tuple, class Functor> constexpr void run_functor_with_tuple_return_void(Functor functor) {
45-
detail::run_functor_with_tuple_index_return_void<Tuple>(functor,
43+
template <typename Tuple, class Functor> constexpr void run_functor_with_tuple_return_void(Functor&& functor) {
44+
detail::run_functor_with_tuple_index_return_void<Tuple>(std::forward<Functor>(functor),
4645
std::make_index_sequence<std::tuple_size_v<Tuple>>{});
4746
}
4847

power_grid_model_c/power_grid_model/include/power_grid_model/main_core/main_model_type.hpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,14 @@ concept validate_component_types_c =
6565

6666
} // namespace detail
6767

68-
template <class T, class U> struct MainModelType;
68+
template <class T, class U> class MainModelType;
6969

7070
// TODO: discussion on checking dependent types can also be done here.
7171
template <class... ExtraRetrievableType, class... ComponentType>
7272
requires detail::validate_component_types_c<ComponentList<ComponentType...>>
73-
struct MainModelType<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentList<ComponentType...>> {
73+
class MainModelType<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentList<ComponentType...>> {
7474

75+
public:
7576
using ComponentContainer = Container<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentType...>;
7677
using MainModelState = main_core::MainModelState<ComponentContainer>;
7778
using ComponentTypesTuple = std::tuple<ComponentType...>;
@@ -116,11 +117,12 @@ struct MainModelType<ExtraRetrievableTypes<ExtraRetrievableType...>, ComponentLi
116117
std::array{index_of_component<Line>, index_of_component<Link>, index_of_component<Transformer>};
117118
static constexpr auto shunt_param_in_seq_map = std::array{index_of_component<Shunt>};
118119

119-
template <class Functor> static constexpr void run_functor_with_all_component_types_return_void(Functor functor) {
120-
(functor.template operator()<ComponentType>(), ...);
120+
template <class Functor> static constexpr void run_functor_with_all_component_types_return_void(Functor&& functor) {
121+
(std::forward<Functor>(functor).template operator()<ComponentType>(), ...);
121122
}
122-
template <class Functor> static constexpr auto run_functor_with_all_component_types_return_array(Functor functor) {
123-
return std::array { functor.template operator()<ComponentType>()... };
123+
template <class Functor>
124+
static constexpr auto run_functor_with_all_component_types_return_array(Functor&& functor) {
125+
return std::array { std::forward<Functor>(functor).template operator()<ComponentType>()... };
124126
}
125127
};
126128

0 commit comments

Comments
 (0)