From f8338dbb73e042b4d501c96e7e9fb75dd81037ea Mon Sep 17 00:00:00 2001 From: logan Date: Thu, 10 Jun 2021 09:42:24 -0700 Subject: [PATCH] Use std::optional::emplace() when loading to construct and load the contained value directly in place --- include/cereal/types/optional.hpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/cereal/types/optional.hpp b/include/cereal/types/optional.hpp index 3b244465..a68c055b 100644 --- a/include/cereal/types/optional.hpp +++ b/include/cereal/types/optional.hpp @@ -56,9 +56,8 @@ namespace cereal { if (nullopt) { optional = std::nullopt; } else { - T value; - ar(CEREAL_NVP_("data", value)); - optional = std::move(value); + optional.emplace(); + ar(CEREAL_NVP_("data", *optional)); } } } // namespace cereal