This is the C++11 fork of the GSL LIbrary, to make it compile for C++11 compilers.
Note that the CMakeList.txt needs to be adapted yet so that you will need to hack them :(
The fork adds a gsl_config.hpp file to manage with C++14 constexpr and the definition in stdex of some C++14 library missing in C++11.
The GSL sources have been modified taking in account the constexpr macro and the stdex features.
See also section GSL: Guideline support library of the C++ Core Guidelines [2].
V11-GSL means master branch of this fork viboes-GSL.
Feature / library | GSL | M-GSL | GSL-Lite | V11-GSL | Notes |
---|---|---|---|---|---|
1.Lifetime safety | |||||
1.1 Indirection | |||||
not_null<> | ✓ | ✓ | ✓ | ✓ | Wrap any indirection and enforce non-null |
maybe_null<> | - | ✓ | - | - | |
1.2 Ownership | |||||
owner<> | ✓ | ✓ | >=C++11 | ✓ | Owned raw pointers |
Owner() | - | - | ✓ | - | Macro for pre-C++11; |
unique_ptr<> | ✓ | ✓ | >=C++11 | ✓ | std::unique_ptr<> |
unique_ptr<> | - | - | < C++11 | - | VC10, VC11 |
shared_ptr<> | ✓ | ✓ | >=C++11 | ✓ | std::shared_ptr<> |
shared_ptr<> | - | - | < C++11 | - | VC10, VC11 |
stack_array<> | ✓ | - | - | - | A stack-allocated array, fixed size |
dyn_array<> | ? | - | - | - | A heap-allocated array, fixed size |
2.Bounds safety | |||||
2.1 Tag Types | |||||
zstring | ✓ | ✓ | ✓ | ✓ | a char* (C-style string) |
wzstring | - | ✓ | ✓ | ✓ | a wchar_t* (C-style string) |
czstring | ✓ | ✓ | ✓ | ✓ | a const char* (C-style string) |
cwzstring | - | ✓ | ✓ | ✓ | a const wchar_t* (C-style string) |
2.2 Views | |||||
span<> | ✓ | ✓ | 1D views | ✓ | A view of contiguous T's, replace (*,len) |
span_p<> | ✓ | - | - | - | A view of contiguous T's that ends at the first element for which predicate(*p) is true |
as_span() | - | ✓ | ✓ | ✓ | Create a span |
string_span | ✓ | ✓ | ✓ | ✓ | span<char> |
wstring_span | - | ✓ | ✓ | ✓ | span<wchar_t > |
cstring_span | ✓ | ✓ | ✓ | ✓ | span<const char> |
cwstring_span | - | ✓ | ✓ | ✓ | span<const wchar_t > |
ensure_z() | - | ✓ | ✓ | ✓ | Create a cstring_span or cwstring_span |
to_string() | - | ✓ | ✓ | ✓ | Convert a string_span to std::string or std::wstring |
2.3 Indexing | |||||
at() | ✓ | ✓ | >=C++11 | ✓ | Bounds-checked way of accessing static arrays, std::array, std::vector |
at() | - | - | < C++11 | - | static arrays, std::vector std::array : VC11 |
3. Assertions | |||||
Expects() | ✓ | ✓ | ✓ | ✓ | Precondition assertion |
Ensures() | ✓ | ✓ | ✓ | ✓ | Postcondition assertion |
4. Utilities | |||||
final_act<> | ✓ | ✓ | >=C++11 | ✓ | Action at the end of a scope |
final_act | - | - | < C++11 | ✓ | Currently only void(*)() |
finally() | ✓ | ✓ | >=C++11 | ✓ | Make a final_act<> |
finally() | - | - | < C++11 | ✓ | Make a final_act |
narrow_cast<> | ✓ | ✓ | ✓ | ✓ | Searchable narrowing casts of values |
narrow() | ✓ | ✓ | ✓ | ✓ | Checked version of narrow_cast() |
implicit | ✓ | - | ✓ | - | Symmetric with explicit |
move_owner | ? | - | - | - | ... |
5. Concepts | |||||
... |
The table below mentions the compiler versions viboes-GSL master is reported to work with.
OS | Compiler | Versions | Status | Language version |
---|---|---|---|---|
Windows | Clang/LLVM | ? | ✓ | ? |
GCC | ? | ✓ | ? | |
Visual C++ (Visual Studio) |
8 (2005), 10 (2010), 11 (2012), 12 (2013), 14 (2015) |
? | ? | |
GNU/Linux | Clang/LLVM | 3.4 | ? | ? |
GCC | 5.1 | ? | ? | |
OS X | Clang/LLVM | 3.7.0 | ✓ | -std=c++11 -std=c++14 -std=c++1z |
Clang/LLVM | 3.9.0 | ✓ | -std=c++11 -std=c++14 -std=c++1z | |
GCC | 5.2.0 | ✓ | -std=c++11 -std=c++14 -std=c++1z | |
GCC | 6.1.0 | ✓ | -std=c++11 -std=c++14 -std=c++1z |
- Microsoft. Guidelines Support Library (GSL).
- Microsoft. GSL Lite.
- Mattia Basaglia. CxxMiscLib gsl.hpp, tests.
#@ Notes and references
[1] Standard C++ Foundation.
[2] Standard C++ Foundation. C++ Core Guidelines.
[3] Microsoft. Guidelines Support Library (GSL).
[4] Bjarne Stroustrup. Writing good C++14 (PDF) — Video. CppCon 2015.
[5] Herb Sutter. Writing good C++14… By default (PDF) — Video. CppCon 2015.
[6] Gabriel Dos Reis. Contracts for Dependable C++ (PDF) — Video. CppCon 2015.
[7] Bjarne Stroustrup et al. A brief introduction to C++’s model for type- and resource-safety.
[8] Herb Sutter and Neil MacIntosh. Lifetime Safety: Preventing Leaks and Dangling. 21 Sep 2015.
Some useful links
[9] Brief documentation of GSL: Guideline support library.
[10] Talks and slides related to GSL and the C++ Core Guielines in particular:
[11] Evolving array_view and string_view for safe C++ code Video
The Guideline Support Library (GSL) contains functions and types that are suggested for use by the C++ Core Guidelines maintained by the Standard C++ Foundation. This repo contains Microsoft's implementation of GSL.
The library includes types like span<T>
, string_span
, owner<>
and others.
The entire implementation is provided inline in the headers under the gsl directory. The implementation generally assumes a platform that implements C++14 support. There are specific workarounds to support MSVC 2013 and 2015.
While some types have been broken out into their own headers (e.g. gsl/span), it is simplest to just include gsl/gsl and gain access to the entire library.
NOTE: We encourage contributions that improve or refine any of the types in this library as well as ports to other platforms. Please see CONTRIBUTING.md for more information about contributing.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.
The test suite that exercises GSL has been built and passes successfully on the following platforms:1)
- Windows using Visual Studio 2013
- Windows using Visual Studio 2015
- Windows using Visual Studio 2017
- Windows using Clang/LLVM 3.6
- Windows using GCC 5.1
- GNU/Linux using Clang/LLVM 3.6
- GNU/Linux using GCC 5.1
- OS X Yosemite using Xcode with AppleClang 7.0.0.7000072
- OS X Yosemite using GCC-5.2.0
- FreeBSD 10.x with Clang/LLVM 3.6
If you successfully port GSL to another platform, we would love to hear from you. Please submit an issue to let us know. Also please consider contributing any changes that were necessary back to this project to benefit the wider community.
1) For gsl::byte
to work correctly with Clang and GCC you might have to use the -fno-strict-aliasing
compiler option.
To build the tests, you will require the following:
- CMake, version 2.8.7 or later to be installed and in your PATH.
- UnitTest-cpp, to be cloned under the tests/unittest-cpp directory of your GSL source.
These steps assume the source code of this repository has been cloned into a directory named c:\GSL
.
-
Create a directory to contain the build outputs for a particular architecture (we name it c:\GSL\build-x86 in this example).
cd GSL md build-x86 cd build-x86
-
Configure CMake to use the compiler of your choice (you can see a list by running
cmake --help
).cmake -G "Visual Studio 14 2015" c:\GSL
-
Build the test suite (in this case, in the Debug configuration, Release is another good choice).
cmake --build . --config Debug
-
Run the test suite.
ctest -C Debug
All tests should pass - indicating your platform is fully supported and you are ready to use the GSL types!
As the types are entirely implemented inline in headers, there are no linking requirements.
You can copy the gsl directory into your source tree so it is available to your compiler, then include the appropriate headers in your program.
Alternatively set your compiler's include path flag to point to the GSL development folder (c:\GSL
in the example above) or installation folder (after running the install). Eg.
MSVC++
/I c:\GSL
GCC/clang
-I$HOME/dev/GSL
Include the library using:
#include <gsl/gsl>
<<<<<<< HEAD
=======
For Visual Studio users, the file GSL.natvis in the root directory of the repository can be added to your project if you would like more helpful visualization of GSL types in the Visual Studio debugger than would be offered by default.
96eaf274f8c57829080100f7cd1d2e7744bae1ae