title: Concurrent producer/consumer queue design for different class types
body: <p>I have two threads running, where the producer thread enqueues the concurrent queue (<a href="https://github.com/cameron314/readerwriterqueue.git" rel="nofollow noreferrer">https://github.com/cameron314/readerwriterqueue.git</a>) with different types of updates and a consumer thread which dequeues updates and executes different code paths based on the update type. These updates have to be processed in the correct order.</p>
  <p>I do not want to use any additional dependencies that can't be quickly linked via CMake FetchContent.</p>
  <p>I came up with this, but i am wondering if there is a better way to do this :</p>
  <pre><code>enum UpdateType {
      A,
      B
  };
  
  class Update {
      const std::shared_ptr&lt;DataA&gt; _dataA;
      const std::shared_ptr&lt;DataB&gt; _dataB;
      UpdateType _type;
  public:
      Update(std::shared_ptr&lt;DataA&gt; dataA) : _dataA(std::move(dataA)) {
          _type = A;
      }
      Update(std::shared_ptr&lt;DataB&gt; dataB) : _dataB(std::move(dataB)) {
          _type = B;
      }
      UpdateType GetType() const { return _type; }
      std::shared_ptr&lt;DataA&gt; GetA() const { return _dataA; }
      std::shared_ptr&lt;DataB&gt; GetB() const { return _dataB; }
  };
  
  auto queue = moodycamel::BlockingReaderWriterQueue&lt;std::shared_ptr&lt;Update&gt;&gt;(200);
  
  Update a(std::make_shared&lt;DataA&gt;(DataA()));
  Update b(std::make_shared&lt;DataB&gt;(DataB()));
  
  queue.enqueue(std::make_shared&lt;Update&gt;(a));
  queue.enqueue(std::make_shared&lt;Update&gt;(b));
  
  std::shared_ptr&lt;Update&gt; q;
  queue.wait_dequeue(q);
  
  switch (q-&gt;GetType())
  {
  case A:
      // Process A
      break;
  case B:
      // Process B
      break;
  }
  </code></pre>