Overload resolution: assignment of empty braces

Why is operator=(int) selected here, instead of “ambiguous” or the other one? {} to int is the identity conversion ([over.ics.list]/9). {} to S is a user-defined conversion ([over.ics.list]/6) (technically, it’s {} to const S&, and goes through [over.ics.list]/8 and [over.ics.ref] first before coming back to [over.ics.list]/6). The first wins. Is there a tidy workaround? A … Read more

Most terse and reusable way of wrapping template or overloaded functions in function objects

You can create a macro like #define FUNCTORIZE(func) [](auto&&… val) \ noexcept(noexcept(func(std::forward<decltype(val)>(val)…))) -> decltype(auto) \ {return func(std::forward<decltype(val)>(val)…);} which will let you wrap any callable into a closure object. You would use it like auto constexpr predObj = FUNCTORIZE(pred);

C++ template functions overload resolution

The unspecialized function templates are also called the underlying base templates. Base templates can be specialized. The overloading rules to see which ones get called in different situations, are pretty simple, at least at a high level: Nontemplate functions are first-class citizens. A plain old nontemplate function that matches the parameter types as well as … Read more

Overloaded method-group argument confuses overload resolution?

First off, I note that this is a duplicate of: Why is Func<T> ambiguous with Func<IEnumerable<T>>? What’s the exact problem here? Thomas’s guess is essentially correct. Here are the exact details. Let’s go through it a step at a time. We have an invocation: “test”.Select<char, Tuple<char>>(Tuple.Create); Overload resolution must determine the meaning of the call … Read more