Code Monkey home page Code Monkey logo

Comments (7)

BenPope avatar BenPope commented on August 29, 2024

I don't know if this is the preferred way, but I have made the attached patch for this reason.

Index: boost/fiber/future/future.hpp
===================================================================
--- boost/fiber/future/future.hpp   (revision 4246)
+++ boost/fiber/future/future.hpp   (revision 4247)
@@ -152,7 +152,7 @@

     shared_future< R & > share();

-    R & get() {
+    R get() {
         if ( ! valid() ) {
             throw future_uninitialized();
         }
Index: boost/fiber/future/detail/shared_state.hpp
===================================================================
--- boost/fiber/future/detail/shared_state.hpp  (revision 4246)
+++ boost/fiber/future/detail/shared_state.hpp  (revision 4247)
@@ -81,12 +81,12 @@
         mark_ready_and_notify_( lk);
     }

-    R const& get_( std::unique_lock< mutex > & lk) {
+    R get_( std::unique_lock< mutex > & lk) {
         wait_( lk);
         if ( except_) {
             std::rethrow_exception( except_);
         }
-        return value_.get();
+        return std::move(value_.get());
     }

     std::exception_ptr get_exception_ptr_( std::unique_lock< mutex > & lk) {
@@ -161,7 +161,7 @@
         set_exception_( except, lk);
     }

-    R const& get() {
+    R get() {
         std::unique_lock< mutex > lk( mtx_);
         return get_( lk);
     }

from fiber.

olk avatar olk commented on August 29, 2024

unfortunately it is not fixed yet
the C++ standard requires signature R & future< R & >::get()

from fiber.

dvd0101 avatar dvd0101 commented on August 29, 2024

Can you help me understand?

This code compiles fine:

#include <iostream>
#include <future>

struct A {
    A() = default;
    A(A const&) = delete;
    A(A&&) = default;

    int value;
};

int main() {
    using namespace std;

    promise<A> p;
    auto future = p.get_future();
    std::cout << future.get().value << std::endl;
}

So I don't understand your comment about the C++ standard

from fiber.

olk avatar olk commented on August 29, 2024

my comment was related to the comment of BenPope

from fiber.

BenPope avatar BenPope commented on August 29, 2024

The standard (ยง 30.6.6.13) requires:

R future<R>::get();
R& future<R&>::get();
void future<void>::get();

I believe I corrected the signature for future< R >, leaving future< R& > alone.

Update: I was wrong, looks like I messed up the patch to future.hpp, but the one to shared_state still seems valid. If I make a pull request, against which branch would you prefer?

from fiber.

dvd0101 avatar dvd0101 commented on August 29, 2024

What do you think about this patch? It introduces a small asymmetry in the
implementations of future::get and shared_future::get but the observable
behaviour should be preserved.

diff -u -r ./detail/shared_state.hpp ../../../../../support/deps/include/boost/fiber/future/detail/shared_state.hpp
--- ./detail/shared_state.hpp   2015-10-14 19:17:13.169202093 +0200
+++ ../../../../../support/deps/include/boost/fiber/future/detail/shared_state.hpp  2015-10-14 19:28:04.844428815 +0200
@@ -89,6 +89,14 @@
         return value_.get();
     }

+    R detach_( std::unique_lock< mutex > & lk) {
+        wait_( lk);
+        if ( except_) {
+            std::rethrow_exception( except_);
+        }
+        return std::move(value_.get());
+    }
+
     std::exception_ptr get_exception_ptr_( std::unique_lock< mutex > & lk) {
         wait_( lk);
         return except_;
@@ -166,6 +174,11 @@
         return get_( lk);
     }

+    R detach() {
+        std::unique_lock< mutex > lk( mtx_);
+        return detach_( lk);
+    }
+
     std::exception_ptr get_exception_ptr() {
         std::unique_lock< mutex > lk( mtx_);
         return get_exception_ptr_( lk);
diff -u -r ./future.hpp ../../../../../support/deps/include/boost/fiber/future/future.hpp
--- ./future.hpp    2015-10-14 19:17:13.169202093 +0200
+++ ../../../../../support/deps/include/boost/fiber/future/future.hpp   2015-10-14 19:26:14.656559563 +0200
@@ -77,7 +77,7 @@
         }
         ptr_t tmp;
         tmp.swap( state_);
-        return tmp->get();
+        return tmp->detach();
     }

     std::exception_ptr get_exception_ptr() {

BTW: there is a reason why this issue is closed? We should continue elsewhere?

from fiber.

olk avatar olk commented on August 29, 2024

please note that boost.fiber is still in development ...
I've pushed a new version to branch develop - futures support moveable-only objects now

from fiber.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.