From e890321a3baac2a1964984f3e1775814b0b774fc Mon Sep 17 00:00:00 2001 From: Mikael Lund Date: Tue, 2 Jul 2024 09:37:57 +0200 Subject: [PATCH] Minor cleanup of conditions --- src/atomdata.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/atomdata.cpp b/src/atomdata.cpp index 6cc421d48..1e036e3b8 100644 --- a/src/atomdata.cpp +++ b/src/atomdata.cpp @@ -115,16 +115,15 @@ void to_json(json& j, const AtomData& a) } /// Handles optional translational and rotational displacement -void set_dp_and_dprot(const json& j, AtomData& a) +void set_dp_and_dprot(const json& j, AtomData& atomdata) { - a.dp = get_optional(j, "dp"); - if (a.dp.has_value()) { // Later use C++23 `and_then()` - a.dp = a.dp.value() * 1.0_angstrom; + // todo: use `std::optional::and_then()` when C++23 is available + if (const auto dp = get_optional(j, "dp")) { + atomdata.dp = dp.value() * 1.0_angstrom; } - a.dprot = get_optional(j, "dprot"); - if (a.dprot.has_value()) { // Later use C++23 `and_then()` - a.dprot = a.dprot.value() * 1.0_rad; - if (std::fabs(a.dprot.value()) > 2.0 * pc::pi) { + if (const auto dprot = get_optional(j, "dprot")) { + atomdata.dprot = dprot.value() * 1.0_rad; + if (std::fabs(atomdata.dprot.value()) > 2.0 * pc::pi) { faunus_logger->warn("rotational displacement should be between [0:2π]"); } }