Skip to content

Instantly share code, notes, and snippets.

@Fiona-J-W
Created August 3, 2015 18:33
Show Gist options
  • Save Fiona-J-W/d77ac2ef953b809f99ca to your computer and use it in GitHub Desktop.
Save Fiona-J-W/d77ac2ef953b809f99ca to your computer and use it in GitHub Desktop.
bind_first
#include <iostream>
#include <utility>
#define RESOLVE_OVERLOAD(...) \
[](auto&&...args)->decltype(auto){return __VA_ARGS__(std::forward<decltype(args)>(args)...);}
template<typename Fun, typename Arg>
auto bind_first(Fun f, Arg&& arg1) {
return [arg1 = std::forward<Arg>(arg1), f](auto&&... args) -> decltype(auto){
return f(arg1, std::forward<decltype(args)>(args)...);
};
}
void print_all(){}
template<typename Head, typename... Tail>
void print_all(const Head& h, const Tail&... tail) {
std::cout << h;
print_all(tail...);
}
int main() {
auto f23 = bind_first(bind_first(RESOLVE_OVERLOAD(print_all), 2), '3');
f23();
f23('\n');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment