{"id":2888,"date":"2025-03-24T09:00:00","date_gmt":"2025-03-24T17:00:00","guid":{"rendered":"https:\/\/journal.copperspice.com\/?p=2888"},"modified":"2025-08-24T19:08:12","modified_gmt":"2025-08-25T03:08:12","slug":"2888","status":"publish","type":"post","link":"https:\/\/journal.copperspice.com\/?p=2888","title":{"rendered":"Moving to C++20"},"content":{"rendered":"\n<p>As of the CopperSpice 2.0 release our libraries require a compiler which supports the C++20 standard. We have made this transition to use new functionality available in the core C++ language. This change requires a modification to the build files for projects which link with CopperSpice.<br><br>For convenience, we have modified the zip file for examples 1 through 47. Line 35 of the CMakeLists.txt file was changed as shown below.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; first-line: 35; title: ; notranslate\" title=\"\">\nset(CMAKE_CXX_STANDARD 20)\n<\/pre><\/div>\n\n\n<h3>New in C++20<\/h3>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container\">\n<p>Transitioning to C++20 allowed the project to use concepts, enable new functionality in std::chrono, improve CopperSpice unit tests, report additional type conversion warnings, and a slew of other things.<br><br>There were two changes in CopperSpice which had the most effect and improved the code base. These are described below.<br><br>** <strong>Spaceship<\/strong><br><br>Three-way comparison operator is also known as the &#8220;spaceship operator&#8221; because of the shape of the operator, which is <code><strong>&lt;=&gt;<\/strong><\/code>. This operator is used to compare two values and determine their equality or if one is less than or greater than the other value. <br><br>This new operator simplifies implementing comparison operations and usually results in more efficient code.<br><br>** <strong>char8_t<\/strong> <br><br>A string literal is a sequence of characters enclosed in double quotes. For example, &#8220;Hello CopperSpice&#8221;. String literals are commonly used to initialize the value of an std::string or a QString.<br><br>C++11 added a UTF-16 string literal which has the data type of <strong>char16_t<\/strong> and UTF-32 string literals with a data type of <strong>char32_t<\/strong>. The standard committee forgot to add a new data type for UTF-8 string literals. This was corrected in C++20. <br><br>Prior to C++20 the data type of a UTF-8 string literal was <strong>char<\/strong>. With the release of C++20 a UTF-8 string literal finally has a unique data type of <strong>char8_t<\/strong>.<\/p>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>As of the CopperSpice 2.0 release our libraries require a compiler which supports the C++20 standard. We have made this transition to use new functionality available in the core C++ language. This change requires a modification to the build files for projects which link with CopperSpice.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/journal.copperspice.com\/index.php?rest_route=\/wp\/v2\/posts\/2888"}],"collection":[{"href":"https:\/\/journal.copperspice.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/journal.copperspice.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/journal.copperspice.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/journal.copperspice.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2888"}],"version-history":[{"count":55,"href":"https:\/\/journal.copperspice.com\/index.php?rest_route=\/wp\/v2\/posts\/2888\/revisions"}],"predecessor-version":[{"id":3114,"href":"https:\/\/journal.copperspice.com\/index.php?rest_route=\/wp\/v2\/posts\/2888\/revisions\/3114"}],"wp:attachment":[{"href":"https:\/\/journal.copperspice.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2888"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/journal.copperspice.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2888"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/journal.copperspice.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2888"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}