Implement LWG2442, use references to call_once arguments instead of decay-copying them.
Details
Diff Detail
Event Timeline
include/mutex | ||
---|---|---|
445 | This change is being made in order to support non-copyable Callable objects, right? I'm not convinced that always adding const is the correct thing to do. Without the const the new signature won't accept rvalues as input but adding const requires Callable to be const-callable. Why not provide two signatures? It's not perfect but I think it is better. void call_once(once_flag&, _Callable&); // accepts non-const lvalues. void call_once(once_flag&, _Callable const&); // accepts rvalues and const lvalues. Thoughts? | |
test/std/thread/thread.mutex/thread.once/thread.once.callonce/call_once.pass.cpp | ||
160 | That seems like it might indicate a problem. Do you know what is going on here? Are you sure you want to work around this? | |
236 | Could you also add tests for the following:
|
include/mutex | ||
---|---|---|
445 | I initially considered adding a perfectly forwarding non-variadic version when rvalue-refs are supported, and the two overloads you suggest above otherwise. This would add quite a lot of noise (each signature is present thrice). I guestimated const-ref to be enough, but I will add as many overloads and workarounds as you deem necessary. | |
test/std/thread/thread.mutex/thread.once/thread.once.callonce/call_once.pass.cpp | ||
160 | If you expand the context a bit you will see that I took it from MoveOnly right above, I have not experienced the issue myself. | |
236 |
This is already the case, NonCopyable() is the function.
Good idea, will do. |
Addressed review comments:
- Added a non-const lvalue ref overload for the non-variadic case
- Added test case using ref-qualifiers
LGTM and thanks! I'm going to cleanup the original call_once tests and add new tests once this is committed.
@mclow.lists We want to adopt this change retroactively, correct?
@K-ballo Do you want me to commit this for you?
A nit, but other than that, LGTM.
test/std/thread/thread.mutex/thread.once/thread.once.callonce/call_once.pass.cpp | ||
---|---|---|
242 | Let's use the TEST_STD_VERS macro instead of the naked __cplusplus here |
This change is being made in order to support non-copyable Callable objects, right? I'm not convinced that always adding const is the correct thing to do. Without the const the new signature won't accept rvalues as input but adding const requires Callable to be const-callable.
Why not provide two signatures? It's not perfect but I think it is better.
Thoughts?