title: Store function inputs for threads
body: <p>Im trying to make a job system with a similar feature as std::thread where you can pass in parameters in a lambda which get captured e.g ( <code>std::thread([&amp;](int index){...} ), 5)</code> )</p>
  <p>This is the entire thread class</p>
  <pre><code>#include &lt;condition_variable&gt;
  #include &lt;functional&gt;
  #include &lt;thread&gt;
  
  using uint = unsigned int;
  
  class Thread {
  public:
  
      Thread() {
          Start();
      }
  
      virtual ~Thread() {
          Shutdown();
      }
  
      void Start() {
          m_Thread = std::thread(&amp;Thread::Poll, this);
      }
  
      void Poll() {
              {
                  std::unique_lock&lt;std::mutex&gt; lock(m_Mutex);
                  m_Condition.wait(lock, [this]() 
                  {
                      return !m_Jobs.empty() &amp;&amp; !m_Stop;
                  });
  
                  m_Job = m_Jobs.front();
                  m_Jobs.pop_back();
              }
              m_Job(); // function&lt;void()&gt; type
          
      }
  
      void Execute(std::function&lt;void()&gt; New_Job) {
          { std::unique_lock&lt;std::mutex&gt; lock(m_Mutex);
              m_Jobs.push_back(New_Job);
          }
          m_Condition.notify_one();
      }
  
      template &lt;typename Func, typename... Args&gt;
      void ExecuteParams(Func f, Args... args) {  
          Execute(std::bind(f, args...));
      }
  
      void Wait() {
          while (!m_Jobs.empty() &amp;&amp; !m_Stop) {
              Poll();
          }
      }
  
  
      void Shutdown() {
          {
              std::unique_lock&lt;std::mutex&gt; lock(m_Mutex);
              m_Stop = true;
          }
  
          m_Condition.notify_all();
          m_Thread.join();
      }
      
  
  std::thread m_Thread;
  std::mutex m_Mutex;
  std::condition_variable m_Condition;
  bool m_Stop = false;
  std::function&lt;void()&gt; m_Job;
  std::vector&lt;std::function&lt;void()&gt;&gt; m_Jobs;
  };
  </code></pre>
  <p>This currently works sort of but if i pass in an index from a for loop for example, the index will just stay 0 for each job...</p>
  <pre><code>for(uint i = 0; i &lt; 5; i++) {
          MainThread.ExecuteParams([&amp;](uint test)
          {
              std::unique_lock&lt;std::mutex&gt; L(lock);
              std::cout &lt;&lt; &quot;executing on thread &quot; &lt;&lt; std::this_thread::get_id() &lt;&lt; std::endl;
              std::cout &lt;&lt; test &lt;&lt; std::endl;
          }, i);
      }   
  </code></pre>