X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/d24c7ee63727f700573deebfab7022ba0bce6dae..4634214e18b847f6346048fa12179d3d99ae82c9:/include/xbt/future.hpp diff --git a/include/xbt/future.hpp b/include/xbt/future.hpp index a374bec117..3c1f761ab7 100644 --- a/include/xbt/future.hpp +++ b/include/xbt/future.hpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2015-2016. The SimGrid Team. +/* Copyright (c) 2015-2018. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -14,6 +14,7 @@ #include #include #include +#include namespace simgrid { namespace xbt { @@ -33,7 +34,7 @@ class Result { exception, }; public: - Result() {} + Result() { /* Nothing to do */} ~Result() { this->reset(); } // Copy (if T is copyable) and move: @@ -47,12 +48,14 @@ public: switch (that.status_) { case ResultStatus::invalid: break; - case ResultStatus::valid: + case ResultStatus::value: new (&value_) T(that.value); break; case ResultStatus::exception: new (&exception_) T(that.exception); break; + default: + THROW_IMPOSSIBLE; } return *this; } @@ -66,7 +69,7 @@ public: switch (that.status_) { case ResultStatus::invalid: break; - case ResultStatus::valid: + case ResultStatus::value: new (&value_) T(std::move(that.value)); that.value.~T(); break; @@ -74,6 +77,8 @@ public: new (&exception_) T(std::move(that.exception)); that.exception.~exception_ptr(); break; + default: + THROW_IMPOSSIBLE; } that.status_ = ResultStatus::invalid; return *this; @@ -94,6 +99,8 @@ public: case ResultStatus::exception: exception_.~exception_ptr(); break; + default: + THROW_IMPOSSIBLE; } status_ = ResultStatus::invalid; } @@ -123,9 +130,6 @@ public: T get() { switch (status_) { - case ResultStatus::invalid: - default: - throw std::logic_error("Invalid result"); case ResultStatus::value: { T value = std::move(value_); value_.~T(); @@ -139,6 +143,8 @@ public: std::rethrow_exception(std::move(exception)); break; } + default: + throw std::logic_error("Invalid result"); } } private: