<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.8" -->
<?xml-stylesheet href="https://www.baszerr.eu/lib/exe/css.php?s=feed" type="text/css"?>
<rss version="2.0">
    <channel xmlns:g="http://base.google.com/ns/1.0">
        <title>BaSzErr - blog:2023:08:26</title>
        <description></description>
        <link>https://www.baszerr.eu/</link>
        <lastBuildDate>Wed, 06 May 2026 07:55:18 +0000</lastBuildDate>
        <generator>FeedCreator 1.8</generator>
        <image>
            <url>https://www.baszerr.eu/lib/exe/fetch.php?media=wiki:dokuwiki.svg</url>
            <title>BaSzErr</title>
            <link>https://www.baszerr.eu/</link>
        </image>
        <item>
            <title>2023-08-26_-_handling_enums_in_c</title>
            <link>https://www.baszerr.eu/doku.php?id=blog:2023:08:26:2023-08-26_-_handling_enums_in_c</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;handling_enums_in_c&quot;&gt;2023-08-26 - handling enums in C++&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
handling &lt;code&gt;enum&lt;/code&gt;s in &lt;a href=&quot;https://en.wikipedia.org/wiki/C++&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/C++&quot;&gt;C++&lt;/a&gt; is tricky. but there are good practices that can help you out. here are two from the set.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;2023-08-26 - handling enums in C++&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;handling_enums_in_c&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:1,&amp;quot;range&amp;quot;:&amp;quot;1-174&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit2&quot; id=&quot;handling_all_values&quot;&gt;handling all values&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
let&amp;#039;s say we have a simple &lt;code&gt;enum&lt;/code&gt; called &lt;code&gt;Foo&lt;/code&gt;, with some values. we want to add a &lt;code&gt;str()&lt;/code&gt; helper, that would covert it to sth more human-readable than a number. very common implementation would be:
&lt;/p&gt;
&lt;pre class=&quot;code cpp&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;enum&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt; Foo &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt; A, B, C &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co1&quot;&gt;// ...&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw4&quot;&gt;auto&lt;/span&gt; str&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Foo f&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&quot;kw1&quot;&gt;switch&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;f&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;case&lt;/span&gt; Foo&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;A&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;case&lt;/span&gt; Foo&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;B&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;B&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;case&lt;/span&gt; Foo&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;C&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;C&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;&amp;lt;unknown&amp;gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
looks good, all tests pass. however there is a potential for a problem – it&amp;#039;s not future proof. let&amp;#039;s now add &lt;code&gt;Foo::D&lt;/code&gt;:
&lt;/p&gt;
&lt;pre class=&quot;code cpp&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;enum&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt; Foo &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt; A, B, C, D &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;co1&quot;&gt;// notice Foo::D is added!&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co1&quot;&gt;// ...&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw4&quot;&gt;auto&lt;/span&gt; str&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Foo f&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&quot;kw1&quot;&gt;switch&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;f&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;case&lt;/span&gt; Foo&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;A&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;case&lt;/span&gt; Foo&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;B&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;B&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;case&lt;/span&gt; Foo&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;C&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;C&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;&amp;lt;unknown&amp;gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
looks good, all tests pass… however now there _is_ a problem! new value is not handled and it will return an incorrect value at runtime!
&lt;/p&gt;

&lt;p&gt;
there&amp;#039;s a neat way of fixing this problem and making code future-proof. compile with &lt;code&gt;-Wall -Werror&lt;/code&gt; (as you anyway should!) and make sure no &lt;code&gt;switch&lt;/code&gt; has any &lt;code&gt;default&lt;/code&gt;. eg.:
&lt;/p&gt;
&lt;pre class=&quot;code cpp&quot;&gt;&lt;span class=&quot;kw4&quot;&gt;auto&lt;/span&gt; str&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Foo f&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&quot;kw1&quot;&gt;switch&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;f&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;case&lt;/span&gt; Foo&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;A&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;case&lt;/span&gt; Foo&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;B&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;B&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;case&lt;/span&gt; Foo&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;C&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;C&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
  &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;&amp;lt;unknown&amp;gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
change looks insignificant, but now if we miss handling 1 value, we get a warning from a compiler and with &lt;code&gt;-Werror&lt;/code&gt; it stops the build right away.
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;c.cpp: In function ‘auto str(Foo)’:
c.cpp:11:9: error: enumeration value ‘D’ not handled in switch [-Werror=switch]
   11 |   switch(f)
      |         ^
cc1plus: all warnings being treated as errors&lt;/pre&gt;

&lt;p&gt;
bug is detected at compile time! nice… :)
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;handling all values&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;handling_all_values&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:2,&amp;quot;range&amp;quot;:&amp;quot;175-1909&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit3&quot; id=&quot;handling_some_values&quot;&gt;handling some values&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
another common case where &lt;code&gt;enum&lt;/code&gt;s are used is adding special functions, that check if value is in a given logical state / group. eg. determining if it&amp;#039;s an error:
&lt;/p&gt;
&lt;pre class=&quot;code cpp&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;enum&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt; State
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
  Initializing,
  Running,
  InputError
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw4&quot;&gt;bool&lt;/span&gt; isOk&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;State s&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; s &lt;span class=&quot;sy3&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;sy1&quot;&gt;=&lt;/span&gt; State&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;InputError&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
looks good, all tests pass. however… you probably already know where it&amp;#039;s going. ;) let&amp;#039;s consider extending &lt;code&gt;State&lt;/code&gt; with a new error state:
&lt;/p&gt;
&lt;pre class=&quot;code cpp&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;enum&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt; State
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
  Initializing,
  Running,
  InputError,
  OutputError
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
…and now &lt;code&gt;isOk(State::OutputError) == true&lt;/code&gt;. whoops…
&lt;/p&gt;

&lt;p&gt;
a better way of writing these kind of function is to list all &lt;code&gt;enum&lt;/code&gt; values explicitly, and assign &lt;code&gt;return&lt;/code&gt;s accordingly, eg.:
&lt;/p&gt;
&lt;pre class=&quot;code cpp&quot;&gt;&lt;span class=&quot;co2&quot;&gt;#include &amp;lt;cassert&amp;gt;&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;// ...&lt;/span&gt;
&lt;span class=&quot;kw4&quot;&gt;bool&lt;/span&gt; isOk&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;State s&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&quot;kw1&quot;&gt;switch&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;s&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;case&lt;/span&gt; State&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;Initializing&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;case&lt;/span&gt; State&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;Running&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;case&lt;/span&gt; State&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;InputError&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
  &lt;span class=&quot;kw3&quot;&gt;assert&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;sy3&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;unknown value&amp;quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
now, if states change, we get a proper error:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;4.cpp: In function ‘bool isOk(State)’:
4.cpp:13:9: error: enumeration value ‘OutputError’ not handled in switch [-Werror=switch]
   13 |   switch(s)
      |         ^
cc1plus: all warnings being treated as errors&lt;/pre&gt;

&lt;p&gt;
so we know we need to fix it:
&lt;/p&gt;
&lt;pre class=&quot;code cpp&quot;&gt;&lt;span class=&quot;co2&quot;&gt;#include &amp;lt;cassert&amp;gt;&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;// ...&lt;/span&gt;
&lt;span class=&quot;kw4&quot;&gt;bool&lt;/span&gt; isOk&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;State s&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&quot;kw1&quot;&gt;switch&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;s&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;case&lt;/span&gt; State&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;Initializing&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;case&lt;/span&gt; State&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;Running&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;case&lt;/span&gt; State&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;InputError&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;case&lt;/span&gt; State&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;OutputError&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kw2&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
  &lt;span class=&quot;kw3&quot;&gt;assert&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;sy3&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;unknown value&amp;quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
while writing this kind of functions using &lt;code&gt;switch&lt;/code&gt;-&lt;code&gt;case&lt;/code&gt; may look a bit odd at first, it has a very nice property of ensuring code being future-proof. as a side effect, it also makes core far easier to read. for comparison just imagine &lt;code&gt;isOk()&lt;/code&gt; where there are 7 “ok” states and 13 “error” states…
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;handling some values&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;handling_some_values&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:3,&amp;quot;secid&amp;quot;:3,&amp;quot;range&amp;quot;:&amp;quot;1910-&amp;quot;} --&gt;</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Sat, 26 Aug 2023 15:50:55 +0000</pubDate>
        </item>
        <item>
            <title>2023-08-26_-_qed</title>
            <link>https://www.baszerr.eu/doku.php?id=blog:2023:08:26:2023-08-26_-_qed</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;qed&quot;&gt;2023-08-26 - QED&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
i&amp;#039;ve recently came across a nice explanation of electromagnetism unification on Veritasium channel:
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://www.youtube.com/watch?v=1TKSfAkWWN0&quot; class=&quot;urlextern&quot; title=&quot;https://www.youtube.com/watch?v=1TKSfAkWWN0&quot; rel=&quot;ugc nofollow&quot;&gt;how special relativity makes magnets work&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://www.youtube.com/watch?v=hFAOXdXZ5TM&quot; class=&quot;urlextern&quot; title=&quot;https://www.youtube.com/watch?v=hFAOXdXZ5TM&quot; rel=&quot;ugc nofollow&quot;&gt;magnets -- how do they work&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
long story short – magnetic field is just an electric field, viewed from a different frame of reference! this is the key insight behind &lt;a href=&quot;https://en.wikipedia.org/wiki/Quantum electrodynamics&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/Quantum electrodynamics&quot;&gt;QED&lt;/a&gt; and a Nobel prize in physics in 1965. nice…
&lt;/p&gt;

&lt;/div&gt;
</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Sat, 26 Aug 2023 15:56:38 +0000</pubDate>
        </item>
    </channel>
</rss>
