From a695b05b21f3fb3b5dfc680f00f95a873c51dd13 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Tue, 3 Dec 2019 19:15:30 -0800 Subject: [PATCH] Add support for std::optional to PointerWrap --- Source/Core/Common/ChunkFile.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/Source/Core/Common/ChunkFile.h b/Source/Core/Common/ChunkFile.h index aef3a2ec4a..d947339fcd 100644 --- a/Source/Core/Common/ChunkFile.h +++ b/Source/Core/Common/ChunkFile.h @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -144,6 +145,36 @@ public: Do(x.second); } + template + void Do(std::optional& x) + { + bool present = x.has_value(); + Do(present); + + switch (mode) + { + case MODE_READ: + if (present) + { + x = std::make_optional(); + Do(x.value()); + } + else + { + x = std::nullopt; + } + break; + + case MODE_WRITE: + case MODE_MEASURE: + case MODE_VERIFY: + if (present) + Do(x.value()); + + break; + } + } + template void DoArray(std::array& x) {