A C++ template library for embedded applications
MIT licensed
Designed and
maintained by
John Wellbelove
Support the development
of the ETL

Overload

20.14.0

For C++11 and above


Allows creation of a functor of overloaded lambdas

etl::overload<typename... TOverloads>
____________________________________________________________________________________________________

Template deduction guide

For C++17 and above


template <typename... TOverloads>
overload(TOverloads...) -> overload<TOverloads...>;
____________________________________________________________________________________________________

Non-member functions


template <typename... TOverloads>
constexpr overload<TOverloads...> make_overload(TOverloads&&... overloads)
Creates an etl::overload from a set of lambdas.
____________________________________________________________________________________________________

Example

____________________________________________________________________________________________________

C++11 and above.

int         result_int;
double      result_double;
std::string result_string;

auto overloaded = etl::make_overload([](int i) { result_int = i; },
                                     [](double d) { result_double = d; },
                                     [](const std::string& s) { result_string = d; });

template <typename T, typename TOverload>
void Function(T value, TOverload&& ol)
{
  ol(value);
}

Function(int(1), overloaded);           // result_int    == 1
Function(double(2.2), overloaded);      // result_double == 2.2
Function(std::string("3"), overloaded); // result_string == "3"
____________________________________________________________________________________________________

C++17 and above.

Function(int(1), etl::overload
                 {
                   [](int i) { result_int = i; },
                   [](double d) { result_double = d; },
                   [](const std::string& s) { result_string = d; }
                 });

overload.h

WYSIWYG Web Builder