A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
[SMPI] Renamed default SMPI instance for smpirun
[simgrid.git]
/
include
/
xbt
/
future.hpp
diff --git
a/include/xbt/future.hpp
b/include/xbt/future.hpp
index
aa559db
..
55abdc7
100644
(file)
--- a/
include/xbt/future.hpp
+++ b/
include/xbt/future.hpp
@@
-1,4
+1,4
@@
-/* Copyright (c) 2015-201
6
. The SimGrid Team.
+/* Copyright (c) 2015-201
7
. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
@@
-9,20
+9,22
@@
#include <cstddef>
#include <cstddef>
-#include <utility>
#include <exception>
#include <exception>
+#include <functional>
#include <stdexcept>
#include <stdexcept>
-
#include <type_traits>
#include <type_traits>
-
-
+#include <utility>
+#include <xbt/ex.h>
namespace simgrid {
namespace xbt {
namespace simgrid {
namespace xbt {
-/** A value or an exception
+/** A value or an exception
(or nothing)
*
*
- * The API is similar to the one of future and promise.
+ * This is similar to `optional<expected<T>>`` but it with a Future/Promise
+ * like API.
+ *
+ * Also the name is not so great.
**/
template<class T>
class Result {
**/
template<class T>
class Result {
@@
-32,7
+34,7
@@
class Result {
exception,
};
public:
exception,
};
public:
- Result() {}
+ Result() {
/* Nothing to do */
}
~Result() { this->reset(); }
// Copy (if T is copyable) and move:
~Result() { this->reset(); }
// Copy (if T is copyable) and move:
@@
-46,12
+48,14
@@
public:
switch (that.status_) {
case ResultStatus::invalid:
break;
switch (that.status_) {
case ResultStatus::invalid:
break;
- case ResultStatus::val
id
:
+ case ResultStatus::val
ue
:
new (&value_) T(that.value);
break;
case ResultStatus::exception:
new (&exception_) T(that.exception);
break;
new (&value_) T(that.value);
break;
case ResultStatus::exception:
new (&exception_) T(that.exception);
break;
+ default:
+ THROW_IMPOSSIBLE;
}
return *this;
}
}
return *this;
}
@@
-65,7
+69,7
@@
public:
switch (that.status_) {
case ResultStatus::invalid:
break;
switch (that.status_) {
case ResultStatus::invalid:
break;
- case ResultStatus::val
id
:
+ case ResultStatus::val
ue
:
new (&value_) T(std::move(that.value));
that.value.~T();
break;
new (&value_) T(std::move(that.value));
that.value.~T();
break;
@@
-73,6
+77,8
@@
public:
new (&exception_) T(std::move(that.exception));
that.exception.~exception_ptr();
break;
new (&exception_) T(std::move(that.exception));
that.exception.~exception_ptr();
break;
+ default:
+ THROW_IMPOSSIBLE;
}
that.status_ = ResultStatus::invalid;
return *this;
}
that.status_ = ResultStatus::invalid;
return *this;
@@
-93,6
+99,8
@@
public:
case ResultStatus::exception:
exception_.~exception_ptr();
break;
case ResultStatus::exception:
exception_.~exception_ptr();
break;
+ default:
+ THROW_IMPOSSIBLE;
}
status_ = ResultStatus::invalid;
}
}
status_ = ResultStatus::invalid;
}
@@
-117,14
+125,11
@@
public:
/** Extract the value from the future
*
/** Extract the value from the future
*
- * After this the value is invalid.
+ * After this
,
the value is invalid.
**/
T get()
{
switch (status_) {
**/
T get()
{
switch (status_) {
- case ResultStatus::invalid:
- default:
- throw std::logic_error("Invalid result");
case ResultStatus::value: {
T value = std::move(value_);
value_.~T();
case ResultStatus::value: {
T value = std::move(value_);
value_.~T();
@@
-138,6
+143,8
@@
public:
std::rethrow_exception(std::move(exception));
break;
}
std::rethrow_exception(std::move(exception));
break;
}
+ default:
+ throw std::logic_error("Invalid result");
}
}
private:
}
}
private:
@@
-184,7
+191,7
@@
public:
* promise.set_value(code());
* </pre>
*
* promise.set_value(code());
* </pre>
*
- * but it takes care of exceptions and works with
void
.
+ * but it takes care of exceptions and works with
`void`
.
*
* We might need this when working with generic code because
* the trivial implementation does not work with `void` (before C++1z).
*
* We might need this when working with generic code because
* the trivial implementation does not work with `void` (before C++1z).
@@
-217,7
+224,7
@@
auto fulfillPromise(P& promise, F&& code)
}
}
}
}
-/** Set a promise/result from a future/resul
+/** Set a promise/result from a future/resul
t
*
* Roughly this does:
*
*
* Roughly this does:
*