Collectives: why use rvalue references and not const reference ?

Issue #96 resolved
Mathias Jacquelin created an issue

My discussion with P. Ghysels led to the following comment:

Why do we have: future<T> broadcast(T && val, intrank_t sender);

instead of : future<T> broadcast(const T & val, intrank_t sender);

if "val" is never modified ? The second signature should also be able to handle rvalues, right ?

Comments (3)

  1. Amir Kamil

    In the context where we use &&, it doesn't necessarily result in an rvalue reference. Since the T is a template parameter, T&& is what's often called a universal reference. The result is that if the user passes an lvalue, the argument type deduces as const T&, but if the user passes an rvalue, it deduces as T&&. The latter allows us to move the rvalue into upcxx-managed storage instead of having to make a copy, which is especially important if the value is expensive to copy. On the other hand, we can't move a const T&.

  2. Log in to comment