{"id":30051,"date":"2022-02-01T15:45:22","date_gmt":"2022-02-01T15:45:22","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/cppblog\/?p=30051"},"modified":"2022-02-01T15:45:22","modified_gmt":"2022-02-01T15:45:22","slug":"gsl-4-0-0-is-available-now","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/cppblog\/gsl-4-0-0-is-available-now\/","title":{"rendered":"GSL 4.0.0 is Available Now"},"content":{"rendered":"<p>Version 4.0.0 of Microsoft\u2019s implementation of the <a href=\"https:\/\/github.com\/microsoft\/GSL\">C++ Core Guidelines Support Library<\/a> (GSL) is now available for you to download on the <a href=\"https:\/\/github.com\/microsoft\/gsl\/releases\">releases page<\/a>. This release maintains the safety guarantees that we have always offered and adds improvements to various parts of the library.<\/p>\n<h2>What changed in this release?<\/h2>\n<ul>\n<li><a href=\"#deprecation-of-gslstring_span\">Deprecation of <code>gsl::string_span<\/code><\/a><\/li>\n<li><a href=\"#removal-of-gsl-multi_span\">Removal of <code>&lt;gsl\/multi_span&gt;<\/code><\/a><\/li>\n<li><a href=\"#header-files-dropped-the-gsl_-prefix\">Header files dropped the <code>gsl_<\/code> prefix<\/a><\/li>\n<li><a href=\"#changes-to-not_null\">Changes to <code>not_null<\/code><\/a><\/li>\n<li><a href=\"#gslspan-and-stdspan-now-use-the-correct-specialization-of-gslat\"><code>gsl::span<\/code> and <code>std::span<\/code> now use the correct specialization of <code>gsl::at<\/code><\/a><\/li>\n<li>The <code>zstring<\/code> family no longer requires empty brackets to be used: <a href=\"https:\/\/github.com\/microsoft\/GSL\/issues\/992\">issue#992<\/a>\n<ul>\n<li>for example, <code>void foo(zstring&lt;&gt; str);<\/code> should now be <code>void foo(zstring str);<\/code><\/li>\n<\/ul>\n<\/li>\n<li><code>gsl::narrowing_error<\/code> now has a helpful <code>what()<\/code> message<\/li>\n<li><code>finally<\/code> and <code>final_action<\/code> are now <code>[[nodiscard]]<\/code><\/li>\n<li><a href=\"#gsl-will-work-in-environments-where-exceptions-are-disabled-with-some-caveats\">GSL will work in environments where exceptions are disabled, with some caveats<\/a><\/li>\n<li>GSL will work in environments which do not support iostreams, via the addition of the <code>GSL_NO_IOSTREAMS<\/code> flag: <a href=\"https:\/\/github.com\/microsoft\/GSL\/pull\/935\">#953<\/a><\/li>\n<li><a href=\"#C-compilers\">Updated compiler support<\/a><\/li>\n<li><a href=\"#cmake-and-build-improvements\">CMake and build improvements<\/a><\/li>\n<\/ul>\n<h2>Deprecation of <code>gsl::string_span<\/code><\/h2>\n<p><a href=\"https:\/\/github.com\/isocpp\/CppCoreGuidelines\/pull\/1680\">isocpp\/CppCoreGuidelines#1680<\/a> removed <code>string_span<\/code> from the C++ Core Guidelines. The recommendation is to use <code>std::string_view<\/code>, <code>std::span&lt;char&gt;<\/code> or <code>gsl::span&lt;char&gt;<\/code> instead. To more closely align Microsoft\u2019s GSL with the C++ Core Guidelines, we deprecated our implementation of <code>string_span<\/code> and <code>zstring_span<\/code>, including <code>basic_string_span<\/code>, <code>basic_zstring_span<\/code>, and all related types. For the time being, we will continue to provide the <code>&lt;gsl\/string_span&gt;<\/code> header, but it will not be actively worked on or maintained. A table of all supported and unsupported types\/features can be found in the <a href=\"https:\/\/github.com\/microsoft\/GSL\/blob\/main\/README.md\">README.md<\/a>.<\/p>\n<h2>Removal of <code>&lt;gsl\/multi_span&gt;<\/code><\/h2>\n<p><code>multi_span<\/code>, <code>strided_span<\/code>, and everything else in <code>&lt;gsl\/multi_span&gt;<\/code> were deprecated over a year ago in <a href=\"https:\/\/github.com\/microsoft\/GSL\/releases\/tag\/v3.0.0\">GSL 3.0.0<\/a>, and it is time for them and their associated tests to be removed from the library.<\/p>\n<h2>Header files dropped the <code>gsl_<\/code> prefix<\/h2>\n<p>All headers which previously contained a <code>gsl_<\/code> prefix in their name have had this prefix removed. For example, <code>&lt;gsl\/gsl_algorithm&gt;<\/code> is now <code>&lt;gsl\/algorithm&gt;<\/code>. The <code>gsl_<\/code> prefixed files still exist and pass through to the updated files, but will be removed in a future release.<\/p>\n<h2>Changes to <code>not_null<\/code><\/h2>\n<p>To more closely align Microsoft\u2019s GSL with the C++ Core Guidelines, <code>gsl::not_null<\/code> now accepts only types which are <em>comparable<\/em> to <code>nullptr<\/code>. Previously, it accepted only types which are <em>assignable<\/em> from <code>nullptr<\/code>, but this was stricter than what was intended by the <a href=\"http:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#gslview-views\">Core Guidelines<\/a>.<\/p>\n<p>The functions <code>make_not_null<\/code> and <code>make_strict_not_null<\/code>, and the <code>not_null<\/code> comparison operators, are now all <code>noexcept<\/code>.<\/p>\n<h2><code>gsl::span<\/code> and <code>std::span<\/code> now use the correct specialization of <code>gsl::at<\/code><\/h2>\n<p><code>gsl::span<\/code> and <code>std::span<\/code> now have their own separate specializations of <code>gsl::at<\/code>, to ensure consistent behavior between the two versions of span. Both overloads are included when importing <code>&lt;gsl\/span&gt;<\/code>. The <code>std::span<\/code> overload can be separately included from <code>&lt;gsl\/util&gt;<\/code>.<\/p>\n<h2>GSL will work in environments where exceptions are disabled, with some caveats<\/h2>\n<p><code>gsl::narrow<\/code> is the only part of the library which may throw exceptions and has been moved into its own header <code>&lt;gsl\/narrow&gt;<\/code>. This header is included in <code>&lt;gsl\/gsl&gt;<\/code> only if exceptions are enabled. This allows users of the library who are working in environments without exceptions to use all of the other components of the library.<\/p>\n<p>Note: <code>gsl::narrow_cast<\/code> is still in <code>&lt;gsl\/util&gt;<\/code>, since it does not throw exceptions.<\/p>\n<h2>Updated compiler support<\/h2>\n<p>The list of supported compilers\/toolsets has been updated with newer versions. More info on compiler support can be found in the <a href=\"https:\/\/github.com\/microsoft\/GSL\/blob\/main\/README.md#supported-compilers--toolsets\">README.md<\/a>.<\/p>\n<table>\n<thead>\n<tr>\n<th>Compiler\/Toolset<\/th>\n<th>Version<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>XCode<\/td>\n<td>13.2.1 &amp; 12.5.1<\/td>\n<\/tr>\n<tr>\n<td>GCC<\/td>\n<td>11.1.0 &amp; 10.3.0<\/td>\n<\/tr>\n<tr>\n<td>Clang<\/td>\n<td>12.0.0 &amp; 11.0.0<\/td>\n<\/tr>\n<tr>\n<td>Visual Studio with MSVC<\/td>\n<td>VS2022 (17.0) &amp; VS2019 (16.11)<\/td>\n<\/tr>\n<tr>\n<td>Visual Studio with LLVM<\/td>\n<td>VS2022 (17.0) &amp; VS2019 (16.11)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>CMake and build improvements<\/h2>\n<ul>\n<li>GSL Install logic is now guarded by a cmake option <code>GSL_INSTALL<\/code>: <a href=\"https:\/\/github.com\/microsoft\/GSL\/pull\/964\">#964<\/a><\/li>\n<li>Fix bug which prevented the library from being built on a 32-bit host and then being used on a 64-bit machine: <a href=\"https:\/\/github.com\/microsoft\/GSL\/pull\/893\">#893<\/a><\/li>\n<li>Build will now use <code>CMAKE_CXX_STANDARD<\/code> if it&#8217;s provided <a href=\"https:\/\/github.com\/microsoft\/GSL\/pull\/953\">#953<\/a><\/li>\n<li>Clean up <code>GSL_SUPPRESS<\/code> warning for intel compilers: <a href=\"https:\/\/github.com\/microsoft\/GSL\/pull\/906\">#906<\/a><\/li>\n<li>Fix build failure for C++20 compilers which don&#8217;t have <code>std::span<\/code>: <a href=\"https:\/\/github.com\/microsoft\/GSL\/pull\/993\">#993<\/a><\/li>\n<li>Cleaned up some static analysis warnings<\/li>\n<li>The cmake cache variable <code>VS_ADD_NATIVE_VISUALIZERS<\/code> has been renamed to <code>GSL_VS_ADD_NATIVE_VISUALIZERS<\/code>: <a href=\"https:\/\/github.com\/microsoft\/GSL\/pull\/941\">#941<\/a><\/li>\n<\/ul>\n<h2>Summary<\/h2>\n<p>This has been a list of the changes in the GSL 4.0.0 release. You can download the code at the <a href=\"https:\/\/github.com\/microsoft\/GSL\">GSL GitHub page<\/a>. Please stay tuned for future releases!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>GSL 4.0.0 has been released! Here is a summary of the changes.<\/p>\n","protected":false},"author":82454,"featured_media":35994,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[270,1,512,277],"tags":[],"class_list":["post-30051","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-announcement","category-cplusplus","category-general-cpp-series","category-writing-code"],"acf":[],"blog_post_summary":"<p>GSL 4.0.0 has been released! Here is a summary of the changes.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/30051","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/users\/82454"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/comments?post=30051"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/posts\/30051\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media\/35994"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/media?parent=30051"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/categories?post=30051"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/cppblog\/wp-json\/wp\/v2\/tags?post=30051"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}