Created
          August 3, 2015 18:33 
        
      - 
      
- 
        Save Fiona-J-W/d77ac2ef953b809f99ca to your computer and use it in GitHub Desktop. 
    bind_first
  
        
  
    
      This file contains hidden or 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 <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