[PATCH] D11553: [libcxx] Rewrite C++03 __invoke.

Eric Fiselier eric at efcs.ca
Mon Jul 27 22:14:37 PDT 2015


EricWF added a comment.

Add inline comment describing part of the change. Sorry about all the spam :S


================
Comment at: include/functional:1266
@@ -1265,2 +1265,3 @@
+    _LIBCPP_INLINE_VISIBILITY
     typename __invoke_return0<type, _A0>::type
     operator() (_A0& __a0) const {
----------------
This part of the change adds extra overloads in `mem_fn` so that the call operator can accept rvalues and temporaries as input.

A template argument `Ax&` will bind to any cv-qualified lvalue. However it will not bind to an rvalue. In order to accept an rvalue in C++03 we need to accept it as `Ax const&`.  Therefore we need to enumerate  every possible combination of const and non-const arguments for each `operator()(...)` function. 

Unfortunately this solution isn't perfect. Non-const rvalues will be forwarded as const by  `__invoke(...)` and anything that required the values to be non-const will not compile. However I think this is the best we can do.

This same change is made to `reference_wrapper`.


http://reviews.llvm.org/D11553







More information about the cfe-commits mailing list