{"id":1760,"date":"2025-04-13T13:10:42","date_gmt":"2025-04-13T20:10:42","guid":{"rendered":"https:\/\/nanzhou.cc\/?p=1760"},"modified":"2025-04-13T13:10:42","modified_gmt":"2025-04-13T20:10:42","slug":"c-17-features","status":"publish","type":"post","link":"https:\/\/nanzhou.cc\/index.php\/2025\/04\/13\/c-17-features\/","title":{"rendered":"C++ 17 Features"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">std::string_view<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"cpp\" class=\"language-cpp\">\/\/ Regular strings.\nstd::string_view cppstr {\"foo\"};\n\/\/ Wide strings.\nstd::wstring_view wcstr_v {L\"baz\"};<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">std::optional<\/h2>\n\n\n\n<p>A common use case for optional is the return value of a function that may fail.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">std::optional&lt;std::string> create(bool b) {\n  if (b) {\n    return \"Godzilla\";\n  } else {\n    return {};\n  }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">std::filesystem<a href=\"https:\/\/github.com\/AnthonyCalandra\/modern-cpp-features\/blob\/master\/CPP17.md#stdfilesystem\"><\/a><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">const auto bigFilePath {\"bigFileToCopy\"};\nif (std::filesystem::exists(bigFilePath)) {\n  const auto bigFileSize {std::filesystem::file_size(bigFilePath)};\n  std::filesystem::path tmpPath {\"\/tmp\"};\n  if (std::filesystem::space(tmpPath).available > bigFileSize) {\n    std::filesystem::create_directory(tmpPath.append(\"example\"));\n    std::filesystem::copy_file(bigFilePath, tmpPath.append(\"newFile\"));\n  }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>std::string_view std::optional A common use case for optional is the return value of a function that may fail. std::filesystem<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"0","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,5],"tags":[],"class_list":["post-1760","post","type-post","status-publish","format-standard","hentry","category-c","category-proglang"],"_links":{"self":[{"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/posts\/1760","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/comments?post=1760"}],"version-history":[{"count":1,"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/posts\/1760\/revisions"}],"predecessor-version":[{"id":1761,"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/posts\/1760\/revisions\/1761"}],"wp:attachment":[{"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/media?parent=1760"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/categories?post=1760"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nanzhou.cc\/index.php\/wp-json\/wp\/v2\/tags?post=1760"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}