"The GSL is the small set of types and aliases specified in these guidelines. At the time of writing, their specification herein is too sparse; we plan to add a WG21-style interface specification to ensure that different implementations agree, and to propose as a contribution for possible standardization, subject as usual to whatever the committee decides to accept/improve/alter/reject." – FAQ.50 of the C++ Core Guidelines.
Adding GSL in your makefile
Getting ready
Go to GitHub and go to the C++ Core Guideline document: http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines.
How to do it...
In this section, we'll integrate the Guideline Supporting Library (gsl) to a program by modifying a makefile:
- Download and copy a gsl implementation (for example, https://github.com/microsoft/GSL).
- Copy the gsl folder into your project.
- Add the include to the makefile: -I$HOME/dev/GSL/include.
- In your source file, include #include <gsl/gsl>.
The gsl currently provides the following:
- GSL.view
- GSL.owner
- GSL.assert: Assertions
- GSL.util: Utilities
- GSL.concept: Concepts
How it works...
You might have noticed that to get the gsl working, you just need to specify the header file folder path in the makefile, that is, -I$HOME/dev/GSL/include. Another detail to note is that no library is specified in the makefile.
This is because the whole implementation is provided inline in the header files under the gsl folder.
There's more...
The Microsoft GSL (http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines) is just one implementation maintained by Microsoft. You can find another implementation here: https://github.com/martinmoene/gsl-lite. Both implementations have been released under the MIT license type.
See also
The C++ Core Guidelines recipe of this chapter.