How to handle units in c++ interface
<p>I am currently designing an API where I want that the user to be able to write code like this:</p>

<pre><code>PowerMeter.forceVoltage(1 mV);
PowerMeter.settlingTime(1 ms);
</code></pre>

<p>Currently we do this using defines like:</p>

<pre><code>#define mV *1.0e-03
</code></pre>

<p>This makes it very convenient for the user to write their code and it is also very readable, but of course has also drawbacks:</p>

<pre><code>int ms;
</code></pre>

<p>Will throw some compiler errors which are hard to understand. So I am looking for a better solution.</p>

<p>I tried the new C++11 literals, but with this all I could achieve is:</p>

<pre><code>long double operator "" _mV(long double value) {
  return value * 1e-3;
}
PowerMeter.forceVoltage(1_mV);
</code></pre>

<p>In the end the API does not care about the unit like Volt or second but only takes the number, so I don't want to do any checking if you really input Volts in forceVoltage or not. So this should also be possible:</p>

<pre><code>PowerMeter.forceVoltage(2 ms);
</code></pre>

<p>Any idea besides staying with the defines?</p>
