title: concatenate bits C++
body: <p>I am looking for an elegant C++ using SystemC to concatenate bits.</p>
  
  <p>A System Verilog example in one nice line:</p>
  
  <pre><code>bool my_variable;
  uint bits_combination = {8'b0, {8{my_variable}}, 8'b1, 4'b0, 2'b1, 2'b0};
  </code></pre>
  
  <p>My best solution for C++:</p>
  
  <pre><code>bool my_variable;
  sc_uint&lt;32&gt; bits_combination;
  bits_combination.range(31,24) = 0;
  bits_combination.range(23,16) = my_variable ? (1 &lt;&lt; 8)-1  : 0;
  bits_combination.range(15,8)  = (1 &lt;&lt; 8)-1;
  bits_combination.range(7,4)   = 0;
  bits_combination.range(3,2)   = (1 &lt;&lt; 2)-1;
  bits_combination.range(1,0)   = 0;
  </code></pre>
  
  <p>Improving this line to a non ternary operator will also help: </p>
  
  <pre><code>my_variable ? (1 &lt;&lt; 8)-1  : 0
  </code></pre>