/README.md

https://github.com/martinmoene/gsl-lite · Markdown · 1183 lines · 945 code · 238 blank · 0 comment · 0 complexity · ef3cf7eab8ffd6389a24b00f72e5f084 MD5 · raw file

  1. # *gsl-lite*: Guidelines Support Library for C++98, C++11 up
  2. | metadata | build | packages | try online |
  3. | -------- | ------ | -------- | ---------- |
  4. | [![Language](https://img.shields.io/badge/C%2B%2B-98/11/14/17-blue.svg)](https://en.wikipedia.org/wiki/C%2B%2B#Standardization) <br> [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT) <br> [![Version](https://badge.fury.io/gh/gsl-lite%2Fgsl-lite.svg)](https://github.com/gsl-lite/gsl-lite/releases) | [![Azure Pipelines build status](https://dev.azure.com/gsl-lite/gsl-lite/_apis/build/status/gsl-lite.gsl-lite?branchName=master)](https://dev.azure.com/gsl-lite/gsl-lite/_build/latest?definitionId=1&branchName=master) <br> [![Travis build status](https://travis-ci.com/gsl-lite/gsl-lite.svg?branch=master)](https://travis-ci.com/gsl-lite/gsl-lite) <br> [![AppVeyor build status](https://ci.appveyor.com/api/projects/status/1v6eqy68m8g7tm06?svg=true)](https://ci.appveyor.com/project/gsl-lite/gsl-lite) | [![Vcpkg](https://img.shields.io/badge/on-Vcpkg-blue.svg)](https://github.com/microsoft/vcpkg/tree/master/ports/gsl-lite) <br> [![Conan](https://img.shields.io/badge/on-conan-blue.svg)](https://bintray.com/conan/conan-center/gsl-lite%3A_/_latestVersion) <br> [![single header](https://img.shields.io/badge/latest-single%20header%20file-blue.svg)](https://raw.githubusercontent.com/gsl-lite/gsl-lite/master/include/gsl/gsl-lite.hpp) | [![Try it on Compiler Explorer](https://img.shields.io/badge/on-godbolt-blue.svg)](https://gcc.godbolt.org/z/JVtM2c) <br> [![Try it on Wandbox](https://img.shields.io/badge/on-wandbox-blue.svg)](https://wandbox.org/permlink/p9YnfiUTOYEQx0QL) |
  5. *gsl-lite* is an implementation of the [C++ Core Guidelines Support Library](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#S-gsl) originally based on [Microsoft GSL](https://github.com/microsoft/gsl).
  6. **Contents**
  7. - [Example usage](#example-usage)
  8. - [In a nutshell](#in-a-nutshell)
  9. - [License](#license)
  10. - [Dependencies](#dependencies)
  11. - [Installation and use](#installation-and-use)
  12. - [Version semantics](#version-semantics)
  13. - [Using *gsl-lite* in libraries](#using-gsl-lite-in-libraries)
  14. - [Configuration options](#configuration-options)
  15. - [Features](#features)
  16. - [Deprecation](#deprecation)
  17. - [Reported to work with](#reported-to-work-with)
  18. - [Building the tests](#building-the-tests)
  19. - [Other GSL implementations](#other-gsl-implementations)
  20. - [Notes and references](#notes-and-references)
  21. - [Appendix](#appendix)
  22. Example usage
  23. -------------
  24. ```Cpp
  25. #include <gsl/gsl-lite.hpp>
  26. int * use( gsl::not_null<int *> p )
  27. {
  28. // use p knowing it's not nullptr, NULL or 0.
  29. return p;
  30. }
  31. struct Widget
  32. {
  33. Widget() : owned_ptr_( new int(42) ) {}
  34. ~Widget() { delete owned_ptr_; }
  35. void work() { non_owned_ptr_ = use( owned_ptr_ ); }
  36. gsl::owner<int *> owned_ptr_; // if alias template support
  37. int * non_owned_ptr_;
  38. };
  39. int main()
  40. {
  41. Widget w;
  42. w.work();
  43. }
  44. ```
  45. ### Compile and run
  46. ```
  47. prompt> g++ -std=c++03 -Wall -I../include -o 01-basic.exe 01-basic.cpp && 01-basic.exe
  48. ```
  49. In a nutshell
  50. -------------
  51. **gsl-lite** is a single-file header-only implementation of the [C++ Core Guidelines Support Library](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#S-gsl) originally based on [Microsoft GSL](https://github.com/microsoft/gsl) and adapted for C++98, C++03. It also works when compiled as C++11, C++14, C++17, C++20.
  52. The Guidelines Support Library (GSL) contains functions and types that are suggested for use by the [C++ Core Guidelines](https://github.com/isocpp/CppCoreGuidelines) maintained by the [Standard C++ Foundation](https://isocpp.org/). The library includes types like `owner<>`, `not_null<>`, `span<>`, `string_span` and [others](#features).
  53. *gsl-lite* recognizes when it is compiled for the CUDA platform and decorates some functions with `__host__` and `__device__`. See also section [API macro](#api-macro).
  54. License
  55. -------
  56. *gsl-lite* uses the [MIT](LICENSE) license.
  57. Dependencies
  58. ------------
  59. *gsl-lite* has no other dependencies than the [C++ standard library](http://en.cppreference.com/w/cpp/header).
  60. Installation and use
  61. --------------------
  62. ### As CMake package
  63. The recommended way to consume *gsl-lite* in your CMake project is to use `find_package()` and `target_link_libraries()`:
  64. ```CMake
  65. cmake_minimum_required( VERSION 3.15 FATAL_ERROR )
  66. find_package( gsl-lite 0.37 REQUIRED )
  67. project( my-program LANGUAGES CXX )
  68. add_executable( my-program main.cpp )
  69. target_link_libraries( my-program PRIVATE gsl::gsl-lite )
  70. ```
  71. There are various ways to make the `gsl-lite` package available to your project:
  72. <details>
  73. <summary>Using Vcpkg</summary>
  74. <p>
  75. 1. For the [Vcpkg package manager](https://github.com/microsoft/vcpkg/), simply run Vcpkg's install command:
  76. vcpkg install gsl-lite
  77. 2. Now, configure your project passing the Vcpkg toolchain file as a parameter:
  78. cd <my-program-source-dir>
  79. mkdir build
  80. cd build
  81. cmake -DCMAKE_TOOLCHAIN_FILE=<vcpkg-root>/scripts/buildsystems/vcpkg.cmake ..
  82. cmake --build ../build
  83. </p></details>
  84. <details>
  85. <summary>Using an exported build directory</summary>
  86. <p>
  87. 1. Clone the *gsl-lite* repository and configure a build directory with CMake:
  88. git clone git@github.com:gsl-lite/gsl-lite.git <gsl-lite-source-dir>
  89. cd <gsl-lite-source-dir>
  90. mkdir build
  91. cd build
  92. cmake ..
  93. 2. Now, configure your project passing the CMake build directory as a parameter:
  94. cd <my-program-source-dir>
  95. mkdir build
  96. cd build
  97. cmake -Dgsl-lite_DIR:PATH=<gsl-lite-source-dir>/build ..
  98. cmake --build ../build
  99. See [example/cmake-pkg/Readme.md](example/cmake-pkg/Readme.md) for a complete example.
  100. </p></details>
  101. <details>
  102. <summary>Using Conan</summary>
  103. <p>
  104. For the [Conan package manager](https://www.conan.io/), follow these steps:
  105. 1. Add Conan Center to the conan remotes:
  106. conan remote add center https://api.bintray.com/conan/conan/conan-center
  107. 2. Add a reference to *gsl-lite* to the *requires* section of your project's `conanfile.txt` file:
  108. [requires]
  109. gsl-lite/0.37@center/stable
  110. 3. Run conan's install command:
  111. conan install gsl-lite
  112. Now *gsl-lite* can be consumed as a Conan package. (TODO: elaborate!)
  113. </p></details>
  114. <details>
  115. <summary>Using Conda</summary>
  116. <p>
  117. 1. For the [conda package manager](https://conda.io), first use **one of these options** to install `gsl-lite` from the [`conda-forge`](https://conda-forge.org/) channel:
  118. * Install it in the current environment:
  119. conda install -c conda-forge gsl-lite
  120. * Install it in a different environment (named `env_name` in this example):
  121. conda install -n env_name -c conda-forge gsl-lite
  122. * Create a new environment containing *gsl-lite* (and possibly other packages, appended at the end of the command):
  123. conda create -n env_name -c conda-forge gsl-lite cmake
  124. * Add it to an already existing [`environment.yml`](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-from-an-environment-yml-file) file, and update the environment using:
  125. conda env update
  126. 2. Then activate the environment using `conda activate env_name` (if not already activated) and proceed using the instructions from step 2 of ["As CMake package"](#as-cmake-package). Note that it's also useful to have the `cmake` package in the same environment, and explicitly passing `-DCMAKE_INSTALL_PREFIX` is not necessary.
  127. </p></details>
  128. ### Other options
  129. <details>
  130. <summary>As external Git project</summary>
  131. <p>
  132. TODO: this section needs updating
  133. Another approach is to automatically fetch the entire *gsl-lite* repository from GitHub and configure it as an external project.
  134. ```CMake
  135. cmake_minimum_required( VERSION 3.15 FATAL_ERROR )
  136. project( use-gsl-lite LANGUAGES CXX )
  137. # Set default ExternalProject root directory and add gsl-lite:
  138. set( GSL_LITE_URL https://github.com/gsl-lite/gsl-lite.git )
  139. include( ExternalProject )
  140. find_package( Git REQUIRED )
  141. set_directory_properties( PROPERTIES EP_PREFIX ${CMAKE_BINARY_DIR}/3rd_party )
  142. ExternalProject_Add(
  143. gsl-extern
  144. GIT_REPOSITORY ${GSL_LITE_URL}
  145. TIMEOUT 10
  146. UPDATE_COMMAND ${GIT_EXECUTABLE} pull
  147. CONFIGURE_COMMAND ""
  148. BUILD_COMMAND ""
  149. INSTALL_COMMAND ""
  150. LOG_DOWNLOAD ON
  151. )
  152. # Provide #include access to gsl-lite as <gsl/gsl-lite.hpp>:
  153. ExternalProject_Get_Property( gsl-extern SOURCE_DIR )
  154. set( GSL_LITE_INCLUDE_DIR ${SOURCE_DIR}/include CACHE INTERNAL "Include folder for gsl-lite" )
  155. add_library( gsl INTERFACE )
  156. target_include_directories( gsl INTERFACE ${GSL_LITE_INCLUDE_DIR} )
  157. # Build program from src:
  158. add_subdirectory( src )
  159. ```
  160. In folder src:
  161. ```CMake
  162. cmake_minimum_required( VERSION 3.15 FATAL_ERROR )
  163. project( program-using-gsl-lite LANGUAGES CXX )
  164. # Make program executable:
  165. add_executable( program main.cpp )
  166. target_link_libraries( program PRIVATE gsl::gsl-lite )
  167. ```
  168. This setup brings in more than you need, but also makes it easy to update *gsl-lite* to the latest version. See [example/cmake-extern](example/cmake-extern) for a complete example.
  169. </p></details>
  170. <details>
  171. <summary>As copied header</summary>
  172. <p>
  173. Put a copy of [`gsl-lite.hpp`](include/gsl/gsl-lite.hpp) located in folder [include/gsl](include/gsl) directly into the project source tree or somewhere reachable from your project, for example in *project-root*/include/gsl. A minimal CMake setup using this header might look as follows.
  174. In project root folder:
  175. ```CMake
  176. cmake_minimum_required( VERSION 3.15 FATAL_ERROR )
  177. project( use-gsl-lite LANGUAGES CXX )
  178. # Provide #include access to gsl-lite as 'gsl/gsl-lite.hpp':
  179. add_library( gsl-lite INTERFACE )
  180. target_include_directories( gsl-lite INTERFACE include ) # adapt as necessary
  181. # Build program from src:
  182. add_subdirectory( src )
  183. ```
  184. In folder src:
  185. ```CMake
  186. cmake_minimum_required( VERSION 3.15 FATAL_ERROR )
  187. project( program-using-gsl-lite LANGUAGES CXX )
  188. # Make program executable:
  189. add_executable( program main.cpp )
  190. target_link_libraries( program PRIVATE gsl-lite )
  191. ```
  192. </p></details>
  193. Version semantics
  194. -----------------
  195. *gsl-lite* strives to follow [Semantic Versioning](https://semver.org/) guidelines. Although we are still in the "initial development" stage (version 0\.*), we generally maintain
  196. [API](https://en.wikipedia.org/wiki/Application_programming_interface) and [ABI](https://en.wikipedia.org/wiki/Application_binary_interface) compatibility and avoid breaking changes in minor and patch releases.
  197. Development of *gsl-lite* happens in the `master` branch. Versioning semantics apply only to tagged releases: there is no stability guarantee between individual commits in the `master` branch, i.e. anything
  198. added since the last tagged release may be renamed, removed, have the semantics changed, etc. without further notice.
  199. A minor-version release will be compatible (in both ABI and API) with the previous minor-version release (with [rare exceptions](https://github.com/gsl-lite/gsl-lite/issues/156) while we're still in version 0.\*).
  200. Thus, once a change is released, it becomes part of the API.
  201. Some of the [configuration options](#configuration-options) affect the API and ABI of *gsl-lite*. Most configuration options exist because a change we wanted to make would have broken backward compatibility,
  202. so many recent changes and improvements are currently opt-in. The current plan is to toggle the default values of these configuration options for the next major version release.
  203. To simplify migration to the next major version, *gsl-lite* 0.36 introduces the notion of *versioned defaults*. By setting the configuration option `gsl_CONFIG_DEFAULTS_VERSION=0` or `gsl_CONFIG_DEFAULTS_VERSION=1`,
  204. a set of version-specific default options can be selected. Alternatively, when consuming *gsl-lite* [as a CMake package](#as-cmake-package), versioned defaults can be selected by linking to the target
  205. `gsl::gsl-lite-v0` or `gsl::gsl-lite-v1` rather than `gsl::gsl-lite`.
  206. The following table gives an overview of the configuration options affected by versioned defaults:
  207. Macro | v0 default | v1 default | |
  208. ------------------------------------------------------------------------------------:|:---------------------------------------------------------|-------------------|-|
  209. [`gsl_FEATURE_OWNER_MACRO`](#gsl_feature_owner_macro1) | 1 | 0 | an unprefixed macro `Owner()` may interfere with user code |
  210. [`gsl_FEATURE_GSL_LITE_NAMESPACE`](#gsl_feature_gsl_lite_namespace0) | 0 | 1 | cf. [Using *gsl-lite* in libraries](#using-gsl-lite-in-libraries) |
  211. [`gsl_CONFIG_DEPRECATE_TO_LEVEL`](#gsl_config_deprecate_to_level0) | 0 | 6 | |
  212. [`gsl_CONFIG_INDEX_TYPE`](#gsl_config_index_typegsl_config_span_index_type) | `gsl_CONFIG_SPAN_INDEX_TYPE` (defaults to `std::size_t`) | `std::ptrdiff_t` | the GSL specifies `gsl::index` to be a signed type, and M-GSL also uses `std::ptrdiff_t` |
  213. [`gsl_CONFIG_ALLOWS_SPAN_COMPARISON`](#gsl_config_allows_span_comparison1) | 1 | 0 | C++20 `std::span<>` does not support comparison because semantics (deep vs. shallow) are unclear |
  214. [`gsl_CONFIG_NOT_NULL_EXPLICIT_CTOR`](#gsl_config_not_null_explicit_ctor0) | 0 | 1 | cf. reasoning in [M-GSL/#395](https://github.com/Microsoft/GSL/issues/395) (note that `not_null<>` in M-GSL has an implicit constructor, cf. [M-GSL/#699](https://github.com/Microsoft/GSL/issues/699)) |
  215. [`gsl_CONFIG_TRANSPARENT_NOT_NULL`](#gsl_config_transparent_not_null0) | 0 | 1 | enables conformant behavior for `not_null<>::get()` |
  216. [`gsl_CONFIG_NARROW_THROWS_ON_TRUNCATION`](#gsl_config_narrow_throws_on_truncation0) | 0 | 1 | enables conformant behavior for `narrow<>()` (cf. [#52](https://github.com/gsl-lite/gsl-lite/issues/52)) |
  217. Note that the v1 defaults are not yet stable; future 0.\* releases may introduce more configuration switches with different version-specific defaults.
  218. Using *gsl-lite* in libraries
  219. -----------------------------
  220. Many features of *gsl-lite* are very useful for defining library interfaces, e.g. spans, precondition checks, or `gsl::not_null<>`. As such, we encourage using *gsl-lite* in your libraries.
  221. However, please mind the following considerations:
  222. - *gsl-lite* is an implementation of the [Guidelines Support Library](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#S-gsl), which is not a library but a non-formal specification.
  223. There are other libraries implementing the GSL, most notably the [Microsoft GSL](https://github.com/microsoft/GSL/) (herein often referred to as "M-GSL"). Both libraries live in different headers and consist
  224. of unrelated implementations. There is considerable API compatibility between M-GSL and *gsl-lite*, but some differences are inevitable because the GSL specification is rather loose and informal, and because
  225. both implementations take some liberties at interpreting and extending the specification (cf. e.g. [#6](https://github.com/gsl-lite/gsl-lite/issues/6), [#52](https://github.com/gsl-lite/gsl-lite/issues/52),
  226. [#153](https://github.com/gsl-lite/gsl-lite/issues/153)). Also, the ABIs of *gsl-lite* and M-GSL are generally incompatible.
  227. - It is not clear whether the GSL specification envisions that multiple implementations of the specification should coexist (cf. [CppCoreGuidelines/#1519](https://github.com/isocpp/CppCoreGuidelines/issues/1519)),
  228. but because all existing implementations currently live in the same `namespace gsl`, using more than one GSL implementation in the same target will usually fail with compile/link errors. This is clearly
  229. an impediment for using either in a library because the library would thereby force its consumers to pick the same GSL implementation.
  230. - The API and ABI of *gsl-lite* can be altered by some of the [configuration options](#configuration-options). We consider the availability of these options a strength of *gsl-lite*, but the lack
  231. of an option-invariant API and ABI is another burden for libraries, which may or may not depend on a particular choice of configuration settings and implicitly force these upon their users.
  232. Our goal is to make *gsl-lite* suitable for use in libraries; we want to address all of these concerns in the next major version. But if you want to use *gsl-lite* in a library today, we recommend to
  233. - use version-1 defaults (cf. [Version semantics](#version-semantics))
  234. - include the new header \<gsl-lite/gsl-lite.hpp\> rather than \<gsl/gsl-lite.hpp\>
  235. - refer to the new `namespace gsl_lite` instead of `namespace gsl` (or define a `namespace gsl = ::gsl_lite;` alias in your own namespace)
  236. - use the prefixed contract checking macros `gsl_Expects()`/`gsl_Ensures()` rather than the unprefixed `Expects()`/`Ensures()`
  237. (M-GSL prefixes its macros with uppercase `GSL_`; we traditionally consider lowercase `gsl_` the realm of *gsl-lite*)
  238. - avoid any changes to the configuration options
  239. Example:
  240. ```cmake
  241. # my-statistics-lib/CMakeLists.txt
  242. find_package( gsl-lite 0.37 REQUIRED )
  243. add_library( my-statistics-lib STATIC mean.cpp )
  244. target_link_libraries( my-statistics-lib PUBLIC gsl::gsl-lite-v1 )
  245. ```
  246. ```c++
  247. // my-statistics-lib/include/my-statistics-lib/mean.hpp
  248. #include <gsl-lite/gsl-lite.hpp> // instead of <gsl/gsl-lite.hpp>
  249. namespace my_statistics_lib {
  250. namespace gsl = ::gsl_lite; // convenience alias
  251. double mean( gsl::span<double const> elements )
  252. {
  253. gsl_Expects( !elements.empty() ); // instead of Expects()
  254. ...
  255. }
  256. } // namespace my_statistics_lib
  257. ```
  258. The idea is that *gsl-lite* will move all its definitions to `namespace gsl_lite` in the next major version, and provide a `namespace gsl` with aliases only if the traditional header \<gsl/gsl-lite.hpp\> is
  259. included. This way, any code that only uses the new header \<gsl-lite/gsl-lite.hpp\> will not risk collision with M-GSL.
  260. Configuration options
  261. ---------------------
  262. **Contents**
  263. - [API macro](#api-macro)
  264. - [Standard selection macro](#standard-selection-macro)
  265. - [Feature selection macros](#feature-selection-macros)
  266. - [Contract checking configuration macros](#contract-checking-configuration-macros)
  267. - [Microsoft GSL compatibility macros](#microsoft-gsl-compatibility-macros)
  268. - [Other configuration macros](#other-configuration-macros)
  269. ### API macro
  270. #### `gsl_api`
  271. Functions in *gsl-lite* are decorated with `gsl_api` where appropriate. **By default `gsl_api` is defined empty for non-CUDA platforms and `__host__ __device__` for the CUDA platform.** Define this macro to specify your own function decoration.
  272. ### Standard selection macro
  273. #### `gsl_CPLUSPLUS`
  274. Define this macro to override the auto-detection of the supported C++ standard if your compiler does not set the `__cplusplus` macro correctly.
  275. ### Feature selection macros
  276. #### `gsl_FEATURE_WITH_CONTAINER_TO_STD=99`
  277. Define this to the highest C++ standard (98, 3, 11, 14, 17, 20) you want to include tagged-construction via `with_container`. **Default is 99 for inclusion with any standard.**
  278. #### `gsl_FEATURE_MAKE_SPAN_TO_STD=99`
  279. Define this to the highest C++ standard (98, 3, 11, 14, 17, 20) you want to include `make_span()` creator functions. **Default is 99 for inclusion with any standard.**
  280. #### `gsl_FEATURE_BYTE_SPAN_TO_STD=99`
  281. Define this to the highest C++ standard (98, 3, 11, 14, 17, 20) you want to include `byte_span()` creator functions. **Default is 99 for inclusion with any standard.**
  282. #### `gsl_FEATURE_IMPLICIT_MACRO=0`
  283. Define this macro to 1 to provide the `implicit` macro. **Default is 0.**
  284. #### `gsl_FEATURE_OWNER_MACRO=1`
  285. At default macro `Owner()` is defined for all C++ versions. This may be useful to transition from a compiler that doesn't provide alias templates to one that does. Define this macro to 0 to omit the `Owner()` macro. **Default is 1.**
  286. #### `gsl_FEATURE_EXPERIMENTAL_RETURN_GUARD=0`
  287. Provide experimental types `final_action_return` and `final_action_error` and convenience functions `on_return()` and `on_error()`. **Default is 0.**
  288. #### `gsl_FEATURE_GSL_LITE_NAMESPACE=0`
  289. Define this to additionally define a `namespace gsl_lite` with most of the *gsl-lite* API available, cf. [Using *gsl-lite* in libraries](#using-gsl-lite-in-libraries). **Default is 0.**
  290. ### Contract checking configuration macros
  291. *gsl-lite* provides contract violation response control as originally suggested in proposal [N4415](http://wg21.link/n4415), with some refinements inspired by [P1710](http://wg21.link/P1710)/[P1730](http://wg21.link/P1730).
  292. There are four macros for expressing pre- and postconditions:
  293. - `gsl_Expects()` for simple preconditions
  294. - `gsl_Ensures()` for simple postconditions
  295. - `gsl_ExpectsAudit()` for preconditions that are expensive or include potentially opaque function calls
  296. - `gsl_EnsuresAudit()` for postconditions that are expensive or include potentially opaque function calls
  297. The macros `Expects()` and `Ensures()` are also provided as aliases for `gsl_Expects()` and `gsl_Ensures()`.
  298. The following macros control whether contracts are checked at runtime:
  299. - **`gsl_CONFIG_CONTRACT_CHECKING_AUDIT`**
  300. Define this macro to have all contracts checked at runtime.
  301. - **`gsl_CONFIG_CONTRACT_CHECKING_ON` (default)**
  302. Define this macro to have contracts expressed with `gsl_Expects()` and `gsl_Ensures()` checked at runtime, and contracts expressed with `gsl_ExpectsAudit()` and `gsl_EnsuresAudit()` not checked and not evaluated at runtime. **This is the default.**
  303. - **`gsl_CONFIG_CONTRACT_CHECKING_OFF`**
  304. Define this macro to disable all runtime checking of contracts.
  305. The following macros can be used to selectively disable checking for a particular kind of contract:
  306. - **`gsl_CONFIG_CONTRACT_CHECKING_EXPECTS_OFF`**
  307. Define this macro to disable runtime checking of precondition contracts expressed with `gsl_Expects()` and `gsl_ExpectsAudit()`.
  308. - **`gsl_CONFIG_CONTRACT_CHECKING_ENSURES_OFF`**
  309. Define this macro to disable runtime checking of precondition contracts expressed with `gsl_Ensures()` and `gsl_EnsuresAudit()`.
  310. The following macros control the handling of runtime contract violations:
  311. - **`gsl_CONFIG_CONTRACT_VIOLATION_TERMINATES` (default)**
  312. Define this macro to call `std::terminate()` on a GSL contract violation in `gsl_Expects()`, `gsl_ExpectsAudit()`, `gsl_Ensures()`, and `gsl_EnsuresAudit()`. **This is the default.**
  313. - **`gsl_CONFIG_CONTRACT_VIOLATION_THROWS`**
  314. Define this macro to throw a std::runtime_exception-derived exception `gsl::fail_fast` instead of calling `std::terminate()` on a GSL contract violation in `gsl_Expects()`, `gsl_ExpectsAudit()`, `gsl_Ensures()`, and `gsl_EnsuresAudit()`.
  315. - **`gsl_CONFIG_CONTRACT_VIOLATION_CALLS_HANDLER`**
  316. Define this macro to call a user-defined handler function `gsl::fail_fast_assert_handler()` instead of calling `std::terminate()` on a GSL contract violation in `gsl_Expects()`, `gsl_ExpectsAudit()`, `gsl_Ensures()`, and `gsl_EnsuresAudit()`. The user must provide a definition of the following function:
  317. ```c++
  318. namespace gsl {
  319. gsl_api void fail_fast_assert_handler(
  320. char const * const expression, char const * const message,
  321. char const * const file, int line );
  322. }
  323. ```
  324. The following macros control what happens with contract checks not enforced at runtime:
  325. - **`gsl_CONFIG_UNENFORCED_CONTRACTS_ELIDE` (default)**
  326. Define this macro to disable all runtime checking and evaluation of contracts. **This is the default.**
  327. - **`gsl_CONFIG_UNENFORCED_CONTRACTS_ASSUME`**
  328. Define this macro to let the compiler assume that contracts expressed with `gsl_Expects()` and `gsl_Ensures()` always hold true, and to have contracts expressed with `gsl_ExpectsAudit()` and `gsl_EnsuresAudit()` not checked and not evaluated at runtime. With this setting, contract violations lead to undefined behavior, which gives the compiler more opportunities for optimization but can be dangerous if the code is not prepared for it.
  329. Note that the distinction between regular and audit-level contracts is subtly different from the C++2a Contracts proposals. When `gsl_CONFIG_UNENFORCED_CONTRACTS_ASSUME` is defined, the compiler is instructed that the
  330. condition expressed by regular contracts can be assumed to hold true. This is meant to be an aid for the optimizer; runtime evaluation of the condition is not desired. However, because the GSL implements contract checks
  331. with macros rather than as a language feature, it cannot reliably suppress runtime evaluation of a condition for all compilers. If the contract comprises a function call which is opaque to the compiler, many compilers will
  332. generate the runtime function call.
  333. Therefore, `gsl_Expects()` and `gsl_Ensures()` should be used only for conditions that can be proven side-effect-free by the compiler, and `gsl_ExpectsAudit()` and `gsl_EnsuresAudit()` for everything else. In practice, this implies that
  334. `gsl_Expects()` and `gsl_Ensures()` should only be used for simple comparisons of scalar values, for simple inlineable getters, and for comparisons of class objects with trivially inlineable comparison operators.
  335. Example:
  336. ```c++
  337. template< class RandomIt >
  338. auto median( RandomIt first, RandomIt last )
  339. {
  340. // Comparing iterators for equality boils down to a comparison of pointers. An optimizing
  341. // compiler will inline the comparison operator and understand that the comparison is free
  342. // of side-effects, and hence generate no code in gsl_CONFIG_UNENFORCED_CONTRACTS_ASSUME mode.
  343. gsl_Expects( first != last );
  344. // Verifying that a range of elements is sorted may be an expensive operation, and we
  345. // cannot trust the compiler to understand that it is free of side-effects, so we use an
  346. // audit-level contract check.
  347. gsl_ExpectsAudit( std::is_sorted( first, last ) );
  348. auto count = last - first;
  349. return count % 2 != 0
  350. ? first[ count / 2 ]
  351. : std::midpoint( first[ count / 2 ], first[ count / 2 + 1 ] );
  352. }
  353. ```
  354. ### Microsoft GSL compatibility macros
  355. #### `GSL_UNENFORCED_ON_CONTRACT_VIOLATION`
  356. Equivalent to defining `gsl_CONFIG_CONTRACT_CHECKING_OFF`.
  357. #### `GSL_TERMINATE_ON_CONTRACT_VIOLATION`
  358. Equivalent to defining `gsl_CONFIG_CONTRACT_VIOLATION_TERMINATES`.
  359. #### `GSL_THROW_ON_CONTRACT_VIOLATION`
  360. Equivalent to defining `gsl_CONFIG_CONTRACT_VIOLATION_THROWS`.
  361. ### Other configuration macros
  362. #### `gsl_CONFIG_DEPRECATE_TO_LEVEL=0`
  363. Define this to and including the level you want deprecation; see table [Deprecation](#deprecation) below. **Default is 0 for no deprecation.**
  364. #### `gsl_CONFIG_SPAN_INDEX_TYPE=std::size_t`
  365. Define this macro to the type to use for indices in `span<>` and `basic_string_span<>`. Microsoft GSL uses `std::ptrdiff_t`. **Default for *gsl-lite* is `std::size_t`.**
  366. #### `gsl_CONFIG_INDEX_TYPE=gsl_CONFIG_SPAN_INDEX_TYPE`
  367. Define this macro to the type to use for `gsl::index`. Microsoft's GSL uses `std::ptrdiff_t`. **Default for *gsl-lite* is `std::size_t`.**
  368. #### `gsl_CONFIG_NOT_NULL_EXPLICIT_CTOR=0`
  369. Define this macro to 1 to make `not_null<>`'s constructor explicit. **Default is 0.** Note that in Microsoft's GSL the constructor is explicit. For implicit construction you can also use the *gsl-lite*-specific `not_null<>`-derived class `not_null_ic<>`.
  370. #### `gsl_CONFIG_TRANSPARENT_NOT_NULL=0`
  371. Define this macro to 1 to have `not_null<>` support typical member functions of the underlying smart pointer transparently (currently `get()`), while adding precondition checks. This is conformant behavior but may be incompatible with older code which expects that `not_null<>::get()` returns the underlying pointer itself. **Default is 0.**
  372. #### `gsl_CONFIG_NOT_NULL_GET_BY_CONST_REF=0`
  373. Define this macro to 1 to have the legacy non-transparent version of `not_null<>::get()` return `T const &` instead of `T`. This may improve performance with types that have an expensive copy-constructor. This macro may not be defined if `gsl_CONFIG_TRANSPARENT_NOT_NULL` is 1. **Default is 0 for `T`.**
  374. #### `gsl_CONFIG_ALLOWS_SPAN_COMPARISON=1`
  375. Define this macro to 0 to omit the ability to compare spans. C++20 `std::span<>` does not support comparison because semantics (deep vs. shallow) are unclear. **Default is 1.**
  376. #### `gsl_CONFIG_ALLOWS_NONSTRICT_SPAN_COMPARISON=1`
  377. Define this macro to 0 to omit the ability to compare spans of different types, e.g. of different const-volatile-ness. To be able to compare a string_span with a cstring_span, non-strict span comparison must be available. **Default is 1.**
  378. #### `gsl_CONFIG_ALLOWS_UNCONSTRAINED_SPAN_CONTAINER_CTOR=0`
  379. Define this macro to 1 to add the unconstrained span constructor for containers for pre-C++11 compilers that cannot constrain the constructor. This constructor may prove too greedy and interfere with other constructors. **Default is 0.**
  380. Note: an alternative is to use the constructor tagged `with_container`: `span<V> s(gsl::with_container, cont)`.
  381. #### `gsl_CONFIG_NARROW_THROWS_ON_TRUNCATION=0`
  382. Define this macro to 1 to have `narrow<>()` always throw a `narrowing_error` exception if the narrowing conversion loses information due to truncation. If `gsl_CONFIG_NARROW_THROWS_ON_TRUNCATION` is 0 and `gsl_CONFIG_CONTRACT_VIOLATION_THROWS` is not defined, `narrow<>()` instead calls `std::terminate()` on information loss. **Default is 0.**
  383. #### `gsl_CONFIG_CONFIRMS_COMPILATION_ERRORS=0`
  384. Define this macro to 1 to experience the by-design compile-time errors of the GSL components in the test suite. **Default is 0.**
  385. Features
  386. --------
  387. See also section [GSL: Guidelines Support Library](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#S-gsl) of the C++ Core Guidelines [9].
  388. Feature / library | GSL | M-GSL | *gsl-lite* | Notes |
  389. ----------------------------|:-------:|:-------:|:----------:|:------|
  390. **1.Lifetime&nbsp;safety** | &nbsp; | &nbsp; | &nbsp; | &nbsp; |
  391. **1.1 Indirection** | &nbsp; | &nbsp; | &nbsp; | &nbsp; |
  392. `not_null<>` | | | | Wrap any indirection and enforce non-null,<br>see also [Other configuration macros](#other-configuration-macros) |
  393. `not_null_ic<>` | - | - | | not_null with implicit constructor, allowing [copy-initialization](https://en.cppreference.com/w/cpp/language/copy_initialization) |
  394. **1.2 Ownership** | &nbsp; | &nbsp; | &nbsp; | &nbsp; |
  395. `owner<>` | | | &nbsp;C++11 | Owned raw pointers |
  396. `Owner()` | - | - | | Macro for pre-C++11;<br>see also [Feature selection macros](#feature-selection-macros) |
  397. `unique_ptr<>` | | | &nbsp;C++11 | `std::unique_ptr<>` |
  398. `unique_ptr<>` | - | - | <&nbsp;C++11 | VC10, VC11 |
  399. `shared_ptr<>` | | | &nbsp;C++11 | `std::shared_ptr<>` |
  400. `shared_ptr<>` | - | - | <&nbsp;C++11 | VC10, VC11 |
  401. `stack_array<>` | | - | - | A stack-allocated array, fixed size |
  402. `dyn_array<>` | ? | - | - | A heap-allocated array, fixed size |
  403. **2.Bounds&nbsp;safety** | &nbsp; | &nbsp; | &nbsp; | &nbsp; |
  404. **2.1 Tag Types** | &nbsp; | &nbsp; | &nbsp; | &nbsp; |
  405. `zstring` | | | | a `char*` (C-style string) |
  406. `wzstring` | - | | | a `wchar_t*` (C-style string) |
  407. `czstring` | | | | a `const char*` (C-style string) |
  408. `cwzstring` | - | | | a `const wchar_t*` (C-style string) |
  409. `**2.2 Views** | &nbsp; | &nbsp; | &nbsp; | &nbsp; |
  410. `span<>` | ✓ | ✓ | 1D&nbsp;views | A view of contiguous T's, replace (*,len),<br>see also proposal [p0122](http://wg21.link/p0122) |
  411. `span_p<>` | ✓ | - | - | A view of contiguous T's that ends at the first element for which predicate(*p) is true |
  412. `make_span()` | - | ✓ | ✓ | Create a span |
  413. `byte_span()` | - | - | ✓ | Create a span of bytes from a single object |
  414. `as_bytes()` | - | ✓ | ✓ | A span as bytes |
  415. `as_writable_bytes` | - | ✓ | ✓ | A span as writable bytes |
  416. `basic_string_span<>` | - | ✓ | ✓ | See also proposal [p0123](http://wg21.link/p0123) |
  417. `string_span` | ✓ | ✓ | ✓ | `basic_string_span< char >` |
  418. `wstring_span` | - | ✓ | ✓ | `basic_string_span< wchar_t >` |
  419. `cstring_span` | ✓ | ✓ | ✓ | `basic_string_span< const char >` |
  420. `cwstring_span` | - | ✓ | ✓ | `basic_string_span< const wchar_t >` |
  421. `zstring_span` | - | ✓ | ✓ | `basic_zstring_span< char >` |
  422. `wzstring_span` | - | ✓ | ✓ | `basic_zstring_span< wchar_t >` |
  423. `czstring_span` | - | ✓ | ✓ | `basic_zstring_span< const char >` |
  424. `cwzstring_span` | - | ✓ | ✓ | `basic_zstring_span< const wchar_t >` |
  425. `ensure_z()` | - | ✓ | ✓ | Create a `cstring_span` or `cwstring_span` |
  426. `to_string()` | - | ✓ | ✓ | Convert a `string_span` to `std::string` or `std::wstring` |
  427. **2.3 Indexing** | &nbsp; | &nbsp; | &nbsp; | &nbsp; |
  428. `at()` | ✓ | ✓ | ≥&nbsp;C++11 | Bounds-checked way of accessing<br>static arrays, `std::array<>`, `std::vector<>` |
  429. `at()` | - | - | <&nbsp;C++11 | static arrays, `std::vector<>`<br>`std::array<>` : VC11 |
  430. **3. Assertions** | &nbsp; | &nbsp; | &nbsp; | &nbsp; |
  431. `Expects()` | ✓ | ✓ | ✓ | Precondition assertion |
  432. `Ensures()` | ✓ | ✓ | ✓ | Postcondition assertion |
  433. `gsl_Expects()` | - | - | ✓ | Precondition assertion |
  434. `gsl_Ensures()` | - | - | ✓ | Postcondition assertion |
  435. `gsl_ExpectsAudit()` | - | - | ✓ | Audit-level precondition assertion |
  436. `gsl_EnsuresAudit()` | - | - | ✓ | Audit-level postcondition assertion |
  437. **4. Utilities** | &nbsp; | &nbsp; | &nbsp; | &nbsp; |
  438. `index` | ✓ | ✓ | ✓ | type for container indexes and subscripts, <br>see [Other configuration macros](#other-configuration-macros) |
  439. `dim` | - | - | ✓ | type for container sizes |
  440. `stride` | - | - | ✓ | type for index strides |
  441. `diff` | - | - | ✓ | type for index differences |
  442. `byte` | - | ✓ | ✓ | byte type, see also proposal [p0298](http://wg21.link/p0298) |
  443. `final_action<>` | ✓ | ✓ | ≥&nbsp;C++11 | Action at the end of a scope |
  444. `final_action` | - | - | <&nbsp;C++11 | Currently only `void(*)()` |
  445. `finally()` | ✓ | ✓ | ≥&nbsp;C++11 | Make a `final_action<>` |
  446. `finally()` | - | - | <&nbsp;C++11 | Make a `final_action` |
  447. `final_action_return` | - | - | <&nbsp;C++11 | Currently only `void(*)()`, [experimental](#feature-selection-macros) |
  448. `on_return()` | - | - | ≥&nbsp;C++11 | Make a `final_action_return<>, [experimental](#feature-selection-macros) |
  449. `on_return()` | - | - | <&nbsp;C++11 | Make a `final_action_return, [experimental](#feature-selection-macros) |
  450. `final_action_error` | - | - | <&nbsp;C++11 | Currently only `void(*)()`, [experimental](#feature-selection-macros) |
  451. `on_error()` | - | - | ≥&nbsp;C++11 | Make a `final_action_error<>`, [experimental](#feature-selection-macros) |
  452. `on_error()` | - | - | <&nbsp;C++11 | Make a `final_action_error`, [experimental](#feature-selection-macros) |
  453. `narrow_cast<>` | ✓ | ✓ | ✓ | Searchable narrowing casts of values |
  454. `narrow<>()` | ✓ | ✓ | ✓ | Checked narrowing cast |
  455. `narrow_failfast<>()` | - | - | ✓ | Fail-fast narrowing cast |
  456. `[[implicit]]` | ✓ | - | C++?? | Symmetric with explicit |
  457. `implicit` | - | - | ✓ | Macro, see [Feature selection macros](#feature-selection-macros) |
  458. `move_owner` | ? | - | - | ... |
  459. **5. Algorithms** | &nbsp; | &nbsp; | &nbsp; | &nbsp; |
  460. `copy()` | &nbsp; | &nbsp; | &nbsp; | Copy from source span to destination span |
  461. `size()` | &nbsp; | &nbsp; | &nbsp; | Size of span, unsigned |
  462. `ssize()` | &nbsp; | &nbsp; | &nbsp; | Size of span, signed |
  463. **6. Concepts** | &nbsp; | &nbsp; | &nbsp; | &nbsp; |
  464. ... | &nbsp; | &nbsp; | &nbsp; | &nbsp; |
  465. Note: *gsl-lite* treats VC12 (VS2013) and VC14 (VS2015) as C++11 (`gsl_CPP11_OR_GREATER`: 1).
  466. Deprecation
  467. -----------
  468. The following features are deprecated since the indicated version. See macro [`gsl_CONFIG_DEPRECATE_TO_LEVEL`](#other-configuration-macros) on how to control deprecation using the indicated level.
  469. Version | Level | Feature / Notes |
  470. -------:|:-----:|:----------------|
  471. 0.37.0 | 6 | `as_writeable_bytes()`, call indexing for spans, and `span::at()` |
  472. &nbsp; |&nbsp; | `as_writable_bytes()`, subscript indexing is used |
  473. 0.35.0 | - | `gsl_CONFIG_CONTRACT_LEVEL_ON`, `gsl_CONFIG_CONTRACT_LEVEL_OFF`, `gsl_CONFIG_CONTRACT_LEVEL_EXPECTS_ONLY` and `gsl_CONFIG_CONTRACT_LEVEL_ENSURES_ONLY` |
  474. &nbsp; |&nbsp; | Use `gsl_CONFIG_CONTRACT_CHECKING_ON`, `gsl_CONFIG_CONTRACT_CHECKING_OFF`, `gsl_CONFIG_CONTRACT_CHECKING_ENSURES_OFF`, `gsl_CONFIG_CONTRACT_CHECKING_EXPECTS_OFF` |
  475. 0.31.0 | 5 | `span( std::nullptr_t, index_type )` |
  476. &nbsp; |&nbsp; | `span( pointer, index_type )` is used |
  477. 0.31.0 | 5 | `span( U *, index_type size )` |
  478. &nbsp; |&nbsp; | `span( pointer, index_type )` is used |
  479. 0.31.0 | 5 | `span( U (&arr)[N] )` |
  480. &nbsp; |&nbsp; | `span( element_type (&arr)[N] )` is used |
  481. 0.31.0 | 5 | `span( std::array< U, N > [const] & arr )` |
  482. &nbsp; |&nbsp; | `span( std::array< value_type, N > [const] & arr )` is used |
  483. 0.29.0 | 4 | `span( std::shared_ptr<T> const & p )` |
  484. &nbsp; |&nbsp; | &mdash; |
  485. 0.29.0 | 4 | `span( std::unique_ptr<T> const & p )` |
  486. &nbsp; |&nbsp; | &mdash; |
  487. 0.29.0 | 3 | `span<>::length()` |
  488. &nbsp; |&nbsp; | Use `span<>::size()` |
  489. 0.29.0 | 3 | `span<>::length_bytes()` |
  490. &nbsp; |&nbsp; | Use `span<>::size_bytes()` |
  491. 0.17.0 | 2 | member `span<>::as_bytes()`, `span<>::as_writeable_bytes()` |
  492. &nbsp; |&nbsp; | &mdash; |
  493. 0.7.0 | - | `gsl_CONFIG_ALLOWS_SPAN_CONTAINER_CTOR` |
  494. &nbsp; |&nbsp; | Use `gsl_CONFIG_ALLOWS_UNCONSTRAINED_SPAN_CONTAINER_CTOR`,<br>or consider `span(with_container, cont)`. |
  495. Reported to work with
  496. ---------------------
  497. The table below mentions the compiler versions and platforms *gsl-lite* is reported to work with.
  498. Compiler | OS | Platforms | Versions | CI |
  499. --------------------:|:----------------|-----------|------------------:|----|
  500. GCC | Linux | x64 | 4.7 and newer | [4.7, 4.8, 4.9, 5](https://travis-ci.com/gsl-lite/gsl-lite/), [6, 7, 8, 9, 10](https://dev.azure.com/gsl-lite/gsl-lite/_build?definitionId=1) |
  501. GCC (MinGW) | Windows | x86, x64 | 4.8.4 and newer | |
  502. GCC (DJGPP) | DOSBox, FreeDOS | x86 | 7.2 | |
  503. GCC | MacOS | x64 | 6 and newer | [6, 7, 8, 9, 10](https://dev.azure.com/gsl-lite/gsl-lite/_build?definitionId=1) |
  504. Clang | Linux | x64 | 3.5 and newer | [3.5, 3.6, 3.7, 3.8, 3.9](https://travis-ci.com/gsl-lite/gsl-lite/), [4, 5, 6, 7, 8, 9, 10](https://dev.azure.com/gsl-lite/gsl-lite/_build?definitionId=1) |
  505. Clang | Windows | x64 | 9 and newer | [9, 10](https://dev.azure.com/gsl-lite/gsl-lite/_build?definitionId=1) |
  506. MSVC (Visual Studio) | Windows | x86, x64 | VS 2010 and newer | VS [2010, 2012, 2013, 2015](https://ci.appveyor.com/project/gsl-lite/gsl-lite), [2017, 2019](https://dev.azure.com/gsl-lite/gsl-lite/_build?definitionId=1) |
  507. AppleClang (Xcode) | MacOS | x64 | 7.3 and newer | [7.3, 8, 8.1, 9](https://travis-ci.com/gsl-lite/gsl-lite/), [9.1, 10, 10.0.1, 11, 11.0.3](https://dev.azure.com/gsl-lite/gsl-lite/_build?definitionId=1) |
  508. NVCC (CUDA Toolkit) | Linux, Windows | x64 | 10.2 and newer | [10.2, 11.0](https://dev.azure.com/gsl-lite/gsl-lite/_build?definitionId=1) |
  509. Building the tests
  510. ------------------
  511. To build the tests:
  512. - [CMake](http://cmake.org), version 3.15 or later to be installed and in your PATH.
  513. - A [suitable compiler](#reported-to-work-with).
  514. The [*lest* test framework](https://github.com/martinmoene/lest) is included in the [test folder](test).
  515. The following steps assume that the [*gsl-lite* source code](https://github.com/gsl-lite/gsl-lite) has been cloned into a directory named `C:\gsl-lite`.
  516. 1. Create a directory for the build outputs.
  517. Here we use `C:\gsl-lite\build`.
  518. cd C:\gsl-lite
  519. mkdir build
  520. cd build
  521. 2. Configure the build directory with CMake:
  522. cmake -DGSL_LITE_OPT_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Debug ..
  523. 3. Build the test suite:
  524. cmake --build . --config Debug
  525. 4. Run the test suite:
  526. ctest -V -C Debug
  527. All tests should pass, indicating your platform is supported and you are ready to use *gsl-lite*. See the table with [supported types and functions](#features).
  528. Other GSL implementations
  529. -------------------------
  530. - Microsoft. [Guidelines Support Library (GSL)](https://github.com/microsoft/GSL).
  531. - Vicente J. Botet Escriba. [Guidelines Support Library (GSL)](https://github.com/viboes/GSL).
  532. Notes and references
  533. --------------------
  534. ### Proposals, specification
  535. [1] [`std::span<>` on cppreference](https://en.cppreference.com/w/cpp/container/span).
  536. [2] [`std::span<>` in C++20 Working Draft](http://eel.is/c++draft/views).
  537. [3] [P0091 - Template argument deduction for class templates](http://wg21.link/p0091).
  538. [4] [P0122 - span: bounds-safe views for sequences of objects](http://wg21.link/p0122).
  539. [5] [P0123 - string_span: bounds-safe views for sequences of characters](http://wg21.link/p0123).
  540. [6] [P0298 - A byte type definition](http://wg21.link/p0298).
  541. [7] [P0805 - Comparing Containers](http://wg21.link/p0805).
  542. ### Articles
  543. [8] [Standard C++ Foundation](https://isocpp.org/).
  544. [9] Standard C++ Foundation. [C++ Core Guidelines](https://github.com/isocpp/CppCoreGuidelines).
  545. [10] Microsoft. [Guidelines Support Library (GSL)](https://github.com/microsoft/gsl).
  546. [11] Bjarne Stroustrup. [Writing good C++14 (PDF)](https://github.com/isocpp/CppCoreGuidelines/raw/master/talks/Stroustrup%20-%20CppCon%202015%20keynote.pdf) &mdash; [Video](https://www.youtube.com/watch?t=9&v=1OEu9C51K2A). CppCon 2015.
  547. [12] Herb Sutter. [Writing good C++14&hellip; By default (PDF)](https://github.com/isocpp/CppCoreGuidelines/raw/master/talks/Sutter%20-%20CppCon%202015%20day%202%20plenary%20.pdf) &mdash; [Video](https://www.youtube.com/watch?v=hEx5DNLWGgA). CppCon 2015.
  548. [13] Gabriel Dos Reis. [Contracts for Dependable C++ (PDF)](https://github.com/isocpp/CppCoreGuidelines/raw/master/talks/Contracts-for-Dependable-C%2B%2B.pdf) &mdash; Video. CppCon 2015.
  549. [14] Bjarne Stroustrup et al. [A brief introduction to C++’s model for type- and resource-safety](https://github.com/isocpp/CppCoreGuidelines/raw/master/docs/Introduction%20to%20type%20and%20resource%20safety.pdf).
  550. [15] Herb Sutter and Neil MacIntosh. [Lifetime Safety: Preventing Leaks and Dangling](https://github.com/isocpp/CppCoreGuidelines/raw/master/docs/Lifetimes%20I%20and%20II%20-%20v0.9.1.pdf). 21 Sep 2015.
  551. ### Compiler feature testing
  552. [16] cppreference.com. [Feature testing](https://en.cppreference.com/w/cpp/feature_test).
  553. ### C++ features in various compilers
  554. [17] cppreference.com. [C++ compiler support](https://en.cppreference.com/w/cpp/compiler_support).
  555. Appendix
  556. --------
  557. <a id="a1"></a>
  558. ### A.1 Compile-time information
  559. In the test runner, the version of *gsl-lite* is available via tag `[.version]`. The following tags are available for information on the compiler and on the C++ standard library used: `[.compiler]`, `[.stdc++]`, `[.stdlanguage]` and `[.stdlibrary]`.
  560. <a id="a2"></a>
  561. ### A.2 *gsl-lite* test specification
  562. <details>
  563. <summary>click to expand</summary>
  564. <p>
  565. ```
  566. gsl_Expects(): Allows a true expression
  567. gsl_Ensures(): Allows a true expression
  568. gsl_Expects(): Terminates on a false expression
  569. gsl_Ensures(): Terminates on a false expression
  570. gsl_ExpectsAudit(): Allows a true expression
  571. gsl_EnsuresAudit(): Allows a true expression
  572. gsl_ExpectsAudit(): Terminates on a false expression in AUDIT mode
  573. gsl_EnsuresAudit(): Terminates on a false expression in AUDIT mode
  574. at(): Terminates access to non-existing C-array elements
  575. at(): Terminates access to non-existing std::array elements (C++11)
  576. at(): Terminates access to non-existing std::vector elements
  577. at(): Terminates access to non-existing std::initializer_list elements (C++11)
  578. at(): Terminates access to non-existing gsl::span elements
  579. at(): Allows to access existing C-array elements
  580. at(): Allows to access existing std::array elements (C++11)
  581. at(): Allows to access existing std::vector elements
  582. at(): Allows to access std::initializer_list elements (C++11)
  583. at(): Allows to access gsl::span elements
  584. byte: Allows to construct from integral via static cast (C++17)
  585. byte: Allows to construct from integral via byte() (C++17)
  586. byte: Allows to construct from integral via to_byte()
  587. byte: Allows to convert to integral via to_integer()
  588. byte: Allows comparison operations
  589. byte: Allows bitwise or operation
  590. byte: Allows bitwise and operation
  591. byte: Allows bitwise x-or operation
  592. byte: Allows bitwise or assignment
  593. byte: Allows bitwise and assignment
  594. byte: Allows bitwise x-or assignment
  595. byte: Allows shift-left operation
  596. byte: Allows shift-right operation
  597. byte: Allows shift-left assignment
  598. byte: Allows shift-right assignment
  599. byte: Provides constexpr non-assignment operations (C++11)
  600. byte: Provides constexpr assignment operations (C++14)
  601. byte: Provides hash support (C++11)
  602. conjunction<> and disjunction<>: Short-circuiting is handled correctly
  603. conjunction<> and disjunction<>: First suitable type is chosen as base
  604. span<>: free comparation functions fail for different const-ness [issue #32]
  605. span<>: constrained container constructor suffers hard failure for arguments with reference-returning data() function [issue #242]
  606. byte: aliasing rules lead to undefined behaviour when using enum class [issue #34](GSL issue #313, PR #390)
  607. string_span<>: must not include terminating '\0' [issue #53]
  608. string_span<>: to_string triggers SFINAE errors on basic_string_span's move & copy constructor with Clang-3.9 (define gsl_CONFIG_CONFIRMS_COMPILATION_ERRORS) [issue #53a]
  609. narrow<>(): Allows narrowing double to float without MSVC level 4 warning C4127: conditional expression is constant [issue #115]
  610. detail::is_compatible_container<>: Not a proper type trait [PR #238]
  611. not_null<>: Disallows default construction (define gsl_CONFIG_CONFIRMS_COMPILATION_ERRORS)
  612. not_null<>: Disallows construction from nullptr_t, NULL or 0 (define gsl_CONFIG_CONFIRMS_COMPILATION_ERRORS)
  613. not_null<>: Disallows construction from a unique pointer to underlying type (define gsl_CONFIG_CONFIRMS_COMPILATION_ERRORS)
  614. not_null<>: Layout is compatible to underlying type
  615. not_null<>: Convertibility is correctly reported by type traits
  616. not_null<>: Copyability and assignability are correctly reported by type traits
  617. not_null<>: Disallows assignment from unrelated pointers (define gsl_CONFIG_CONFIRMS_COMPILATION_ERRORS)
  618. not_null<>: Terminates construction from a null pointer value (raw pointer)
  619. not_null<>: Terminates construction from related pointer types for null pointer value (raw pointer)
  620. not_null<>: Terminates assignment from a null pointer value (raw pointer)
  621. not_null<>: Terminates assignment from related pointer types for null pointer value (raw pointer)
  622. not_null<>: Allows to construct from a non-null underlying pointer (raw pointer)
  623. not_null<>: Returns underlying pointer with get() (raw pointer)
  624. not_null<>: Allows to construct from a non-null underlying pointer (raw pointer) with make_not_null()
  625. not_null<>: Allows to construct from a non-null underlying pointer (raw pointer) with deduction guide
  626. not_null<>: Allows to construct a const pointer from a non-null underlying pointer (raw pointer)
  627. not_null<>: Converts to underlying pointer (raw pointer)
  628. not_null<>: Allows to construct from a non-null related pointer (raw pointer)
  629. not_null<>: Allows to construct a const pointer from a non-null related pointer (raw pointer)
  630. not_null<>: Allows to construct from a not_null related pointer type (raw pointer)
  631. not_null<>: Allows to construct a const pointer from a not_null related pointer type (raw pointer)
  632. not_null<>: Converts to a related pointer (raw pointer)
  633. not_null<>: Allows assignment from a not_null related pointer type (raw pointer)
  634. not_null<>: Allows assignment to a const pointer from a not_null related pointer type (raw pointer)
  635. not_null<>: Allows indirect member access (raw pointer)
  636. not_null<>: Allows dereferencing (raw pointer)
  637. not_null<>: Terminates swap of a moved-from value (shared_ptr)
  638. not_null<>: Terminates self-swap of a moved-from value (shared_ptr)
  639. not_null<>: Terminates construction from a null pointer value (shared_ptr)
  640. not_null<>: Terminates construction from related pointer types for null pointer value (shared_ptr)
  641. not_null<>: Terminates assignment from a null pointer value (shared_ptr)
  642. not_null<>: Terminates assignment from related pointer types for null pointer value (shared_ptr)
  643. not_null<>: Terminates propagation of a moved-from value (shared_ptr)
  644. not_null<>: Allows self-swap (shared_ptr)
  645. not_null<>: Allows swap (shared_ptr)
  646. not_null<>: Allows to construct from a non-null underlying pointer (shared_ptr)
  647. not_null<>: Allows to construct from a non-null raw pointer with explicit conversion (shared_ptr)
  648. not_null<>: Returns underlying pointer or raw pointer with get() (shared_ptr)
  649. not_null<>: Allows to move from a not_null pointer to an underlying pointer (shared_ptr)
  650. not_null<>: Allows to construct from a non-null underlying pointer (shared_ptr) with make_not_null()
  651. not_null<>: Allows to construct from a non-null underlying pointer (shared_ptr) with deduction guide
  652. not_null<>: Allows to construct a const pointer from a non-null underlying pointer (shared_ptr)
  653. not_null<>: Converts to underlying pointer (shared_ptr)
  654. not_null<>: Allows to construct from a non-null related pointer (shared_ptr)
  655. not_null<>: Allows to construct a const pointer from a non-null related pointer (shared_ptr)
  656. not_null<>: Allows to construct from a not_null related pointer type (shared_ptr)
  657. not_null<>: Allows to construct a const pointer from a not_null related pointer type (shared_ptr)
  658. not_null<>: Converts to a related pointer (shared_ptr)
  659. not_null<>: Allows assignment from a not_null related pointer type (shared_ptr)
  660. not_null<>: Allows assignment to a const pointer from a not_null related pointer type (shared_ptr)
  661. not_null<>: Allows indirect member access (shared_ptr)
  662. not_null<>: Allows dereferencing (shared_ptr)
  663. not_null<>: Terminates swap of a moved-from value (unique_ptr)
  664. not_null<>: Terminates self-swap of a moved-from value (unique_ptr)
  665. not_null<>: Terminates construction from a null pointer value (unique_ptr)
  666. not_null<>: Terminates construction from related pointer types for null pointer value (unique_ptr)
  667. not_null<>: Terminates assignment from a null pointer value (unique_ptr)
  668. not_null<>: Terminates assignment from related pointer types for null pointer value (unique_ptr)
  669. not_null<>: Terminates propagation of a moved-from value (unique_ptr)
  670. not_null<>: Allows self-swap (unique_ptr)
  671. not_null<>: Allows swap (unique_ptr)
  672. not_null<>: Allows to construct from a non-null underlying pointer (unique_ptr)
  673. not_null<>: Allows to construct from a non-null raw pointer with explicit conversion (unique_ptr)
  674. not_null<>: Returns underlying pointer or raw pointer with get() (unique_ptr)
  675. not_null<>: Allows to move from a not_null pointer to an underlying pointer (unique_ptr)
  676. not_null<>: Allows to move to a related pointer from a not_null pointer (unique_ptr)
  677. not_null<>: Allows to construct from a non-null underlying pointer (unique_ptr) with make_not_null()
  678. not_null<>: Allows to construct from a non-null underlying pointer (unique_ptr) with deduction guide
  679. not_null<>: Allows to construct a const pointer from a non-null underlying pointer (unique_ptr)
  680. not_null<>: Converts to underlying pointer (unique_ptr)
  681. not_null<>: Allows to construct from a non-null related pointer (unique_ptr)
  682. not_null<>: Allows to construct a const pointer from a non-null related pointer (unique_ptr)
  683. not_null<>: Allows to construct from a not_null related pointer type (unique_ptr)
  684. not_null<>: Allows to construct a const pointer from a not_null related pointer type (unique_ptr)
  685. not_null<>: Converts to a related pointer (unique_ptr)
  686. not_null<>: Allows assignment from a not_null related pointer type (unique_ptr)
  687. not_null<>: Allows assignment to a const pointer from a not_null related pointer type (unique_ptr)
  688. not_null<>: Allows indirect member access (unique_ptr)
  689. not_null<>: Allows dereferencing (unique_ptr)
  690. not_null<>: Allows to construct a not_null<shared_ptr<T>> from a non-null unique_ptr<T>
  691. not_null<>: Allows to construct a not_null<shared_ptr<const T>> from a non-null unique_ptr<T>
  692. not_null<>: Allows to construct a not_null<shared_ptr<T>> from a related non-null unique_ptr<U>
  693. not_null<>: Allows to construct a not_null<shared_ptr<const T>> from a related non-null unique_ptr<U>
  694. not_null<>: Allows to construct a not_null<shared_ptr<T>> from a not_null<unique_ptr<T>>
  695. not_null<>: Allows to construct a not_null<shared_ptr<const T>> from a not_null<unique_ptr<T>>
  696. not_null<>: Allows to construct a not_null<shared_ptr<T>> from a related not_null<unique_ptr<U>>
  697. not_null<>: Allows to construct a not_null<shared_ptr<const T>> from a related not_null<unique_ptr<U>>
  698. not_null<>: Allows assignment to a not_null<shared_ptr<T>> from a related not_null<unique_ptr<U>>
  699. not_null<>: Allows assignment to a not_null<shared_ptr<const T>> from a related not_null<unique_ptr<U>>
  700. not_null<>: Allows assignment from a non-null bare recast pointer
  701. not_null<>: Allows implicit conversion to underlying type
  702. not_null<>: Allows to construct from a non-null user-defined ref-counted type
  703. not_null<>: Allows to compare equal to another not_null of the same type
  704. not_null<>: Allows to compare unequal to another not_null of the same type
  705. not_null<>: Allows to compare less than another not_null of the same type
  706. not_null<>: Allows to compare less than or equal to another not_null of the same type
  707. not_null<>: Allows to compare greater than another not_null of the same type
  708. not_null<>: Allows to compare greater than or equal to another not_null of the same type
  709. not_null<>: Allows to compare equal to a raw pointer of the same type
  710. not_null<>: Allows to compare unequal to a raw pointer of the same type
  711. not_null<>: Allows to compare less than a raw pointer of the same type
  712. not_null<>: Allows to compare less than or equal to a raw pointer of the same type
  713. not_null<>: Allows to compare greater than a raw pointer of the same type
  714. not_null<>: Allows to compare greater than or equal to a raw pointer of the same type
  715. not_null<>: Able to deduce element_type of raw pointers
  716. not_null<>: Able to deduce element_type of unique_ptr
  717. not_null<>: Able to deduce element_type of shared_ptr
  718. not_null<>: Able to deduce element_type of normal user-defined smart pointers
  719. not_null<>: Able to correctly deduce element_type of user-defined smart pointers even if typedef and result of dereferencing differs
  720. not_null<>: Able to deduce element_type of user-defined smart pointers even if they do not have an element_type typedef
  721. not_null<>: Able to deduce element_type of user-defined smart pointers even if they do not have an element_type typedef, and element_type differs from T
  722. owner<>: Disallows construction from a non-pointer type (define gsl_CONFIG_CONFIRMS_COMPILATION_ERRORS)
  723. owner<>: Allows its use as the (pointer) type it stands for
  724. Owner(): Allows its use as the (pointer) type it stands for
  725. span<>: Disallows construction from a temporary value (C++11) (define gsl_CONFIG_CONFIRMS_COMPILATION_ERRORS)
  726. span<>: Disallows construction from a C-array of incompatible type (define gsl_CONFIG_CONFIRMS_COMPILATION_ERRORS)
  727. span<>: Disallows construction from a std::array of incompatible type (C++11) (define gsl_CONFIG_CONFIRMS_COMPILATION_ERRORS)
  728. span<>: Terminates construction from a nullptr and a non-zero size (C++11)
  729. span<>: Terminates construction from two pointers in the wrong order
  730. span<>: Terminates construction from a null pointer and a non-zero size
  731. span<>: Terminates creation of a sub span of the first n elements for n exceeding the span
  732. span<>: Terminates creation of a sub span of the last n elements for n exceeding the span
  733. span<>: Terminates creation of a sub span outside the span
  734. span<>: Terminates access outside the span
  735. span<>: Terminates access with front() and back() on empty span
  736. span<>: Allows to default-construct
  737. span<>: Allows to construct from a nullptr and a zero size (C++11)
  738. span<>: Allows to construct from a single object (C++11)
  739. span<>: Allows to construct from a const single object (C++11)
  740. span<>: Allows to construct from two pointers
  741. span<>: Allows to construct from two pointers to const
  742. span<>: Allows to construct from a non-null pointer and a size
  743. span<>: Allows to construct from a non-null pointer to const and a size
  744. span<>: Allows to construct from a temporary pointer and a size
  745. span<>: Allows to construct from a temporary pointer to const and a size
  746. span<>: Allows to construct from any pointer and a zero size
  747. span<>: Allows to construct from a C-array
  748. span<>: Allows to construct from a const C-array
  749. span<>: Allows to construct from a C-array with size via decay to pointer (potentially dangerous)
  750. span<>: Allows to construct from a const C-array with size via decay to pointer (potentially dangerous)
  751. span<>: Allows to construct from a std::initializer_list<> (C++11)
  752. span<>: Allows to construct from a std::array<> (C++11)
  753. span<>: Allows to construct from a std::array<> with const data (C++11) [deprecated-5]
  754. span<>: Allows to construct from a container (std::vector<>)
  755. span<>: Allows to construct from a temporary container (potentially dangerous)
  756. span<>: Allows to tag-construct from a container (std::vector<>)
  757. span<>: Allows to tag-construct from a temporary container (potentially dangerous)
  758. span<>: Allows to construct from an empty gsl::shared_ptr (C++11) [deprecated-4]
  759. span<>: Allows to construct from an empty gsl::unique_ptr (C++11) [deprecated-4]
  760. span<>: Allows to construct from an empty gsl::unique_ptr (array, C++11) [deprecated-4]
  761. span<>: Allows to construct from a non-empty gsl::shared_ptr (C++11) [deprecated-4]
  762. span<>: Allows to construct from a non-empty gsl::unique_ptr (C++11) [deprecated-4]
  763. span<>: Allows to construct from a non-empty gsl::unique_ptr (array, C++11) [deprecated-4]
  764. span<>: Allows to copy-construct from another span of the same type
  765. span<>: Allows to copy-construct from another span of a compatible type
  766. span<>: Allows to move-construct from another span of the same type (C++11)
  767. span<>: Allows to copy-assign from another span of the same type
  768. span<>: Allows to move-assign from another span of the same type (C++11)
  769. span<>: Allows to create a sub span of the first n elements
  770. span<>: Allows to create a sub span of the last n elements
  771. span<>: Allows to create a sub span starting at a given offset
  772. span<>: Allows to create a sub span starting at a given offset with a given length
  773. span<>: Allows to create an empty sub span at full offset
  774. span<>: Allows to create an empty sub span at full offset with zero length
  775. span<>: Allows forward iteration
  776. span<>: Allows const forward iteration
  777. span<>: Allows reverse iteration
  778. span<>: Allows const reverse iteration
  779. span<>: Allows to observe an element via array indexing
  780. span<>: Allows to observe an element via front() and back()
  781. span<>: Allows to observe an element via data()
  782. span<>: Allows to change an element via array indexing
  783. span<>: Allows to change an element via front() and back()
  784. span<>: Allows to change an element via data()
  785. span<>: Allows to test for empty span via empty(), empty case
  786. span<>: Allows to test for empty span via empty(), non-empty case
  787. span<>: Allows to obtain the number of elements via size(), as configured
  788. span<>: Allows to obtain the number of elements via ssize(), signed
  789. span<>: Allows to obtain the number of elements via length() [deprecated-3]
  790. span<>: Allows to obtain the number of bytes via size_bytes()
  791. span<>: Allows to obtain the number of bytes via length_bytes() [deprecated-3]
  792. span<>: Allows to swap with another span of the same type
  793. span<>: Allows to view the elements as read-only bytes [deprecated-2 as member]
  794. span<>: Allows to view and change the elements as writable bytes [deprecated-2 as member]
  795. span<>: Allows to view the elements as a span of another type
  796. span<>: Allows to change the elements from a span of another type
  797. copy(): Allows to copy a span to another span of the same element type
  798. copy(): Allows to copy a span to another span of a different element type
  799. size(): Allows to obtain the number of elements in span via size(span), unsigned
  800. ssize(): Allows to obtain the number of elements in span via ssize(span), signed
  801. make_span(): (gsl_FEATURE_MAKE_SPAN=1)
  802. make_span(): Allows to build from two pointers
  803. make_span(): Allows to build from two const pointers
  804. make_span(): Allows to build from a non-null pointer and a size
  805. make_span(): Allows to build from a non-null const pointer and a size
  806. make_span(): Allows to build from a C-array
  807. make_span(): Allows to build from a const C-array
  808. make_span(): Allows building from a std::initializer_list<> (C++11)
  809. make_span(): Allows to build from a std::array<> (C++11)
  810. make_span(): Allows to build from a const std::array<> (C++11)
  811. make_span(): Allows to build from a container (std::vector<>)
  812. make_span(): Allows to build from a const container (std::vector<>)
  813. make_span(): Allows to build from a temporary container (potentially dangerous)
  814. make_span(): Allows to tag-build from a container (std::vector<>)
  815. make_span(): Allows to tag-build from a temporary container (potentially dangerous)
  816. make_span(): Allows to build from an empty gsl::shared_ptr (C++11) [deprecated-4]
  817. make_span(): Allows to build from an empty gsl::unique_ptr (C++11) [deprecated-4]
  818. make_span(): Allows to build from an empty gsl::unique_ptr (array, C++11) [deprecated-4]
  819. make_span(): Allows to build from a non-empty gsl::shared_ptr (C++11) [deprecated-4]
  820. make_span(): Allows to build from a non-empty gsl::unique_ptr (C++11) [deprecated-4]
  821. make_span(): Allows to build from a non-empty gsl::unique_ptr (array, C++11) [deprecated-4]
  822. byte_span() (gsl_FEATURE_BYTE_SPAN=1)
  823. byte_span(): Allows to build a span of gsl::byte from a single object
  824. byte_span(): Allows to build a span of const gsl::byte from a single const object
  825. string_span: Disallows construction of a string_span from a cstring_span (define gsl_CONFIG_CONFIRMS_COMPILATION_ERRORS)
  826. string_span: Disallows construction of a string_span from a const std::string (define gsl_CONFIG_CONFIRMS_COMPILATION_ERRORS)
  827. string_span: Allows to default-construct
  828. string_span: Allows to construct from a nullptr (C++11)
  829. string_span: Allows to construct a cstring_span from a const C-string
  830. string_span: Allows to construct a string_span from a non-const C-string and size
  831. string_span: Allows to construct a string_span from a non-const C-string begin and end pointer
  832. string_span: Allows to construct a string_span from a non-const C-array
  833. string_span: Allows to construct a string_span from a non-const std::string
  834. string_span: Allows to construct a string_span from a non-const std::array (C++11)
  835. string_span: Allows to construct a string_span from a non-const container (std::vector)
  836. string_span: Allows to construct a string_span from a non-const container, via a tag (std::vector)
  837. string_span: Allows to construct a cstring_span from a non-const C-string and size
  838. string_span: Allows to construct a cstring_span from a non-const C-string begin and end pointer
  839. string_span: Allows to construct a cstring_span from a non-const C-array
  840. string_span: Allows to construct a cstring_span from a non-const std::string
  841. string_span: Allows to construct a cstring_span from a non-const std::array (C++11)
  842. string_span: Allows to construct a cstring_span from a non-const container (std::vector)
  843. string_span: Allows to construct a cstring_span from a non-const container, via a tag (std::vector)
  844. string_span: Allows to construct a cstring_span from a const C-string and size
  845. string_span: Allows to construct a cstring_span from a non-const C-string begin and end pointer
  846. string_span: Allows to construct a cstring_span from a const C-array
  847. string_span: Allows to construct a cstring_span from a const std::string
  848. string_span: Allows to construct a cstring_span from a const std::array (C++11)
  849. string_span: Allows to construct a cstring_span from a const container (std::vector)
  850. string_span: Allows to construct a cstring_span from a const container, via a tag (std::vector)
  851. string_span: Allows to construct a wstring_span from a non-const C-string and size
  852. string_span: Allows to construct a wstring_span from a non-const C-string begin and end pointer
  853. string_span: Allows to construct a wstring_span from a non-const C-array
  854. string_span: Allows to construct a wstring_span from a non-const std::wstring
  855. string_span: Allows to construct a wstring_span from a non-const std::array (C++11)
  856. string_span: Allows to construct a wstring_span from a non-const container (std::vector)
  857. string_span: Allows to construct a wstring_span from a non-const container, via a tag (std::vector)
  858. string_span: Allows to construct a cwstring_span from a non-const C-string and size
  859. string_span: Allows to construct a cwstring_span from a non-const C-string begin and end pointer
  860. string_span: Allows to construct a cwstring_span from a non-const C-array
  861. string_span: Allows to construct a cwstring_span from a non-const std::wstring
  862. string_span: Allows to construct a cwstring_span from a non-const std::array (C++11)
  863. string_span: Allows to construct a cwstring_span from a non-const container (std::vector)
  864. string_span: Allows to construct a cwstring_span from a non-const container, via a tag (std::vector)
  865. string_span: Allows to construct a cwstring_span from a const C-string and size
  866. string_span: Allows to construct a cwstring_span from a const C-string begin and end pointer
  867. string_span: Allows to construct a cwstring_span from a const C-array
  868. string_span: Allows to construct a cwstring_span from a const std::wstring
  869. string_span: Allows to construct a cwstring_span from a const std::array (C++11)
  870. string_span: Allows to construct a cwstring_span from a const container (std::vector)
  871. string_span: Allows to construct a cwstring_span from a const container, via a tag (std::vector)
  872. string_span: Allows to copy-construct from another span of the same type
  873. string_span: Allows to copy-construct from another span of a compatible type
  874. string_span: Allows to move-construct from another span of the same type (C++11)
  875. string_span: Allows to copy-assign from another span of the same type
  876. string_span: Allows to move-assign from another span of the same type (C++11)
  877. string_span: Allows to create a sub span of the first n elements
  878. string_span: Allows to create a sub span of the last n elements
  879. string_span: Allows to create a sub span starting at a given offset
  880. string_span: Allows to create a sub span starting at a given offset with a given length
  881. string_span: Allows to create an empty sub span at full offset
  882. string_span: Allows to create an empty sub span at full offset with zero length
  883. string_span: Allows forward iteration
  884. string_span: Allows const forward iteration
  885. string_span: Allows reverse iteration
  886. string_span: Allows const reverse iteration
  887. string_span: Allows to observe an element via array indexing
  888. string_span: Allows to observe an element via front() and back()
  889. string_span: Allows to observe an element via data()
  890. string_span: Allows to change an element via array indexing
  891. string_span: Allows to change an element via front() and back()
  892. string_span: Allows to change an element via data()
  893. string_span: Allows to compare a string_span with another string_span
  894. string_span: Allows to compare empty span to non-empty span
  895. string_span: Allows to compare a string_span with a cstring_span
  896. string_span: Allows to compare with types convertible to string_span
  897. string_span: Allows to test for empty span via empty(), empty case
  898. string_span: Allows to test for empty span via empty(), non-empty case
  899. string_span: Allows to obtain the number of elements via length()
  900. string_span: Allows to obtain the number of elements via size()
  901. string_span: Allows to obtain the number of bytes via length_bytes()
  902. string_span: Allows to obtain the number of bytes via size_bytes()
  903. string_span: Allows to view the elements as read-only bytes
  904. zstring_span: Allows to construct a zstring_span from a zero-terminated empty string (via span)
  905. zstring_span: Allows to construct a zstring_span from a zero-terminated non-empty string (via span)
  906. zstring_span: Terminates construction of a zstring_span from a non-zero-terminated string (via span)
  907. zstring_span: Allows to construct a wzstring_span from a zero-terminated empty string (via span)
  908. zstring_span: Allows to construct a wzstring_span from a zero-terminated non-empty string (via span)
  909. zstring_span: Terminates construction of a wzstring_span from a non-zero-terminated string (via span)
  910. zstring_span: Allows to use a zstring_span with a legacy API via member assume_z()
  911. zstring_span: Allows to use a wzstring_span with a legacy API via member assume_z()
  912. to_string(): Allows to explicitly convert from string_span to std::string
  913. to_string(): Allows to explicitly convert from cstring_span to std::string
  914. to_string(): Allows to explicitly convert from wstring_span to std::wstring
  915. to_string(): Allows to explicitly convert from cwstring_span to std::wstring
  916. ensure_z(): Disallows to build a string_span from a const C-string
  917. ensure_z(): Disallows to build a wstring_span from a const wide C-string
  918. ensure_z(): Allows to build a string_span from a non-const C-string
  919. ensure_z(): Allows to build a cstring_span from a non-const C-string
  920. ensure_z(): Allows to build a cstring_span from a const C-string
  921. ensure_z(): Allows to build a wstring_span from a non-const wide C-string
  922. ensure_z(): Allows to build a cwstring_span from a non-const wide C-string
  923. ensure_z(): Allows to build a cwstring_span from a const wide C-string
  924. ensure_z(): Allows to specify ultimate location of the sentinel and ensure its presence
  925. operator<<: Allows printing a string_span to an output stream
  926. operator<<: Allows printing a cstring_span to an output stream
  927. operator<<: Allows printing a wstring_span to an output stream
  928. operator<<: Allows printing a cwstring_span to an output stream
  929. finally: Allows to run lambda on leaving scope
  930. finally: Allows to run function (bind) on leaving scope
  931. finally: Allows to run function (pointer) on leaving scope
  932. finally: Allows to move final_action
  933. on_return: Allows to perform action on leaving scope without exception (gsl_FEATURE_EXPERIMENTAL_RETURN_GUARD)
  934. on_error: Allows to perform action on leaving scope via an exception (gsl_FEATURE_EXPERIMENTAL_RETURN_GUARD)
  935. narrow_cast<>: Allows narrowing without value loss
  936. narrow_cast<>: Allows narrowing with value loss
  937. narrow<>(): Allows narrowing without value loss
  938. narrow<>(): Terminates when narrowing with value loss
  939. narrow<>(): Terminates when narrowing with sign loss
  940. narrow_failfast<>(): Allows narrowing without value loss
  941. narrow_failfast<>(): Terminates when narrowing with value loss
  942. narrow_failfast<>(): Terminates when narrowing with sign loss
  943. ```
  944. </p>
  945. </details>