Commit Graph

155 Commits

Author SHA1 Message Date
menete
2ad93a38dd Iosfwd (#586)
* Solves #567 with <iosfwd> approach

* adds a little testing to not_null ostream
2017-11-14 08:14:20 -08:00
Tiago
4862a270b9 Move GSL pointers to a separate header (#566) 2017-10-31 10:19:12 -07:00
menete
1d936eb90c additional span tests (pointer length constructor) (#568) 2017-10-31 10:11:45 -07:00
Casey Carter
211e195d8f Revert inadvertent addition of tests/unittest-cpp submodule from #561 (#562) 2017-10-18 17:56:11 -07:00
Casey Carter
166ea80f66 Update std::byte detection in gsl_byte for MSVC (#561)
* Only check that `_HAS_STD_BYTE` is defined to a non-zero value
2017-10-18 16:35:11 -07:00
Galik
4c5fdb541f Made string_span details::string_length() generic (Fix issue #542) (#543)
* 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.
2017-09-18 15:20:51 -07:00
Edward Betts
77e081e88b correct spelling mistake (#554) 2017-09-06 17:33:49 -07:00
Nicholas Guriev
e249f861e3 Allow to use system version of the catch test framework (#549) 2017-08-16 19:00:30 -07:00
Tiago
25f913e200 Fix catch installation issue (#540)
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.
2017-08-16 18:38:47 -07:00
Neil MacIntosh
b2ee484334 Move from unittest-cpp to catch for unit testing. (#533)
Many thanks to @rianquinn. This should fix #495, #494 and #529.
2017-07-13 13:53:56 -07:00
Alexey Malov
247c4250d4 Fixes dereferencing operator issue #517 introduced in PR #513 (#516)
* 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*
2017-05-31 11:18:55 -07:00
saurabh singh
30595c1f1d Restricting usage of owner<T> to pointer types (#507)
* 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
2017-05-30 20:08:12 -07:00
saurabh singh
23581d4d63 Adding derference operator to not_null (#513) 2017-05-30 10:06:21 -07:00
Tiago
8b320e3f5d Update CMake usage (#493)
* 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.
2017-04-25 17:08:36 -07:00
Tiago
ebe7ebfd85 Reformat files to follow clang-format style (#492)
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.
2017-04-20 07:51:37 -07:00
Casey Carter
c5851a8161 Turn warnings into errors (#488) 2017-04-17 12:26:38 -07:00
Julien Monat Rodier
66cf6896e5 Updated submodule reference for unittest-cpp to latest (#483)
- updated to latest unittest-cpp
2017-04-13 10:46:31 -07:00
Alexey Malov
534bb4c663 Added support of not_null<smart_ptr> comparison (#473)
* 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
2017-04-12 17:34:39 -07:00
Casey Carter
ebab8cab7f gsl::at clean-up: (#479)
* 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.
2017-04-03 22:43:43 -07:00
MikeGitb
ade86caa92 Fix some corechecker warnings (#470)
* 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
2017-04-02 12:30:49 -07:00
Casey Carter
3819df6e37 Properly qualify std::size_t (#448) 2017-02-13 12:11:45 -08:00
Casey Carter
6367b42ac5 Silence warning in algorithm_tests with VS2017 (#453)
Now that the STL respects /W4, this test that uses std::copy_n to copy a span of ints to a span of chars triggers "warning C4244: '=': conversion from 'int' to 'char', possible loss of data". Switch the source & destination spans to short and int to maintain the test's cross-type nature but without narrowing.
2017-02-13 11:25:09 -08:00
Casey Carter
4e8f95b418 Cleanup include structure, constexpr and noexcept compiler workarounds.
* Nest "gsl" directory inside a new "include" directory.

* Cleanup the _MSC_VER conditionals a bit; use constexpr on VS2017+.

* Don't #define noexcept on non-Microsoft implementations.

* Workaround VS2017 bug in multi_span. (Also implement == and != for static_bounds_dynamic_range_t because I'm an EoP semantic soundness snob.)

Fixes #441.
2017-02-07 15:59:37 -08:00
Casey Carter
96eaf274f8 Make is_default_constructible work for spans. 2017-01-28 00:08:48 -08:00
David Doria
c52d54f955 Fix a signed/unsigned comparison warning. 2016-11-29 18:08:32 -08:00
MikeGitb
d2dafe2ddf Add a copy() function for span. 2016-11-17 10:45:06 -08:00
Rian Quinn
2df9f85385 Add make_span()
This patch provides a make_span function to simplify the
creation of spans until C++17 is available. In addition
this patch updates the unit tests to includes tests that
verify this new functionality.
2016-11-16 10:17:04 -08:00
Neil MacIntosh
9523c1842e Fix template pack expansion bug in multi_span.
* Fix issue #333 by moving a parenthesis.
* Added test to prove fix is good.
2016-11-16 10:15:04 -08:00
Rian Quinn
bdcef948a5 Cleanup compiler warnings
The unique_ptr / shared_ptr patch introduced a compiler
warning. This corrects that issue.
2016-11-16 09:42:46 -08:00
Neil MacIntosh
0d31109d41 Fixed compile flags for tests when using MSVC. 2016-11-04 14:48:22 -07:00
Rian Quinn
2b51b8767a Add span construction from unique_ptr and shared_ptr
This patch adds support for std::unique_ptr and
std::shared_ptr to the gsl::span
class instead of having to manually grab the pointer via
get().

For reference, this is part of the following issue:
https://github.com/Microsoft/GSL/issues/402
2016-11-03 18:55:41 -07:00
Rian Quinn
d641796b21 Cleanup additional GCC warnings
When turning on the following flags, several additional warnings
were generated, which have been cleaned up in this patch. The
flags included:

-Wextra
-Wpedantic
-Wconversion
-Wsign-conversion
-Wctor-dtor-privacy
-Wshadow
-Wnon-virtual-dtor
-Wold-style-cast
-Wcast-align
-Woverloaded-virtual
2016-11-03 18:38:32 -07:00
Rian Quinn
fb1a89fb14 Fix gsl::at()'s use of size_t
gsl::at should use std::ptrdiff_t instead of size_t. This patch
fixes that, and adds missing unit tests
2016-10-28 11:46:14 -07:00
Rian Quinn
6cffe0d14c Adds gsl::span::at()
As per this discussion:
https://github.com/Microsoft/GSL/issues/402

This patch adds support for at() to gsl::span
2016-10-26 14:11:24 -07:00
Marc Mutz
1e95421889 [#392] Don't install tests
'make install' should install the GSL library (ie. the headers),
not the tests.

It still installs the UnitTest++ headers, but that will be more
complex to fix, as GSL just imports UnitTest++ as a git submodule,
and the install command propagates down to UnitTest++'s
CMakeLists.txt.
2016-10-17 12:42:58 -07:00
MikeGitb
1287e624cd Address #313: try to guard against strict-aliasing bugs with gsl::byte
* Add test to demonstrate byte aliasing problem on g++ and clang++

* Add note about no-strict-aliasing flag in README

* Activate aliasing unit test and use -fno-strict-aliasing flag
2016-10-17 12:36:11 -07:00
Neil MacIntosh
fd5ad87bf2 Add tests for to_integer(), fix to_integer() 2016-09-20 08:47:49 -07:00
Neil MacIntosh
e4de6cccdd Fix wrong types in multi_span_test for comparison operators. 2016-09-20 08:46:27 -07:00
Krzysztof Wrzalik
22c2785452 Added tests for negative multi-span access. 2016-09-18 17:44:45 +02:00
Michael Balszun
95f465aeca fix wrong types in multi_span_test (<comparison_operators>) 2016-09-17 16:09:21 +02:00
Martin Moene
ad991370da Add tests for to_integer(): they fail 2016-09-17 09:16:15 +02:00
Neil MacIntosh
6bc1e7e709 Fix for #313 Corrected SFINAE for conversion constructors on span 2016-09-13 12:19:19 -07:00
Neil MacIntosh
3b2419532e Corrected SFINAE for conversion constructors on span. 2016-09-12 18:51:23 -07:00
Kris
d5847ceef0 Merge remote-tracking branch 'Microsoft/master' 2016-09-07 22:16:19 +01:00
Kris Cruickshank
55b232dde4 Issue: #329
This is my best attempt at fixing the issues raised by @gdr-at-ms while supporting VS2013, VS2015, providing shorter syntax than the static_cast and giving developer meaningful errors when they do the wrong thing.
2016-09-07 21:38:43 +01:00
Gary Furnish
ec109d2374 Add to_basic_string 2016-09-04 00:29:10 -06:00
Kris
95bbaa1ec2 Added to_byte method for issue #329
I have added the to_byte method and updated the unit tests.

This gives slightly nicer syntax than static_cast, is better than the
c-style cast used in the unit test.

See: https://github.com/Microsoft/GSL/issues/329#issuecomment-240588515
2016-08-28 21:55:58 +01:00
ericLemanissier
134f2db5d9 Specialize gsl::at for span
span being a view and not a container, the generic version of gsl::at is not valid any more for span.
This commits adds a specialization of gsl::at for span
2016-08-23 12:18:36 +02:00
Neil MacIntosh
f3e660a5a5 Added basic test for interop with std::regex as per Issue #271. 2016-08-10 19:39:48 -07:00
Neil MacIntosh
d6ac640271 Added basic test for interop with std::regex as per Issue #271. 2016-08-10 19:32:00 -07:00