<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I said earlier (maybe in a different thread?) that I didn't want to implement units in C++ even though I was pretty sure you could do it because I'd just pull my hair for hours. Well, there's no better way to learn than to pull your hair for hours, so I did it anyway.<div class=""><br class=""></div><div class=""><a href="http://coliru.stacked-crooked.com/a/b1dde8e8320b55b7" class="">http://coliru.stacked-crooked.com/a/b1dde8e8320b55b7</a></div><div class=""><div class=""><br class=""></div><div class="">The bottom part is the interesting part and shows how to use units with that system:</div><div class=""><br class=""></div><div class=""><div class=""></div><blockquote type="cite" class=""><div class="">#pragma mark - (actually using units)</div><div class="">enum class Units</div><div class="">{</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>Meter,</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>Second,</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>Kilogram,</div><div class="">};</div><div class=""><br class=""></div><div class="">template&lt;Units U&gt;</div><div class="">using SimpleUnit = Quantity&lt;double, UnitQuotient&lt;UnitProduct&lt;Units, U&gt;, UnitProduct&lt;Units&gt;&gt;&gt;;</div><div class=""><br class=""></div><div class="">SimpleUnit&lt;Units::Meter&gt; _m(1);</div><div class="">SimpleUnit&lt;Units::Meter&gt; _ft(0.3048);</div><div class="">SimpleUnit&lt;Units::Second&gt; _s(1);</div><div class="">SimpleUnit&lt;Units::Kilogram&gt; _Kg(1);</div><div class="">auto _N = (_Kg * _m) / (_s * _s);</div><div class=""><br class=""></div><div class="">int main()</div><div class="">{</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>decltype(_m) distance = 12.5 * _m;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>decltype(_m * _m) area = 2 * _ft * distance;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>decltype(_Kg) mass = 18 * _Kg;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>decltype(_N) force = mass * distance / (1.2 * _s * 1.8 * _s);</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>// uncomment for an error</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>// decltype(_N) notForce = mass / distance;</div><div class="">}</div></blockquote><div class=""><br class=""></div></div><div class=""><div class="">Of course, `auto` would work too, but it doesn't convey type/unit safety as well.</div><div class=""><br class=""></div><div class="">I'd like to be able to write that in Swift one day (with less incomprehensible template boilerplate) :-) I personally really like that you can "create" units just by declaring a variable, that you can get their type by using `decltype(unit)` and that they are very easy to compose.</div><div class="">
<br class="Apple-interchange-newline"><span style="color: rgb(0, 0, 0); font-family: 'Lucida Grande'; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none;" class="">Félix</span>
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">Le 8 janv. 2016 à 08:54:52, Thorsten Seitz &lt;<a href="mailto:tseitz42@icloud.com" class="">tseitz42@icloud.com</a>&gt; a écrit :</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">Am 07.01.2016 um 20:26 schrieb Félix Cloutier &lt;<a href="mailto:felixcca@yahoo.ca" class="">felixcca@yahoo.ca</a>&gt;:</div><br class="Apple-interchange-newline"><div class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Given that it relies on variadic templates and non-type template arguments, this wouldn't be feasible in Swift at the moment</span></div></blockquote></div><br class=""><div class="">Having non-type template arguments (and the ability to operate on them at compile time) would make it possible to drop all that stuff modeling this in the type system with peano numbers like I tried. Much more simple!&nbsp;</div><div class=""><br class=""></div><div class="">This would reduce my example to the following (no need for variadic templates because I give each SI unit it fixed place in the parameter list — your idea of using variadic templates would probably allow to extend the system by new base units, though, and allow to cut down the long template parameter lists in the arithmetic functions which will grow longer with each base unit added in my example...):</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(88, 110, 117);" class="">// TODO: extend by more type parameters for the remaining SI units</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(88, 110, 117);" class="">// missing language feature: non-type generic arguments, here: Int</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">public</span> <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">struct</span> Quantity&lt;Length = Int, Time = Int, Mass = Int&gt; : <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Equatable</span>, <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Comparable</span> {</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150); min-height: 15px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">let</span> value: <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Double</span></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150); min-height: 15px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">init</span>(<span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">_</span> value: <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Double</span>) {</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">self</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">value</span> = value</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class="">}</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150); min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">public</span> <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">func</span> ==&lt;L,T,M&gt;(lhs: <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Quantity</span>&lt;<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">L</span>,<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">T</span>,<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">M</span>&gt;, rhs: <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Quantity</span>&lt;<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">L</span>,<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">T</span>,<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">M</span>&gt;) -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Bool</span> {</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">return</span> lhs.<span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">value</span> == rhs.<span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">value</span></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class="">}</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150); min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">public</span> <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">func</span> &lt;&lt;L,T,M&gt;(lhs: <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Quantity</span>&lt;<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">L</span>,<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">T</span>,<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">M</span>&gt;, rhs: <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Quantity</span>&lt;<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">L</span>,<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">T</span>,<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">M</span>&gt;) -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Bool</span> {</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">return</span> lhs.<span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">value</span> &lt; rhs.<span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">value</span></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class="">}</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150); min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">public</span> <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">func</span> +&lt;L,T,M&gt;(lhs: <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Quantity</span>&lt;<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">L</span>,<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">T</span>,<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">M</span>&gt;, rhs: <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Quantity</span>&lt;<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">L</span>,<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">T</span>,<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">M</span>&gt;) -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Quantity</span>&lt;<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">L</span>,<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">T</span>,<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">M</span>&gt; {</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">return</span> <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Quantity</span>&lt;<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">L</span>,<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">T</span>,<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">M</span>&gt;(lhs.<span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">value</span> + rhs.<span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">value</span>)</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class="">}</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150); min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(133, 153, 1);" class="">public<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> </span>func<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> *</span></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; &lt;L1,T1,M1,L2,T2,M2,L,T,M <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">where</span> <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">L</span> == <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">L1</span>+L2, T == T1+T2, M == M1+M2&gt;</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(181, 137, 1);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">&nbsp; &nbsp; (lhs: </span>Quantity<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">&lt;</span>L1<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">,</span>T1<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">,</span>M1<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">&gt;, rhs: </span>Quantity<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">&lt;</span>L2<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">,</span>T2<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">,</span>M2<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">&gt;) -&gt; </span>Quantity<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">&lt;</span>L<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">,</span>T<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">,</span>M<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">&gt;</span></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class="">{</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">return</span> <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Quantity</span>&lt;<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">L</span>,<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">T</span>,<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">M</span>&gt;(lhs.<span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">value</span> * rhs.<span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">value</span>)</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class="">}</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150); min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(133, 153, 1);" class="">public<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> </span>func<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> /</span></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; &lt;L1,T1,M1,L2,T2,M2,L,T,M <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">where</span> <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">L</span> == <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">L1</span>-L2, T == T1-T2, M == M1-M2&gt;</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(181, 137, 1);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">&nbsp; &nbsp; (lhs: </span>Quantity<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">&lt;</span>L1<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">,</span>T1<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">,</span>M1<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">&gt;, rhs: </span>Quantity<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">&lt;</span>L2<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">,</span>T2<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">,</span>M2<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">&gt;) -&gt; </span>Quantity<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">&lt;</span>L<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">,</span>T<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">,</span>M<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">&gt;</span></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class="">{</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">return</span> <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Quantity</span>&lt;<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">L</span>,<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">T</span>,<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">M</span>&gt;(lhs.<span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">value</span> / rhs.<span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">value</span>)</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class="">}</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150); min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150); min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(88, 110, 117);" class="">// Defining some nice typealiases with which to work</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150); min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">public</span> <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">typealias</span> Scalar &nbsp; = Quantity&lt;<span style="font-variant-ligatures: no-common-ligatures; color: #29a198" class="">0</span>, <span style="font-variant-ligatures: no-common-ligatures; color: #29a198" class="">0</span>, <span style="font-variant-ligatures: no-common-ligatures; color: #29a198" class="">0</span>&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #586e75" class="">// dimensionless</span></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">public</span> <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">typealias</span> Length &nbsp; = Quantity&lt;<span style="font-variant-ligatures: no-common-ligatures; color: #29a198" class="">1</span>, <span style="font-variant-ligatures: no-common-ligatures; color: #29a198" class="">0</span>, <span style="font-variant-ligatures: no-common-ligatures; color: #29a198" class="">0</span>&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #586e75" class="">// meter</span></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">public</span> <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">typealias</span> Time &nbsp; &nbsp; = Quantity&lt;<span style="font-variant-ligatures: no-common-ligatures; color: #29a198" class="">0</span>, <span style="font-variant-ligatures: no-common-ligatures; color: #29a198" class="">1</span>, <span style="font-variant-ligatures: no-common-ligatures; color: #29a198" class="">0</span>&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #586e75" class="">// seconds</span></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">public</span> <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">typealias</span> Mass &nbsp; &nbsp; = Quantity&lt;<span style="font-variant-ligatures: no-common-ligatures; color: #29a198" class="">0</span>, <span style="font-variant-ligatures: no-common-ligatures; color: #29a198" class="">0</span>, <span style="font-variant-ligatures: no-common-ligatures; color: #29a198" class="">1</span>&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #586e75" class="">// kilogram</span></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">public</span> <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">typealias</span> Velocity = Quantity&lt;<span style="font-variant-ligatures: no-common-ligatures; color: #29a198" class="">1</span>, -<span style="font-variant-ligatures: no-common-ligatures; color: #29a198" class="">1</span>, <span style="font-variant-ligatures: no-common-ligatures; color: #29a198" class="">0</span>&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #586e75" class="">// m/s</span></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">public</span> <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">typealias</span> Newton &nbsp; = Quantity&lt;<span style="font-variant-ligatures: no-common-ligatures; color: #29a198" class="">1</span>, -<span style="font-variant-ligatures: no-common-ligatures; color: #29a198" class="">2</span>, <span style="font-variant-ligatures: no-common-ligatures; color: #29a198" class="">1</span>&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #586e75" class="">// m*kg/s^2</span></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150); min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150); min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(133, 153, 1);" class="">public<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> </span>extension<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Double</span><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> {</span></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150); min-height: 15px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">public</span> <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">var</span> m: <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Length</span> {</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">return</span> <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Length</span>(<span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">self</span>)</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">public</span> <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">var</span> s: <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Time</span> {</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">return</span> <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Time</span>(<span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">self</span>)</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">public</span> <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">var</span> kg: <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Mass</span> {</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">return</span> <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Mass</span>(<span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">self</span>)</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class="">&nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class="">}</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150); min-height: 15px;" class=""><br class=""></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">let</span> dist = <span style="font-variant-ligatures: no-common-ligatures; color: #29a198" class="">10</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">m</span> <span style="font-variant-ligatures: no-common-ligatures; color: #6c71c4" class="">+</span> <span style="font-variant-ligatures: no-common-ligatures; color: #29a198" class="">5</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">m</span></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">let</span> time = <span style="font-variant-ligatures: no-common-ligatures; color: #29a198" class="">20</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">s</span></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">let</span> mass = <span style="font-variant-ligatures: no-common-ligatures; color: #29a198" class="">5</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">kg</span></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">let</span> velocity: <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Velocity</span> = <span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">dist</span> <span style="font-variant-ligatures: no-common-ligatures; color: #6c71c4" class="">/</span> <span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">time</span></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">let</span> force: <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Newton</span> = <span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">mass</span> <span style="font-variant-ligatures: no-common-ligatures; color: #6c71c4" class="">*</span> <span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">dist</span> / (<span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">time</span> <span style="font-variant-ligatures: no-common-ligatures; color: #6c71c4" class="">*</span> <span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">time</span>)</div></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class=""><br class=""></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class=""><br class=""></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class=""><span style="font-family: Helvetica; font-size: 12px;" class="">-Thorsten</span></div></div></div></blockquote></div><br class=""></div></div></body></html>