On 2014-11-17 14:11, Thiago Macieira wrote:
> On Tuesday 18 November 2014 03:06:50 David Krauss wrote:
>> On 2014–11–18, at 3:02 AM, Matthew Woehlke wrote:
>>> Taking the address of an overloaded function or method is painful. From
>>> a language processing standpoint, is there a reason why this needs to be
>>> the case?
>>
>> I agree, it’s a problem that should be solved. With lambdas we
>> don’t need to take addresses quite as often, but the wart is still
>> there.
It's *required* for the address style of Qt signal/slot connections, at
least for the signal. (A lambda is also still quite a bit uglier than an
address for the slot, and worse, you lose automatic disconnection when
the receiver is destroyed.) So, while lambdas help some cases, not so
much this case :-).
Incidentally, this (Qt signals/slots using addresses) was the specific
pain point that motivated the original question.
>>> auto p = &Foo::bar(int);
>>
>> With this syntax, how would you query an empty argument type list?
>
> auto p = &Foo::bar(void);
>
> *ugh* /me runs
Uhm... right... yeah, you'd need the type there to disambiguate. Well,
that's not the end of the world.
I was also thinking about using something besides ()'s for the argument
list to disambiguate taking an address vs. calling, but not sure that
would be a good idea.
For now I'm using a library solution:
template <typename... Args>
class resolved
{
public:
template <typename Class, typename Result>
auto operator()(Result (Class::*m)(Args...)) const
-> decltype(m)
{ return m; }
};
...which is an immense improvement:
auto p1 = resolved<int>{}(&Foo::bar);
auto p2 = resolved<void>{}(&Foo::bar);
...but I still feel like there should be a simple, clean way...
That said, if anyone can make one of the {}'s or ()'s in the above go
away, I'd be pretty happy with that...
(Before someone (fairly) points out that the existing syntax for
assigning a member pointer isn't all *that* bad, I should note that the
motivating case is where one like to be able to pass a pointer to some
other function/method *without* needing to assign it to a local variable
at all.)
--
Matthew