Have an extra data member only when something is active in c++
<p>I have an implementation of a queue, something like <code>template &lt;typename T&gt; queue&lt;T&gt;</code> with a <code>struct QueueItem { T data;}</code> and I have a separate library that times the passage of data across different places (including from one producer thread to consumer thread via this queue). In order to do this, I inserted code from that timing library into the push and pop functions of the queue so that when they assign a <code>BufferItem.data</code> they also assign an extra member i added of type <code>void*</code> to some timing metadata from that library. I.e. what used to be something like:</p>

<pre><code>void push(T t)
{
  QueueItem i;
  i.data = t;
  //insert i into queue
}
</code></pre>

<p>became</p>

<pre><code>void push(T t)
{
  QueueItem i;
  i.data = t;

  void* fox = timinglib.getMetadata();
  i.timingInfo = fox;
  //insert i into queue
}
</code></pre>

<p>with QueueItem going from</p>

<pre><code>struct QueueItem
{
 T data;
}
</code></pre>

<p>to</p>

<pre><code>struct QueueItem
{
  T data;
  void* timingInfo;
}
</code></pre>

<p>What I would like to achieve, however, is the ability to swap out of the latter struct in favor of the lighter weight struct whenever the timing library is not activated. Something like:</p>

<pre><code>if timingLib.isInactive()
 ;//use the smaller struct QueueItem
else
 ;//use the larger struct QueueItem
</code></pre>

<p>as cheaply as possible. What would be a good way to do this?</p>
