From 1a9f2bbd7a41ab99e93f730cee4bfb60369dca85 Mon Sep 17 00:00:00 2001 From: zoeprieto Date: Thu, 8 Aug 2024 07:53:47 -0500 Subject: [PATCH] generalize concatenate function and minor changes --- include/openmc/string_utils.h | 11 ++++++++--- src/mgxs.cpp | 4 ++-- src/nuclide.cpp | 5 +++-- src/thermal.cpp | 4 ++-- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/include/openmc/string_utils.h b/include/openmc/string_utils.h index 6b197fd63ad..ed02e89d975 100644 --- a/include/openmc/string_utils.h +++ b/include/openmc/string_utils.h @@ -26,11 +26,16 @@ bool ends_with(const std::string& value, const std::string& ending); bool starts_with(const std::string& value, const std::string& beginning); template -inline std::string concatenate(const T& temps) +inline std::string concatenate(const T& values, const std::string& del = " ") { std::ostringstream oss; - for (const auto& temp : temps) { - oss << temp << " "; + auto it = values.begin(); + if (it != values.end()) { + oss << *it; // Insert the first element without a delimiter + ++it; + } + for (; it != values.end(); ++it) { + oss << del << *it; } return oss.str(); } diff --git a/src/mgxs.cpp b/src/mgxs.cpp index 5f539710610..cc9620b1c6f 100644 --- a/src/mgxs.cpp +++ b/src/mgxs.cpp @@ -110,9 +110,9 @@ void Mgxs::metadata_from_hdf5(hid_t xs_id, const vector& temperature, fatal_error(fmt::format( "MGXS library does not contain cross sections " "for {} at or near {} K. Available temperatures " - "are {} K consider making use of openmc.Settings.temperature " + "are {} K. Consider making use of openmc.Settings.temperature " "to specify how intermediate temperatures are treated.", - in_name, std::round(T), concatenate(temps_available))); + in_name, std::round(T), concatenate(temps_available, ", "))); } } break; diff --git a/src/nuclide.cpp b/src/nuclide.cpp index c7cd9ac987c..7e676bf46b6 100644 --- a/src/nuclide.cpp +++ b/src/nuclide.cpp @@ -161,9 +161,10 @@ Nuclide::Nuclide(hid_t group, const vector& temperature) fatal_error(fmt::format( "Nuclear data library does not contain cross sections " "for {} at or near {} K. Available temperatures " - "are {} K consider making use of openmc.Settings.temperature " + "are {} K. Consider making use of openmc.Settings.temperature " "to specify how intermediate temperatures are treated.", - name_, std::to_string(T_desired), concatenate(temps_available))); + name_, std::to_string(T_desired), + concatenate(temps_available, ", "))); } } break; diff --git a/src/thermal.cpp b/src/thermal.cpp index 26e5577c2ed..4af02b8d005 100644 --- a/src/thermal.cpp +++ b/src/thermal.cpp @@ -93,9 +93,9 @@ ThermalScattering::ThermalScattering( fatal_error(fmt::format( "Nuclear data library does not contain cross sections " "for {} at or near {} K. Available temperatures " - "are {} K consider making use of openmc.Settings.temperature " + "are {} K. Consider making use of openmc.Settings.temperature " "to specify how intermediate temperatures are treated.", - name_, std::to_string(std::round(T)), concatenate(temps_available))); + name_, std::round(T), concatenate(temps_available, ", "))); } } break;