{"id":6763,"date":"2023-12-18T16:34:54","date_gmt":"2023-12-18T22:34:54","guid":{"rendered":"https:\/\/www.logikalsolutions.com\/wordpress\/?p=6763"},"modified":"2023-12-18T16:34:56","modified_gmt":"2023-12-18T22:34:56","slug":"stdoptional","status":"publish","type":"post","link":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/stdoptional\/","title":{"rendered":"std::optional Example and Explanation"},"content":{"rendered":"\n<p>std::optional is an attempt by the academics on the C++ standards committee to &#8220;fix&#8221; what they believe to be abhorrent behavior. As usual they created a <em>committee quality<\/em> result. To understand my disgust with what they created you have to understand that I&#8217;ve been programming on real computers since the early 1980s. Even then VAX BASIC had OPTIONAL and a much better implementation for OPTIONAL parameters. You can read more about it in <a href=\"https:\/\/www.theminimumyouneedtoknow.com\/app_book.html\">this book<\/a>. Here is a snippet.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"570\" height=\"364\" src=\"https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2023\/12\/basic-optional.png\" alt=\"\" class=\"wp-image-6764\" srcset=\"https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2023\/12\/basic-optional.png 570w, https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2023\/12\/basic-optional-300x192.png 300w\" sizes=\"(max-width: 570px) 100vw, 570px\" \/><\/figure>\n<\/div>\n\n\n<p>Languages created in the 1970s all tended to have some form of OPTIONAL keyword and you just put in commas for the parameters you skipped. If the standards committee would have went the extra step it the result would have been far sweeter.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Academics: size_t vs. int<\/h2>\n\n\n\n<p>Academics have been sitting around telling us how great they are, having never worked in the real world supporting production code on real computers. They chastise and brow beat all developers who wish to use integers with strings instead of size_t. For those who don&#8217;t know, on most platforms size_t is an unsigned integer of some size.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>The length of a string cannot be negative!<\/p>\n<cite>academics<\/cite><\/blockquote>\n\n\n\n<p>Technically a string can be of negative length when rendering right to left text in a left to right editor, but that is a conversation for a different time.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>You artificially limit the length of a string by using integer!<\/p>\n<cite>academics<\/cite><\/blockquote>\n\n\n\n<p>Well, maybe. Again, technically we can have 128-bit integers on 64-bit systems and arbitrary length integers given Integer classes.<\/p>\n\n\n\n<p>Emphatic belief by academics that they could be the only ones who were right lead to bastardizations <a href=\"https:\/\/cplusplus.com\/reference\/string\/string\/find\/\">like this with std::string<\/a>. For those who have yet to experience such joy, when any of the &#8220;find&#8221; functions fail to find they return the length of the string because they cannot return -1. Now, you have to make an additional function call to obtain the length of the string then compare the two results to see if your find succeeded.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Adding Insult to Injury<\/h2>\n\n\n\n<p>The STL (Standard Template Library) has been around in various flavors for many decades now. While std::optional is the academics attempting to &#8220;fix&#8221; their complete hosing of the standard, they can&#8217;t fix std::string without completely braking the ABI. You can&#8217;t just presto-chango :<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#b392f0;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1f1f1f\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"size_t find( ...)\" style=\"color:#b392f0;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki min-dark\" style=\"background-color: #1f1f1f\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F97583\">size_t<\/span><span style=\"color: #B392F0\"> find( ...)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>to<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#b392f0;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1f1f1f\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"std::optional<size_t&gt; find ( ...)\" style=\"color:#b392f0;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki min-dark\" style=\"background-color: #1f1f1f\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #B392F0\">std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">optional&lt;<\/span><span style=\"color: #F97583\">size_t<\/span><span style=\"color: #B392F0\">&gt; find ( ...)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>because the signatures won&#8217;t match at dynamic link time.<\/p>\n\n\n\n<p>The C++17 standard finally added machinery that could un-hose an avalanche of academic hosings that have happened over the past 3+ decades, . . . but . . . using it will break 3+ decades of code in production.<\/p>\n\n\n\n<p>Know this. That major ABI break is coming and it will make Y2K look like one short debug session.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Previous Optional Parameter Work<\/h2>\n\n\n\n<p>The C++ language standard has dabbled with &#8220;optional parameters&#8221; for decades. You know them as &#8220;default parameters.&#8221;<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#b392f0;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1f1f1f\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"void promptUser( const QString &amp;promptText,\n                     bool allowDirection = false, bool ctrlMSubstitution = false );\" style=\"color:#b392f0;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki min-dark\" style=\"background-color: #1f1f1f\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F97583\">void<\/span><span style=\"color: #B392F0\"> promptUser( <\/span><span style=\"color: #F97583\">const<\/span><span style=\"color: #B392F0\"> QString <\/span><span style=\"color: #F97583\">&amp;<\/span><span style=\"color: #B392F0\">promptText<\/span><span style=\"color: #BBBBBB\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">                     <\/span><span style=\"color: #F97583\">bool<\/span><span style=\"color: #B392F0\"> allowDirection <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">false<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">bool<\/span><span style=\"color: #B392F0\"> ctrlMSubstitution <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">false<\/span><span style=\"color: #B392F0\"> );<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>If the user doesn&#8217;t provide a value for direction or ctrlMSubstitution they &#8220;default&#8221; to the values provided in the prototype. This works well when you have a predictable default behavior. What, per chance, do you provide to indicate a boolean value was omitted? How do you indicate &#8220;unknown?&#8221;<\/p>\n\n\n\n<p>std::optional was created to help with this, mainly because the academics painted themselves into a corner not using int for the string functions. They just can&#8217;t un-pooch their previous pooches without breaking everything.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Code<\/h2>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#b392f0;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1f1f1f\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"cmake_minimum_required(VERSION 3.10)\n\n# Set some basic project attributes\nproject (OptionalExample\n\tVERSION 0.1\n\tDESCRIPTION &quot;OptionalExample to show std::optional&quot;)\n\nset(CMAKE_CXX_STANDARD_REQUIRED ON)\nset(CMAKE_CXX_STANDARD 17)  \n\n# This project will output an executable file\nadd_executable(${PROJECT_NAME} OptionalExample.cpp)\n\n# Create a simple configuration header\nconfigure_file(config.h.in config.h)\n\n# Include the configuration header in the build\ntarget_include_directories(${PROJECT_NAME} PUBLIC &quot;${PROJECT_BINARY_DIR}&quot;)\n\" style=\"color:#b392f0;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki min-dark\" style=\"background-color: #1f1f1f\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F97583\">cmake_minimum_required<\/span><span style=\"color: #B392F0\">(VERSION 3.10)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\"># Set some basic project attributes<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">project<\/span><span style=\"color: #B392F0\"> (OptionalExample<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tVERSION 0.1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tDESCRIPTION <\/span><span style=\"color: #9DB1C5\">&quot;OptionalExample to show std::optional&quot;<\/span><span style=\"color: #B392F0\">)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">set<\/span><span style=\"color: #B392F0\">(CMAKE_CXX_STANDARD_REQUIRED <\/span><span style=\"color: #F97583\">ON<\/span><span style=\"color: #B392F0\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">set<\/span><span style=\"color: #B392F0\">(CMAKE_CXX_STANDARD 17)  <\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\"># This project will output an executable file<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">add_executable<\/span><span style=\"color: #B392F0\">(${PROJECT_NAME} OptionalExample.cpp)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\"># Create a simple configuration header<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">configure_file<\/span><span style=\"color: #B392F0\">(config.h.in config.h)<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #6B737C\"># Include the configuration header in the build<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">target_include_directories<\/span><span style=\"color: #B392F0\">(${PROJECT_NAME} PUBLIC <\/span><span style=\"color: #9DB1C5\">&quot;${PROJECT_BINARY_DIR}&quot;<\/span><span style=\"color: #B392F0\">)<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This time I remembered to change the description at line 6 while adding lines 8 and 9. I didn&#8217;t remember for <a href=\"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/string_view\/\">our string_view discussion<\/a>.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#b392f0;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1f1f1f\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"#include &lt;iostream&gt;\n#include &lt;iomanip&gt;\n#include &lt;string&gt;\n#include &lt;optional&gt;\n\n#include &quot;config.h&quot;\n\nusing std::optional;\n\noptional&lt;double&gt; divide_these( int first, int second);\nvoid threeParameters( optional&lt;int&gt; parm1 = std::nullopt,\n\t\t\t\t\t  optional&lt;double&gt; parm2 = std::nullopt,\n\t\t\t\t\t  optional&lt;std::string&gt; str1 = std::nullopt);\n\nconst int WE_ARE_FINISHED {999};\n\nint main(int argc, char **argv) {\n\tstd::cout &lt;&lt; &quot;OptionalExample&quot; &lt;&lt; std::endl;\n\tstd::cout &lt;&lt; &quot;Version &quot; &lt;&lt; OptionalExample_VERSION_MAJOR &lt;&lt; &quot;.&quot; &lt;&lt; OptionalExample_VERSION_MINOR &lt;&lt; std::endl;\n\n\tstd::cout &lt;&lt; &quot;\\n\\n\\nOur first test will prompt you for 2 integers to divide \\n&quot;;\n\tstd::cout &lt;&lt; &quot;in a loop until you type 999 as the first integer. Enter 0 as the\\n&quot;;\n\tstd::cout &lt;&lt; &quot;second integer to see hopw optional can work for return values: \\n\\n&quot;;\n\n\tbool finished = false;\n\twhile (!finished)\n\t{\n\t\tint first {};\n\t\tint second {};\n\n\t\tstd::cout &lt;&lt; &quot;Enter the number to be divided: &quot;;\n\t\tstd::cin &gt;&gt; first;\n\t\tif (first != WE_ARE_FINISHED)\n\t\t{\n\t\t\tstd::cout &lt;&lt; &quot;\\nEnter a number to divide the first by: &quot;;\n\t\t\tstd::cin &gt;&gt; second;\n\t\t\tconst optional&lt;double&gt; dbl {divide_these( first, second)};\n\t\t\tif (dbl.has_value())\n\t\t\t{\n\t\t\t\tstd::cout &lt;&lt; &quot;\\n\\nThe result is: &quot; &lt;&lt; std::setprecision(4) &lt;&lt; dbl.value() &lt;&lt; std::endl;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tstd::cout &lt;&lt; &quot;\\n\\nYou cannot divide by zero!!!!&quot; &lt;&lt; std::endl;\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tfinished = true;\n\t\t}\n\t}\n\n\tstd::cout &lt;&lt; &quot;\\n\\nNow trying optional parameters\\n&quot; &lt;&lt; std::endl;\n\n\tthreeParameters();\n\tthreeParameters( std::nullopt, std::nullopt, &quot;This is a string&quot;);\n\tthreeParameters( std::nullopt, 3.14159);\n\tthreeParameters(8);\n\n\treturn (EXIT_SUCCESS);\n}\n\noptional&lt;double&gt; divide_these( int first, int second)\n{\n\tif (second == 0)\n\t{\n\t\treturn (std::nullopt);\n\t}\n\n\treturn (first\/second);\n}\n\nvoid threeParameters( optional&lt;int&gt; parm1, optional&lt;double&gt; parm2, optional&lt;std::string&gt; str1)\n{\n\tstd::cout &lt;&lt; &quot;Three parameters called with:   &quot;;\n\n\tif (parm1.has_value())\n\t{\n\t\tstd::cout &lt;&lt; &quot;first parameter: &quot; &lt;&lt; parm1.value() &lt;&lt; &quot;   &quot;;\n\t}\n\n\tif (parm2.has_value())\n\t{\n\t\tstd::cout &lt;&lt; &quot;second parameter: &quot; &lt;&lt; std::setprecision(4) &lt;&lt; parm2.value() &lt;&lt; &quot;    &quot;;\n\t}\n\n\tif (str1.has_value())\n\t{\n\t\tstd::cout &lt;&lt; &quot;str1:  &quot; &lt;&lt; str1.value();\n\t}\n\n\tif (!parm1.has_value() &amp;&amp; !parm2.has_value() &amp;&amp; !str1.has_value())\n\t{\n\t\tstd::cout &lt;&lt; &quot;  no parameters\\n&quot;;\n\t}\n\n\tstd::cout &lt;&lt; std::endl;\n}\n\" style=\"color:#b392f0;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki min-dark\" style=\"background-color: #1f1f1f\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F97583\">#include<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&lt;iostream&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">#include<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&lt;iomanip&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">#include<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&lt;string&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">#include<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&lt;optional&gt;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">#include<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;config.h&quot;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">using<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">optional;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">optional&lt;<\/span><span style=\"color: #F97583\">double<\/span><span style=\"color: #B392F0\">&gt; divide_these( <\/span><span style=\"color: #F97583\">int<\/span><span style=\"color: #B392F0\"> first<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">int<\/span><span style=\"color: #B392F0\"> second);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">void<\/span><span style=\"color: #B392F0\"> threeParameters( optional&lt;<\/span><span style=\"color: #F97583\">int<\/span><span style=\"color: #B392F0\">&gt; parm1 <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">nullopt<\/span><span style=\"color: #BBBBBB\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t\t\t\t  optional&lt;<\/span><span style=\"color: #F97583\">double<\/span><span style=\"color: #B392F0\">&gt; parm2 <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">nullopt<\/span><span style=\"color: #BBBBBB\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t\t\t\t  optional&lt;std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">string&gt; str1 <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">nullopt);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">const<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">int<\/span><span style=\"color: #B392F0\"> WE_ARE_FINISHED {<\/span><span style=\"color: #F8F8F8\">999<\/span><span style=\"color: #B392F0\">};<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">int<\/span><span style=\"color: #B392F0\"> main(<\/span><span style=\"color: #F97583\">int<\/span><span style=\"color: #B392F0\"> argc<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">char<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">**<\/span><span style=\"color: #B392F0\">argv) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cout <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;OptionalExample&quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cout <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;Version &quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> OptionalExample_VERSION_MAJOR <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;.&quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> OptionalExample_VERSION_MINOR <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">endl;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cout <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;\\n\\n\\nOur first test will prompt you for 2 integers to divide \\n&quot;<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cout <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;in a loop until you type 999 as the first integer. Enter 0 as the\\n&quot;<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cout <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;second integer to see hopw optional can work for return values: \\n\\n&quot;<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">bool<\/span><span style=\"color: #B392F0\"> finished <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">false<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">while<\/span><span style=\"color: #B392F0\"> (<\/span><span style=\"color: #F97583\">!<\/span><span style=\"color: #B392F0\">finished)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t<\/span><span style=\"color: #F97583\">int<\/span><span style=\"color: #B392F0\"> first {};<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t<\/span><span style=\"color: #F97583\">int<\/span><span style=\"color: #B392F0\"> second {};<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cout <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;Enter the number to be divided: &quot;<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cin <\/span><span style=\"color: #F97583\">&gt;&gt;<\/span><span style=\"color: #B392F0\"> first;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t<\/span><span style=\"color: #F97583\">if<\/span><span style=\"color: #B392F0\"> (first <\/span><span style=\"color: #F97583\">!=<\/span><span style=\"color: #B392F0\"> WE_ARE_FINISHED)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cout <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;\\nEnter a number to divide the first by: &quot;<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cin <\/span><span style=\"color: #F97583\">&gt;&gt;<\/span><span style=\"color: #B392F0\"> second;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t\t<\/span><span style=\"color: #F97583\">const<\/span><span style=\"color: #B392F0\"> optional<\/span><span style=\"color: #F97583\">&lt;double&gt;<\/span><span style=\"color: #B392F0\"> dbl {divide_these( first<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> second)};<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t\t<\/span><span style=\"color: #F97583\">if<\/span><span style=\"color: #B392F0\"> (<\/span><span style=\"color: #79B8FF\">dbl<\/span><span style=\"color: #BBBBBB\">.<\/span><span style=\"color: #B392F0\">has_value())<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t\t{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t\t\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cout <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;\\n\\nThe result is: &quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">setprecision(<\/span><span style=\"color: #F8F8F8\">4<\/span><span style=\"color: #B392F0\">) <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">dbl<\/span><span style=\"color: #BBBBBB\">.<\/span><span style=\"color: #B392F0\">value() <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t\t<\/span><span style=\"color: #F97583\">else<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t\t{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t\t\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cout <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;\\n\\nYou cannot divide by zero!!!!&quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t<\/span><span style=\"color: #F97583\">else<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t\tfinished <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">true<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cout <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;\\n\\nNow trying optional parameters\\n&quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">endl;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tthreeParameters();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tthreeParameters( std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">nullopt<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">nullopt<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;This is a string&quot;<\/span><span style=\"color: #B392F0\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tthreeParameters( std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">nullopt<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F8F8F8\">3.14159<\/span><span style=\"color: #B392F0\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tthreeParameters(<\/span><span style=\"color: #F8F8F8\">8<\/span><span style=\"color: #B392F0\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">return<\/span><span style=\"color: #B392F0\"> (EXIT_SUCCESS);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">optional&lt;<\/span><span style=\"color: #F97583\">double<\/span><span style=\"color: #B392F0\">&gt; divide_these( <\/span><span style=\"color: #F97583\">int<\/span><span style=\"color: #B392F0\"> first<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">int<\/span><span style=\"color: #B392F0\"> second)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">if<\/span><span style=\"color: #B392F0\"> (second <\/span><span style=\"color: #F97583\">==<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F8F8F8\">0<\/span><span style=\"color: #B392F0\">)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t<\/span><span style=\"color: #F97583\">return<\/span><span style=\"color: #B392F0\"> (std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">nullopt);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">return<\/span><span style=\"color: #B392F0\"> (first<\/span><span style=\"color: #F97583\">\/<\/span><span style=\"color: #B392F0\">second);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">void<\/span><span style=\"color: #B392F0\"> threeParameters( optional&lt;<\/span><span style=\"color: #F97583\">int<\/span><span style=\"color: #B392F0\">&gt; parm1<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> optional&lt;<\/span><span style=\"color: #F97583\">double<\/span><span style=\"color: #B392F0\">&gt; parm2<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> optional&lt;std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">string&gt; str1)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cout <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;Three parameters called with:   &quot;<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">if<\/span><span style=\"color: #B392F0\"> (<\/span><span style=\"color: #79B8FF\">parm1<\/span><span style=\"color: #BBBBBB\">.<\/span><span style=\"color: #B392F0\">has_value())<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cout <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;first parameter: &quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">parm1<\/span><span style=\"color: #BBBBBB\">.<\/span><span style=\"color: #B392F0\">value() <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;   &quot;<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">if<\/span><span style=\"color: #B392F0\"> (<\/span><span style=\"color: #79B8FF\">parm2<\/span><span style=\"color: #BBBBBB\">.<\/span><span style=\"color: #B392F0\">has_value())<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cout <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;second parameter: &quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">setprecision(<\/span><span style=\"color: #F8F8F8\">4<\/span><span style=\"color: #B392F0\">) <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">parm2<\/span><span style=\"color: #BBBBBB\">.<\/span><span style=\"color: #B392F0\">value() <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;    &quot;<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">if<\/span><span style=\"color: #B392F0\"> (<\/span><span style=\"color: #79B8FF\">str1<\/span><span style=\"color: #BBBBBB\">.<\/span><span style=\"color: #B392F0\">has_value())<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cout <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;str1:  &quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">str1<\/span><span style=\"color: #BBBBBB\">.<\/span><span style=\"color: #B392F0\">value();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t<\/span><span style=\"color: #F97583\">if<\/span><span style=\"color: #B392F0\"> (<\/span><span style=\"color: #F97583\">!<\/span><span style=\"color: #79B8FF\">parm1<\/span><span style=\"color: #BBBBBB\">.<\/span><span style=\"color: #B392F0\">has_value() <\/span><span style=\"color: #F97583\">&amp;&amp;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">!<\/span><span style=\"color: #79B8FF\">parm2<\/span><span style=\"color: #BBBBBB\">.<\/span><span style=\"color: #B392F0\">has_value() <\/span><span style=\"color: #F97583\">&amp;&amp;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">!<\/span><span style=\"color: #79B8FF\">str1<\/span><span style=\"color: #BBBBBB\">.<\/span><span style=\"color: #B392F0\">has_value())<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cout <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;  no parameters\\n&quot;<\/span><span style=\"color: #B392F0\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t}<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cout <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Before we go too far, I want to show you the output.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>OptionalExample<br \/>Version 0.1<br \/><br \/><br \/><br \/>Our first test will prompt you for 2 integers to divide <br \/>in a loop until you type 999 as the first integer. Enter 0 as the<br \/>second integer to see hopw optional can work for return values: <br \/><br \/>Enter the number to be divided: 47<br \/><br \/>Enter a number to divide the first by: 3<br \/><br \/><br \/>The result is: 15<br \/>Enter the number to be divided: 45<br \/><br \/>Enter a number to divide the first by: 0<br \/><br \/><br \/>You cannot divide by zero!!!!<br \/>Enter the number to be divided: 999<br \/><br \/><br \/>Now trying optional parameters<br \/><br \/>Three parameters called with:     no parameters<br \/><br \/>Three parameters called with:   str1:  This is a string<br \/>Three parameters called with:   second parameter: 3.142    <br \/>Three parameters called with:   first parameter: 8   <br \/><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">std::optional Return Discussion<\/h2>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#b392f0;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1f1f1f\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"optional&lt;double&gt; divide_these( int first, int second);\nvoid threeParameters( optional&lt;int&gt; parm1 = std::nullopt,\n\t\t\t\t\t  optional&lt;double&gt; parm2 = std::nullopt,\n\t\t\t\t\t  optional&lt;std::string&gt; str1 = std::nullopt);\n\" style=\"color:#b392f0;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki min-dark\" style=\"background-color: #1f1f1f\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #B392F0\">optional&lt;<\/span><span style=\"color: #F97583\">double<\/span><span style=\"color: #B392F0\">&gt; divide_these( <\/span><span style=\"color: #F97583\">int<\/span><span style=\"color: #B392F0\"> first<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">int<\/span><span style=\"color: #B392F0\"> second);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">void<\/span><span style=\"color: #B392F0\"> threeParameters( optional&lt;<\/span><span style=\"color: #F97583\">int<\/span><span style=\"color: #B392F0\">&gt; parm1 <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">nullopt<\/span><span style=\"color: #BBBBBB\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t\t\t\t  optional&lt;<\/span><span style=\"color: #F97583\">double<\/span><span style=\"color: #B392F0\">&gt; parm2 <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">nullopt<\/span><span style=\"color: #BBBBBB\">,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t\t\t\t  optional&lt;std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">string&gt; str1 <\/span><span style=\"color: #F97583\">=<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">nullopt);<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>Our two function prototypes show quite a few uses of std::optional. The first has an optional return value. The second has three optional parameters. You will note that this is really just a specialized case of &#8220;default values.&#8221; Instead of being OPTIONAL as VAX BASIC and so many languages from the 1980s provided. The C++ standard has a ways to go to catch up to the 1980s.<\/p>\n\n\n\n<p>Calling a function that returns a std::optional result can look a bit funky. Using the value might look a bit funkier still.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#b392f0;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1f1f1f\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"\t\t\tconst optional&lt;double&gt; dbl {divide_these( first, second)};\n\t\t\tif (dbl.has_value())\n\t\t\t{\n\t\t\t\tstd::cout &lt;&lt; &quot;\\n\\nThe result is: &quot; &lt;&lt; std::setprecision(4) &lt;&lt; dbl.value() &lt;&lt; std::endl;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tstd::cout &lt;&lt; &quot;\\n\\nYou cannot divide by zero!!!!&quot; &lt;&lt; std::endl;\n\t\t\t}\n\" style=\"color:#b392f0;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki min-dark\" style=\"background-color: #1f1f1f\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #B392F0\">\t\t\t<\/span><span style=\"color: #F97583\">const<\/span><span style=\"color: #B392F0\"> optional<\/span><span style=\"color: #F97583\">&lt;double&gt;<\/span><span style=\"color: #B392F0\"> dbl {divide_these( first<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> second)};<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t\t<\/span><span style=\"color: #F97583\">if<\/span><span style=\"color: #B392F0\"> (<\/span><span style=\"color: #79B8FF\">dbl<\/span><span style=\"color: #BBBBBB\">.<\/span><span style=\"color: #B392F0\">has_value())<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t\t{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t\t\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cout <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;\\n\\nThe result is: &quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">setprecision(<\/span><span style=\"color: #F8F8F8\">4<\/span><span style=\"color: #B392F0\">) <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #79B8FF\">dbl<\/span><span style=\"color: #BBBBBB\">.<\/span><span style=\"color: #B392F0\">value() <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t\t}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t\t<\/span><span style=\"color: #F97583\">else<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t\t{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t\t\tstd<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">cout <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;\\n\\nYou cannot divide by zero!!!!&quot;<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F97583\">&lt;&lt;<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">endl;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\t\t\t}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p><strong>Never use auto in production code!<\/strong><\/p>\n\n\n\n<p>We have to declare a matching std::optional entity to receive the value. I declared it const because I don&#8217;t want to mess around with changing its value (or lack thereof). To see if we had a value we use <strong>has_value()<\/strong>. Yes, many\/most compilers will also convert a std::optional entity to a bool for a test condition, but <\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#b392f0;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1f1f1f\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"if (dbl)\" style=\"color:#b392f0;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki min-dark\" style=\"background-color: #1f1f1f\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F97583\">if<\/span><span style=\"color: #B392F0\"> (dbl)<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>would be confusing as all get out to new or very old developers. When a std::optional has a value it is retrieved by <strong>value()<\/strong>. Don&#8217;t worry if it takes you a while to get used to seeing what your mind believes to be a native data type with a .value() behind it. That is normal. The else of the above if statement is interesting only from the standpoint we have successfully tested for something that doesn&#8217;t exist.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">std::optional Parameter Discussion<\/h2>\n\n\n\n<p>Here is where much of my beginning rant will make sense.<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#b392f0;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1f1f1f\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" data-code=\"\tthreeParameters();\n\tthreeParameters( std::nullopt, std::nullopt, &quot;This is a string&quot;);\n\tthreeParameters( std::nullopt, 3.14159);\n\tthreeParameters(8);\n\" style=\"color:#b392f0;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki min-dark\" style=\"background-color: #1f1f1f\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #B392F0\">\tthreeParameters();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tthreeParameters( std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">nullopt<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">nullopt<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #FFAB70\">&quot;This is a string&quot;<\/span><span style=\"color: #B392F0\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tthreeParameters( std<\/span><span style=\"color: #BBBBBB\">::<\/span><span style=\"color: #B392F0\">nullopt<\/span><span style=\"color: #BBBBBB\">,<\/span><span style=\"color: #B392F0\"> <\/span><span style=\"color: #F8F8F8\">3.14159<\/span><span style=\"color: #B392F0\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #B392F0\">\tthreeParameters(<\/span><span style=\"color: #F8F8F8\">8<\/span><span style=\"color: #B392F0\">);<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>They aren&#8217;t &#8220;optional.&#8221; You can&#8217;t skip them. You can only &#8220;not provide&#8221; trailing ones. What I really don&#8217;t like about this situation is if threeParameters() was an overloaded method\/function. You can&#8217;t be certain which one got used. With VAX BASIC and 3GLs of the 1960-1980s you had documentation in the code of which one got called.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>threeParameters(,,);<br \/>threeParameters( ,, \"This is a string\");<br \/>threeParameters( , 3.14159 ,);<br \/>threeParameters(8 ,,);<br \/><\/code><\/pre>\n\n\n\n<p>Then again, many of those languages didn&#8217;t allow for overloading of functions.<\/p>\n\n\n\n<p>About the only thing the standards committee did was give us a universal invalid value. They still haven&#8217;t admitted that making size_t an unsigned integer was a bullshit thing to do. It has existed so long it cannot really be undone at this point.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<p>Now that we have a universal invalid value via std::optional you can quit throwing away one value in a fixed range as was too often done to indicate error. The academics, however, still need to admit they&#8217;ve been wrong for decades.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>std::optional is an attempt by the academics on the C++ standards committee to &#8220;fix&#8221; what they believe to be abhorrent behavior. As usual they created a committee quality result. To understand my disgust with what they created you have to understand that I&#8217;ve been programming on real computers since the early 1980s. Even then VAX BASIC had OPTIONAL and a much better implementation for OPTIONAL parameters. You can read more about it in this book. &hellip; <a title=\"std::optional Example and Explanation\" class=\"bnm-read-more\" href=\"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/stdoptional\/\"><span class=\"screen-reader-text\">std::optional Example and Explanation<\/span>Read more<\/a><\/p>\n","protected":false},"author":2,"featured_media":6765,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[1504,9,2183,2184,2160],"class_list":["post-6763","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-information-technology","tag-c","tag-openvms","tag-stdoptional","tag-stdstring","tag-vax-basic","bnm-entry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>std::optional Example and Explanation &#8211; Logikal Blog<\/title>\n<meta name=\"description\" content=\"std::optional is an attempt by the academics on the C++ standards committee to &quot;fix&quot; what they believe to be abhorrent behavior.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/stdoptional\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"std::optional Example and Explanation &#8211; Logikal Blog\" \/>\n<meta property=\"og:description\" content=\"std::optional is an attempt by the academics on the C++ standards committee to &quot;fix&quot; what they believe to be abhorrent behavior.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/stdoptional\/\" \/>\n<meta property=\"og:site_name\" content=\"Logikal Blog\" \/>\n<meta property=\"article:published_time\" content=\"2023-12-18T22:34:54+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-18T22:34:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2023\/12\/pexels-photo-5766609.jpeg\" \/>\n\t<meta property=\"og:image:width\" content=\"1880\" \/>\n\t<meta property=\"og:image:height\" content=\"1259\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"seasoned_geek\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"seasoned_geek\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/stdoptional\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/stdoptional\\\/\"},\"author\":{\"name\":\"seasoned_geek\",\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/#\\\/schema\\\/person\\\/c077f770ade13de7faaf616c3eac6842\"},\"headline\":\"std::optional Example and Explanation\",\"datePublished\":\"2023-12-18T22:34:54+00:00\",\"dateModified\":\"2023-12-18T22:34:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/stdoptional\\\/\"},\"wordCount\":1019,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/#\\\/schema\\\/person\\\/c077f770ade13de7faaf616c3eac6842\"},\"image\":{\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/stdoptional\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/wp-content\\\/uploads\\\/2023\\\/12\\\/pexels-photo-5766609.jpeg\",\"keywords\":[\"C++\",\"OpenVMS\",\"std::optional\",\"std::string\",\"VAX BASIC\"],\"articleSection\":[\"Information Technology\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/stdoptional\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/stdoptional\\\/\",\"url\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/stdoptional\\\/\",\"name\":\"std::optional Example and Explanation &#8211; Logikal Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/stdoptional\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/stdoptional\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/wp-content\\\/uploads\\\/2023\\\/12\\\/pexels-photo-5766609.jpeg\",\"datePublished\":\"2023-12-18T22:34:54+00:00\",\"dateModified\":\"2023-12-18T22:34:56+00:00\",\"description\":\"std::optional is an attempt by the academics on the C++ standards committee to \\\"fix\\\" what they believe to be abhorrent behavior.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/stdoptional\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/stdoptional\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/stdoptional\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/wp-content\\\/uploads\\\/2023\\\/12\\\/pexels-photo-5766609.jpeg\",\"contentUrl\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/wp-content\\\/uploads\\\/2023\\\/12\\\/pexels-photo-5766609.jpeg\",\"width\":1880,\"height\":1259,\"caption\":\"Photo by Ksenia Chernaya on Pexels.com\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/information-technology\\\/stdoptional\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"std::optional Example and Explanation\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/#website\",\"url\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/\",\"name\":\"Logikal Blog\",\"description\":\"For people with attention spans longer than a Tweet\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/#\\\/schema\\\/person\\\/c077f770ade13de7faaf616c3eac6842\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/#\\\/schema\\\/person\\\/c077f770ade13de7faaf616c3eac6842\",\"name\":\"seasoned_geek\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/ae9adac14079d84b909e635d7af986fe4568053af4fd9ff8d4109298c392493e?s=96&d=mm&r=r\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/ae9adac14079d84b909e635d7af986fe4568053af4fd9ff8d4109298c392493e?s=96&d=mm&r=r\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/ae9adac14079d84b909e635d7af986fe4568053af4fd9ff8d4109298c392493e?s=96&d=mm&r=r\",\"caption\":\"seasoned_geek\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/ae9adac14079d84b909e635d7af986fe4568053af4fd9ff8d4109298c392493e?s=96&d=mm&r=r\"},\"description\":\"Roland Hughes started his IT career in the early 1980s. He quickly became a consultant and president of Logikal Solutions, a software consulting firm specializing in OpenVMS application and C++\\\/Qt touchscreen\\\/embedded Linux development. Early in his career he became involved in what is now called cross platform development. Given the dearth of useful books on the subject he ventured into the world of professional author in 1995 writing the first of the \\\"Zinc It!\\\" book series for John Gordon Burke Publisher, Inc. A decade later he released a massive (nearly 800 pages) tome \\\"The Minimum You Need to Know to Be an OpenVMS Application Developer\\\" which tried to encapsulate the essential skills gained over what was nearly a 20 year career at that point. From there \\\"The Minimum You Need to Know\\\" book series was born. Three years later he wrote his first novel \\\"Infinite Exposure\\\" which got much notice from people involved in the banking and financial security worlds. Some of the attacks predicted in that book have since come to pass. While it was not originally intended to be a trilogy, it became the first book of \\\"The Earth That Was\\\" trilogy: Infinite Exposure Lesedi - The Greatest Lie Ever Told John Smith - Last Known Survivor of the Microsoft Wars When he is not consulting Roland Hughes posts about technology and sometimes politics on his blog. He also has regularly scheduled Sunday posts appearing on the Interesting Authors blog.\",\"sameAs\":[\"https:\\\/\\\/theminimumyouneedtoknow.com\"],\"url\":\"https:\\\/\\\/www.logikalsolutions.com\\\/wordpress\\\/author\\\/seasoned_geek\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"std::optional Example and Explanation &#8211; Logikal Blog","description":"std::optional is an attempt by the academics on the C++ standards committee to \"fix\" what they believe to be abhorrent behavior.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/stdoptional\/","og_locale":"en_US","og_type":"article","og_title":"std::optional Example and Explanation &#8211; Logikal Blog","og_description":"std::optional is an attempt by the academics on the C++ standards committee to \"fix\" what they believe to be abhorrent behavior.","og_url":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/stdoptional\/","og_site_name":"Logikal Blog","article_published_time":"2023-12-18T22:34:54+00:00","article_modified_time":"2023-12-18T22:34:56+00:00","og_image":[{"width":1880,"height":1259,"url":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2023\/12\/pexels-photo-5766609.jpeg","type":"image\/jpeg"}],"author":"seasoned_geek","twitter_card":"summary_large_image","twitter_misc":{"Written by":"seasoned_geek","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/stdoptional\/#article","isPartOf":{"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/stdoptional\/"},"author":{"name":"seasoned_geek","@id":"https:\/\/www.logikalsolutions.com\/wordpress\/#\/schema\/person\/c077f770ade13de7faaf616c3eac6842"},"headline":"std::optional Example and Explanation","datePublished":"2023-12-18T22:34:54+00:00","dateModified":"2023-12-18T22:34:56+00:00","mainEntityOfPage":{"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/stdoptional\/"},"wordCount":1019,"commentCount":0,"publisher":{"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/#\/schema\/person\/c077f770ade13de7faaf616c3eac6842"},"image":{"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/stdoptional\/#primaryimage"},"thumbnailUrl":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2023\/12\/pexels-photo-5766609.jpeg","keywords":["C++","OpenVMS","std::optional","std::string","VAX BASIC"],"articleSection":["Information Technology"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/stdoptional\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/stdoptional\/","url":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/stdoptional\/","name":"std::optional Example and Explanation &#8211; Logikal Blog","isPartOf":{"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/stdoptional\/#primaryimage"},"image":{"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/stdoptional\/#primaryimage"},"thumbnailUrl":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2023\/12\/pexels-photo-5766609.jpeg","datePublished":"2023-12-18T22:34:54+00:00","dateModified":"2023-12-18T22:34:56+00:00","description":"std::optional is an attempt by the academics on the C++ standards committee to \"fix\" what they believe to be abhorrent behavior.","breadcrumb":{"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/stdoptional\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/stdoptional\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/stdoptional\/#primaryimage","url":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2023\/12\/pexels-photo-5766609.jpeg","contentUrl":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-content\/uploads\/2023\/12\/pexels-photo-5766609.jpeg","width":1880,"height":1259,"caption":"Photo by Ksenia Chernaya on Pexels.com"},{"@type":"BreadcrumbList","@id":"https:\/\/www.logikalsolutions.com\/wordpress\/information-technology\/stdoptional\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.logikalsolutions.com\/wordpress\/"},{"@type":"ListItem","position":2,"name":"std::optional Example and Explanation"}]},{"@type":"WebSite","@id":"https:\/\/www.logikalsolutions.com\/wordpress\/#website","url":"https:\/\/www.logikalsolutions.com\/wordpress\/","name":"Logikal Blog","description":"For people with attention spans longer than a Tweet","publisher":{"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/#\/schema\/person\/c077f770ade13de7faaf616c3eac6842"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.logikalsolutions.com\/wordpress\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.logikalsolutions.com\/wordpress\/#\/schema\/person\/c077f770ade13de7faaf616c3eac6842","name":"seasoned_geek","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/ae9adac14079d84b909e635d7af986fe4568053af4fd9ff8d4109298c392493e?s=96&d=mm&r=r","url":"https:\/\/secure.gravatar.com\/avatar\/ae9adac14079d84b909e635d7af986fe4568053af4fd9ff8d4109298c392493e?s=96&d=mm&r=r","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ae9adac14079d84b909e635d7af986fe4568053af4fd9ff8d4109298c392493e?s=96&d=mm&r=r","caption":"seasoned_geek"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/ae9adac14079d84b909e635d7af986fe4568053af4fd9ff8d4109298c392493e?s=96&d=mm&r=r"},"description":"Roland Hughes started his IT career in the early 1980s. He quickly became a consultant and president of Logikal Solutions, a software consulting firm specializing in OpenVMS application and C++\/Qt touchscreen\/embedded Linux development. Early in his career he became involved in what is now called cross platform development. Given the dearth of useful books on the subject he ventured into the world of professional author in 1995 writing the first of the \"Zinc It!\" book series for John Gordon Burke Publisher, Inc. A decade later he released a massive (nearly 800 pages) tome \"The Minimum You Need to Know to Be an OpenVMS Application Developer\" which tried to encapsulate the essential skills gained over what was nearly a 20 year career at that point. From there \"The Minimum You Need to Know\" book series was born. Three years later he wrote his first novel \"Infinite Exposure\" which got much notice from people involved in the banking and financial security worlds. Some of the attacks predicted in that book have since come to pass. While it was not originally intended to be a trilogy, it became the first book of \"The Earth That Was\" trilogy: Infinite Exposure Lesedi - The Greatest Lie Ever Told John Smith - Last Known Survivor of the Microsoft Wars When he is not consulting Roland Hughes posts about technology and sometimes politics on his blog. He also has regularly scheduled Sunday posts appearing on the Interesting Authors blog.","sameAs":["https:\/\/theminimumyouneedtoknow.com"],"url":"https:\/\/www.logikalsolutions.com\/wordpress\/author\/seasoned_geek\/"}]}},"_links":{"self":[{"href":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-json\/wp\/v2\/posts\/6763","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-json\/wp\/v2\/comments?post=6763"}],"version-history":[{"count":0,"href":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-json\/wp\/v2\/posts\/6763\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-json\/wp\/v2\/media\/6765"}],"wp:attachment":[{"href":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-json\/wp\/v2\/media?parent=6763"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-json\/wp\/v2\/categories?post=6763"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.logikalsolutions.com\/wordpress\/wp-json\/wp\/v2\/tags?post=6763"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}