summaryrefslogtreecommitdiff
path: root/zen/optional.h
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2014-04-18 17:27:42 +0200
committerDaniel Wilhelm <daniel@wili.li>2014-04-18 17:27:42 +0200
commitb916407a2a06f8452e82b74dc44c54acbcc572b0 (patch)
tree46358e0bb035fca0f42edb4b5b8aa5f1613814af /zen/optional.h
parent5.20 (diff)
downloadFreeFileSync-b916407a2a06f8452e82b74dc44c54acbcc572b0.tar.gz
FreeFileSync-b916407a2a06f8452e82b74dc44c54acbcc572b0.tar.bz2
FreeFileSync-b916407a2a06f8452e82b74dc44c54acbcc572b0.zip
5.21
Diffstat (limited to 'zen/optional.h')
-rw-r--r--zen/optional.h19
1 files changed, 7 insertions, 12 deletions
diff --git a/zen/optional.h b/zen/optional.h
index 6e54408a..15d27f4b 100644
--- a/zen/optional.h
+++ b/zen/optional.h
@@ -7,6 +7,8 @@
#ifndef OPTIONAL_H_2857428578342203589
#define OPTIONAL_H_2857428578342203589
+#include <cassert>
+
namespace zen
{
/*
@@ -45,26 +47,19 @@ public:
if (tmp.valid)
value = tmp.value;
valid = tmp.valid;
- return *this;
+ return *this;
}
////rvalue optimization: only basic exception safety:
// Opt(Opt&& tmp) : value(std::move(tmp.value)), valid(tmp.valid) {}
-#ifdef _MSC_VER
-private:
- struct ConversionToBool { int dummy; };
-public:
- operator int ConversionToBool::* () const { return valid ? &ConversionToBool::dummy : nullptr; }
-#else
explicit operator bool() const { return valid; } //thank you C++11!!!
-#endif
- const T& operator*() const { return value; }
- /**/ T& operator*() { return value; }
+ const T& operator*() const { assert(valid); return value; }
+ /**/ T& operator*() { assert(valid); return value; }
- const T* operator->() const { return &value; }
- /**/ T* operator->() { return &value; }
+ const T* operator->() const { assert(valid); return &value; }
+ /**/ T* operator->() { assert(valid); return &value; }
void reset() { valid = false; }
bgstack15