namespace X
{
struct Y{};
template<typename F>
void myfunc(F f, Y y) {}
}
double identity(double x){return x;}
int main()
{
myfunc(identity, X::Y()); //ADL Works as expected
myfunc([](double x){return x;}, X::Y()); //THIS FAILS! Doesn't seem
to like rvalue lambdas
auto f = [](double x){return x;};
myfunc(f, X::Y()); //Strangely, this works fine
}
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
This link seems truncated and I could not successfully resolve it (not
even from your OP).
> namespace X
> {
> struct Y{};
>
> template<typename F>
> void myfunc(F f, Y y) {}
> }
[..]
> int main()
> {
[..]
> myfunc([](double x){return x;}, X::Y()); //THIS FAILS! Doesn't seem
> to like rvalue lambdas
>
> auto f = [](double x){return x;};
> myfunc(f, X::Y()); //Strangely, this works fine
> }
The difference between these two invocations of myfunc looks
like a compiler bug to me. The compiler should accept both
versions. In fact the lambda closure case is not essentially
different from
struct { double operator()(double x) const { return x; } } obj;
myfunc(decltype(obj)(), X::Y());
within the function body of main. The conditions for
ADL require a function call (this is satisfied) and an
/unqualified-id/ as /postfix-expression/. This seems
to be satisfied as well. Comparing the mechanism of
ADL with the specification of a lambda-expression I
don't see a special interaction here, especially not
one related to the value category of the argument.
HTH & Greetings from Bremen,
Daniel Krügler
> The difference between these two invocations of myfunc looks
> like a compiler bug to me. The compiler should accept both
> versions. In fact thelambdaclosure case is not essentially
> different from
Thanks for taking a look at this. Microsoft has confirmed it is a
bug, but says that they will not fix it
(or will wait to the next major release). This is a pretty awful bug
for DSEL, so if it helps feel free
to 'vote' for the bug (though I am not sure if it helps)
https://connect.microsoft.com/VisualStudio/feedback/details/585643/