summaryrefslogtreecommitdiff
path: root/zen/optional.h
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2014-04-18 17:20:29 +0200
committerDaniel Wilhelm <daniel@wili.li>2014-04-18 17:20:29 +0200
commitb8f13e45be884dc12884ebe8f3dcd9eecb23a106 (patch)
tree22a6d8b96815d626061ff3e2d432c13078fca5c4 /zen/optional.h
parent5.4 (diff)
downloadFreeFileSync-b8f13e45be884dc12884ebe8f3dcd9eecb23a106.tar.gz
FreeFileSync-b8f13e45be884dc12884ebe8f3dcd9eecb23a106.tar.bz2
FreeFileSync-b8f13e45be884dc12884ebe8f3dcd9eecb23a106.zip
5.5
Diffstat (limited to 'zen/optional.h')
-rw-r--r--zen/optional.h15
1 files changed, 12 insertions, 3 deletions
diff --git a/zen/optional.h b/zen/optional.h
index 2bd272ae..34e3d21d 100644
--- a/zen/optional.h
+++ b/zen/optional.h
@@ -38,9 +38,17 @@ public:
Opt(NoValue) : value() , valid(false) {}
Opt(const T& val) : value(val), valid(true ) {}
- //rvalue optimization: only basic exception safety:
- Opt(Opt&& tmp) : value(std::move(tmp.value)), valid(tmp.valid) {}
- Opt& operator=(const Opt& tmp) { value = std::move(tmp.value); valid = tmp.valid; }
+ Opt(const Opt& tmp) : value(tmp.valid ? tmp.value : T()), valid(tmp.valid) {}
+
+ Opt& operator=(const Opt& tmp)
+ {
+ if (tmp.valid)
+ value = tmp.value;
+ valid = tmp.valid;
+ }
+
+ ////rvalue optimization: only basic exception safety:
+ // Opt(Opt&& tmp) : value(std::move(tmp.value)), valid(tmp.valid) {}
#ifdef _MSC_VER
private:
@@ -58,6 +66,7 @@ public:
/**/ T* operator->() { return &value; }
void reset() { valid = false; }
+
private:
T value;
bool valid;
bgstack15