Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The actually confusing part is that && has two different meanings:

Rvalue reference, the passed value either has no memory location yet or has a memory location that won't be accessed anymore (e.g. Marked with std::move)

     void foo(int&& a)
Universal reference. `a` is inferred as an rvalue reference if it is initialized with an rvalue and a normal reference otherwise:

    template <class T>  void foo(T&& a)
So && with type deduction tries to forward rvalue-ness. It does a terrible job, though, which is why std::forward exists.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: