{"id":4999,"date":"2016-10-28T15:26:25","date_gmt":"2016-10-28T15:26:25","guid":{"rendered":"https:\/\/www.modernescpp.com\/index.php\/user-defined-literals\/"},"modified":"2023-06-26T12:38:20","modified_gmt":"2023-06-26T12:38:20","slug":"user-defined-literals","status":"publish","type":"post","link":"https:\/\/www.modernescpp.com\/index.php\/user-defined-literals\/","title":{"rendered":"User-Defined Literals"},"content":{"rendered":"<p>User-defined literals are a unique feature in all mainstream programming languages. They empower you to combine values with units.<\/p>\n<p><!--more--><\/p>\n<h2>The syntax<\/h2>\n<p>Literals are explicit values in a program. This can be a boolean like <span style=\"font-family: courier new,courier;\">true,<\/span> the number <span style=\"font-family: courier new,courier;\">3<\/span> or <span style=\"font-family: courier new,courier;\">4.15<\/span>; but this can also be the character &#8216;<span style=\"font-family: courier new,courier;\">a&#8217;<\/span> or the C string <span style=\"font-family: courier new,courier;\">&#8220;hallo&#8221;.<\/span> Even the lambda function <span style=\"font-family: courier new,courier;\">[](int a, int b){ return a+b; }<\/span> is a function literal. With C++11, it&#8217;s possible to generate user-defined literals by adding a suffix to a built-in literal for integers, floating points, characters, and C strings.<\/p>\n<p>User-defined literals must obey the following syntax:<span style=\"font-family: courier new,courier;\"> built-in literal + _ + suffix.<\/span><\/p>\n<p>Usually, you use the suffix for a unit:<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\">101000101_b\r\n63_s\r\n10345.5_dm\r\n123.45_km\r\n100_m\r\n131094_cm\r\n33_cent\r\n<span style=\"color: #a31515;\">\"Hallo\"<\/span>_i18n\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>But what is the critical benefit of user-defined literals? The C++ compiler maps the user-defined literals to the corresponding literal operator. This literal operator has &#8211; of course &#8211; to be implemented by the programmer.<\/p>\n<\/p>\n<h3>The magic<\/h3>\n<p>Let&#8217;s look at the user-defined literal <span style=\"font-family: courier new,courier; color: #000080;\"><span style=\"color: #339966;\">0101001000<\/span><\/span><span style=\"color: #ff0000;\"><span style=\"font-family: courier new,courier;\">_b<\/span><\/span> that represents a binary value. The compiler maps the user-defined literal&nbsp;<span style=\"font-family: courier new,courier; color: #000080;\"><span style=\"color: #339966;\">0101001000<\/span><\/span><span style=\"color: #ff0000;\"><span style=\"font-family: courier new,courier;\">_b<\/span> <span style=\"color: #000000;\">to the literal operator <span style=\"font-family: courier new,courier;\">operator&#8221;&#8221; <span style=\"color: #ff0000;\">_b<\/span>(long long int <span style=\"color: #339966;\">bin<\/span>)<\/span>. A few special rules are still missing. <\/span> <\/span><\/p>\n<ul>\n<li><span style=\"color: #ff0000;\"><span style=\"color: #000000;\">There has to be a space between the quotation marks&nbsp; (&#8220;&#8221;) and the underscore with the suffix (<span style=\"color: #ff0000;\">_b<\/span>). <\/span> <\/span><\/li>\n<li><span style=\"color: #ff0000;\"><span style=\"color: #000000;\">You have the binary value (<span style=\"font-family: courier new,courier; color: #000080;\"><span style=\"color: #339966;\">0101001000<\/span><\/span>) in the variable <span style=\"color: #ff0000;\"><span style=\"color: #000000;\"><span style=\"font-family: courier new,courier;\"><span style=\"color: #339966;\">bin.<\/span><\/span> <\/span> <\/span> <\/span> <\/span><\/li>\n<li>The compilation will fail if the compiler doesn&#8217;t find the corresponding literal operator.<\/li>\n<\/ul>\n<p>We get with C++14 an alternative syntax for user-defined types. They differ from the C++11 syntax because it requires no space. Therefore, it is possible to use&nbsp;<a href=\"http:\/\/en.cppreference.com\/w\/cpp\/language\/identifiers\">reserved keywords<\/a> like <span style=\"font-family: courier new,courier;\">_C<\/span> as a suffix and a user-defined literal of the form <span style=\"font-family: courier new,courier;\">11_C<\/span>. The compiler will map <span style=\"font-family: courier new,courier;\">11_C <\/span>to the literal <span style=\"font-family: courier new,courier;\">operator&#8221;&#8221;<span style=\"color: #ff0000;\">_C<\/span>(unsigned long long<span style=\"color: #339966;\"> int)<\/span><\/span>.&nbsp; The simple rule is now that you can use suffixes starting with an upper letter.<\/p>\n<p>User-defined literals are the killer feature in modern C++ if you want to write safety-critical software. Why? Thanks to automatically mapping the user-defined literal to the literal operator, you can implement type-safe arithmetic. The compiler takes care that you don&#8217;t add apples and pears. Example?<\/p>\n<p>How many meters do I drive on average per week? The question has occupied me for a long time.<\/p>\n<h2>Typesafe calculation with distances<\/h2>\n<p>Before I deal with the details, here is the main program.<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\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_km \/ 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>The literal operators are implemented in the namespace <span style=\"font-family: courier new,courier;\">Distance::unit<\/span>. You should use namespaces for user-defined literals because name collisions are, for two reasons, very likely. First, the suffixes are usually very short; second, the suffixes&nbsp;usually stand for units that already established abbreviations. I used the suffixes km, m, dm, a, and cm in the program<span style=\"font-family: courier new,courier;\">.<\/span><\/p>\n<p>Here is the output of the program. My unit for distances is a meter.<\/p>\n<p><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>I display in lines 12 &#8211; 15 the various distances; I calculate in lines 19 &#8211; 22 the meter in various resolutions. The last test looks quite promising.<br \/><span style=\"font-family: courier new,courier;\">1.0_km + 2.0_dm +&nbsp; 3.0_dm + 4.0_cm<\/span>&nbsp; is <span style=\"font-family: courier new,courier;\">1000.54 m<\/span> (line 54). The compiler takes care of the calculations with all units.<\/p>\n<p>The key question remains. How many meters will I drive on average a week? For convenience, I define a few constants: <span style=\"font-family: courier new,courier;\">work, workPerDay, abbrevationToWork, <\/span>and <span style=\"font-family: courier new,courier;\">shopping.<\/span>&nbsp;These are my building blocks for the four weeks (lines 34 &#8211; 37). I went 493 km in the first week by car. The function <span style=\"font-family: courier new, courier;\">getAverageDisttance<\/span> (line 41) helps me to get the average. I have to invoke it with an initializer list. I drive 255900m on average per week. That needs to change! And that has changed. I&#8217;m now an independent trainer.<\/p>\n<h3>Under the hood<\/h3>\n<p>I ignored one fact. Where are the <span style=\"font-family: courier new,courier;\">MyDistance<\/span> objects defined? They are hidden in the program behind the automatic type deduction. Therefore, the explicit type for the variable work (line 28) is <span style=\"font-family: courier new,courier;\">Distance::Distance<\/span>. Line 28 is equivalent to <span style=\"font-family: courier new,courier;\">Distance::MyDistance work= 63.0_km;<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-4998\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/arithmetik.png\" alt=\"arithmetik\" width=\"800\" height=\"486\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/arithmetik.png 928w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/arithmetik-300x182.png 300w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/arithmetik-768x467.png 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>The following steps will automatically happen if I use 1.5_km + 105.1_m in the source code. The compiler maps at first the suffixes<span style=\"font-family: courier new, courier;\"> km<\/span> and <span style=\"font-family: courier new, courier;\">m<\/span> to the corresponding literal operators; second, the compiler maps the + operator to the overloaded + operator of the<span style=\"font-family: courier new, courier;\"> MyDistance<\/span> objects. Both steps can only work if the programmer implements the right operators in his contract. In this concrete case, he has to implement the literal operator and + operator. The black arrows in the graphic stand for the automatically performed mapping of the compiler. The red arrows stand for the functionality that the programmer has to implement.<\/p>\n<p>What&#8217;s still missing to make the graphic complete? Right! The meat behind the red arrows.<\/p>\n<h3>Tasks of the programmer<\/h3>\n<p>At first, to the known overloading of operators. I overloaded for the class <span style=\"font-family: courier new,courier;\">MyDistance<\/span> basic arithmetic (lines 15 &#8211; 28) and the output operator (lines 30 &#8211; 33). The operators are global functions and can use &#8211; thanks to their friendship &#8211; the internals of the class. I store in the private variable <span style=\"font-family: courier new,courier;\">m<\/span> the distance. The function <span style=\"font-family: courier new,courier;\">getAverageDistance<\/span> (lines 41 &#8211; 45) is applying the overloaded addition and division operator.<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\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 <br \/>      <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        <span style=\"color: #0000ff;\">return<\/span> MyDistance(m*a.m);\r\n      }\r\n\t  \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: #2b91af;\">int<\/span> n){\r\n        <span style=\"color: #0000ff;\">return<\/span> MyDistance(a.m\/n);\r\n      }\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>Shorter but more thrilling are the literal operators.<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\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: #2b91af;\">long<\/span> <span style=\"color: #2b91af;\">double<\/span> d){\r\n      <span style=\"color: #0000ff;\">return<\/span> MyDistance(1000*d);\r\n    }\r\n    MyDistance <span style=\"color: #0000ff;\">operator<\/span> <span style=\"color: #a31515;\">\"\"<\/span> _m(<span style=\"color: #2b91af;\">long<\/span> <span style=\"color: #2b91af;\">double<\/span> m){\r\n      <span style=\"color: #0000ff;\">return<\/span> MyDistance(m);\r\n    }\r\n    MyDistance <span style=\"color: #0000ff;\">operator<\/span> <span style=\"color: #a31515;\">\"\"<\/span> _dm(<span style=\"color: #2b91af;\">long<\/span> <span style=\"color: #2b91af;\">double<\/span> d){\r\n      <span style=\"color: #0000ff;\">return<\/span> MyDistance(d\/10);\r\n    }\r\n    MyDistance <span style=\"color: #0000ff;\">operator<\/span> <span style=\"color: #a31515;\">\"\"<\/span> _cm(<span style=\"color: #2b91af;\">long<\/span> <span style=\"color: #2b91af;\">double<\/span> c){\r\n      <span style=\"color: #0000ff;\">return<\/span> MyDistance(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>The literal operators take as an argument a long double and return a <span style=\"font-family: courier new, courier;\">MyDistance<\/span> object.&nbsp;<span style=\"font-family: courier new, courier;\">MyDistance<\/span> is automatically normalized to meters. And now? That was the whole functionality that the programmer has to provide.<\/p>\n<p>I ignored one big optimization potential in my program. Almost all operations can be performed at compile time; almost all objects can be instantiated at compile time. To make that happen, I must declare the operations and objects as <span style=\"font-family: courier new,courier;\">constexpr<\/span>. <\/p>\n<h2>What&#8217;s next?<\/h2>\n<p>You can define user-defined literals not only for floating-point numbers. You can do it for integers, characters, and C strings. In addition, C++ has two ways to do integers and floating-point numbers. One is called cooked, the other raw. I have a lot more to write about user-defined literals. Wait for the <a href=\"https:\/\/www.modernescpp.com\/index.php\/raw-and-cooked\">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>User-defined literals are a unique feature in all mainstream programming languages. They empower you to combine values with units.<\/p>\n","protected":false},"author":21,"featured_media":4997,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[364],"tags":[517],"class_list":["post-4999","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-embedded","tag-user-defined-literals"],"_links":{"self":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/4999","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=4999"}],"version-history":[{"count":1,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/4999\/revisions"}],"predecessor-version":[{"id":6933,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/4999\/revisions\/6933"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media\/4997"}],"wp:attachment":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media?parent=4999"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/categories?post=4999"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/tags?post=4999"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}