This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

functional: _Bind class function-call operator template has wrong return typeâ default parameterâ


The _Bind class function-call operator looks something like this:
template<typename... _Args, typename _Result
= decltype( std::declval<_Functor>()(_Mu<_Bound_args>()(
std::declval<_Bound_args&>(), std::declval<tuple<_Args...>&>() )... )
)>
_Result operator()(_Args&&... __args) { ... }
The problem is that std::declval returns an rvalue reference, but the
functor is invoked in an lvalue context. As a result, the following
(valid) code will fail to compile:
#include<functional>
struct B {};
struct C {};
struct A {
B operator()(int, double, char) & { return B(); }
C operator()(int, double, char) && {return C(); }
};
int main() {
A a;
auto bound = std::bind(a, 5, 4.3, 'c');
auto res = bound();
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]