Created
          September 2, 2019 18:13 
        
      - 
      
 - 
        
Save Pibben/9ff01b67232944d76f68d0d41b494d2f to your computer and use it in GitHub Desktop.  
  
    
      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 <functional> | |
| #include <string> | |
| #include <tuple> | |
| #include <array> | |
| struct Thread { | |
| struct InternalBase { | |
| virtual void call() = 0; | |
| }; | |
| InternalBase* ibptr; | |
| template <class Ret, class... Args> | |
| struct Internal : public InternalBase { | |
| Ret(*mFunc)(Args...); | |
| std::tuple<Args...> mArgs; | |
| Internal(Ret(*func)(Args...), Args... args) : mFunc(func), mArgs(std::forward<Args>(args)...) { } | |
| void call() override { | |
| std::apply(mFunc, mArgs); | |
| } | |
| }; | |
| template <class Ret, class... Args> | |
| Thread(Ret(*func)(Args...), Args... args) { | |
| ibptr = new Internal<Ret, Args...>(func, args...); | |
| } | |
| void call() { | |
| ibptr->call(); | |
| } | |
| }; | |
| static void func(int a, double d) { | |
| printf("%d\n", a); | |
| } | |
| int main() { | |
| Thread a(func, 1, 1.0); | |
| a.call(); | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment