This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.

2774. std::function construction vs assignment

Section: [func.wrap.func.con] Status: New Submitter: Barry Revzin Opened: 2016-09-14 Last modified: 2017-02-03

Priority: 3

View other active issues in [func.wrap.func.con].

View all other issues in [func.wrap.func.con].

View all issues with New status.


I think there's a minor defect in the std::function interface. The constructor template is:

template <class F> function(F f);

while the assignment operator template is

template <class F> function& operator=(F&& f);

The latter came about as a result of LWG 1288, but that one was dealing with a specific issue that wouldn't have affected the constructor. I think the constructor should also take f by forwarding reference, this saves a move in the lvalue/xvalue cases and is also just generally more consistent. Should just make sure that it's stored as std::decay_t<F> instead of F.

Is there any reason to favor a by-value constructor over a forwarding-reference constructor?

Proposed resolution: