as per 23.7.2.1:
- span() and span(nullptr) can only be used if extent is dynamic or 0
- span( element_type(&arr)[N] ) can only be used if extent is dynamic or N
- std::array can be used for initialization if extent is dynamic or size of the array
- Containers can be used for initialization if pointer type is convertible
as per 23.7.2.2
- first<N> and last<N> may no longer exceed the span extents
changes:
- minimal cmake version updated to 3.7(first version with .natvis file handling)
- updated cmake version in readme file
- GSL.natvis file is added only to VS projects
* rewrite span subspan checks to help optimizations
* Removed checking pointer for null for subspans. We would never
check pointer for null in between ptr and ptr+size in the
original span, so there seems to be no reason to do so for
subspans, provided that the subspan's boundaries are ensured
to be within the range of the original span's boundaries.
This change allows to simplify generated code, for example, to
remove 5 out of 9 branches in code generated from the following
by MSVC, and 4 out 8 branches in clang and gcc-generated code:
span<int> mysubspan(int* p, std::ptrdiff_t size, std::ptrdiff_t i)
{
if (p != nullptr)
{
span<int> s = { p, size };
return s.subspan(i);
}
return { nullptr };
}
Similar effects are achieved for dynamic subspans of static spans,
where in the following code we remove 2 out of 4 branchs in MSVC
and GCC-generated code:
int test_dynamic_subspan_of_static_span(std::ptrdiff_t i)
{
int x[] = { 0,1,2,3,4,5 };
span<int, 6> s = { x };
auto subspan = s.subspan(i);
return subspan.size();
}
* travis.yml clean up
- Remove trailling spaces
- Move notification setting from the bottom to the top
- Set Linux as default OS
- Simplify cache directory
- Add banners around different configurations
* Update CMake installation routine
- Make it depend on variable (easier to update)
- Simplify code a bit
* Re-organize build matrix and LLVM install
- make logic depend on a single COMPILER variable
- Update LLVM installation process
* Update compilers to latest stable version
* Made string_span details::string_length() generic
removed overloads & specialized classes
Creating string_spans using `char16_t` and `char32_t` was not possible
without creating new specializations and function overloads.
This patch makes details::string_length() generic removing the need to
extend the overloads and specializations.
* added type aliases for string_span types char16_t and char32_t
* Added char16_t & char32_t overloads for ensure_z
* added string_span tests for char16_T & char32_t
* added zstring type aliases for char16_t & char32_t
* Added tests for char16_t & char31_t zstring and string_span types
* applies clang format to <gsl/string_span>
* Clang format tests/string_span_tests.cpp
* Removed ensure_z() overloads as they don't add functionality.
using the GSL with MSVC 2017 causes the following warning"
`'std::copy_n::_Unchecked_iterators::_Deprecate': Call to 'std::copy_n'`
This patch removes this since the point of this code is to deal with this issue.
Catch was being installed to the root of the cmake project. This
violated the source code tree itself and would not work at all if GSL
was being consumed with add_subdirectory.
CMake will now install catch to the build tree under /dependencies.
not called even by the unit test (it was calling the "container" ctor
instead). I mimicked the constructor taking a non-const std::array to fix
the issue.
* Fixes issue with dereferencing operator issue #491 introduced in PR #513
dereferencing operator added in PR#513 returned a copy of the object
instead of reference to it.
Adding decltype(auto) as return type of operator* fixes this issue.
* added more tests for not_null::operator*
* Restricting usage of owner<T> to pointer types
* Removing an additional type that was created for testing
* Added comment about the new constraint on owner
* Adding dereference operator to not_null
* Removing dereference operator changes for not-null
* Removing dereference operator changes for not-null
* Review comments
Fixes#510.
* Constrain the converting constructor to not participate in overload resolution when IsConst is true, so that it is never a copy constructor.
* Use Default Member Initializers for span_iterator's data members so that the default constructor can be explicitly defaulted.
* Declare all members of span_iterator GSL_NOEXCEPT: they only throw when contract violations throw.
* Don't use & in operator-> since evil types may overload it.
* Refactor cmake file to have GSL as an interface
CMake supports header only libraries as INTERFACE libraries. Using
interfaces libraries make is easier for users to use the library because
one just need to "link" agaisnt the library and necessary include paths,
definitions, flags... will be taken care of.
This commit creates a new interface library called GSL. It then add the
following things to the GSL library:
- compiler flags ex: (-std=c++14)
- definitions ex: _SCL_SECURE_NO_WARNINGS
- include paths ex: include/gsl
- natvis file
Another project can now have the GSL project as a git submodule and one
only need to add the two following lines to their project to use the
GSL.
add_subdirectory(GSL)
target_link_libraries(<some target> GSL)
After cmake 3.8.0 a lot of the logic can be simplified. Right now the
cmake file has an if for version checking, but when the minimun required
version is 3.8.0 one can just delete the branching and keep the simpler
version.
* Cut support for c++11
Compiling on GCC6.2 with only the c++11 flag will generate compilation
errors. For example some of the errors are related to the use of
enable_if_t which is a c++14 feature.
To avoid compilation errors this comiit removes c++11 support on linux.
* Refactor code that pulls unittest-cpp
Two minor changes:
- uses cmake to find a proper installation of git (in case user does not
have it on the path)
- checks for the CMakeLists file instead. This is needed for the build
itself and seems like a better way to do the checking
* Refactor tests so they show together on VS
This commit will make a VS geenrated project to group all tests under
GSL_tests
* Refactor tests configuration
This creates a test configuration interface and add all the previous
compiler options to that interface. compiler options are now sorted so
it is easier to find them, and also one per line, so that modifications
are easier to track from git.
Project files were not following the clang-format style. For people
using IDEs were clang-format is always run after a save this would
cause unwanted changes.
This commit only applies "clang-format -i" to files.
* Add value_type to span
Currently I'm working on project which involves a lot of `span`s and mocking via Google Mock. Unfortunately a lot of standard matchers requires `value_type` type definition inside container which `gsl::span` lacks.
This pull request add `value_type` type definition inside `gsl::span`
* Strip cv from value_type of span and span_iterator
* Added support of not_null<smart_ptr> comparison
* The return type of not_null comparison operators is determined using SFINAE
#474
* tests for gsl::not_null comparison were added
* not_null comparison tests were rewritten to compare pointers to objects located in the same array
* not_null<shared_ptr> comparison was simplified
* initializer_list overload returns by value to avoid lifetime issues
* generic overload uses expression SFINAE to work with any type that has member size() and operator[], which notably includes const/non-const vector and array.
* Add test coverage for const objects, rvalue initializer_lists, and constexpr usage.
Fixes#357.
* Improve const correctness in string_span
* Improve const correctness in bounds_tests.cpp and byte_tests.cpp
* Improve const correctness in span_tests.cpp
* Improve const correctness in utils_tests.cpp
* Use gsl::owner for dynamically allocated memory in string_span_tests.cpp
* Improve const correctness in string_span_tests.cpp
* Improve const correctness for strided_span_tests.cpp