From 15f6ec224c29499fcfc87e9c3034aed66e96be7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20P=C3=B6schel?= Date: Wed, 11 Oct 2023 09:25:44 +0200 Subject: [PATCH] Two little fixes --- include/openPMD/auxiliary/DerefDynamicCast.hpp | 14 +++++++++++--- src/Mesh.cpp | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/include/openPMD/auxiliary/DerefDynamicCast.hpp b/include/openPMD/auxiliary/DerefDynamicCast.hpp index 6b2674ae9e..ecbf2033e1 100644 --- a/include/openPMD/auxiliary/DerefDynamicCast.hpp +++ b/include/openPMD/auxiliary/DerefDynamicCast.hpp @@ -22,6 +22,7 @@ #include #include +#include namespace openPMD { @@ -64,10 +65,17 @@ namespace auxiliary inline std::optional dynamic_cast_optional(Old_Type *ptr) noexcept { - auto const tmp_ptr = dynamic_cast(ptr); - if (tmp_ptr == nullptr) + try + { + auto const tmp_ptr = dynamic_cast(ptr); + if (tmp_ptr == nullptr) + return std::nullopt; + return {tmp_ptr}; + } + catch (std::bad_cast const &) + { return std::nullopt; - return {tmp_ptr}; + } } } // namespace auxiliary diff --git a/src/Mesh.cpp b/src/Mesh.cpp index d9ad2963d4..97e8fa4387 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -264,7 +264,7 @@ namespace { for (auto [unit, exponent] : udim) { - *(it + static_cast(unit)) = exponent; + it[static_cast(unit)] = exponent; } } } // namespace