laitimes

Writing Modern C++ Code: GSL 4.0.0 is generally available

author:A long road to development

Happy New Year!

To understand what GSL is, you need to first understand what the C++ Core Guidelines are.

The C++ Core Guidelines are a simple documentation that describes a set of guidelines designed to write modern C++ code. Initiated and led by Bjarne Stroustrup, the original author of C++, the project focuses on various top-level design issues that arise in some C++ projects, such as interface design, resource management, memory management, and concurrency. These top-level designs affect the design of the application architecture and libraries. Following this set of guidelines allows you to implement statically type-safe code, avoid potential resource leaks, and discover more code logic errors while running faster.

The GSL (Guidelines Support Library) is an implementation code base developed by Microsoft and the C++ Core Guidelines guidelines, which contains the various functions, types, etc. suggested in the C++ Core Guidelines. The entire code base is implemented in various header files, and to use this code base, a compiler that supports C++14 is required.

Okay, the main text begins

Version 4.0.0 of GSL is already generally available, and this one includes all the secure encoding rules, plus we've added some additional optimizations.

What has changed?

> Abandoned gsl::string_span

> Remove <gsl/multi_span>

> header file removes the gsl_ prefix

> Modifications have been made to the not_null

> gsl::span and std::span are now using the correct specialized versions of gsl::at

> zstring series no longer requires empty angle brackets, for example we can use void foo(zstring str) instead: void foo(zstring<> str)

> gsl::narrowing_error added a new function what() to display the details of the error

> finally and final_action are now labeled [[[nodiscard]]

> GSL will be able to work in environments where exceptions are disabled, but there are some caveats

> By adding the GSL_NO_IOSTREAMS flag, GSL will work in environments that do not support iostream

compiler support has been updated >

> CMake and build optimizations

Abandoned gsl::string_span

The latest version of CppCoreGuidelines removes string_span. It is recommended to use std::string_view, std::span or gsl::span instead. To align GSL more closely with CppCoreGuidelines, we deprecate implementations of string_span and zstring_span, including basic_string_span, basic_zstring_span, and all related types. For now, we will continue to keep the <gsl/string_span> header file, but will not actively process or maintain it. A list of all supported and unsupported types/features can be found in README.md.

Remove <gsl/multi_span>

multi_span, strided_span, and everything else in the <gsl/multi_span> was deprecated in GSL 3.0.0 a year ago, and it's time to remove them and their associated tests from the library.

The header file removes the gsl_ prefix

All headers that previously included gsl_ prefix in their names have this prefix removed. For example, <gsl/gsl_algorithm> is now < gsl/algorithm >. gsl_ prefix file still exists and is passed to the updated file, but will be removed in a future release.

Modifications were made to the not_null

To align GSL more closely with CppCoreGuidelines, gsl:::not_null now only accept types equivalent to nullptr. Previously, it only accepted types that could be assigned from nulptr, but this was stricter than CppCoreGuidelines' intent.

Functions make_not_null and make_strict_not_null, as well as not_null comparison operators, are now noexcept.

gsl::span and std::span are now using the correct specialized versions of gsl::at

GSL::span and std::span now have their own separate GSL::at specialization to ensure consistent behavior between the two versions of span. Importing <gsl/span > introduces two overloaded versions. Std::span overloads can be included separately from <gsl/util>.

GSL will be able to work in environments where exceptions are disabled, but there are some caveats

gsl::narrow is the only part of the library that can throw an exception and has been moved to its own header file <gsl/narrow>. This header file is included in the <gsl/gsl> only when exceptions are enabled. This allows library users working in the environment to use all other components of the library without exception.

Note: gsl::narrow_cast is still in <gsl/util > because it does not throw exceptions.

Updated compiler support

The list of supported compilers/toolsets has been updated to an updated version, as shown in the following figure:

Writing Modern C++ Code: GSL 4.0.0 is generally available

CMake and build optimizations

> GSL installation logic is now protected by the CMake option GSL_INSTALL

> Fixed an issue where the GSL library was built on a 32-bit host and then used on a 64-bit machine

> If a CMAKE_CXX_STANDARD is defined, the build uses it

> Clean up the Intel Compiler's GSL SUPPRESS warnings

> Fixed a build failure for the C++20 compiler without std::span

> cleaned up some static analysis warnings

> CMake cache variable VS_ADD_NATIVE_VISUALIZERS renamed to GSL_VS_ADD_NATIVE_VISUALIZERS

summary

Bjarne Stroustrup created the Dragon Slayer C++, but children like me were prone to misuse and hurt people, and thoughtfully created the Swiss Army Knife C++ Core Guidelines.

At last

The Microsoft Visual C++ team's blog is one of my favorite blogs, with a lot of knowledge and the latest developments in Visual C++. If you're still so interested in visual C++, an ancient technology, you can visit them (or me) often.

This article is from: GSL 4.0.0 is Available Now

Writing Modern C++ Code: GSL 4.0.0 is generally available