X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/84402e8e2ee2a2d0bef25fdceb0a263ed8b471f6..4b0fa756ae6e58a74c374a519389ecb9e8b6a4d9:/include/simgrid/kernel/future.hpp diff --git a/include/simgrid/kernel/future.hpp b/include/simgrid/kernel/future.hpp index 7a1a1d3293..b41008eb64 100644 --- a/include/simgrid/kernel/future.hpp +++ b/include/simgrid/kernel/future.hpp @@ -48,7 +48,7 @@ public: FutureStateBase(FutureStateBase const&) = delete; FutureStateBase& operator=(FutureStateBase const&) = delete; - XBT_PUBLIC void schedule(simgrid::xbt::Task&& job); + XBT_PUBLIC void schedule(simgrid::xbt::Task&& job) const; void set_exception(std::exception_ptr exception) { @@ -283,13 +283,9 @@ public: // Move type: Future(Future&) = delete; - Future& operator=(Future&) = delete; - Future(Future&& that) : state_(std::move(that.state_)) {} - Future& operator=(Future&& that) - { - state_ = std::move(that.state_); - return *this; - } + Future& operator=(const Future&) = delete; + Future(Future&&) noexcept = default; + Future& operator=(Future&&) noexcept = default; /** Whether the future is valid:. * @@ -451,9 +447,9 @@ public: // Move type Promise(Promise const&) = delete; Promise& operator=(Promise const&) = delete; - Promise(Promise&& that) : state_(std::move(that.state_)) { std::swap(future_get_, that.future_get_); } + Promise(Promise&& that) noexcept : state_(std::move(that.state_)) { std::swap(future_get_, that.future_get_); } - Promise& operator=(Promise&& that) + Promise& operator=(Promise&& that) noexcept { this->state_ = std::move(that.state_); this->future_get_ = that.future_get_; @@ -489,7 +485,7 @@ public: } private: - std::shared_ptr> state_{new FutureState()}; + std::shared_ptr> state_ = std::make_shared>(); bool future_get_ = false; }; @@ -508,8 +504,8 @@ public: // Move type Promise(Promise const&) = delete; Promise& operator=(Promise const&) = delete; - Promise(Promise&& that) : state_(std::move(that.state_)) { std::swap(future_get_, that.future_get_); } - Promise& operator=(Promise&& that) + Promise(Promise&& that) noexcept : state_(std::move(that.state_)) { std::swap(future_get_, that.future_get_); } + Promise& operator=(Promise&& that) noexcept { this->state_ = std::move(that.state_); this->future_get_ = that.future_get_; @@ -526,13 +522,13 @@ public: future_get_ = true; return Future(state_); } - void set_value() + void set_value() const { if (state_ == nullptr) throw std::future_error(std::future_errc::no_state); state_->set_value(); } - void set_exception(std::exception_ptr exception) + void set_exception(std::exception_ptr exception) const { if (state_ == nullptr) throw std::future_error(std::future_errc::no_state); @@ -540,7 +536,7 @@ public: } private: - std::shared_ptr> state_{new FutureState()}; + std::shared_ptr> state_ = std::make_shared>(); bool future_get_ = false; };