Created
December 16, 2016 07:06
-
-
Save enobayram/5f8c7f6551933e6121eb65779c78b69d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <stdio.h> | |
template<class Func> | |
struct overload_base { | |
Func f; | |
template <class ... T> | |
friend decltype(f(std::declval<T>()...)) call(overload_base * b, T ... in) { | |
return b->f(in...); | |
} | |
}; | |
template<class ... Funcs> | |
struct overload_impl: overload_base<Funcs>... { | |
overload_impl(Funcs...funcs): overload_base<Funcs>{funcs}...{} | |
template <class ... T> | |
auto operator()(T ... i) { | |
return call(this, i ...); | |
} | |
}; | |
template<class ... Funcs> | |
overload_impl<Funcs...> overload(Funcs...funcs){return {funcs...};} | |
struct MyNewVisitor { | |
int operator()(double d) { | |
return d*2; | |
} | |
std::string operator()(std::string i) { | |
return "kafama gore string"; | |
} | |
}; | |
int main() { | |
auto var = overload([](double d) {return d*2;}, [](std::string i){return "kafama gore string";})(6.0); | |
printf("%f", var); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment