Skip to content

C++ Core Guidelines # GSL: Guidelines support library

在阅读 hsutter/gcpp 的source code的时候,发现了其中使用了gsl。

Summary of GSL components:

1、GSL.view: Views

2、GSL.owner

3、GSL.assert: Assertions

4、GSL.util: Utilities

5、GSL.concept: Concepts

GSL.view: Views

These types allow the user to distinguish between owning and non-owning pointers and between pointers to a single object and pointers to the first element of a sequence.

NOTE:

一、"owning and non-owning pointers"告诉我们需要阐明清楚ownership,它的实现是通过gsl::owner来实现的。

二、"pointers to a single object and pointers to the first element of a sequence"告诉我们需要区分清楚range,它的实现主要是通过gsl::span

microsoft/GSL 中,"GSL.view: Views"包含的内容进行了梳理:

1. Views
owner an alias for a raw pointer
not_null restricts a pointer / smart pointer to hold non-null values
span a view over a contiguous sequence of memory. Based on the standardized verison of std::span, however gsl::span enforces bounds checking. See the wiki for additional information.
span_p spans a range starting from a pointer to the first place for which the predicate is true
basic_zstring A pointer to a C-string (zero-terminated array) with a templated char type
zstring An alias to basic_zstring with a char type of char
czstring An alias to basic_zstring with a char type of const char
wzstring An alias to basic_zstring with a char type of wchar_t
cwzstring An alias to basic_zstring with a char type of const wchar_t
u16zstring An alias to basic_zstring with a char type of char16_t
cu16zstring An alias to basic_zstring with a char type of const char16_t
u32zstring An alias to basic_zstring with a char type of char32_t
cu32zstring An alias to basic_zstring with a char type of const char32_t

TODO

stackoverflow What “are” the C++ GSL guidelines?

modernescpp C++ Core Guideline: The Guideline Support Library

gsl library implementation

gsl-lite

特点:

1、C++98、C++11

stackoverflow How can I use GSL with C++11 and the new STL?