Document use of futures with C++17 structured bindings and other C++17/20 idioms
The C++ standard specifies that structured bindings can use get<i>(e)
, found by ADL, to enable structured bindings for a custom class. By providing this function in the upcxx
namespace for upcxx::future
or as a hidden friend in upcxx::future
, we can enable this functionality for UPC++ futures.
upcxx::future<int,double> fut = /* ... */;
auto [a,b] = fut;
Comments (8)
-
-
- changed title to Document use of futures with C++17 structured bindings and other C++17/20 idioms
- changed component to Documentation
-
assigned issue to
This issue was discussed in the 2021-04-21 Pagoda meeting.
The consensus was we should start some documentation that collects and demonstrates useful C++17/C++20 idioms as applied to UPC++ types, functions and common operations. This could eventually become a section in the Programming Guide, but for now we can develop it as a page for the wiki, as a pull request against this repo
Colin was nominated to work on this documentation.
-
Please let me know if you do not have the necessary access to the wiki repo Dan mentions in the previous comment.
-
- changed milestone to 2022.3.0 release
Mass roll-over of open issues to next release milestone
-
- changed milestone to 2022.9.0 release
Mass roll-over of open issues to next release milestone
-
- changed milestone to 2023.3.0 release
Mass roll-over of open issues to next release milestone
-
-
assigned issue to
Daniel will look into this doc improvement, probably in a new section of the guide focused on new language levels
-
assigned issue to
-
- changed status to resolved
- Log in to comment
At first glance this proposal seemed like a good idea, but after some further thought I realized that
future::wait()
andfuture::result()
already provide the requested functionality. I.e., the following already works (in -std=c++17 mode):Similarly
future::wait_reference()
andfuture::result_reference()
also work in the way you'd expect, declaring const references to the future elements and eliding data copy.I think this already seems like the right design, because each of these four cases make sense under different circumstances, and I'd prefer the user be explicit about what they want, rather than us arbitrarily choosing one semantic. I'd also be opposed to standardizing any implicit syntax that hid a
wait
operation, since those have such a large potential impact on application performance.@Colin MacLean assuming you agree, we can convert this to a documentation issue to add an example of this idiom somewhere in our training materials. We already have some examples that accomplish a similar effect using C++11
std::tie
, but C++17 makes this much more convenient with auto structured bindings and that seems worth demonstrating somewhere.