Skip to content

Commit 060af71

Browse files
authored
Merge pull request #930 from PowerGridModel/fix/pgm-cpp-api-cpp17
The public CPP API from PGM should rely on c++17 standard
2 parents 840e833 + ba4203a commit 060af71

File tree

5 files changed

+18
-8
lines changed

5 files changed

+18
-8
lines changed

power_grid_model_c/power_grid_model_cpp/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ target_sources(power_grid_model_cpp PUBLIC
3030
set_target_properties(power_grid_model_cpp PROPERTIES
3131
VERSION ${PGM_VERSION}
3232
SOVERSION ${PGM_VERSION}
33+
CXX_STANDARD 17
3334
)
3435

3536

power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/handle.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ class Handle {
7171
auto const* const failed_scenario_seqs = PGM_failed_scenarios(handle_ptr);
7272
auto const* const failed_scenario_messages = PGM_batch_errors(handle_ptr);
7373
for (Idx i = 0; i < n_failed_scenarios; ++i) {
74-
failed_scenarios[i] = PowerGridBatchError::FailedScenario{.scenario = failed_scenario_seqs[i],
75-
.error_message = failed_scenario_messages[i]};
74+
failed_scenarios[i] =
75+
PowerGridBatchError::FailedScenario{failed_scenario_seqs[i], failed_scenario_messages[i]};
7676
}
7777
clear_error();
7878
throw PowerGridBatchError{error_message, std::move(failed_scenarios)};

power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/serialization.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ inline OwningDataset create_owning_dataset(DatasetWritable& writable_dataset) {
116116
writable_dataset.set_buffer(component_name, indptr, current_buffer);
117117
dataset_mutable.add_buffer(component_name, elements_per_scenario, component_size, indptr, current_buffer);
118118
}
119-
return OwningDataset{.dataset = std::move(dataset_mutable), .storage = std::move(storage)};
119+
return OwningDataset{std::move(dataset_mutable), std::move(storage)};
120120
}
121121
} // namespace power_grid_model_cpp
122122

power_grid_model_c/power_grid_model_cpp/include/power_grid_model_cpp/utils.hpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,19 @@ constexpr double nan = std::numeric_limits<double>::quiet_NaN();
3131
constexpr int8_t na_IntS = std::numeric_limits<int8_t>::min();
3232
constexpr ID na_IntID = std::numeric_limits<ID>::min();
3333

34-
template <std::same_as<double> T> constexpr T nan_value() { return nan; }
35-
template <std::same_as<std::array<double, 3>> T> constexpr T nan_value() { return {nan, nan, nan}; }
36-
template <std::same_as<ID> T> constexpr T nan_value() { return na_IntID; }
37-
template <std::same_as<int8_t> T> constexpr T nan_value() { return na_IntS; }
34+
template <typename T> constexpr T nan_value() {
35+
if constexpr (std::is_same_v<T, double>) {
36+
return nan;
37+
} else if constexpr (std::is_same_v<T, ID>) {
38+
return na_IntID;
39+
} else if constexpr (std::is_same_v<T, int8_t>) {
40+
return na_IntS;
41+
} else if constexpr (std::is_same_v<T, std::array<double, 3>>) {
42+
return std::array<double, 3>{nan, nan, nan};
43+
} else {
44+
static_assert(false, "Unsupported type for nan_value");
45+
}
46+
}
3847

3948
class UnsupportedPGM_CType : public PowerGridError {
4049
public:

tests/package_tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ cmake_minimum_required (VERSION 3.23)
66

77
project(power_grid_model_package_tests)
88

9-
set(CMAKE_CXX_STANDARD 20)
9+
set(CMAKE_CXX_STANDARD 17)
1010
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1111
set(CMAKE_CXX_EXTENSIONS OFF)
1212
set(CMAKE_CXX_VISIBILITY_PRESET hidden)

0 commit comments

Comments
 (0)