title: How to check if the units are the same with class templates?
body: <p>I have the following program in which two templated structs called Measure are passed to another templated struct called Measure_add. The Measure struct has two attributes.
  A value and a unit.</p>
  <p><strong>Problem statement:</strong></p>
  <p>I managed to add the values to, but the unit's still don't work. I need to work with struct template spezialization. I want to first check if the units are the same.</p>
  <p>If the units are both in meter (m), then the class Unit can be set to m.</p>
  <p>If the units are not the same, I need to convert the highest unit to the lower unit. So imagine that Measure1 has Unit km and Measure2 has Unit m, then I need to convert the Measure1 value to meters.</p>
  <p>I note that there are at least two different tasks if case of 2 different units:</p>
  <ul>
  <li>determining which unit is the smallest</li>
  <li>converting the value of Measure1 and do the addition again.</li>
  </ul>
  <p><strong>What do I need in order to proceed?:</strong></p>
  <p>How do I do this without if statements? Since if statements are not allowed withing structs?</p>
  <p>Could someone please show me how to do this for a case when Measure1 is km and Measure2 is m? I think I could reproduce that for other cases</p>
  <p><strong>Code:</strong></p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;type_traits&gt;
  
  enum class Unit { km, m, cm };
  
  template&lt;int v, Unit u&gt;
  struct Measure
  {
      static const int value = v;
      static const Unit unit = u;
  };
  
  template&lt; typename  a, typename b&gt;
  struct Measure_add
  {
      static const Unit unit = a::unit;
      static const int value = a::value + b ::value;
  };
  
  
  int main()
  {
      
      std::cout &lt;&lt; Measure_add&lt; Measure&lt;4, Unit::m&gt;, Measure&lt;4, Unit::km&gt; &gt;::value &lt;&lt; std::endl;
  
      return 0;
  }
  </code></pre>