gsl-lite – A single-file header-only version of ISO C++ Guidelines Support Library (GSL) for C++98, C++11, and later

Overview

gsl-lite: Guidelines Support Library for C++98, C++11 up

metadata build packages try online
Language
License
Version
Azure Pipelines build status
Travis build status
AppVeyor build status
Vcpkg
single header
Try it on Compiler Explorer
Try it on Wandbox

gsl-lite is an implementation of the C++ Core Guidelines Support Library originally based on Microsoft GSL.

Contents

Example usage

#include <gsl/gsl-lite.hpp>

int * use( gsl::not_null<int *> p ) 
{
    // use p knowing it's not nullptr, NULL or 0.
    return p;
}

struct Widget
{
    Widget() : owned_ptr_( new int(42) ) {}
    ~Widget() { delete owned_ptr_; }

    void work() { non_owned_ptr_ = use( owned_ptr_ ); }
    
    gsl::owner<int *> owned_ptr_;  // if alias template support
    int * non_owned_ptr_;
};

int main()
{
    Widget w;
    w.work();
}

In a nutshell

gsl-lite is a single-file header-only implementation of the C++ Core Guidelines Support Library originally based on Microsoft GSL and adapted for C++98, C++03. It also works when compiled as C++11, C++14, C++17, C++20.

The Guidelines Support Library (GSL) contains functions and types that are suggested for use by the C++ Core Guidelines maintained by the Standard C++ Foundation. The library includes types like owner<>, not_null<>, span<>, string_span and others.

gsl-lite recognizes when it is compiled for the CUDA platform and decorates some functions with __host__ and __device__. See also section API macro.

License

gsl-lite uses the MIT license.

Dependencies

gsl-lite has no other dependencies than the C++ standard library.

Installation and use

As CMake package

The recommended way to consume gsl-lite in your CMake project is to use find_package() and target_link_libraries():

cmake_minimum_required( VERSION 3.15 FATAL_ERROR )
    
find_package( gsl-lite 0.38 REQUIRED )
    
project( my-program LANGUAGES CXX )
    
add_executable( my-program main.cpp )
target_link_libraries( my-program PRIVATE gsl::gsl-lite-v1 )

There are different ways to make the gsl-lite package available to your project:

Using Vcpkg

  1. For the Vcpkg package manager, simply run Vcpkg's install command:

     vcpkg install gsl-lite
    
  2. Now, configure your project passing the Vcpkg toolchain file as a parameter:

     cd <my-program-source-dir>
     mkdir build
     cd build
     cmake -DCMAKE_TOOLCHAIN_FILE=<vcpkg-root>/scripts/buildsystems/vcpkg.cmake ..
     cmake --build ../build
    

Using an exported build directory

  1. Clone the gsl-lite repository and configure a build directory with CMake:

     git clone [email protected]:gsl-lite/gsl-lite.git <gsl-lite-source-dir>
     cd <gsl-lite-source-dir>
     mkdir build
     cd build
     cmake ..
    
  2. Now, configure your project passing the CMake build directory as a parameter:

     cd <my-program-source-dir>
     mkdir build
     cd build
     cmake -Dgsl-lite_DIR:PATH=<gsl-lite-source-dir>/build ..
     cmake --build ../build
    

    See example/cmake-pkg/Readme.md for a complete example.

Other options

gsl-lite is a header-only library; if you do not want to use the CMake package, or if you use a different build system, all you need to do is to add the "include" subdirectory of the gsl-lite source directory to your include path:

    git clone [email protected]:gsl-lite/gsl-lite.git <gsl-lite-source-dir>
    g++ -std=c++03 -I<gsl-lite-source-dir>/include main.cpp

gsl-lite is also a single-header library; if you want to avoid external dependencies, it suffices to copy the header file "include/gsl/gsl-lite.hpp" to a subdirectory of your project:

    git clone [email protected]:gsl-lite/gsl-lite.git <gsl-lite-source-dir>
    mkdir -p external/include/gsl
    cp <gsl-lite-source-dir>/include/gsl/gsl-lite.hpp external/include/gsl/
    
    g++ -std=c++03 -Iexternal/include main.cpp

Version semantics

gsl-lite strives to follow Semantic Versioning guidelines. Although we are still in the "initial development" stage (version 0.*), we generally maintain API and ABI compatibility and avoid breaking changes in minor and patch releases.

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 added since the last tagged release may be renamed, removed, have the semantics changed, etc. without further notice.

A minor-version release will be compatible (in both ABI and API) with the previous minor-version release (with rare exceptions while we're still in version 0.*). Thus, once a change is released, it becomes part of the API.

Some of the 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, 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.

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, a set of version-specific default options can be selected. Alternatively, when consuming gsl-lite as a CMake package, versioned defaults can be selected by linking to the target gsl::gsl-lite-v0 or gsl::gsl-lite-v1 rather than gsl::gsl-lite.

The following table gives an overview of the configuration options affected by versioned defaults:

Macro v0 default v1 default
gsl_FEATURE_OWNER_MACRO 1 0 an unprefixed macro Owner() may interfere with user code
gsl_FEATURE_GSL_LITE_NAMESPACE 0 1 cf. Using gsl-lite in libraries
gsl_CONFIG_DEPRECATE_TO_LEVEL 0 6
gsl_CONFIG_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
gsl_CONFIG_ALLOWS_SPAN_COMPARISON 1 0 C++20 std::span<> does not support comparison because semantics (deep vs. shallow) are unclear
gsl_CONFIG_NOT_NULL_EXPLICIT_CTOR 0 1 cf. reasoning in M-GSL/#395 (note that not_null<> in M-GSL has an implicit constructor, cf. M-GSL/#699)
gsl_CONFIG_TRANSPARENT_NOT_NULL 0 1 enables conformant behavior for not_null<>::get()
gsl_CONFIG_NARROW_THROWS_ON_TRUNCATION 0 1 enables conformant behavior for narrow<>() (cf. #52)

Note that the v1 defaults are not yet stable; future 0.* releases may introduce more configuration switches with different version-specific defaults.

Using gsl-lite in libraries

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. However, please mind the following considerations:

  • gsl-lite is an implementation of the Guidelines Support Library, which is not a library but a non-formal specification. There are other libraries implementing the GSL, most notably the Microsoft GSL (herein often referred to as "M-GSL"). Both libraries live in different headers and consist 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 both implementations take some liberties at interpreting and extending the specification (cf. e.g. #6, #52, #153). Also, the ABIs of gsl-lite and M-GSL are generally incompatible.

  • It is not clear whether the GSL specification envisions that multiple implementations of the specification should coexist (cf. CppCoreGuidelines/#1519), 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 an impediment for using either in a library because the library would thereby force its consumers to pick the same GSL implementation.

  • The API and ABI of gsl-lite can be altered by some of the configuration options. We consider the availability of these options a strength of gsl-lite, but the lack 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.

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

  • use version-1 defaults (cf. Version semantics)
  • include the new header <gsl-lite/gsl-lite.hpp> rather than <gsl/gsl-lite.hpp>
  • refer to the new namespace gsl_lite instead of namespace gsl (or define a namespace gsl = ::gsl_lite; alias in your own namespace)
  • use the prefixed contract checking macros gsl_Expects()/gsl_Ensures() rather than the unprefixed Expects()/Ensures()
    (M-GSL prefixes its macros with uppercase GSL_; we traditionally consider lowercase gsl_ the realm of gsl-lite)
  • avoid any changes to the configuration options

Example:

# my-statistics-lib/CMakeLists.txt
find_package( gsl-lite 0.38 REQUIRED )

add_library( my-statistics-lib STATIC mean.cpp )
target_link_libraries( my-statistics-lib PUBLIC gsl::gsl-lite-v1 )
// my-statistics-lib/include/my-statistics-lib/mean.hpp

#include <gsl-lite/gsl-lite.hpp>  // instead of <gsl/gsl-lite.hpp>

namespace my_statistics_lib {

    namespace gsl = ::gsl_lite; // convenience alias

    double mean( gsl::span<double const> elements )
    {
        gsl_Expects( !elements.empty() );  // instead of Expects()
        ...
    }

} // namespace my_statistics_lib

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 included. This way, any code that only uses the new header <gsl-lite/gsl-lite.hpp> will not risk collision with M-GSL.

Configuration options

Contents

API macro

gsl_api

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.

Standard selection macro

gsl_CPLUSPLUS

Define this macro to override the auto-detection of the supported C++ standard if your compiler does not set the __cplusplus macro correctly.

Feature selection macros

gsl_FEATURE_WITH_CONTAINER_TO_STD=99

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.

gsl_FEATURE_MAKE_SPAN_TO_STD=99

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.

gsl_FEATURE_BYTE_SPAN_TO_STD=99

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.

gsl_FEATURE_IMPLICIT_MACRO=0

Define this macro to 1 to provide the implicit macro. Default is 0.

gsl_FEATURE_OWNER_MACRO=1

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.

gsl_FEATURE_EXPERIMENTAL_RETURN_GUARD=0

Provide experimental types final_action_return and final_action_error and convenience functions on_return() and on_error(). Default is 0.

gsl_FEATURE_GSL_LITE_NAMESPACE=0

Define this to additionally define a namespace gsl_lite with most of the gsl-lite API available, cf. Using gsl-lite in libraries. Default is 0.

Contract checking configuration macros

gsl-lite provides contract violation response control as originally suggested in proposal N4415, with some refinements inspired by P1710/P1730.

There are several macros for expressing preconditions, postconditions, and invariants:

  • gsl_Expects( cond ) for simple preconditions
  • gsl_Ensures( cond ) for simple postconditions
  • gsl_Assert( cond ) for simple assertions
  • gsl_FailFast() to indicate unreachable code
  • gsl_ExpectsAudit( cond ) for preconditions that are expensive or include potentially opaque function calls
  • gsl_EnsuresAudit( cond ) for postconditions that are expensive or include potentially opaque function calls
  • gsl_AssertAudit( cond ) for assertions that are expensive or include potentially opaque function calls

The macros Expects() and Ensures() are also provided as aliases for gsl_Expects() and gsl_Ensures().

The following macros control whether contracts are checked at runtime:

  • gsl_CONFIG_CONTRACT_CHECKING_AUDIT
    Define this macro to have all contracts checked at runtime.

  • gsl_CONFIG_CONTRACT_CHECKING_ON (default)
    Define this macro to have contracts expressed with gsl_Expects(), gsl_Ensures(), gsl_Assert(), and gsl_FailFast() checked at runtime, and contracts expressed with gsl_ExpectsAudit(), gsl_EnsuresAudit(), and gsl_AssertAudit() not checked and not evaluated at runtime. This is the default.

  • gsl_CONFIG_CONTRACT_CHECKING_OFF
    Define this macro to disable all runtime checking of contracts and invariants. (Note that gsl_FailFast() checks will trigger runtime failure even if runtime checking is disabled.)

The following macros can be used to selectively disable checking for a particular kind of contract:

  • gsl_CONFIG_CONTRACT_CHECKING_EXPECTS_OFF
    Define this macro to disable runtime checking of precondition contracts expressed with gsl_Expects() and gsl_ExpectsAudit().

  • gsl_CONFIG_CONTRACT_CHECKING_ENSURES_OFF
    Define this macro to disable runtime checking of postcondition contracts expressed with gsl_Ensures() and gsl_EnsuresAudit().

  • gsl_CONFIG_CONTRACT_CHECKING_ASSERT_OFF
    Define this macro to disable runtime checking of assertions expressed with gsl_Assert() and gsl_AssertAudit().

The following macros control the handling of runtime contract violations:

  • gsl_CONFIG_CONTRACT_VIOLATION_TERMINATES (default)
    Define this macro to call std::terminate() on a GSL contract violation in gsl_Expects(), gsl_ExpectsAudit(), gsl_Ensures(), gsl_EnsuresAudit(), gsl_Assert(), gsl_AssertAudit(), and gsl_FailFast(). This is the default.

  • gsl_CONFIG_CONTRACT_VIOLATION_ASSERTS
    If this macro is defined, the assert() macro is used to check GSL contracts expressed with gsl_Expects(), gsl_ExpectsAudit(), gsl_Ensures(), gsl_EnsuresAudit(), gsl_Assert(), gsl_AssertAudit(), and gsl_FailFast(). (Note that gsl_FailFast() will call std::terminate() if NDEBUG is defined.)

  • gsl_CONFIG_CONTRACT_VIOLATION_TRAPS
    Define this macro to execute a trap instruction on a GSL contract violation in gsl_Expects(), gsl_ExpectsAudit(), gsl_Ensures(), gsl_EnsuresAudit(), gsl_Assert(), gsl_AssertAudit(), and gsl_FailFast().

  • gsl_CONFIG_CONTRACT_VIOLATION_THROWS
    Define this macro to throw a std::runtime_exception-derived exception gsl::fail_fast on a GSL contract violation in gsl_Expects(), gsl_ExpectsAudit(), gsl_Ensures(), gsl_EnsuresAudit(), gsl_Assert(), gsl_AssertAudit(), and gsl_FailFast().

  • gsl_CONFIG_CONTRACT_VIOLATION_CALLS_HANDLER
    Define this macro to call a user-defined handler function gsl::fail_fast_assert_handler() on a GSL contract violation in gsl_Expects(), gsl_ExpectsAudit(), gsl_Ensures(), gsl_EnsuresAudit(), gsl_Assert(), gsl_AssertAudit(), and gsl_FailFast(). The user must provide a definition of the following function:

    namespace gsl {
        gsl_api void fail_fast_assert_handler(
            char const * const expression, char const * const message,
            char const * const file, int line );
    }

Note that gsl_FailFast() will call std::terminate() if fail_fast_assert_handler() returns.

The following macros control what happens with contract checks not enforced at runtime:

  • gsl_CONFIG_UNENFORCED_CONTRACTS_ELIDE (default)
    Define this macro to disable all runtime checking and evaluation of unenforced contracts and invariants. (Note that gsl_FailFast() calls are never elided.) This is the default.

  • gsl_CONFIG_UNENFORCED_CONTRACTS_ASSUME
    Define this macro to let the compiler assume that contracts expressed with gsl_Expects(), gsl_Ensures(), and gsl_Assert() always hold true, and to have contracts expressed with gsl_ExpectsAudit(), gsl_EnsuresAudit(), and gsl_AssertAudit() 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.

Note that the distinction between regular and audit-level contracts is subtly different from the C++2a Contracts proposals. Defining gsl_CONFIG_UNENFORCED_CONTRACTS_ASSUME instructs the compiler that the conditions expressed by GSL 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 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 generate the runtime function call.

Therefore, gsl_Expects(), gsl_Ensures(), and gsl_Assert() should be used only for conditions that can be proven side-effect-free by the compiler, and gsl_ExpectsAudit(), gsl_EnsuresAudit(), and gsl_AssertAudit() for everything else. In practice, this implies that gsl_Expects(), gsl_Ensures(), and gsl_Assert() 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.

Example:

template< class RandomIt >
auto median( RandomIt first, RandomIt last )
{
        // Comparing iterators for equality boils down to a comparison of pointers. An optimizing
        // compiler will inline the comparison operator and understand that the comparison is free
        // of side-effects, and hence generate no code in gsl_CONFIG_UNENFORCED_CONTRACTS_ASSUME mode.
    gsl_Expects( first != last );

        // Verifying that a range of elements is sorted may be an expensive operation, and we
        // cannot trust the compiler to understand that it is free of side-effects, so we use an
        // audit-level contract check.
    gsl_ExpectsAudit( std::is_sorted( first, last ) );

    auto count = last - first;
    return count % 2 != 0
        ? first[ count / 2 ]
        : std::midpoint( first[ count / 2 ], first[ count / 2 + 1 ] );
}

Microsoft GSL compatibility macros

GSL_UNENFORCED_ON_CONTRACT_VIOLATION

Equivalent to defining gsl_CONFIG_CONTRACT_CHECKING_OFF.

GSL_TERMINATE_ON_CONTRACT_VIOLATION

Equivalent to defining gsl_CONFIG_CONTRACT_VIOLATION_TERMINATES.

GSL_THROW_ON_CONTRACT_VIOLATION

Equivalent to defining gsl_CONFIG_CONTRACT_VIOLATION_THROWS.

Other configuration macros

gsl_CONFIG_DEPRECATE_TO_LEVEL=0

Define this to and including the level you want deprecation; see table Deprecation below. Default is 0 for no deprecation.

gsl_CONFIG_SPAN_INDEX_TYPE=std::size_t

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.

gsl_CONFIG_INDEX_TYPE=gsl_CONFIG_SPAN_INDEX_TYPE

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.

gsl_CONFIG_NOT_NULL_EXPLICIT_CTOR=0

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<>.

gsl_CONFIG_TRANSPARENT_NOT_NULL=0

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.

gsl_CONFIG_NOT_NULL_GET_BY_CONST_REF=0

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 must not be defined if gsl_CONFIG_TRANSPARENT_NOT_NULL is 1. Default is 0 for T.

gsl_CONFIG_ALLOWS_SPAN_COMPARISON=1

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.

gsl_CONFIG_ALLOWS_NONSTRICT_SPAN_COMPARISON=1

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.

gsl_CONFIG_ALLOWS_UNCONSTRAINED_SPAN_CONTAINER_CTOR=0

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.

Note: an alternative is to use the constructor tagged with_container: span<V> s(gsl::with_container, cont).

gsl_CONFIG_NARROW_THROWS_ON_TRUNCATION=0

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.

gsl_CONFIG_CONFIRMS_COMPILATION_ERRORS=0

Define this macro to 1 to experience the by-design compile-time errors of the GSL components in the test suite. Default is 0.

Features

See also section GSL: Guidelines Support Library of the C++ Core Guidelines [9].

Feature / library GSL M-GSL gsl-lite Notes
1.Lifetime safety        
1.1 Indirection        
not_null<> Wrap any indirection and enforce non-null,
see also Other configuration macros
not_null_ic<> - - not_null with implicit constructor, allowing copy-initialization
1.2 Ownership        
owner<> ≥ C++11 Owned raw pointers
Owner() - - Macro for pre-C++11;
see also Feature selection macros
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),
see also proposal p0122
span_p<> - - A view of contiguous T's that ends at the first element for which predicate(*p) is true
make_span() - Create a span
byte_span() - - Create a span of bytes from a single object
as_bytes() - A span as bytes
as_writable_bytes - A span as writable bytes
basic_string_span<> - See also proposal p0123
string_span basic_string_span< char >
wstring_span - basic_string_span< wchar_t >
cstring_span basic_string_span< const char >
cwstring_span - basic_string_span< const wchar_t >
zstring_span - basic_zstring_span< char >
wzstring_span - basic_zstring_span< wchar_t >
czstring_span - basic_zstring_span< const char >
cwzstring_span - basic_zstring_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
gsl_Expects() - - Precondition assertion
gsl_Ensures() - - Postcondition assertion
gsl_Assert() - - Assertion
gsl_FailFast() - - Fail-fast termination
gsl_ExpectsAudit() - - Audit-level precondition assertion
gsl_EnsuresAudit() - - Audit-level postcondition assertion
gsl_AssertAudit() - - Audit-level assertion
4. Utilities        
index type for container indexes and subscripts,
see Other configuration macros
dim - - type for container sizes
stride - - type for index strides
diff - - type for index differences
byte - byte type, see also proposal p0298
final_action<> ≥ C++11 Action at the end of a scope
final_action - - < C++11 Currently only void(*)()
finally() ≥ C++11 Make a final_action<>
finally() - - < C++11 Make a final_action
final_action_return - - < C++11 Currently only void(*)(), experimental
on_return() - - ≥ C++11 Make a `final_action_return<>, experimental
on_return() - - < C++11 Make a `final_action_return, experimental
final_action_error - - < C++11 Currently only void(*)(), experimental
on_error() - - ≥ C++11 Make a final_action_error<>, experimental
on_error() - - < C++11 Make a final_action_error, experimental
narrow_cast<> Searchable narrowing casts of values
narrow<>() Checked narrowing cast
narrow_failfast<>() - - Fail-fast narrowing cast
[[implicit]] - C++?? Symmetric with explicit
implicit - - Macro, see Feature selection macros
move_owner ? - - ...
5. Algorithms        
copy()       Copy from source span to destination span
size()       Size of span, unsigned
ssize()       Size of span, signed
6. Concepts        
...        

Note: gsl-lite treats VC12 (VS2013) and VC14 (VS2015) as C++11 (gsl_CPP11_OR_GREATER: 1).

Deprecation

The following features are deprecated since the indicated version. See macro gsl_CONFIG_DEPRECATE_TO_LEVEL on how to control deprecation using the indicated level.

Version Level Feature / Notes
0.37.0 6 as_writeable_bytes(), call indexing for spans, and span::at()
    Use as_writable_bytes(), subscript indexing
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
    Use gsl_CONFIG_CONTRACT_CHECKING_ON, gsl_CONFIG_CONTRACT_CHECKING_OFF, gsl_CONFIG_CONTRACT_CHECKING_ENSURES_OFF, gsl_CONFIG_CONTRACT_CHECKING_EXPECTS_OFF
0.31.0 5 span( std::nullptr_t, index_type )
    span( pointer, index_type ) is used
0.31.0 5 span( U *, index_type size )
    span( pointer, index_type ) is used
0.31.0 5 span( U (&arr)[N] )
    span( element_type (&arr)[N] ) is used
0.31.0 5 span( std::array< U, N > [const] & arr )
    span( std::array< value_type, N > [const] & arr ) is used
0.29.0 4 span( std::shared_ptr<T> const & p )
   
0.29.0 4 span( std::unique_ptr<T> const & p )
   
0.29.0 3 span<>::length()
    Use span<>::size()
0.29.0 3 span<>::length_bytes()
    Use span<>::size_bytes()
0.17.0 2 member span<>::as_bytes(), span<>::as_writeable_bytes()
   
0.7.0 - gsl_CONFIG_ALLOWS_SPAN_CONTAINER_CTOR
    Use gsl_CONFIG_ALLOWS_UNCONSTRAINED_SPAN_CONTAINER_CTOR,
or consider span(with_container, cont).

Reported to work with

The table below mentions the compiler versions and platforms gsl-lite is reported to work with.

Compiler OS Platforms Versions CI
GCC Linux x64 4.7 and newer 4.7, 4.8, 4.9, 5, 6, 7, 8, 9, 10
GCC (MinGW) Windows x86, x64 4.8.4 and newer
GCC (DJGPP) DOSBox, FreeDOS x86 7.2
GCC MacOS x64 6 and newer 6, 7, 8, 9, 10
Clang Linux x64 3.5 and newer 3.5, 3.6, 3.7, 3.8, 3.9, 4, 5, 6, 7, 8, 9, 10, 11
Clang with libstdc++ Linux x64 11 11
Clang Windows x64 version shipped with VS 2019 latest
MSVC (Visual Studio) Windows x86, x64 VS 2010 and newer VS 2010, 2012, 2013, 2015, 2017, 2019
AppleClang (Xcode) MacOS x64 7.3 and newer 7.3, 8, 8.1, 9, 9.1, 10, 10.0.1, 11, 11.0.3, 12
NVCC (CUDA Toolkit) Linux, Windows x64 10.2 and newer 10.2, 11.2
ARMCC ARM 5 and newer

Building the tests

To build the tests:

The lest test framework is included in the test folder.

The following steps assume that the gsl-lite source code has been cloned into a directory named C:\gsl-lite.

  1. Create a directory for the build outputs.
    Here we use C:\gsl-lite\build.

     cd C:\gsl-lite
     mkdir build
     cd build
    
  2. Configure the build directory with CMake:

     cmake -DGSL_LITE_OPT_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Debug ..
    
  3. Build the test suite:

     cmake --build . --config Debug
    
  4. Run the test suite:

     ctest -V -C Debug
    

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.

Other GSL implementations

Notes and references

Proposals, specification

[1] std::span<> on cppreference.
[2] std::span<> in C++20 Working Draft.
[3] P0091 - Template argument deduction for class templates.
[4] P0122 - span: bounds-safe views for sequences of objects.
[5] P0123 - string_span: bounds-safe views for sequences of characters.
[6] P0298 - A byte type definition.
[7] P0805 - Comparing Containers.

Articles

[8] Standard C++ Foundation.
[9] Standard C++ Foundation. C++ Core Guidelines.
[10] Microsoft. Guidelines Support Library (GSL).
[11] Bjarne Stroustrup. Writing good C++14 (PDF)Video. CppCon 2015.
[12] Herb Sutter. Writing good C++14… By default (PDF)Video. CppCon 2015.
[13] Gabriel Dos Reis. Contracts for Dependable C++ (PDF) — Video. CppCon 2015.
[14] Bjarne Stroustrup et al. A brief introduction to C++’s model for type- and resource-safety.
[15] Herb Sutter and Neil MacIntosh. Lifetime Safety: Preventing Leaks and Dangling. 21 Sep 2015.

Compiler feature testing

[16] cppreference.com. Feature testing.

C++ features in various compilers

[17] cppreference.com. C++ compiler support.

Appendix

A.1 Compile-time information

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].

A.2 gsl-lite test specification

click to expand

gsl_Expects(): Allows a true expression
gsl_Ensures(): Allows a true expression
gsl_Assert(): Allows a true expression
gsl_Expects(): Terminates on a false expression
gsl_Ensures(): Terminates on a false expression
gsl_Assert(): Terminates on a false expression
gsl_FailFast(): Suppresses compiler warning about missing return value
gsl_FailFast(): Terminates
gsl_ExpectsAudit(): Allows a true expression
gsl_EnsuresAudit(): Allows a true expression
gsl_AssertAudit(): Allows a true expression
gsl_ExpectsAudit(): Terminates on a false expression in AUDIT mode
gsl_EnsuresAudit(): Terminates on a false expression in AUDIT mode
gsl_AssertAudit(): Terminates on a false expression in AUDIT mode
gsl_Expects(): No warnings produced for function calls in precondition checks
gsl_Expects(): Supports explicit conversions to bool
at(): Terminates access to non-existing C-array elements
at(): Terminates access to non-existing std::array elements (C++11)
at(): Terminates access to non-existing std::vector elements
at(): Terminates access to non-existing std::initializer_list elements (C++11)
at(): Terminates access to non-existing gsl::span elements
at(): Allows to access existing C-array elements
at(): Allows to access existing std::array elements (C++11)
at(): Allows to access existing std::vector elements
at(): Allows to access std::initializer_list elements (C++11)
at(): Allows to access gsl::span elements
byte: Allows to construct from integral via static cast (C++17)
byte: Allows to construct from integral via byte() (C++17)
byte: Allows to construct from integral via to_byte()
byte: Allows to convert to integral via to_integer()
byte: Allows comparison operations
byte: Allows bitwise or operation
byte: Allows bitwise and operation
byte: Allows bitwise x-or operation
byte: Allows bitwise or assignment
byte: Allows bitwise and assignment
byte: Allows bitwise x-or assignment
byte: Allows shift-left operation
byte: Allows shift-right operation
byte: Allows shift-left assignment
byte: Allows shift-right assignment
byte: Provides constexpr non-assignment operations (C++11)
byte: Provides constexpr assignment operations (C++14)
byte: Provides hash support (C++11)
equal()
lexicographical_compare()
conjunction<> and disjunction<>: Short-circuiting is handled correctly
conjunction<> and disjunction<>: First suitable type is chosen as base
span<>: free comparation functions fail for different const-ness [issue #32]
span<>: constrained container constructor suffers hard failure for arguments with reference-returning data() function [issue #242]
byte: aliasing rules lead to undefined behaviour when using enum class [issue #34](GSL issue #313, PR #390)
string_span<>: must not include terminating '\0' [issue #53]
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]
narrow<>(): Allows narrowing double to float without MSVC level 4 warning C4127: conditional expression is constant [issue #115]
detail::is_compatible_container<>: Not a proper type trait [PR #238]
not_null<>: Disallows default construction (define gsl_CONFIG_CONFIRMS_COMPILATION_ERRORS)
not_null<>: Disallows construction from nullptr_t, NULL or 0 (define gsl_CONFIG_CONFIRMS_COMPILATION_ERRORS)
not_null<>: Disallows construction from a unique pointer to underlying type (define gsl_CONFIG_CONFIRMS_COMPILATION_ERRORS)
not_null<>: Layout is compatible to underlying type
not_null<>: Convertibility is correctly reported by type traits
not_null<>: Copyability and assignability are correctly reported by type traits
not_null<>: Disallows assignment from unrelated pointers (define gsl_CONFIG_CONFIRMS_COMPILATION_ERRORS)
not_null<>: Terminates construction from a null pointer value (raw pointer)
not_null<>: Terminates construction from related pointer types for null pointer value (raw pointer)
not_null<>: Terminates assignment from a null pointer value (raw pointer)
not_null<>: Terminates assignment from related pointer types for null pointer value (raw pointer)
not_null<>: Allows to construct from a non-null underlying pointer (raw pointer)
not_null<>: Returns underlying pointer with get() (raw pointer)
not_null<>: Allows to construct from a non-null underlying pointer (raw pointer) with make_not_null()
not_null<>: Allows to construct from a non-null underlying pointer (raw pointer) with deduction guide
not_null<>: Allows to construct a const pointer from a non-null underlying pointer (raw pointer)
not_null<>: Converts to underlying pointer (raw pointer)
as_nullable: Converts to underlying pointer (raw pointer)
not_null<>: Allows to construct from a non-null related pointer (raw pointer)
not_null<>: Allows to construct a const pointer from a non-null related pointer (raw pointer)
not_null<>: Allows to construct from a not_null related pointer type (raw pointer)
not_null<>: Allows to construct a const pointer from a not_null related pointer type (raw pointer)
not_null<>: Converts to a related pointer (raw pointer)
as_nullable: Converts to a related pointer (raw pointer)
not_null<>: Allows assignment from a not_null related pointer type (raw pointer)
not_null<>: Allows assignment to a const pointer from a not_null related pointer type (raw pointer)
not_null<>: Allows indirect member access (raw pointer)
not_null<>: Allows dereferencing (raw pointer)
not_null<>: Terminates swap of a moved-from value (shared_ptr)
not_null<>: Tolerates self-move-assignment of a moved-from value (shared_ptr)
not_null<>: Terminates self-swap of a moved-from value (shared_ptr)
not_null<>: Terminates construction from a null pointer value (shared_ptr)
not_null<>: Terminates construction from related pointer types for null pointer value (shared_ptr)
not_null<>: Terminates assignment from a null pointer value (shared_ptr)
not_null<>: Terminates assignment from related pointer types for null pointer value (shared_ptr)
not_null<>: Terminates propagation of a moved-from value (shared_ptr)
not_null<>: Allows self-swap (shared_ptr)
not_null<>: Allows swap (shared_ptr)
not_null<>: Allows to construct from a non-null underlying pointer (shared_ptr)
not_null<>: Allows to construct from a non-null raw pointer with explicit conversion (shared_ptr)
not_null<>: Returns underlying pointer or raw pointer with get() (shared_ptr)
not_null<>: Allows to move from a not_null pointer to an underlying pointer (shared_ptr)
as_nullable: Allows to move from a not_null pointer to an underlying pointer (shared_ptr)
not_null<>: Allows to construct from a non-null underlying pointer (shared_ptr) with make_not_null()
not_null<>: Allows to construct from a non-null underlying pointer (shared_ptr) with deduction guide
not_null<>: Allows to construct a const pointer from a non-null underlying pointer (shared_ptr)
not_null<>: Converts to underlying pointer (shared_ptr)
as_nullable: Converts to underlying pointer (shared_ptr)
as_nullable: Terminates for moved-from pointer (shared_ptr)
not_null<>: Allows to construct from a non-null related pointer (shared_ptr)
not_null<>: Allows to construct a const pointer from a non-null related pointer (shared_ptr)
not_null<>: Allows to construct from a not_null related pointer type (shared_ptr)
not_null<>: Allows to construct a const pointer from a not_null related pointer type (shared_ptr)
not_null<>: Converts to a related pointer (shared_ptr)
as_nullable: Converts to a related pointer (shared_ptr)
not_null<>: Allows assignment from a not_null related pointer type (shared_ptr)
not_null<>: Allows assignment to a const pointer from a not_null related pointer type (shared_ptr)
not_null<>: Allows indirect member access (shared_ptr)
not_null<>: Allows dereferencing (shared_ptr)
not_null<>: Terminates swap of a moved-from value (unique_ptr)
not_null<>: Tolerates self-move-assignment of a moved-from value (unique_ptr)
not_null<>: Terminates self-swap of a moved-from value (unique_ptr)
not_null<>: Terminates construction from a null pointer value (unique_ptr)
not_null<>: Terminates construction from related pointer types for null pointer value (unique_ptr)
not_null<>: Terminates assignment from a null pointer value (unique_ptr)
not_null<>: Terminates assignment from related pointer types for null pointer value (unique_ptr)
not_null<>: Terminates propagation of a moved-from value (unique_ptr)
not_null<>: Allows self-swap (unique_ptr)
not_null<>: Allows swap (unique_ptr)
not_null<>: Allows to construct from a non-null underlying pointer (unique_ptr)
not_null<>: Allows to construct from a non-null raw pointer with explicit conversion (unique_ptr)
not_null<>: Returns underlying pointer or raw pointer with get() (unique_ptr)
not_null<>: Allows to move from a not_null pointer to an underlying pointer (unique_ptr)
as_nullable: Allows to move from a not_null pointer to an underlying pointer (unique_ptr)
not_null<>: Allows to move to a related pointer from a not_null pointer (unique_ptr)
as_nullable: Allows to move to a related pointer from a not_null pointer (unique_ptr)
not_null<>: Allows to construct from a non-null underlying pointer (unique_ptr) with make_not_null()
not_null<>: Allows to construct from a non-null underlying pointer (unique_ptr) with deduction guide
not_null<>: Allows to construct a const pointer from a non-null underlying pointer (unique_ptr)
not_null<>: Converts to underlying pointer (unique_ptr)
as_nullable: Converts to underlying pointer (unique_ptr)
as_nullable: Terminates for moved-from pointer (unique_ptr)
not_null<>: Allows to construct from a non-null related pointer (unique_ptr)
not_null<>: Allows to construct a const pointer from a non-null related pointer (unique_ptr)
not_null<>: Allows to construct from a not_null related pointer type (unique_ptr)
not_null<>: Allows to construct a const pointer from a not_null related pointer type (unique_ptr)
not_null<>: Converts to a related pointer (unique_ptr)
as_nullable: Converts to a related pointer (unique_ptr)
not_null<>: Allows assignment from a not_null related pointer type (unique_ptr)
not_null<>: Allows assignment to a const pointer from a not_null related pointer type (unique_ptr)
not_null<>: Allows indirect member access (unique_ptr)
not_null<>: Allows dereferencing (unique_ptr)
not_null<>: Allows to construct a not_null<shared_ptr<T>> from a non-null unique_ptr<T>
not_null<>: Allows to construct a not_null<shared_ptr<const T>> from a non-null unique_ptr<T>
not_null<>: Allows to construct a not_null<shared_ptr<T>> from a related non-null unique_ptr<U>
not_null<>: Allows to construct a not_null<shared_ptr<const T>> from a related non-null unique_ptr<U>
not_null<>: Allows to construct a not_null<shared_ptr<T>> from a not_null<unique_ptr<T>>
not_null<>: Allows to construct a not_null<shared_ptr<const T>> from a not_null<unique_ptr<T>>
not_null<>: Allows to construct a not_null<shared_ptr<T>> from a related not_null<unique_ptr<U>>
not_null<>: Allows to construct a not_null<shared_ptr<const T>> from a related not_null<unique_ptr<U>>
not_null<>: Allows assignment to a not_null<shared_ptr<T>> from a related not_null<unique_ptr<U>>
not_null<>: Allows assignment to a not_null<shared_ptr<const T>> from a related not_null<unique_ptr<U>>
not_null<>: Allows assignment from a non-null bare recast pointer
not_null<>: Allows implicit conversion to underlying type
not_null<>: Allows to construct from a non-null user-defined ref-counted type
not_null<>: Allows to compare equal to another not_null of the same type
not_null<>: Allows to compare unequal to another not_null of the same type
not_null<>: Allows to compare less than another not_null of the same type
not_null<>: Allows to compare less than or equal to another not_null of the same type
not_null<>: Allows to compare greater than another not_null of the same type
not_null<>: Allows to compare greater than or equal to another not_null of the same type
not_null<>: Allows to compare equal to a raw pointer of the same type
not_null<>: Allows to compare unequal to a raw pointer of the same type
not_null<>: Allows to compare less than a raw pointer of the same type
not_null<>: Allows to compare less than or equal to a raw pointer of the same type
not_null<>: Allows to compare greater than a raw pointer of the same type
not_null<>: Allows to compare greater than or equal to a raw pointer of the same type
not_null<>: Able to deduce element_type of raw pointers
not_null<>: Able to deduce element_type of unique_ptr
not_null<>: Able to deduce element_type of shared_ptr
not_null<>: Able to deduce element_type of normal user-defined smart pointers
not_null<>: Able to correctly deduce element_type of user-defined smart pointers even if typedef and result of dereferencing differs
not_null<>: Able to deduce element_type of user-defined smart pointers even if they do not have an element_type typedef
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
not_null<>: Hashes match the hashes of the wrapped pointer
not_null<>: Hash functor disabled for non-hashable pointers and enabled for hashable pointers
owner<>: Disallows construction from a non-pointer type (define gsl_CONFIG_CONFIRMS_COMPILATION_ERRORS)
owner<>: Allows its use as the (pointer) type it stands for
Owner(): Allows its use as the (pointer) type it stands for
span<>: Disallows construction from a temporary value (C++11) (define gsl_CONFIG_CONFIRMS_COMPILATION_ERRORS)
span<>: Disallows construction from a C-array of incompatible type (define gsl_CONFIG_CONFIRMS_COMPILATION_ERRORS)
span<>: Disallows construction from a std::array of incompatible type (C++11) (define gsl_CONFIG_CONFIRMS_COMPILATION_ERRORS)
span<>: Terminates construction from a nullptr and a non-zero size (C++11)
span<>: Terminates construction from two pointers in the wrong order
span<>: Terminates construction from a null pointer and a non-zero size
span<>: Terminates creation of a sub span of the first n elements for n exceeding the span
span<>: Terminates creation of a sub span of the last n elements for n exceeding the span
span<>: Terminates creation of a sub span outside the span
span<>: Terminates access outside the span
span<>: Terminates access with front() and back() on empty span
span<>: Allows to default-construct
span<>: Allows to construct from a nullptr and a zero size (C++11)
span<>: Allows to construct from a single object (C++11)
span<>: Allows to construct from a const single object (C++11)
span<>: Allows to construct from two pointers
span<>: Allows to construct from two pointers to const
span<>: Allows to construct from a non-null pointer and a size
span<>: Allows to construct from a non-null pointer to const and a size
span<>: Allows to construct from a temporary pointer and a size
span<>: Allows to construct from a temporary pointer to const and a size
span<>: Allows to construct from any pointer and a zero size
span<>: Allows to construct from a C-array
span<>: Allows to construct from a const C-array
span<>: Allows to construct from a C-array with size via decay to pointer (potentially dangerous)
span<>: Allows to construct from a const C-array with size via decay to pointer (potentially dangerous)
span<>: Allows to construct from a std::initializer_list<> (C++11)
span<>: Allows to construct from a std::array<> (C++11)
span<>: Allows constexpr use (C++14)
span<>: Allows to construct from a std::array<> with const data (C++11) [deprecated-5]
span<>: Allows to construct from a container (std::vector<>)
span<>: Allows to construct from a temporary container (potentially dangerous)
span<>: Allows to tag-construct from a container (std::vector<>)
span<>: Allows to tag-construct from a temporary container (potentially dangerous)
span<>: Allows to construct from an empty gsl::shared_ptr (C++11) [deprecated-4]
span<>: Allows to construct from an empty gsl::unique_ptr (C++11) [deprecated-4]
span<>: Allows to construct from an empty gsl::unique_ptr (array, C++11) [deprecated-4]
span<>: Allows to construct from a non-empty gsl::shared_ptr (C++11) [deprecated-4]
span<>: Allows to construct from a non-empty gsl::unique_ptr (C++11) [deprecated-4]
span<>: Allows to construct from a non-empty gsl::unique_ptr (array, C++11) [deprecated-4]
span<>: Allows to default construct in a constexpr context
span<>: Allows to copy-construct from another span of the same type
span<>: Allows to copy-construct from another span of a compatible type
span<>: Allows to move-construct from another span of the same type (C++11)
span<>: Allows to copy-assign from another span of the same type
span<>: Allows to move-assign from another span of the same type (C++11)
span<>: Allows to create a sub span of the first n elements
span<>: Allows to create a sub span of the last n elements
span<>: Allows to create a sub span starting at a given offset
span<>: Allows to create a sub span starting at a given offset with a given length
span<>: Allows to create an empty sub span at full offset
span<>: Allows to create an empty sub span at full offset with zero length
span<>: Allows forward iteration
span<>: Allows const forward iteration
span<>: Allows reverse iteration
span<>: Allows const reverse iteration
span<>: Allows to observe an element via array indexing
span<>: Allows to observe an element via front() and back()
span<>: Allows to observe an element via data()
span<>: Allows to change an element via array indexing
span<>: Allows to change an element via front() and back()
span<>: Allows to change an element via data()
span<>: Allows to test for empty span via empty(), empty case
span<>: Allows to test for empty span via empty(), non-empty case
span<>: Allows to obtain the number of elements via size(), as configured
span<>: Allows to obtain the number of elements via ssize(), signed
span<>: Allows to obtain the number of elements via length() [deprecated-3]
span<>: Allows to obtain the number of bytes via size_bytes()
span<>: Allows to obtain the number of bytes via length_bytes() [deprecated-3]
span<>: Allows to swap with another span of the same type
span<>: Allows to view the elements as read-only bytes [deprecated-2 as member]
span<>: Allows to view and change the elements as writable bytes [deprecated-2 as member]
span<>: Allows to view the elements as a span of another type
span<>: Allows to change the elements from a span of another type
copy(): Allows to copy a span to another span of the same element type
copy(): Allows to copy a span to another span of a different element type
size(): Allows to obtain the number of elements in span via size(span), unsigned
ssize(): Allows to obtain the number of elements in span via ssize(span), signed
make_span(): (gsl_FEATURE_MAKE_SPAN=1)
make_span(): Allows to build from two pointers
make_span(): Allows to build from two const pointers
make_span(): Allows to build from a non-null pointer and a size
make_span(): Allows to build from a non-null const pointer and a size
make_span(): Allows to build from a C-array
make_span(): Allows to build from a const C-array
make_span(): Allows building from a std::initializer_list<> (C++11)
make_span(): Allows to build from a std::array<> (C++11)
make_span(): Allows to build from a const std::array<> (C++11)
make_span(): Allows to build from a container (std::vector<>)
make_span(): Allows to build from a const container (std::vector<>)
make_span(): Allows to build from a temporary container (potentially dangerous)
make_span(): Allows to tag-build from a container (std::vector<>)
make_span(): Allows to tag-build from a temporary container (potentially dangerous)
make_span(): Allows to build from an empty gsl::shared_ptr (C++11) [deprecated-4]
make_span(): Allows to build from an empty gsl::unique_ptr (C++11) [deprecated-4]
make_span(): Allows to build from an empty gsl::unique_ptr (array, C++11) [deprecated-4]
make_span(): Allows to build from a non-empty gsl::shared_ptr (C++11) [deprecated-4]
make_span(): Allows to build from a non-empty gsl::unique_ptr (C++11) [deprecated-4]
make_span(): Allows to build from a non-empty gsl::unique_ptr (array, C++11) [deprecated-4]
byte_span() (gsl_FEATURE_BYTE_SPAN=1)
byte_span(): Allows to build a span of gsl::byte from a single object
byte_span(): Allows to build a span of const gsl::byte from a single const object
string_span: Disallows construction of a string_span from a cstring_span (define gsl_CONFIG_CONFIRMS_COMPILATION_ERRORS)
string_span: Disallows construction of a string_span from a const std::string (define gsl_CONFIG_CONFIRMS_COMPILATION_ERRORS)
string_span: Allows to default-construct
string_span: Allows to construct from a nullptr (C++11)
string_span: Allows to construct a cstring_span from a const C-string
string_span: Allows to construct a string_span from a non-const C-string and size
string_span: Allows to construct a string_span from a non-const C-string begin and end pointer
string_span: Allows to construct a string_span from a non-const C-array
string_span: Allows to construct a string_span from a non-const std::string
string_span: Allows to construct a string_span from a non-const std::array (C++11)
string_span: Allows to construct a string_span from a non-const container (std::vector)
string_span: Allows to construct a string_span from a non-const container, via a tag (std::vector)
string_span: Allows to construct a cstring_span from a non-const C-string and size
string_span: Allows to construct a cstring_span from a non-const C-string begin and end pointer
string_span: Allows to construct a cstring_span from a non-const C-array
string_span: Allows to construct a cstring_span from a non-const std::string
string_span: Allows to construct a cstring_span from a non-const std::array (C++11)
string_span: Allows to construct a cstring_span from a non-const container (std::vector)
string_span: Allows to construct a cstring_span from a non-const container, via a tag (std::vector)
string_span: Allows to construct a cstring_span from a const C-string and size
string_span: Allows to construct a cstring_span from a non-const C-string begin and end pointer
string_span: Allows to construct a cstring_span from a const C-array
string_span: Allows to construct a cstring_span from a const std::string
string_span: Allows to construct a cstring_span from a const std::array (C++11)
string_span: Allows to construct a cstring_span from a const container (std::vector)
string_span: Allows to construct a cstring_span from a const container, via a tag (std::vector)
string_span: Allows to construct a wstring_span from a non-const C-string and size
string_span: Allows to construct a wstring_span from a non-const C-string begin and end pointer
string_span: Allows to construct a wstring_span from a non-const C-array
string_span: Allows to construct a wstring_span from a non-const std::wstring
string_span: Allows to construct a wstring_span from a non-const std::array (C++11)
string_span: Allows to construct a wstring_span from a non-const container (std::vector)
string_span: Allows to construct a wstring_span from a non-const container, via a tag (std::vector)
string_span: Allows to construct a cwstring_span from a non-const C-string and size
string_span: Allows to construct a cwstring_span from a non-const C-string begin and end pointer
string_span: Allows to construct a cwstring_span from a non-const C-array
string_span: Allows to construct a cwstring_span from a non-const std::wstring
string_span: Allows to construct a cwstring_span from a non-const std::array (C++11)
string_span: Allows to construct a cwstring_span from a non-const container (std::vector)
string_span: Allows to construct a cwstring_span from a non-const container, via a tag (std::vector)
string_span: Allows to construct a cwstring_span from a const C-string and size
string_span: Allows to construct a cwstring_span from a const C-string begin and end pointer
string_span: Allows to construct a cwstring_span from a const C-array
string_span: Allows to construct a cwstring_span from a const std::wstring
string_span: Allows to construct a cwstring_span from a const std::array (C++11)
string_span: Allows to construct a cwstring_span from a const container (std::vector)
string_span: Allows to construct a cwstring_span from a const container, via a tag (std::vector)
string_span: Allows to copy-construct from another span of the same type
string_span: Allows to copy-construct from another span of a compatible type
string_span: Allows to move-construct from another span of the same type (C++11)
string_span: Allows to copy-assign from another span of the same type
string_span: Allows to move-assign from another span of the same type (C++11)
string_span: Allows to create a sub span of the first n elements
string_span: Allows to create a sub span of the last n elements
string_span: Allows to create a sub span starting at a given offset
string_span: Allows to create a sub span starting at a given offset with a given length
string_span: Allows to create an empty sub span at full offset
string_span: Allows to create an empty sub span at full offset with zero length
string_span: Allows forward iteration
string_span: Allows const forward iteration
string_span: Allows reverse iteration
string_span: Allows const reverse iteration
string_span: Allows to observe an element via array indexing
string_span: Allows to observe an element via front() and back()
string_span: Allows to observe an element via data()
string_span: Allows to change an element via array indexing
string_span: Allows to change an element via front() and back()
string_span: Allows to change an element via data()
string_span: Allows to compare a string_span with another string_span
string_span: Allows to compare empty span to non-empty span
string_span: Allows to compare a string_span with a cstring_span
string_span: Allows to compare with types convertible to string_span
string_span: Allows to test for empty span via empty(), empty case
string_span: Allows to test for empty span via empty(), non-empty case
string_span: Allows to obtain the number of elements via length()
string_span: Allows to obtain the number of elements via size()
string_span: Allows to obtain the number of bytes via length_bytes()
string_span: Allows to obtain the number of bytes via size_bytes()
string_span: Allows to view the elements as read-only bytes
zstring_span: Terminates construction of a zstring_span from an empty span
zstring_span: Allows to construct a zstring_span from a zero-terminated empty string (via span)
zstring_span: Allows to construct a zstring_span from a zero-terminated non-empty string (via span)
zstring_span: Terminates construction of a zstring_span from a non-zero-terminated string (via span)
zstring_span: Terminates construction of a wzstring_span from an empty span
zstring_span: Allows to construct a wzstring_span from a zero-terminated empty string (via span)
zstring_span: Allows to construct a wzstring_span from a zero-terminated non-empty string (via span)
zstring_span: Terminates construction of a wzstring_span from a non-zero-terminated string (via span)
zstring_span: Allows to use a zstring_span with a legacy API via member assume_z()
zstring_span: Allows to use a wzstring_span with a legacy API via member assume_z()
to_string(): Allows to explicitly convert from string_span to std::string
to_string(): Allows to explicitly convert from cstring_span to std::string
to_string(): Allows to explicitly convert from wstring_span to std::wstring
to_string(): Allows to explicitly convert from cwstring_span to std::wstring
ensure_z(): Disallows to build a string_span from a const C-string
ensure_z(): Disallows to build a wstring_span from a const wide C-string
ensure_z(): Allows to build a string_span from a non-const C-string
ensure_z(): Allows to build a cstring_span from a non-const C-string
ensure_z(): Allows to build a cstring_span from a const C-string
ensure_z(): Allows to build a wstring_span from a non-const wide C-string
ensure_z(): Allows to build a cwstring_span from a non-const wide C-string
ensure_z(): Allows to build a cwstring_span from a const wide C-string
ensure_z(): Allows to specify ultimate location of the sentinel and ensure its presence
operator<<: Allows printing a string_span to an output stream
operator<<: Allows printing a cstring_span to an output stream
operator<<: Allows printing a wstring_span to an output stream
operator<<: Allows printing a cwstring_span to an output stream
finally: Allows to run lambda on leaving scope
finally: Allows to run function (bind) on leaving scope
finally: Allows to run function (pointer) on leaving scope
finally: Allows to move final_action
on_return: Allows to perform action on leaving scope without exception (gsl_FEATURE_EXPERIMENTAL_RETURN_GUARD)
on_error: Allows to perform action on leaving scope via an exception (gsl_FEATURE_EXPERIMENTAL_RETURN_GUARD)
narrow_cast<>: Allows narrowing without value loss
narrow_cast<>: Allows narrowing with value loss
narrow<>(): Allows narrowing without value loss
narrow<>(): Terminates when narrowing with value loss
narrow<>(): Terminates when narrowing with sign loss
narrow_failfast<>(): Allows narrowing without value loss
narrow_failfast<>(): Terminates when narrowing with value loss
narrow_failfast<>(): Terminates when narrowing with sign loss
CUDA: Precondition/postcondition checks and assertions can be used in kernel code
CUDA: span<> can be passed to kernel code
CUDA: span<> can be used in kernel code
CUDA: not_null<> can be passed to and used in kernel code
CUDA: gsl_FailFast() can be used in kernel code

Comments
  • gsl_CONFIG_DEFAULTS_VERSION=1 does not compile without exceptions

    gsl_CONFIG_DEFAULTS_VERSION=1 does not compile without exceptions

    1. gsl::narrow is defined only if we have exception support, or gsl_CONFIG_NARROW_THROWS_ON_TRUNCATION is set to 0. (See discussion in issue #52)
    2. gsl_CONFIG_DEFAULTS_VERSION=1 turns on gsl_CONFIG_NARROW_THROWS_ON_TRUNCATION

    This means gsl::narrow will not be defined in this case. However, the gsl_lite namespace unconditionally imports gsl::narrow, resulting in a compile error.

    My proposed solution is to give a name to gsl_HAVE( EXCEPTIONS ) || !gsl_CONFIG_NARROW_THROWS_ON_TRUNCATION and use that to conditionally compile both gsl::narrow's and gsl_lite::narrow's definitions, but I do not know which prefix I should use - is it a gsl_CONFIG, a gsl_FEATURE, or something else?

    I think @martinmoene migth be able to help me with this.

    opened by petamas 15
  • Comparison operator on string_spans - null-terminated and otherwise.

    Comparison operator on string_spans - null-terminated and otherwise.

    While testing migrating my project from Microsoft's GSL to GSL-Lite, my tests started failing when doing string_span comparisons. This was because some string_spans were null-terminated, some were not.

    Is it intended behaviour for string_spans which are identical other than one being null-terminated to be considered different?

    I have been experimenting with adding an option for special string_span comparison operators that ignore the last element of the operands if they are equal to `'\0' - do you think this is a good approach?

    My additions can be seen on my fork.

    Thank you!

    resolved 
    opened by Magnutic 15
  • Fix awkward issues in `not_null<>` introduced in #202; add tests

    Fix awkward issues in `not_null<>` introduced in #202; add tests

    • get() should not need function ref qualifiers
    • get() should return a plain pointer
    • operator->() can safely return T const & in all cases
    • operator*() should always return element_type &

    Thanks to @petamas for feedback.

    opened by mbeutel 11
  • Fix issue #129: not_null<unique_ptr<T>> is now working as expected

    Fix issue #129: not_null> is now working as expected

    Also:

    • unit tests from earlier PRs #176 and #192 are added to README (along with tests added in this one)
    • fixed -Wunnamed-type-template-args warnings introduced in PR #192
    opened by petamas 11
  • Fix `not_null_ic` copy construction

    Fix `not_null_ic` copy construction

    Without this change, copy construction caused infinite recursion.

    Reproduction including a hacked-in toggle between old and new behavior: https://godbolt.org/z/o9W19o9nh.

    opened by runer112 10
  • Basic NVHPC compiler support.

    Basic NVHPC compiler support.

    gsl-lite does not work out of the box with the NVHPC compilers on my system:

    "include/gsl/gsl-lite.hpp", line 1394: error: identifier "__ORDER_LITTLE_ENDIAN__" is undefined
          little = __ORDER_LITTLE_ENDIAN__,
                   ^
    
    "include/gsl/gsl-lite.hpp", line 1395: error: identifier "__ORDER_BIG_ENDIAN__" is undefined
          big    = __ORDER_BIG_ENDIAN__,
                   ^
    
    "include/gsl/gsl-lite.hpp", line 1396: error: identifier "__BYTE_ORDER__" is undefined
          native = __BYTE_ORDER__
                   ^
    

    This is a minimal patch to recognise the NVHPC compilers as distinct from GCC and assume little-endian order for them.

    I tried to build and run the full set of gsl-lite tests and examples; there were no errors but a few warnings are repeated many times. For example:

    "gsl-lite/test/not_null.t.cpp", line 694: warning: variable "<unnamed>::__lest_registrar__694" was declared but never referenced
      CASE( "not_null<>: Allows to construct a const pointer from a not_null related pointer type (shared_ptr)" )
      ^
    
    opened by olupton 10
  • ssize has not been declared in std

    ssize has not been declared in std

    quickcpplib/include/quickcpplib/gsl-lite/include/gsl/gsl-lite.hpp:984:12: error: ‘ssize’ has not been declared in ‘std’
      984 | using std::ssize;
          |            ^~~~~
    

    Cause:

    #define gsl_HAVE_STD_SSIZE              ( gsl_COMPILER_GNUC_VERSION >= 1000 )
    

    However ssize() is a C++ 20 only feature, not a GCC 10 feature. So this is the wrong check to do.

    opened by ned14 10
  • Should `not_null<>` provide `reset()`, `release()`? Should they be SFINAE-transparent?

    Should `not_null<>` provide `reset()`, `release()`? Should they be SFINAE-transparent?

    not_null<T> aims to be a transparent replacement for the underlying pointer-like type T. Does that mean we should also provide "forwarders" for typical smart-pointer member functions such as release() and reset(), similar to get() which we already provide?

    Another question is whether we want not_null<> to be SFINAE-transparent too, i.e. if calling .release() on a not_null<std::shared_ptr<>> would be a substitution failure. Then we'd have to do gymnastics like

        template < class U = T >
        decltype( std::declval<U>().release() )
        release() { ... }
    
    opened by mbeutel 10
  • Decorate function signatures to support use in CUDA code

    Decorate function signatures to support use in CUDA code

    When compiling GPU code using the CUDA framework, one needs to designate whether a function or a method is to be used on the "host" (the system's main CPU(s) and RAM) or on the "device" (the GPU card). This is done by prepending __host__ and/or __device__ to the declaration.

    By default, code is host-only, thus gsl-lite cannot be used in GPU device code. However, it would be very easy (AFAICT) to make gsl-lite CUDA compatible:

    #ifdef __CUDACC__
    #define CUDA_DESIGNATOR __host__ __device__
    #ifdef Expects
    #undef Expects
    #undef Ensures
    #define Expects(x)
    #define Ensures(x)
    #endif
    #else /* non-CUDA code */
    #define CUDA_DESIGNATOR
    #ifndef Expects
    #define Expects(x)  ::gsl::fail_fast_assert((x))
    #define Ensures(x)  ::gsl::fail_fast_assert((x))
    #endif
    #endif
    

    and then prepending the function and member function definitions with CUDA_DESIGNATOR. It might even be the case that you don't need to get rid of the fail_fast_assert(), but I'm not sure about that.

    There should be no impact on anything at all, i.e. this is a safe change.

    I would very much like to see this committed (for use with my DBMS-oriented CUDA kernel tester, which will soon be sporting a modified version version of gsl-lite as per the above.)

    enhancement 
    opened by eyalroz 10
  • Fix GCC12 dangling pointer error in tests

    Fix GCC12 dangling pointer error in tests

    On GCC 12 (pre-release), this fixes:

    [ 46%] Building CXX object test/CMakeFiles/gsl-lite-v0-cpp20.t.dir/issue.t.cpp.o
    cd /builddir/build/BUILD/gsl-lite-0.40.0/redhat-linux-build/test && /usr/bin/g++ -Dgsl_CONFIG_CONTRACT_CHECKING_AUDIT -Dgsl_CONFIG_CONTRACT_VIOLATION_THROWS -Dgsl_CONFIG_UNENFORCED_CONTRACTS_ELIDE -Dgsl_TESTING_ -I/builddir/build/BUILD/gsl-lite-0.40.0/include -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64  -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -Werror -Wall -Wextra -Wconversion -Wsign-conversion -fno-elide-constructors -fstrict-aliasing -Wstrict-aliasing=2 -pedantic -Wno-long-long -Wno-error=array-bounds -std=c++20 -Winvalid-pch -include /builddir/build/BUILD/gsl-lite-0.40.0/redhat-linux-build/test/CMakeFiles/gsl-lite-v0-cpp20.t.dir/cmake_pch.hxx -MD -MT test/CMakeFiles/gsl-lite-v0-cpp20.t.dir/issue.t.cpp.o -MF CMakeFiles/gsl-lite-v0-cpp20.t.dir/issue.t.cpp.o.d -o CMakeFiles/gsl-lite-v0-cpp20.t.dir/issue.t.cpp.o -c /builddir/build/BUILD/gsl-lite-0.40.0/test/issue.t.cpp
    In file included from /builddir/build/BUILD/gsl-lite-0.40.0/test/gsl-lite.t.hpp:38,
                     from /builddir/build/BUILD/gsl-lite-0.40.0/redhat-linux-build/test/CMakeFiles/gsl-lite-v1-no-exc-cpp98.t.dir/cmake_pch.hxx:5,
                     from <command-line>:
    In member function 'gsl::span<int const>::operator=(gsl::span<int const>)',
        inlined from 'use_span_with_array(int const (&) [3], gsl::span<int const>)' at /builddir/build/BUILD/gsl-lite-0.40.0/test/span.t.cpp:404:10:
    /builddir/build/BUILD/gsl-lite-0.40.0/include/gsl/gsl-lite.hpp:3882:15: error: storing the address of local variable 'array2' in 'sp_6(D)->last_' [-Werror=dangling-pointer=]
     3882 |         last_ = other.last_;
          |         ~~~~~~^~~~~~~~~~~~~
    /builddir/build/BUILD/gsl-lite-0.40.0/test/span.t.cpp: In function 'use_span_with_array(int const (&) [3], gsl::span<int const>)':
    /builddir/build/BUILD/gsl-lite-0.40.0/test/span.t.cpp:402:9: note: 'array2' declared here
      402 |     int array2[3] = { 0, 0, 0 };
          |         ^~~~~~
    /builddir/build/BUILD/gsl-lite-0.40.0/test/span.t.cpp:402:9: note: 'sp_6(D)' declared here
    

    It looks like the dangling pointer would never be dereferenced in practice, but this patch eliminates the compiler error by copying the span and restoring it at the end of use_span_with_array so the local stack pointer cannot leak to the caller.

    opened by musicinmybrain 9
  • not_null<T> construction from T: is the

    not_null construction from T: is the "explicit" constructor explicit enough?

    Problem statement

    Last year, I described Dropbox nn's constructor this way (see my comment in issue #200):

    • it does not have an nn(T) constructor
    • it does have an i_promise_i_checked_for_null_t tag type
    • it does have an nn(i_promise_i_checked_for_null_t, T) constructor
    • you're urged to create some macro named NN_CHECK (or any name you want to use, like CHECK_NOT_NULL), which checks for null, does whatever error handling you want to if the pointer is null, then calls the tagged constructor

    This way, you must be pretty explicit about creating nn objects, but I think it's not much safer to use that version than ours (only advantage is that you can't construct an nn "by accident", using static_casts and such).

    Since then, I have revised my opinion: I think it would be better if you couldn't create a not_null from a nullable without explicitly calling make_not_null. The following is the description of the evolution of my company's codebase, highlighting the problem with our current (explicit) constructor, then my proposed solution.

    Case study

    Original code

    We had several old, pre-C++11 factory methods:

    gsl::owner<Thing1*> createThing1(); // never returns NULL
    gsl::owner<Thing2*> createThing2(); // never returns NULL
    gsl::owner<Thing3*> createThing3(); // my return NULL based on configuration
    

    The client code used std::auto_ptr to manage the memory:

    std::auto_ptr<Thing1> thing1(createThing1());
    std::auto_ptr<Thing2> thing2(createThing2());
    std::auto_ptr<Thing3> thing3(createThing3());
    

    Introducing unique_ptr

    After migrating to C++11, we changed our auto_ptrs to unique_ptrs, an made our factory methods return unique_ptr:

    std::unique_ptr<Thing1> createThing1(); // never returns nullptr
    std::unique_ptr<Thing2> createThing2(); // never returns nullptr
    std::unique_ptr<Thing3> createThing3(); // may return nullptr based on configuration
    // ...
    std::unique_ptr<Thing1> thing1(createThing1());
    std::unique_ptr<Thing2> thing2(createThing2());
    std::unique_ptr<Thing3> thing3(createThing3());
    

    Note that we did the auto_ptr->unique_ptr rather mindlessly, not changing the syntax in the client apart from changing the smart pointer's name.

    Introducing not_null

    When not_null became able to handle unique_ptr, we changed the return type of the factory functions to nn_unique_ptr<T> (i.e. gsl::not_null<std::unique_ptr<T>>):

    nn_unique_ptr<Thing1> createThing1(); // never returns nullptr
    nn_unique_ptr<Thing2> createThing2(); // never returns nullptr
    std::unique_ptr<Thing3> createThing3(); // my return nullptr based on configuration
    // ...
    nn_unique_ptr<Thing1> thing1(createThing1());
    nn_unique_ptr<Thing2> thing2(createThing2());
    nn_unique_ptr<Thing3> thing3(createThing3()); // !!! oooops !!!
    

    During this transition, we made a mistake, and changed the type of thing3 even though it should have been left as a plain old unique_ptr. The above code compiled without errors, and the mistake was only discovered during testing, when createThing3() was configured to return nullptr.

    Proposed solution

    The events described above led me to believe that not_null<T> should not have a converting constructor from T or any other nullable types; the conversion should always be done via explicitly calling make_not_null(). In that case, nn_unique_ptr<Thing3> thing3(createThing3()); would result in a compile-time error instead of a run-time error.

    This could be achieved by stealing the idea from Dropbox nn, and giving it our own spin:

    • make the T->not_null<T> constructor private, and give it a tag argument
    • make make_not_null() a friend of not_null

    This way, only make_not_null() could be used to create not_nulls, while not impacting the converting constructors between different not_null instantiations. Coupled with my proposal in issue #253, it would mean the only transition between nullable- and not_null-land would be through the two named functions make_not_null and as_nullable, making everything explicit and (mostly) mistake-free.

    opened by petamas 9
  • Add tests for `not_null_ic<>`

    Add tests for `not_null_ic<>`

    We have a lot of tests for not_null<> but no test coverage for not_null_ic<>, which seems like an afterthought. We really should add some tests, otherwise people will keep running into embarassing basic issues as in #326.

    opened by mbeutel 0
  • including gsl-lite triggers `-Wuseless-cast` warnings

    including gsl-lite triggers `-Wuseless-cast` warnings

    As mentioned in my comment in #321 we use cmake fetchContent to include gsl-lite, which introduces some warnings into our compilations that we would like to get rid of to switch to using -Werror and have cleaner log output. Since gsl-lite is a non-direct dependency for us, i'm really not familiar with it and could not really determine, if this is something that can be fixed or masked in gsl-lite. The compiler we use is GCC 11.2.0.

    These 4 are triggered for each compilation unit that somewhere includes gsl-lite.

    ./build/_deps/gsl-lite-src/include/gsl/gsl-lite.hpp: In function ‘std::string gsl::to_string(const string_span&)’:
    ./build/_deps/gsl-lite-src/include/gsl/gsl-lite.hpp:4972:37: warning: useless cast to type ‘std::size_t’ {aka ‘long unsigned int’} [-Wuseless-cast]
     4972 |     return std::string( spn.data(), static_cast<std::size_t>( spn.length() ) );
          |                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ./build/_deps/gsl-lite-src/include/gsl/gsl-lite.hpp: In function ‘std::string gsl::to_string(const cstring_span&)’:
    ./build/_deps/gsl-lite-src/include/gsl/gsl-lite.hpp:4978:37: warning: useless cast to type ‘std::size_t’ {aka ‘long unsigned int’} [-Wuseless-cast]
     4978 |     return std::string( spn.data(), static_cast<std::size_t>( spn.length() ) );
          |                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ./build/_deps/gsl-lite-src/include/gsl/gsl-lite.hpp: In function ‘std::wstring gsl::to_string(const wstring_span&)’:
    ./build/_deps/gsl-lite-src/include/gsl/gsl-lite.hpp:4986:38: warning: useless cast to type ‘std::size_t’ {aka ‘long unsigned int’} [-Wuseless-cast]
     4986 |     return std::wstring( spn.data(), static_cast<std::size_t>( spn.length() ) );
          |                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ./build/_deps/gsl-lite-src/include/gsl/gsl-lite.hpp: In function ‘std::wstring gsl::to_string(const cwstring_span&)’:
    ./build/_deps/gsl-lite-src/include/gsl/gsl-lite.hpp:4992:38: warning: useless cast to type ‘std::size_t’ {aka ‘long unsigned int’} [-Wuseless-cast]
     4992 |     return std::wstring( spn.data(), static_cast<std::size_t>( spn.length() ) );
    

    If you need more information please let me know.

    opened by wirew0rm 1
  • Definition of `fail_fast` and of `narrowing_error` triggers `clang`'s `-Wweak-vtables`

    Definition of `fail_fast` and of `narrowing_error` triggers `clang`'s `-Wweak-vtables`

    As fail_fast and narrowing_error are deriving from std::logic_error and from std::exception respectively, they both have a vtable. In a header-only library there is no compilation unit, which implies the vtables are emitted in every client compilation unit, putting burden to the linker to understand this is not a duplicate definition. That is what the warning is about.

    Solution

    • Disable the warning locally.

    Alternatives:

    • introduce a compilation unit (NO because: header-only is wanted)
    • do not use a custom exception (NO because: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#e14-use-purpose-designed-user-defined-types-as-exceptions-not-built-in-types)
    • introduce template<typename = void> fail_fast ... and throw fail_fast<> (NO because: Introduces complexity to hide a warning is never a good idea.)
    • disable all warnings (NO because: 1. Unclear how that would even work if header is copied by clients. 2. Warnings are friends.)

    References:

    • See https://github.com/mrahn/test_gsl_lite_weak_vtables for a reproducer (which is basically: include the header with -Wweak-vtables on)
    • See https://github.com/gsl-lite/gsl-lite/pull/321 for a workaround that disables all warnings for the gsl-lite header
    opened by mrahn 1
  • Migrate Travis CI jobs to other CI provider

    Migrate Travis CI jobs to other CI provider

    Travis CI has recently changed their pricing policy:
    https://blog.travis-ci.com/2020-11-02-travis-ci-new-billing

    As a consequence, OSS projects have up to "10000 credits" per month. I just ran into that limit, so our CI platform/compiler coverage will be impacted in the next month. Fortunately, we use Travis only for ancient GCC/Clang/AppleClang versions, so users with reasonably modern toolchains should not be affected.

    I'd like to migrate away from Travis CI so we don't run into this limit again. Some of the jobs (ancient GCC and Clang on Linux) can probably be migrated to Azure Pipelines with relatively low effort. But I have no idea what to do about ancient Xcode versions which Azure Pipelines doesn't support anymore. Perhaps we just drop support?

    opened by mbeutel 0
  • basic_zstring_span::empty() returns false for an empty string

    basic_zstring_span::empty() returns false for an empty string

    https://github.com/gsl-lite/gsl-lite/blob/503b14bdd1cfa9a797dc3dddab6baac7e13504bf/include/gsl/gsl-lite.hpp#L4309

    Since basic_zstring_span operates on a null terminated strings then the basic_zstring_span::empty() should return true for span_.size() <= 1; since the span of "" has the size of 1.

    You have this logic here: https://github.com/gsl-lite/gsl-lite/blob/503b14bdd1cfa9a797dc3dddab6baac7e13504bf/include/gsl/gsl-lite.hpp#L4317 https://github.com/gsl-lite/gsl-lite/blob/503b14bdd1cfa9a797dc3dddab6baac7e13504bf/include/gsl/gsl-lite.hpp#L4324 https://github.com/gsl-lite/gsl-lite/blob/503b14bdd1cfa9a797dc3dddab6baac7e13504bf/include/gsl/gsl-lite.hpp#L4295

    opened by travnick 8
Releases(v0.40.0)
  • v0.40.0(Nov 4, 2021)

    Additions:

    • Add debug-mode contract checking macros gsl_ExpectsDebug(), gsl_EnsuresDebug(), gsl_AssertDebug() which are sensitive to the NDEBUG macro, and thus similar to assert() (#316)
    • Add dedicated contract check configuration macros for device code: gsl_CONFIG_DEVICE_CONTRACT_CHECKING_AUDIT/ON/OFF, gsl_CONFIG_DEVICE_CONTRACT_VIOLATION_ASSERTS/TRAPS/CALLS_HANDLER, and gsl_CONFIG_DEVICE_UNENFORCED_CONTRACTS_ASSUME/ELIDE (#317)
    • Add gsl::is_valid() for explicitly detecting the moved-from state of a gsl::not_null<> object (#318)
    • Add device code detection macro gsl_DEVICE_CODE (evaluates to 1 when compiling CUDA device code, 0 when compiling host code)

    Changes:

    • Continuous Integration now also tests Clang 13 and updates CUDA version to 11.5
    • Improve documentation for contract checking macros and configuration macros

    Fixes:

    • Check for gsl:: target rather than nonexistent gsl-lite:: target in Config.cmake (#315, thanks to @Ram-Z)
    Source code(tar.gz)
    Source code(zip)
  • v0.39.0(Sep 29, 2021)

    Additions:

    • Add gsl::make_unique<T>() and gsl::make_shared<T>() which resemble the eponymous functions from std but return gsl::not_null<std::unique_ptr<T>> and gsl::not_null<std::shared_ptr<T>> (#312)
    • Add basic support for NVHPC compiler (#308, thanks to @olupton)

    Changes:

    • Continuous Integration now also tests GCC 11, Clang 12, and AppleClang 12.0.5 and 13, and updates CUDA version to 11.4 (#314)
    • Remove C++98 polyfills std98::equal(), std98::lexicographical_compare() from public interface (#313)

    Fixes:

    • gsl::not_null<std::shared_ptr<T>> now correctly converts to std::weak_ptr<T> (#311, thanks to @stohrendorf)
    Source code(tar.gz)
    Source code(zip)
  • v0.38.1(Apr 22, 2021)

    Additions:

    • Add feature detection macro gsl_HAVE( C99_PREPROCESSOR )
    • Add gsl_CONSTRAINT() which can be used to impose concept requirements on template type parameters in a backward-compatible manner: template< gsl_CONSTRAINT(Concept) T > expands to template< Concept T > for C++20 and to template< typename T > otherwise
    • Add C++20 polyfill std20::endian() (#305)
    • Restore Continuous Integration testing for NVCC 10.2
    • Add basic CUDA runtime tests to test suite (#307)

    Changes:

    • Continuous Integration now also tests "RelWithDebInfo" configuration for select compilers and platforms

    Fixes:

    • Fix regression in precondition/postcondition/assertion checks for CUDA (cf. #302, thanks to @Spielix)
    • Add workaround for GCC bug to test suite (cf. #303, thanks to @sanjayankur31)
    • Fix endianness issues in test suite (cf. #304, thanks to @sanjayankur31)
    • Improve constexpr support for span<>; add constexpr tests (#306)
    Source code(tar.gz)
    Source code(zip)
  • v0.38.0(Mar 31, 2021)

    Additions:

    • Add macros gsl_Assert(), gsl_AssertAudit() to express checks which are neither pre- nor postconditions (#294)
    • Add fail-fast operation gsl_FailFast() which is guaranteed to terminate normal execution in some way (exception, std::terminate(), or trap instruction) (#294)
    • Add configuration option gsl_CONFIG_CONTRACT_VIOLATION_TRAPS which makes gsl_Expects()/gsl_Ensures()/gsl_Assert() (and the Audit variants if audit mode is enabled) and gsl_FailFast() execute a trap instruction in case of a contract violation
    • Add configuration option gsl_CONFIG_CONTRACT_VIOLATION_ASSERTS which implements gsl_Expects()/gsl_Ensures()/gsl_Assert() (and the Audit variants if audit mode is enabled) in terms of the assert() macro from the standard library. This has the benefits that both legacy assertions and contract checks can be globally suppressed with a single macro (NDEBUG), and that assert() prints an informative error message which contains the contract check expression.
    • Add as_nullable() function (#251, thanks to @petamas)
    • Add compiler detection macro for NVCC (#294)
    • Add compiler detection macro and tentative support (no CI) for ARMCC (#293; thanks to @woodsking2)
    • Add conditional std::hash<> specialization for not_null<> (#297; thanks to @mbs-c)
    • Track language and library versions separately; new macros gsl_STDLIB_CPPxx_OR_GREATER indicate availability of the standard library
    • Add feature detection macros gsl_HAVE( HASH ), gsl_HAVE( MOVE_FORWARD ), gsl_HAVE( OVERRIDE_FINAL )
    • Add size_type to span<> and basic_string_span<>
    • Add Continuous Integration testing for NVCC 11.0-11.2 (CUDA14, CUDA17), Clang 10-11, GCC 10, Apple Clang 12.0.0
    • Add Continuous Integration testing for Clang with libstdc++
    • Add Valgrind "memcheck" run to Continuous Integration
    • Add testing for more configuration scenarios, e.g. building with exceptions disabled and using different ways of precondition violation handling

    Changes:

    • Remove dependency on standard library headers <algorithm> and <iterator> (#290, #295; thanks to @mpusz)
    • Use of gsl_HAVE(), gsl_CONFIG(), gsl_FEATURE() with unknown arguments now causes compilation errors (#272)
    • narrow<>() now issues a static_assert() that refers to narrow_failfast<>() if exceptions are unavailable (#269)
    • With version-1 defaults, not_null<> now has a specialization for raw pointers which avoids unnecessary contract checks (#300)
    • The contract expression is now part of the exception message in gsl_CONFIG_CONTRACT_VIOLATION_THROWS mode
    • narrowing_error now produces a less unhelpful exception message ("narrowing_error")
    • gsl_noexcept now falls back to throw() if noexcept is unavailable
    • Most symbols are now accessible through both namespace gsl and namespace gsl_lite to ease migration
    • not_null_ic<> is now also visible in namespace gsl_lite (#280; thanks to @woodsking2)
    • nullptr_t comparison operators for not_null<> are now explicitly deleted
    • More uses of gsl_NODISCARD throughout the library
    • For NVCC ≥11.3, make use of new __builtin_unreachable() intrinsic in gsl_CONFIG_UNENFORCED_CONTRACTS_ASSUME mode

    Fixes:

    • Many bugfixes (#249, #250, #255, #256, #262, #263, #268, #270, #271, #286, #287, #292; thanks to @fodinabor, @KazDragon, @martinmoene, @Maximus5, @Pesa, @petamas, @travnick)
    Source code(tar.gz)
    Source code(zip)
  • v0.37.0(Jul 28, 2020)

    Additions:

    Changes:

    • Rename as_writeable_bytes() -> as_writable_bytes() to follow C++20 in spelling; the old name is still provided for compatibility
    • Rename gsl_DEPRECATED() -> gsl_DEPRECATED_MSG(), add gsl_DEPRECATED
    • Add more gsl_DEPRECATED() annotations
    • Deprecate span<>::at(), basic_string_span<>::at(), and call indexing
    • Minor documentation improvements
    • Unify internal SFINAE macros to gsl_ENABLE_IF_() (#238; thanks to @martinmoene)
    • Add more comprehensive tests for narrow<>() and narrow_failfast<>()

    Fixes:

    • Fix spurious static assertion for pre-/postcondition check arguments explicitly convertible to bool if gsl_CONFIG_CONTRACT_CHECKING_OFF is defined
    • Fix hard failure in span<> constrained constructor (#242, thanks to @orangeturtle739)
    • Make gsl::detail::is_compatible_container<> a proper type trait
    Source code(tar.gz)
    Source code(zip)
  • 0.37.0(May 14, 2020)

  • v0.36.0(Jan 24, 2020)

    The repository now moved to a dedicated GitHub organization: https://github.com/gsl-lite/gsl-lite

    gsl-lite is now mostly maintained by @mbeutel (#175).

    Additions:

    Changes:

    • not_null<> now properly supports smart pointers (#184, #197; huge thanks to @petamas)
    • Restructure contract checking configuration macros such that checking policy (off, on, audit), violation handling (throws, terminates, calls handler) and unenforced contract handling (assume, elide) can be configured independently (cf. https://github.com/martinmoene/gsl-lite/#contract-violation-response-macros)
    • gsl_noexcept no longer depends on contract violation settings (cf. https://github.com/martinmoene/gsl-lite/commit/0c296a9c986ac070997610fc7cf86e9c517558bf)
    • gsl_FEATURE_IMPLICIT_MACRO now defaults to 0 (#156, thanks to @tadeu)
    • AppleClang is now considered a separate compiler (use gsl_COMPILER_APPLECLANG_VERSION for checking)
    • CMake installs arch-independent by default
    • CMake doesn't install M-GSL compatibility header <gsl/gsl> and legacy headers <gsl.h>, <gsl.hpp>, and <gsl/gsl-lite.h> by default
    • gsl-lite now compiles warning-free with MSVC at warning level 4
    • Many small improvements (thanks to @AraHaan, @codecircuit, @elnull, @ilyalesokhin-starkware, @ngrodzitski, @petamas, @stohrendorf, @theodelrieu)
    Source code(tar.gz)
    Source code(zip)
  • v0.34.0(Mar 21, 2019)

    This release of gsl lite changes the CMake package folder name to gsl-lite (it was gsl) and it adds a usage description for the Conda package manager to the Readme.

    Further macro gsl_REQUIRES_T() was introduced (nonstd lite issue 18) and the lest test framework has been updated to v1.35.1

    Source code(tar.gz)
    Source code(zip)
  • v0.33.0(Mar 8, 2019)

    This release of gsl lite has changes that originate from the nonstd-lite project and quite a few fixes by its users.

    Additions

    • Add script/create-cov-rpt.py to create OpenCppCoverage report (nonstd-lite project issue 29)
    • Add script/create-vcpkg.py (nonstd-lite-project issue 28)
    • Add script/upload-conan.py (nonstd-lite-project issue 26)
    • Add conanfile.py, edit it from script/update-version.py (nonstd-lite-project issue 26)
    • Add CMake installation and config-file packaging; Let tests and example use gsl-lite interface library
    • Add "LANGUAGES CXX" to CMake project
    • Add GNUC -Wsign-conversion warning to CMake configuration
    • Add AppleClang to CMake configuration
    • Add OSX to Travis configuration
    • Add TOC entry for Standard selection macro (#128, thanks to @egarrulo)
    • Add span::ssize(), ssize(span), size(span) (#144)
    • Add test/tc-cl.bat

    Changes

    • Rename "Guideline support library" to "Guidelines -" (#134)
    • Align Appveyor configuration (plan 9, nonstd-lite-project issue 14)
    • Align CMakefiles.txt (plan 8, nonstd-lite-project issue 13)
    • Align test scripts (nonstd-lite-project issue 12)
    • Align badges in readme (nonstd-lite-project issue 3)
    • Obviate need for -DNOMINMAX with MSVC (nonstd-lite issue 16)
    • Prevent and suppress warnings from clang
    • Let ctest produce output on failure
    • Update lest test framework to v1.35.0.

    Fixes

    • Fix CMake install command (expected-lite issue 25, thanks to @rmorozov)
    • Fix clashing CMake cached variable, use 'gsl' for namespace and package folder (thanks to @rmorozov)
    • Fix template argument in not_null<> comparison operators (#143, thanks @stohrendorf)
    • Fix macro gsl_IN_STD (#142, thanks to @Flamefire)
    • Fix possible int overflow in nonstd::span::subspan() range (issue #138, thanks to @fefe17)
    • Fix link to P0122 (#130, thanks to @alexeyr)
    • Fix for misleading __cplusplus of GCC 4.7.0 and earlier (#127, thanks to @egarrulo)
    • Fix final_action_return() and final_action_error() during stack unwinding (#126, thanks to @patstew)
    • Fix unused parameter if Expects() elided via new macro gsl_EXPECTS_UNUSED_PARAM (#123, #124, thanks to @kugelrund)
    Source code(tar.gz)
    Source code(zip)
  • v0.32.0(May 12, 2018)

    This release of gsl lite changes its not_null towards the same class in Microsoft's GSL (issue #122).

    One step that gsl lite does not (yet) take, is to make not_null's constructor explicit and thereby inhibit implicit conversions and copy-initialization. gsl lite does however offer a configuration setting via gsl_CONFIG_NOT_NULL_EXPLICIT_CTOR to make not_null's constructor explicit. It also offers not_null_ic for implicit construction.

    Implicit not_null construction:

    void use_implicit( not_null<int*> nnp );
    
    void caller_implicit()
    {
      owner<int*> oip( new int(42) );
      use_implicit( oip );
      // ...
    }
    

    Explicit not_null construction:

    void use_explicit( not_null<owner<int*>> nnp );
    
    void caller_explicit()
    {
      owner<int*> oip( new int(42) );
      use_explicit( not_null<owner<int*>>(oip) );
      // ...
    }
    

    Changes

    • Add not_null_ic with implicit constructor, allowing copy-initialization.
    • Enable making not_null constructor explicit via gsl_CONFIG_NOT_NULL_EXPLICIT_CTOR, default 0 (breaking, issue #46).
    • Enable not_null get() return by const & via gsl_CONFIG_NOT_NULL_GET_BY_CONST_REF (via M-GSL PR 651 @xaxxon, PR 675 @ericLemanissier).
    • Change constraint on not_null construction from is_convertible to is_constructible (via M-GSL PR 650, @xaxxon).
    • Change to take not_null constructor argument by const & when rvalue references are not available.
    • Add not_null non-is-default rvalue reference copy-constructor, copy-assignment.
    • Remove not_null converting assignment operator.
    • Rename to gsl_HAVE_EXPLICIT.
    • Adapt several compile-time tests for not_null with explicit construction.
    • Fix GNUC C++98 compilation by making RefCounted conversion function const in not_null.t.cpp.
    Source code(tar.gz)
    Source code(zip)
    gsl-lite.hpp(77.14 KB)
  • v0.31.0(May 11, 2018)

    This release of gsl lite changes its span towards proposal p0122r7 and adds non-standard creator function byte_span() to create a span of bytes for a single object. Further it adds more control over including features or deprecated behaviour.

    Additions

    • Added gsl_lite_MAJOR, gsl_lite_MINOR, gsl_lite_PATCH, updated script/update-version.py.
    • Added configuration selector gsl_CONFIG_DEPRECATE_TO_LEVEL; default no deprecation.
    • Added feature selector gsl_FEATURE_WITH_CONTAINER_TO_STD; default any C++ standard.
    • Added feature selector gsl_FEATURE_MAKE_SPAN_TO_STD; default any C++ standard.
    • Added feature selector gsl_FEATURE_BYTE_SPAN_TO_STD; default any C++ standard.
    • Added macros gsl_DEPRECATE_TO_LEVEL(), gsl_FEATURE(), gsl_FEATURE_TO_STD(), gsl_CONFIG(), gsl_HAVE() and gsl_ADDRESSOF(x).
    • Added span::value_type.
    • Added details::can_construct_span_from<>.
    • Added convertible constraint to span C-array constructor.
    • Added class template argument deduction guides for span.
    • Added make_span( with_container_t, ...) creator functions.
    • Added non-standard byte_span() creator functions (span lite issue #3, thanks to @chris0e3).

    Changes

    • Changed span towards proposal p0122r7 (issue #118).
    • Changed C++14 constexpr to C++11 constexpr where possible.
    • Parenthesized macro arguments.
    • Omitted macros min(), max() via -DNOMINMAX in test/t*.bat.
    • Updated test/t-all.bat for various configuration and feature selections.
    Source code(tar.gz)
    Source code(zip)
    gsl-lite.hpp(75.83 KB)
  • v0.30.0(May 6, 2018)

    This release of gsl lite introduces support for the DJGPP cross compiler. Further it contains the following changes.

    Additions

    • Support for DJGPP cross compiler is introduced (PR #107, thanks to Tomáš Zeman, @zemasoft)
    • A Readme.md has been added to example/cmake-pkg

    Changes

    • The lest test framework has been updated to v1.33.1.
    • Clang and GNUC now allow strict aliasing for gsl::byte (issue #114).
    • The version information on MSVC can now differentiate between 14.0 (VS 2015) and 14.1 (VS 2017).
    • The space after ':' in FILE: LINE in reported locations has been removed (issue #112).
    • MSVC level 4 warning C4127: conditional expression is constant is now avoided (issue #115, thanks to @kpeace)
    • A constructor to allow rvalue to const lvalue conversion has been added (issue #113, PR #117, thanks to @theodelrieu )

    Fixes

    • The missing #include <algorithm> has been added.
    • Clang compilation for C++98 has been fixed by specifying the C++ standard.
    • The gsl-lite version in section "As CMake package" has been fixed.
    • The type in a test of span has been correced (PR #105, thanks to Tomáš Zeman, @zemasoft)
    • The owner alias template has been enabled for VC12 (Issue #111, thanks to @sg-james); the following macros for Visual C++ have been updated:
      • gsl_HAVE_ALIAS_TEMPLATE: VC12 (was VC14)
      • gsl_HAVE_ENUM_CLASS: VC11 (was VC14)
      • gsl_HAVE_EXPLICIT_CONVERSION: VC12 (was VC14)
      • gsl_HAVE_INITIALIZER_LIST: VC12 (was VC14)
    Source code(tar.gz)
    Source code(zip)
    gsl-lite.hpp(68.07 KB)
  • v0.29.0(Mar 3, 2018)

    This release of gsl lite contains the following changes.

    Changes

    You can now use gsl lite via a CMake package, thanks to @FlorianWolters (PR #100, #103).

    The CMake package provides gsl lite as interface library via 'namespaced' headers gsl/gsl and gsl/gsl-lite.hpp.

    In the documentation, the section on installation now describes using gsl-lite as copied header, as external Git project, as CMake package and as Conan package. Further the section Deprecation was added and the table Reported to work with was updated.

    The following methods of class span are now deprecated: span::length(), span::length_bytes() (issue #99) and the span constructors that take a smart pointer, span(shared_ptr<element_type> const & ptr), span(unique_ptr<element_type> const & ptr) (issue #98).

    Additions

    CMake Package Configuration support has been added. This makes gsl-lite usable with CMake's find_package() command. To prevent undesired compilation of tests and examples, two CMake options where added that default to off: GSL_LITE_OPT_BUILD_TESTS and GSL_LITE_OPT_BUILD_EXAMPLES. To support the usage of gsl-lite's CMake package, scripts script/install-gsl-pkg.py was added as well as script use-gsl-pkg.py that is part of an example that uses the package. Further a script was added to update gsl lite's version number in relevant files.

    Type gsl::index has been added for container indices, subscripts and sizes. It is defined by the existing configuration macro gsl_CONFIG_SPAN_INDEX_TYPE.

    Fixes

    In the output stream operator of class string_span the padding has been fixed to pad to the right side, commit 9574552.

    Source code(tar.gz)
    Source code(zip)
    gsl-lite.hpp(66.37 KB)
  • v0.28.0(Jan 1, 2018)

    This release of gsl lite contains the following changes.

    Changes Travis and Appveyor CI compiler matrices have been expanded. CI now uses the CMake configuration.

    Additions The Visual Studio 2015 and 2017 targets now include variants with compiler option -std:c++14, -std:c++17 and -std:c++latest to specify the C++ standard to use.

    For the Visual Studio 2017 target C++ Core Guidelines checking has been added. The checking is limited to GSL Lite itself. Thanks to @AraHaan for drawing attention to the guideline checking in PR #95.

    A test was added to compare an empty to a non-empty string span. Comparing empty string_spans as equal asserts with several configurations and is possibly questionable; it has been suppressed via [.]. See issue #96.

    Fixes The CMake configuration now uses CMAKE_CXX_COMPILER_VERSION to obtain the compiler's version number instead of a version number obtained from gcc via commandline options -dumpversion and -dumpfullversion. The dumped version is a configuration value that is used in filesystem paths. I've noticed erroneous values with it on Travis even in the main version number.

    Source code(tar.gz)
    Source code(zip)
    gsl-lite.hpp(66.01 KB)
  • v0.27.0(Dec 29, 2017)

    This release of gsl lite contains the following changes.

    Changes

    The GSL Lite header file now has extension .hpp. There are headers gsl.h and gsl/gsl-lite.h to provide backwards compatibility, however these have been deprecated as of this version. See issue #94 , thanks to @AraHaan.

    Several warnings from Microsoft's CppCoreCheck have been suppressed. See pull request #95, thanks to @AraHaan.

    There are no additions or fixes in this release.

    Source code(tar.gz)
    Source code(zip)
    gsl-lite.hpp(64.92 KB)
  • v0.26.0(Dec 9, 2017)

    This release of gsl lite contains the following changes.

    Additions

    Conan installation instructions and badge were added (thanks to @agauniyal). An install target has been added to the CMake instructions (issue #85).

    Changes

    final_act has been renamed to final_action (issue #89). Several deleted (or private) methods were added for clang-tidy cppcoreguidelines checks to pass (pull request #91, thanks to @poconbhui).

    Fixes

    In not_nul::get(), nullptr was corrected to gsl_nullptr (pull request #90, thanks to @poconbhui). A -Wshadow warning was fixed (pull request #84, thanks to @MikeLankamp).

    Source code(tar.gz)
    Source code(zip)
    gsl-lite.h(63.50 KB)
  • v0.25.0(Oct 22, 2017)

    This release of gsl lite contains the following changes.

    Additions

    Several deleted operators (issue #82) and comparison operators (issue #83) were added for not_null<>.

    Changes

    If possible, owner<T> is restricted to pointers (issue #80).

    As in not_null<>'s constructor, the parameter in the assignment is taken by value. If available, = default is used for not_null<> copy construction and copy assignment.

    New macros gsl_is_delete and gsl_is_delete_access were added to only write such function prototypes once (issue #81).

    Fixes

    none.

    Source code(tar.gz)
    Source code(zip)
    gsl-lite.h(62.79 KB)
  • v0.24.0(Jul 10, 2017)

  • v0.23.0(Jun 29, 2017)

    This release of gsl lite contains the following changes.

    Additions

    The dereference operator was added to not_null<> and tests were added for it (issue #73, thanks to @minielim). The hidden tests now also report the compiler version and the C++ language version (run gsl-lite @).

    Changes

    The definition of macros that indicate the availability of language and library features was changed to enable the use of option -Wundef. For the same reason the lest test framework was updated to version 1.30.1.

    Fixes

    A check for make_unique was fixed in a test. In the CMake build files compiler selection was fixed as well as setting of common compiler options.

    Source code(tar.gz)
    Source code(zip)
  • v0.22.0(Apr 27, 2017)

    This release of gsl lite contains the following changes.

    Addition

    operator<< was added for string_span (PR #72, thanks to Magnus Bergsten, @Sillamacka).

    Fixes

    Conversion and sign-conversion warnings were fixed, as well as the order of add_compile_options() and its targets in test/CMakeLists.txt (thanks to Magnus Bergsten, @Sillamacka). Further a memory leak was fixed, which prevented tests to pass with address sanitizing (thanks to Vladimir Rapatskiy).

    Changes

    The base class of fail_fast has been replaced with std::logic_error as per issue #69. Test framework lest has been updated to version 1.29.1 (contains above fixes for conversion and sign-conversion warnings).

    Source code(tar.gz)
    Source code(zip)
  • v0.21.0(Nov 28, 2016)

    This release of gsl lite contains a single addition and two fixes.

    Addition

    Added as_bytes() for basic_string_span<> (issue #62, thanks to Magnus Bergsten, @Sillamacka).

    Fixes

    The stray static has been removed from the declaration of the enum in integral_constant. This fixes compilation for Xcode on Mac OS X (thanks to Dave Tallman).

    The call to hash<std::size_t>() for byte's hash function seems undefined with Xcode on Mac OS X and has been removed. Note however that the source of the problem may be with Clang's header files and including functional as last header file in gsl-lite.h makes it possible to use hash<std::size_t>() in said context, see issue #63 (thanks to Dave Tallman).

    Source code(tar.gz)
    Source code(zip)
  • v0.20.0(Nov 18, 2016)

    This release of gsl lite contains various changes and fixes.

    Possibly breaking changes

    To conform to Microsoft's GSL, span's methods bytes() and used_bytes() have been renamed to size_bytes() and length_bytes() and method used_length() has been removed (it was identical to length()).

    Final act for VC11/VS2012

    The full-blown final_act<> and final_act_return<> have been made usable with Visual C++11, Visual Studio 2012 (PR #61, thanks to @lm1458777).

    Fixes

    fail_fast_assert() has been fixed with respect to C++14 constexpr for gcc with a version lower than 6 for the default no-throw/std::terminate() case (comment, thanks to @xsacha).

    The noexcept defaulted constructors of basic_string_span have been fixed for gcc with a version lower than 6 (comment PR #58, thanks to @xsacha).

    Source code(tar.gz)
    Source code(zip)
  • v0.19.0(Nov 17, 2016)

    Following the addition of the make_span creator functions to Microsoft's GSL, this release of gsl lite renames the existing functions as_span to make_span and adds make_span for gsl::shared_ptr and gsl::unique_ptr.

    Source code(tar.gz)
    Source code(zip)
  • v0.18.0(Nov 11, 2016)

    This release of gsl lite contains a variety of changes.

    Fixes Defaulted-constructors of span have been fixed with respect to noexcept for GNUC before version 4.9.0 (adapted PR #58, thanks to Dmitry Banschikov, @ubique).

    Removals Type span::size_type has been removed. It was deprecated since 0.12.0 (issue #42).

    Additions This release adds configuration macro gsl_CONFIG_SPAN_INDEX_TYPE. Its default is size_t, the type that was already used as span's index type (issue #31). A constructor for std::array<> const &. has been added to span besides the existing non-const one. Further, constructors for gsl::unique_ptr and gsl::shared_ptr have been added to span (issue #48).

    Changes Span's unconstrained constructor for compilers that don't support SFINAE is now disabled at default to not inhibit construction from gsl::unique_ptr and gsl::shared_ptr. Warnings on conversions [-Wconversion] and warnings on old-style casts [-Wold-style-cast] are prevented (issue #59). Finally, the lest test framework has been updated to version 1.27.2.

    Source code(tar.gz)
    Source code(zip)
  • v0.17.2(Nov 10, 2016)

    This release of gsl lite contains two workarounds for g++ 5: one to enable throwing from a constexpr function, the other to prevent two failing tests due to a default copy- (move-)constructor. Further several missing gsl_api's have been added and function and method declarations have been written more consistently.

    Source code(tar.gz)
    Source code(zip)
  • v0.17.1(Nov 9, 2016)

  • v0.17.0(Nov 9, 2016)

    This release of gsl lite adds a free-standing variant of as_bytes() and as_writable_bytes() as available in M-GSL.

    Member methods as_bytes() and as_writable_bytes() have been deprecated now.

    Thanks to Dmitry Banschikov (@ubique).

    Source code(tar.gz)
    Source code(zip)
  • v0.16.1(Nov 9, 2016)

    This release fixes a macro used with string_span comparison. As a result Visual C++12 (VS2013) can now also use objects convertible to string span on the left-hand side.

    Source code(tar.gz)
    Source code(zip)
  • v0.16.0(Nov 9, 2016)

    This release of gsl lite expands comparison of string spans to allow comparison with types that are convertible to string_span.

    Note that for compilers that do not support function default template arguments, the convertible types must be on the right-hand side.

    Thanks to Magnus Bergsten (@Sillamacka).

    Source code(tar.gz)
    Source code(zip)
  • v0.15.0(Nov 9, 2016)

    This release adds basic_string_span. It replaces span as the basis for string_span, cstring_span, wstring_span and cwstring_span.

    Thanks to Magnus Bergsten (@Sillamacka).

    Source code(tar.gz)
    Source code(zip)
Owner
gsl-lite
Organization account for gsl-lite
gsl-lite
expected lite - Expected objects in C++11 and later in a single-file header-only library

expected lite: expected objects for C++11 and later expected lite is a single-file header-only library for objects that either represent a valid value

Martin Moene 254 Jan 4, 2023
optional lite - A C++17-like optional, a nullable object for C++98, C++11 and later in a single-file header-only library

optional lite: A single-file header-only version of a C++17-like optional, a nullable object for C++98, C++11 and later Contents Example usage In a nu

Martin Moene 361 Dec 28, 2022
span lite - A C++20-like span for C++98, C++11 and later in a single-file header-only library

span lite: A single-file header-only version of a C++20-like span for C++98, C++11 and later Contents Example usage In a nutshell License Dependencies

Martin Moene 427 Dec 31, 2022
string_view lite - A C++17-like string_view for C++98, C++11 and later in a single-file header-only library

string_view lite: A single-file header-only version of a C++17-like string_view for C++98, C++11 and later Contents Example usage In a nutshell Licens

Martin Moene 357 Dec 28, 2022
variant lite - A C++17-like variant, a type-safe union for C++98, C++11 and later in a single-file header-only library

variant lite: A single-file header-only version of a C++17-like variant, a type-safe union for C++98, C++11 and later Contents Example usage In a nuts

Martin Moene 225 Dec 29, 2022
Guidelines Support Library

GSL: Guidelines Support Library The Guidelines Support Library (GSL) contains functions and types that are suggested for use by the C++ Core Guideline

Microsoft 5.3k Jan 7, 2023
Guidelines Support Library

GSL: Guidelines Support Library The Guidelines Support Library (GSL) contains functions and types that are suggested for use by the C++ Core Guideline

Microsoft 5.3k Jan 5, 2023
Single-header header-only C++11 / C++14 / C++17 library for easily managing set of auto-generated type-safe flags.

Single-header header-only C++11 / C++14 / C++17 library for easily managing set of auto-generated type-safe flags. Quick start #include <bitflags/bitf

Marin Peko 76 Nov 22, 2022
Bsl - Rust 2018 and C++20, "constexpr everything", AUTOSAR compliant header-only library intended to support the development of critical systems applications

Description The Bareflank Support Library (BSL) is a Rust 2018 and C++20, "constexpr everything", AUTOSAR compliant header-only library intended to su

Bareflank 76 Dec 8, 2022
Libft is an individual project at 42 that requires us to re-create some standard C library functions including some additional ones that can be used later to build a library of useful functions for the rest of the program.

?? Index What is Libft? List of Functions Technologies ✨ What is Libft? Libft is an individual project at 42 that requires us to re-create some standa

Paulo Rafael Ramalho 7 Jan 17, 2022
jkds is a modern header-only C++20 library that complements the standard library.

jkds is a modern header-only C++20 library that complements the standard library. It provides generic atypical data structures, ergonomic functional programming abstractions, and then some.

Alberto Schiabel 6 Nov 16, 2022
Lightweight single-file utilities for C99. Portable & zero dependency

plainlibs Lightweight single-file utilities for C99. Key Features Portable across Unix & Windows (including MSVC) Zero dependencies (besides C stdlib)

null 5 Oct 5, 2022
Modern C++ generic header-only template library.

nytl A lightweight and generic header-only template library for C++17. Includes various utility of all kind that i needed across multiple projects: Ex

Jan 95 Nov 3, 2022
A collection of std-like single-header C++ libraries

itlib: iboB's Template Libraries A collection of small single-header C++ libraries similar to or extending the C++ standard library. See below for a l

Borislav Stanimirov 98 Dec 29, 2022
A header-only, unobtrusive, almighty alternative to the C++ switch statement that looks just like the original.

uberswitch A header-only, unobtrusive, almighty alternative to the C++ switch statement that looks just like the original. Sample usage (incomplete -

Fabio 85 Jan 3, 2023
GNU Scientific Library with CMake build support and AMPL bindings

GSL - GNU Scientific Library This is GSL, the GNU Scientific Library, a collection of numerical routines for scientific computing. GSL is free softwar

AMPL 441 Dec 24, 2022
Library that simplify to find header for class from STL library.

Library that simplify to find header for class from STL library. Instead of searching header for some class you can just include header with the class name.

null 6 Jun 7, 2022
C++11/14/17 std::optional with functional-style extensions and reference support

optional Single header implementation of std::optional with functional-style extensions and support for references. Clang + GCC: MSVC: std::optional i

Sy Brand 699 Dec 23, 2022
C++ STL in the Windows Kernel with C++ Exception Support

C++ STL in Windows Drivers This project uses MSVC C++ STL in a Windows Kernel Driver. In this solution jxystl.lib is implemented as a kernel-tuned, po

Johnny Shaw 282 Dec 28, 2022