Hacker News new | past | comments | ask | show | jobs | submit login
A Type for Overload Set (biowpn.github.io)
13 points by aw1621107 4 months ago | hide | past | favorite | 4 comments



I'm really surprised that the first example doesn't work. I would have thought that it decides which overload to use only when instantiating the template, and then doing argument dependent lookup (or whatever it is called) to pick the correct overload to match the type of the elements.

On the other hand, I don't even know how transform is defined. C++ has nothing exactly like IEnumerable<T>, so maybe it is hard to refer to the T? And of course what the article references, that there is no way to refer to the overload set.

I usually like C++, but it is not fun when the abstractions break like that.


The compiler doesn't have enough information yet to pick an overload when instantiating the transform template. transform takes any F as the function parameter, which isn't specific enough to pick a specific function pointer from an overload set.


> The crux of the problem, where all the examples above share in common, is that C++ does not have a type for overload sets.

>There is a recent proposal that aims to address this exact issue: P3312 - Overload Set Types.

Painfully common story.


This is my own version of `OVERLOAD` that works with both, although I forgot how did it works:

    #define FWD(...) ::std::forward<decltype(__VA_ARGS__)>(__VA_ARGS__)

    #define LIFT_CUSTOM(X, CAPTURE) CAPTURE (auto &&... args) \
     noexcept(noexcept(X(FWD(args)...))) -> decltype((X(FWD(args)...))) { \
      return X(FWD(args)...); \
     }

    #define LIFT(X) LIFT_CUSTOM(X, [&])




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: