title: template event class take any arg
body: <p>I have a simple event class, everything works fine with it.</p>
  
  <p>Im trying to add a template class that i can pass arguments to and then read it when wait finishes.</p>
  
  <p>At the moment i have it working with struct only as i need to set the arg to 0 if im not using it.</p>
  
  <p>Is there a better/easier way to do this so i can pass any type of argument to it?</p>
  
  <pre><code>class Event
  {
  public:
  
      Event() : _signalled(false) {}
  
      virtual void notify()
      {
          std::unique_lock&lt;std::mutex&gt; lock(_mutex);
          _signalled = true;
          _condvar.notify_one();
      }
  
      virtual void wait()
      {
          std::unique_lock&lt;std::mutex&gt; lock(_mutex);
          _condvar.wait(lock, [&amp;] { return _signalled; });
          _signalled = false;
      }
  
      void stop()
      {
          std::unique_lock&lt;std::mutex&gt; lock(_mutex);
          _signalled = false;
      }
  
  private:
  
      std::mutex _mutex;
      std::condition_variable _condvar;
      bool _signalled;
  };
  
  template &lt;class T&gt;
  class ArgEvent : public Event
  {
  public:
  
      void notify()
      {
          Event::notify();
          this-&gt;arg = { 0 };
      }
  
      void notify(T arg)
      {
          Event::notify();
          this-&gt;arg = arg;
      }
  
      T getArg()
      {
          return this-&gt;arg;
      }
  
      void wait()
      {
          Event::wait();
      }
  
      void wait(T&amp; arg)
      {
          Event::wait();
          arg = this-&gt;arg;
      }
  
  private:
      T arg;
  };
  </code></pre>