dot-xx
A personal collection of small C++ modules
Loading...
Searching...
No Matches
dxx.overload Module Reference

overload pattern with a few bells and whistles More...

Classes

struct  dxx::overload::overload< Ts >
 Overload pattern implementation. Itself does not differ from https://www.cppstories.com/2019/02/2lines3featuresoverload.html/, extra functionality comes from CTAD. See module description for usage. More...

Detailed Description

overload pattern with a few bells and whistles

Supports, aside from resgular function-like objects, free and member function pointers:

struct S {
void f() const { std::println("S::f()"); }
void g(int) const { std::println("S::g(int)"); }
};
void h(const S&, float) { std::println("h(const S&, float)"); }
// ... someplace else
const dxx::overload::overload callback{
[] (int i) { std::println("lambda"); },
&S::f,
&S::g,
h,
}; // <-- const overload callback
callback(10); // lambda
callback(S{}); // S::f()
callback(S{}, 10); // S::g(int)
callback(S{}, 10.0f); // h(const S&, float)
Overload pattern implementation. Itself does not differ from https://www.cppstories....
Definition overload.xx:107

There is also a utility operator| for the overload that automatically calls std::visit:

std::variant<int, S>{ 10 } | callback;

Files

file  /build-llvm-libcpp/_deps/dot-xx-overload-src/src/overload.xx
 Main interface file of dxx::overload module.