{"id":5004,"date":"2016-10-30T22:01:40","date_gmt":"2016-10-30T22:01:40","guid":{"rendered":"https:\/\/www.modernescpp.com\/index.php\/raw-and-cooked\/"},"modified":"2023-06-26T12:38:00","modified_gmt":"2023-06-26T12:38:00","slug":"raw-and-cooked","status":"publish","type":"post","link":"https:\/\/www.modernescpp.com\/index.php\/raw-and-cooked\/","title":{"rendered":"Raw and Cooked"},"content":{"rendered":"<p>C++11 has user-defined literals for characters, C strings, integers, and floating-point numbers. Integers and floating-point numbers are available in raw and cooked form. Thanks to C++14, we have built-in literals for binary numbers, C++ strings, complex numbers, and time units.<\/p>\n<p><!--more--><\/p>\n<p>&nbsp;<\/p>\n<h2>The four user-defined literals<\/h2>\n<p>After the example in the last post <a href=\"https:\/\/www.modernescpp.com\/index.php\/user-defined-literals\">user-defined literals<\/a> I will provide &#8211; as promised &#8211; the details in this post. To make my intention clear, here are the literal types, including the raw and cooked variations:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-5000\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/RawAndCookedEng.png\" alt=\"RawAndCookedEng\" width=\"800\" height=\"201\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/RawAndCookedEng.png 1213w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/RawAndCookedEng-300x75.png 300w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/RawAndCookedEng-1024x257.png 1024w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/RawAndCookedEng-768x193.png 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/p>\n<p>How should you read the table? The data type character has the form character_suffix. An example is<span style=\"font-family: courier new,courier;\"> &#8216;s&#8217;_c.<\/span> The compiler invokes the literal operator&nbsp;<span style=\"font-family: courier new,courier;\">operator&#8221;&#8221; _c(&#8216;s&#8217;)<\/span>. The character is, in this case, a <span style=\"font-family: courier new,courier;\">char. <span style=\"font-family: arial,helvetica,sans-serif;\">C++ supports, in addition to the data type<span style=\"font-family: courier new, courier;\"> <code>char<\/code><\/span> the data types <span style=\"font-family: courier new, courier;\">wchar_t, char16_t,<\/span> and <span style=\"font-family: courier new, courier;\">char32_t<\/span>. You can use this type as a base for your C string. I used in the table a <code>char<\/code>. The table shows that the compiler maps the C string <span style=\"font-family: courier new,courier;\"><span style=\"font-family: arial,helvetica,sans-serif;\"><span style=\"font-family: courier new,courier;\">&#8220;hi&#8221;_i18<\/span> to the literal operator <span style=\"font-family: courier new,courier;\">operator&#8221;&#8221; _i18n(&#8220;hi&#8221;,2). <\/span><\/span> <\/span> <\/span> <\/span><span style=\"font-family: arial,helvetica,sans-serif;\"><span style=\"font-family: arial,helvetica,sans-serif;\">2 is the length of the c string.<\/span><\/span><span style=\"font-family: courier new,courier;\"><span style=\"font-family: arial,helvetica,sans-serif;\"><span style=\"font-family: courier new,courier;\"> <\/span> <\/span> <\/span><\/p>\n<p>The compiler can map integers or floating-point numbers to integers (<span style=\"font-family: courier new, courier;\">unsigned long long int<\/span>) or floating-point numbers (long double), but the compiler can also map them to C strings. The first variant is called the cooked form; the second variant is the raw form. The compiler will use the raw form if the literal operator wants its arguments as a C string. If not, it uses the cooked form. If you implement both versions, the compiler will choose the cooked form.<\/p>\n<p>Admittedly, in the last lines is a lot of confusion potential. Therefore, I sum it all up from the perspective of the signatures in the following table. The first column has the signature of the literal operator, the second column is the type of the user-defined literal, and the last column an example for a user-defined literal that fits the signature of the literal operator.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-5001\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/literaleSignaturEng.png\" alt=\"literaleSignaturEng\" width=\"700\" height=\"359\" style=\"margin: 15px;\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/literaleSignaturEng.png 1054w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/literaleSignaturEng-300x154.png 300w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/literaleSignaturEng-1024x525.png 1024w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/literaleSignaturEng-768x393.png 768w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/p>\n<\/p>\n<h2>Calculate it once more<\/h2>\n<p>I calculated in the post<a href=\"https:\/\/www.modernescpp.com\/index.php\/user-defined-literals\"> user-defined literals <\/a>how many meters I have to go by car on average per week. I made my calculation based on user-defined literals of the type long double in the cooked form. I have to adjust the literal operators to make my calculation in the raw form.<\/p>\n<p>It&#8217;s only necessary to convert the arguments of the literal operator from type C string to <span style=\"font-family: courier new, courier;\">long double<\/span>. That is relatively easy to do with the new function <a href=\"http:\/\/en.cppreference.com\/w\/cpp\/string\/basic_string\/stof\"><span style=\"font-family: courier new,courier;\">std::stold.<\/span><\/a><\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<table>\n<tbody>\n<tr>\n<td>\n<pre style=\"margin: 0; line-height: 125%;\"> 1\r\n 2\r\n 3\r\n 4\r\n 5\r\n 6\r\n 7\r\n 8\r\n 9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19\r\n20\r\n21\r\n22\r\n23\r\n24\r\n25\r\n26<\/pre>\n<\/td>\n<td>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008000;\">\/\/ unit.h<\/span>\r\n\r\n<span style=\"color: #0000ff;\">#ifndef UNIT_H<\/span>\r\n<span style=\"color: #0000ff;\">#define UNIT_H<\/span>\r\n\r\n<span style=\"color: #0000ff;\">#include &lt;distance.h&gt;<\/span>\r\n\r\n<span style=\"color: #0000ff;\">namespace<\/span> Distance{\r\n\r\n  <span style=\"color: #0000ff;\">namespace<\/span> Unit{\r\n    MyDistance <span style=\"color: #0000ff;\">operator<\/span> <span style=\"color: #a31515;\">\"\"<\/span> _km(<span style=\"color: #0000ff;\">const<\/span> <span style=\"color: #2b91af;\">char<\/span>* k){\r\n      <span style=\"color: #0000ff;\">return<\/span> MyDistance(1000* std::stold(k));\r\n    }\r\n    MyDistance <span style=\"color: #0000ff;\">operator<\/span> <span style=\"color: #a31515;\">\"\"<\/span> _m(<span style=\"color: #0000ff;\">const<\/span> <span style=\"color: #2b91af;\">char<\/span>* m){\r\n      <span style=\"color: #0000ff;\">return<\/span> MyDistance(std::stold(m));\r\n    }\r\n    MyDistance <span style=\"color: #0000ff;\">operator<\/span> <span style=\"color: #a31515;\">\"\"<\/span> _dm(<span style=\"color: #0000ff;\">const<\/span> <span style=\"color: #2b91af;\">char<\/span>* d){\r\n      <span style=\"color: #0000ff;\">return<\/span> MyDistance(std::stold(d)\/10);\r\n    }\r\n    MyDistance <span style=\"color: #0000ff;\">operator<\/span> <span style=\"color: #a31515;\">\"\"<\/span> _cm(<span style=\"color: #0000ff;\">const<\/span> <span style=\"color: #2b91af;\">char<\/span>* c){\r\n      <span style=\"color: #0000ff;\">return<\/span> MyDistance(std::stold(c)\/100);\r\n    }\r\n  }\r\n}\r\n\r\n<span style=\"color: #0000ff;\">#endif<\/span>\r\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>&nbsp;<\/p>\n<p>Either I have not touched the class <span style=\"font-family: courier new,courier;\">MyDistance.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<table>\n<tbody>\n<tr>\n<td>\n<pre style=\"margin: 0; line-height: 125%;\"> 1\r\n 2\r\n 3\r\n 4\r\n 5\r\n 6\r\n 7\r\n 8\r\n 9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19\r\n20\r\n21\r\n22\r\n23\r\n24\r\n25\r\n26\r\n27\r\n28\r\n29\r\n30\r\n31\r\n32\r\n33\r\n34\r\n35\r\n36\r\n37\r\n38\r\n39\r\n40\r\n41\r\n42\r\n43\r\n44\r\n45\r\n46\r\n47\r\n48<\/pre>\n<\/td>\n<td>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008000;\">\/\/ distance.h<\/span>\r\n\r\n<span style=\"color: #0000ff;\">#ifndef DISTANCE_H<\/span>\r\n<span style=\"color: #0000ff;\">#define DISTANCE_H<\/span>\r\n\r\n<span style=\"color: #0000ff;\">#include &lt;iostream&gt;<\/span>\r\n<span style=\"color: #0000ff;\">#include &lt;ostream&gt;<\/span>\r\n\r\n\r\n<span style=\"color: #0000ff;\">namespace<\/span> Distance{\r\n  <span style=\"color: #0000ff;\">class<\/span> <span style=\"color: #2b91af;\">MyDistance<\/span>{\r\n    public:\r\n      MyDistance(<span style=\"color: #2b91af;\">double<\/span> i):m(i){}\r\n\r\n      <span style=\"color: #0000ff;\">friend<\/span> MyDistance <span style=\"color: #0000ff;\">operator<\/span>+(<span style=\"color: #0000ff;\">const<\/span> MyDistance&amp; a, <span style=\"color: #0000ff;\">const<\/span> MyDistance&amp; b){\r\n        <span style=\"color: #0000ff;\">return<\/span> MyDistance(a.m + b.m);\r\n      }\r\n      <span style=\"color: #0000ff;\">friend<\/span> MyDistance <span style=\"color: #0000ff;\">operator<\/span>-(<span style=\"color: #0000ff;\">const<\/span> MyDistance&amp; a,<span style=\"color: #0000ff;\">const<\/span> MyDistance&amp; b){\r\n        <span style=\"color: #0000ff;\">return<\/span> MyDistance(a.m - b.m);\r\n      }\r\n\t  \r\n\t  <span style=\"color: #0000ff;\">friend<\/span> MyDistance <span style=\"color: #0000ff;\">operator<\/span>*(<span style=\"color: #2b91af;\">double<\/span> m, <span style=\"color: #0000ff;\">const<\/span> MyDistance&amp; a){\r\n\t    <span style=\"color: #0000ff;\">return<\/span> MyDistance(m*a.m);\r\n\t  }\r\n\t  \r\n\t  <span style=\"color: #0000ff;\">friend<\/span> MyDistance <span style=\"color: #0000ff;\">operator<\/span>\/(<span style=\"color: #0000ff;\">const<\/span> MyDistance&amp; a, <span style=\"color: #2b91af;\">int<\/span> n){\r\n\t    <span style=\"color: #0000ff;\">return<\/span> MyDistance(a.m\/n);\r\n\t  }\r\n\t  \r\n      <span style=\"color: #0000ff;\">friend<\/span> std::ostream&amp; <span style=\"color: #0000ff;\">operator<\/span>&lt;&lt; (std::ostream &amp;out, <span style=\"color: #0000ff;\">const<\/span> MyDistance&amp; myDist){\r\n        out &lt;&lt; myDist.m &lt;&lt; <span style=\"color: #a31515;\">\" m\"<\/span>;\r\n        <span style=\"color: #0000ff;\">return<\/span> out;\r\n      }\r\n\tprivate:\r\n\t  <span style=\"color: #2b91af;\">double<\/span> m;\r\n\t  \r\n  };\r\n  \r\n}\r\n  \r\nDistance::MyDistance getAverageDistance(std::initializer_list&lt;Distance::MyDistance&gt; inList){\r\n  <span style=\"color: #0000ff;\">auto<\/span> sum= Distance::MyDistance{0.0};\r\n  <span style=\"color: #0000ff;\">for<\/span> (<span style=\"color: #0000ff;\">auto<\/span> i: inList) sum = sum + i ;\r\n  <span style=\"color: #0000ff;\">return<\/span> sum\/inList.size(); \r\n}\r\n\r\n\r\n<span style=\"color: #0000ff;\">#endif<\/span>\r\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>&nbsp;<\/p>\n<p>Nor does the main program need a modification.<\/p>\n<p>&nbsp;<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<table>\n<tbody>\n<tr>\n<td>\n<pre style=\"margin: 0; line-height: 125%;\"> 1\r\n 2\r\n 3\r\n 4\r\n 5\r\n 6\r\n 7\r\n 8\r\n 9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19\r\n20\r\n21\r\n22\r\n23\r\n24\r\n25\r\n26\r\n27\r\n28\r\n29\r\n30\r\n31\r\n32\r\n33\r\n34\r\n35\r\n36\r\n37\r\n38\r\n39\r\n40\r\n41\r\n42\r\n43\r\n44\r\n45\r\n46<\/pre>\n<\/td>\n<td>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008000;\">\/\/ average.cpp<\/span>\r\n\r\n<span style=\"color: #0000ff;\">#include &lt;distance.h&gt;<\/span>\r\n<span style=\"color: #0000ff;\">#include &lt;unit.h&gt;<\/span>\r\n\r\n<span style=\"color: #0000ff;\">using<\/span> <span style=\"color: #0000ff;\">namespace<\/span> Distance::Unit;\r\n\r\n<span style=\"color: #2b91af;\">int<\/span> main(){\r\n\r\n  std:: cout &lt;&lt; std::endl;\r\n\r\n  std::cout &lt;&lt; <span style=\"color: #a31515;\">\"1.0_km: \"<\/span> &lt;&lt; 1.0_km &lt;&lt; std::endl;\r\n  std::cout &lt;&lt; <span style=\"color: #a31515;\">\"1.0_m: \"<\/span> &lt;&lt; 1.0_m &lt;&lt; std::endl;\r\n  std::cout &lt;&lt; <span style=\"color: #a31515;\">\"1.0_dm: \"<\/span> &lt;&lt; 1.0_dm &lt;&lt; std::endl;\r\n  std::cout &lt;&lt; <span style=\"color: #a31515;\">\"1.0_cm: \"<\/span> &lt;&lt; 1.0_cm &lt;&lt; std::endl;\r\n  \r\n  std::cout &lt;&lt; std::endl;\r\n\r\n  std::cout &lt;&lt; <span style=\"color: #a31515;\">\"0.001 * 1.0_km: \"<\/span> &lt;&lt; 0.001 * 1.0_km &lt;&lt; std::endl;\r\n  std::cout &lt;&lt; <span style=\"color: #a31515;\">\"10 * 1_dm: \"<\/span> &lt;&lt; 10 * 1.0_dm &lt;&lt; std::endl;\r\n  std::cout &lt;&lt; <span style=\"color: #a31515;\">\"100 * 1.0cm: \"<\/span> &lt;&lt; 100 * 1.0_cm &lt;&lt; std::endl;\r\n  std::cout &lt;&lt; <span style=\"color: #a31515;\">\"1_.0km \/ 1000: \"<\/span> &lt;&lt; 1.0_km \/ 1000 &lt;&lt; std::endl;\r\n\r\n  std::cout &lt;&lt; std::endl;\r\n  std::cout &lt;&lt; <span style=\"color: #a31515;\">\"1.0_km + 2.0_dm +  3.0_dm + 4.0_cm: \"<\/span> &lt;&lt; 1.0_km + 2.0_dm +  3.0_dm + 4.0_cm &lt;&lt; std::endl;\r\n  std::cout &lt;&lt; std::endl;\r\n  \r\n  <span style=\"color: #0000ff;\">auto<\/span> work= 63.0_km;\r\n  <span style=\"color: #0000ff;\">auto<\/span> workPerDay= 2 * work;\r\n  <span style=\"color: #0000ff;\">auto<\/span> abbrevationToWork= 5400.0_m;\r\n  <span style=\"color: #0000ff;\">auto<\/span> workout= 2 * 1600.0_m;\r\n  <span style=\"color: #0000ff;\">auto<\/span> shopping= 2 * 1200.0_m;\r\n  \r\n  <span style=\"color: #0000ff;\">auto<\/span> distPerWeek1= 4*workPerDay-3*abbrevationToWork+ workout+ shopping;\r\n  <span style=\"color: #0000ff;\">auto<\/span> distPerWeek2= 4*workPerDay-3*abbrevationToWork+ 2*workout;\r\n  <span style=\"color: #0000ff;\">auto<\/span> distPerWeek3= 4*workout + 2*shopping;\r\n  <span style=\"color: #0000ff;\">auto<\/span> distPerWeek4= 5*workout + shopping;\r\n\r\n  std::cout &lt;&lt; <span style=\"color: #a31515;\">\"distPerWeek1: \"<\/span> &lt;&lt; distPerWeek1 &lt;&lt; std::endl;\r\n  \r\n  <span style=\"color: #0000ff;\">auto<\/span> averageDistance= getAverageDistance({distPerWeek1,distPerWeek2,distPerWeek3,distPerWeek4});\r\n  std::cout&lt;&lt; <span style=\"color: #a31515;\">\"averageDistance: \"<\/span> &lt;&lt; averageDistance &lt;&lt; std::endl;\r\n  \r\n  std::cout &lt;&lt; std::endl;\r\n\r\n}\r\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>&nbsp;<\/p>\n<p>Of course, the result is the same.<\/p>\n<p>&nbsp;<img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-4997\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/average.png\" alt=\"average\" width=\"543\" height=\"381\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/average.png 543w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/average-300x210.png 300w\" sizes=\"auto, (max-width: 543px) 100vw, 543px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2>New built-in literals with C++14<\/h2>\n<p>C++ added with C++14 a few new built-in literals. These are built-in literals for binary numbers, C++ strings, complex numbers, and time units. First, here is the overview.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-5002\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/CppLiteralsEng.png\" alt=\"CppLiteralsEng\" width=\"700\" height=\"425\" style=\"margin: 15px;\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/CppLiteralsEng.png 799w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/CppLiteralsEng-300x182.png 300w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/CppLiteralsEng-768x466.png 768w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/p>\n<p>You have to keep a few special rules in mind. The binary numbers start with the prefix <span style=\"font-family: courier new,courier;\">0b<\/span>. The built-in literals have no underscore. That is different from the user-defined literals. C++ support with C++14 the first time a C++ string literal. So far, C++ supports only C-string literals. That means, for example, that you always have to use a C string literal to initialize a C++ string. That was very strange. The time literals are very convenient because they implicitly know their unit. They are of the type <a href=\"http:\/\/en.cppreference.com\/w\/cpp\/chrono\/duration\"><span style=\"font-family: courier new,courier;\">std::chrono::duration.<\/span><\/a><\/p>\n<p>The base unit for time is the second. My 16-year-old son often complains that his school day is exhausting. Of course, the question arises. How many seconds does my son need for a typical school day? The program answers.<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<p>&nbsp;<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<table>\n<tbody>\n<tr>\n<td>\n<pre style=\"margin: 0; line-height: 125%;\"> 1\r\n 2\r\n 3\r\n 4\r\n 5\r\n 6\r\n 7\r\n 8\r\n 9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19\r\n20\r\n21\r\n22\r\n23\r\n24\r\n25\r\n26\r\n27\r\n28\r\n29\r\n30<\/pre>\n<\/td>\n<td>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008000;\">\/\/ literals.cpp<\/span>\r\n\r\n<span style=\"color: #0000ff;\">#include &lt;iostream&gt;<\/span>\r\n<span style=\"color: #0000ff;\">#include &lt;chrono&gt;<\/span>\r\n\r\n<span style=\"color: #0000ff;\">using<\/span> <span style=\"color: #0000ff;\">namespace<\/span> std::literals::chrono_literals;\r\n\r\n<span style=\"color: #2b91af;\">int<\/span> main(){\r\n\r\n  std::cout &lt;&lt; std::endl;\r\n\r\n  <span style=\"color: #0000ff;\">auto<\/span> schoolHour= 45min;\r\n\r\n  <span style=\"color: #0000ff;\">auto<\/span> shortBreak= 300s;\r\n  <span style=\"color: #0000ff;\">auto<\/span> longBreak= 0.25h;\r\n\r\n  <span style=\"color: #0000ff;\">auto<\/span> schoolWay= 15min;\r\n  <span style=\"color: #0000ff;\">auto<\/span> homework= 2h;\r\n\r\n  <span style=\"color: #0000ff;\">auto<\/span> schoolDayInSeconds= 2*schoolWay + 6 * schoolHour + 4 * shortBreak + longBreak + homework;\r\n  \r\n  std::cout &lt;&lt; <span style=\"color: #a31515;\">\"School day in seconds: \"<\/span> &lt;&lt; schoolDayInSeconds.count() &lt;&lt; std::endl;\r\n  \r\n  std::cout &lt;&lt; <span style=\"color: #a31515;\">\"School day in minutes: \"<\/span> &lt;&lt; schoolDayInSeconds.count() \/ 60 &lt;&lt; std::endl;\r\n  \r\n  std::cout &lt;&lt; <span style=\"color: #a31515;\">\"School day in hours: \"<\/span> &lt;&lt; schoolDayInSeconds.count() \/ 3600 &lt;&lt; std::endl;\r\n\r\n  std::cout &lt;&lt; std::endl;\r\n\r\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>&nbsp;<\/p>\n<p>I think the program is self-explanatory. The suffixes are expressive enough. Making the correct additions is the job of the compiler. The time literals support the base arithmetic addition, subtraction, multiplication, division, and modulo operation.<\/p>\n<p>I have no C++14-compliant compiler at my disposal. Not really an issue. The online compiler on <a href=\"http:\/\/en.cppreference.com\/w\/\">en.cppreference.com<\/a> gives me the answers<\/p>\n<p>My son needs 27300 seconds for all his task related to school. This is almost a typical working day in Germany of about 8 hours.<\/p>\n<p>&nbsp;<img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-5003\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/schoolDay.PNG\" alt=\"schoolDay\" width=\"800\" height=\"136\" \/><\/p>\n<h2>What&#8217;s next?<\/h2>\n<p>The classical enumerations <span style=\"font-family: courier new,courier;\">(enum)<\/span> in C++ have three big disadvantages.<\/p>\n<ol>\n<li>They convert implicitly to <span style=\"font-family: courier new,courier;\">int.<\/span><\/li>\n<li>They introduce their enumerators into the enclosing scope.<\/li>\n<li>The type of enumerators can not be defined.<\/li>\n<\/ol>\n<p>In particular, characteristics 1 and 2 are often a reason for bad surprises. The new strong-typed enumerations clear off these issues. Read about it in the <a href=\"https:\/\/www.modernescpp.com\/index.php\/strongly-typed-enums\">next post.<\/a><span id=\"transmark\"><\/span><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>C++11 has user-defined literals for characters, C strings, integers, and floating-point numbers. Integers and floating-point numbers are available in raw and cooked form. Thanks to C++14, we have built-in literals for binary numbers, C++ strings, complex numbers, and time units.<\/p>\n","protected":false},"author":21,"featured_media":5000,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[364],"tags":[428,517],"class_list":["post-5004","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-embedded","tag-constexpr","tag-user-defined-literals"],"_links":{"self":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/5004","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/comments?post=5004"}],"version-history":[{"count":1,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/5004\/revisions"}],"predecessor-version":[{"id":6932,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/5004\/revisions\/6932"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media\/5000"}],"wp:attachment":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media?parent=5004"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/categories?post=5004"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/tags?post=5004"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}