Commit Graph

115 Commits

Author SHA1 Message Date
Anna Gringauze
d846fe50a3
Enable usage of gsl::narrow with exceptions disabled (#640)
* Enable usage of gsl::narrow with exceptions disabled

This solution uses the approach of boost::asio to enabling usage of the
library in environments where exception usage is either prohibited
or not feasible (due to code size constraints). A function template
gsl::throw_exception has been added, which in a normal environment just
throws the exception. However, when GSL_TERMINATE_ON_CONTRACT_VIOLATION
is defined the function is only declared by gsl and the definition of
this function template must be supplied by the library's user.

Closes: #468

Signed-off-by: Damian Jarek <damian.jarek93@gmail.com>

Addition:
- understand STL no exception macro
- use function static variable to set termination handler in kernel mode
- add compile-only tests for no-exception mode

* added termination tests and fixed bugs

* disabled warning C4577 for msvc 2015
2018-03-15 16:00:08 -07:00
Anna Gringauze
c6bf25a5f6
simplified constructors and removed GSL_NOEXCEPT in span (#639)
- simplified storage constructors to reduce branching
- eliminated null check for constructor from array
- removed GSL_NOEXCEPT in span
2018-03-15 12:14:29 -07:00
Alex Howlett
c9e423d7cf Fix warning 4996 on Microsoft compiler (#633) 2018-03-05 12:04:22 -08:00
Neil MacIntosh
6a33b97a84
Fix return type of templated span.subspan() (#625)
* Added support for returning fixed-spize spans from subspan().

* Addressed issues from code review.

* Took simpler approach to static data member.

* Subtle fix to support MSVC 15.

* Helps to not introduce extraneous >
2018-03-03 19:12:45 -08:00
Anna Gringauze
cbd64c9ff6 fixed noexept warnings (#632)
* fixed noexept warnings

- Removed conditional compilation for throwing version of GSL
  vs fail_fast because we don't want users of the code to see
  differences in the span interface dependent on error mechanism
  chosen
- Removed noexcept from functions that may fail at runtime
- Fixed CppCoreCheck warnings related to missing and incorrect
  noexcept
- do not warn on unnown attributes for GCC and Clang

* remove suppress that does not compiler for clang and gcc
2018-03-03 19:12:23 -08:00
Zac Hansen
ed3693fd2e make explicit not_null move constructor so it is noexcept (#630)
* make explicit not_null move constructor so it is noexcept

* added test for not_null being noexcet move constructible
2018-03-03 15:53:23 -08:00
beinhaerter
7eb8f41af5 constexpr for make_span (#627) 2018-02-23 13:35:36 -08:00
paweldac
b3870ca020 add gsl::index typedef (#620)
* rename index in multi_span to span_index

gsl::index is name reserved for different type

* add gsl::index typedef

cppcoreguidelines referece: ES.107: Don't use unsigned for subscripts, prefer gsl::index

https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Res-subscripts

* rename span_index to multi_span_index
2018-02-21 13:33:07 -08:00
Johel Ernesto Guerrero Peña
73db6ef98f Remove inline added for the now unsupported MSVC 2013. (#585) 2018-02-20 14:46:37 -08:00
caleb
13ce102ec0 gsl::index bug fix (#624)
Fixing a bug in the != operator in the gsl::index class
2018-02-20 14:37:50 -08:00
beinhaerter
c87c123d1b Fix code analysis warning in multi_span (#606)
Prevents MSVC code analysis warning
...\gsl\include\gsl\multi_span(1055): warning C26440: Function 'gsl::dim_t<-1>::dim_t<-1>' can be declared 'noexcept' (f.6: http://go.microsoft.com/fwlink/?linkid=853927).
2018-02-13 17:42:37 -08:00
Tamir Bahar
05bf567dcb Use in-class init for final_action members (C.48) (#601)
* Use in-class init for final_action members (C.48)

Initialize `invoke_` in-class, according to http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c48-prefer-in-class-initializers-to-member-initializers-in-constructors-for-constant-initializers

* Empty commit to trigger build.
2018-02-13 17:28:21 -08:00
Anna Gringauze
3a12c55cb6
Merge pull request #616 from neilmacintosh/tidy-comparison-ops
Tidy up span comparison ops
2018-02-11 22:36:32 -08:00
Neil MacIntosh
533494335b Merge branch 'master' of https://github.com/neilmacintosh/GSL into remove-move-ops 2018-02-11 14:27:05 -08:00
Neil MacIntosh
314065b317 Fix span comparison ops to take arguments by-value rather than by-ref. 2018-02-11 14:22:08 -08:00
Neil MacIntosh
f63fe12ba7 Merge from upstream master. 2018-02-11 13:36:18 -08:00
beinhaerter
3ff6004bc3 added const (#605)
Resolves compiler code analysis warning ...\gsl\include\gsl\string_span(101): warning C26496: The variable 'str_span' is assigned only once, mark it as const (con.4: https://go.microsoft.com/fwlink/p/?LinkID=784969).
2018-02-11 12:19:10 -08:00
Casey Carter
95da2fd337 Don't use clang's __builtin_assume as an optimizer hint (#608)
Fixes #607.

Drive-by: use '?:' to contextually convert to bool in the fallback definition of `GSL_ASSUME`
2018-02-11 12:16:39 -08:00
Neil MacIntosh
c23d17a61a
Make iterator access functions on span constexpr (#612)
As per feedback on span received during the C++ standardization discussions.
2018-02-10 21:11:08 -08:00
Neil MacIntosh
87e22faa7e
Removed from-smart-ptr constructors. (#611)
As per feedback during standardization discussions.
2018-02-10 20:02:05 -08:00
Neil MacIntosh
5538021e76 Removed unnecessary move operations. 2018-02-10 20:00:44 -08:00
Neil MacIntosh
2bdbba7418 Removed span from-nullptr_t ctor. 2018-02-10 19:21:22 -08:00
Neil MacIntosh
72688ff009 Removed span.length() as synonym for span.size(). 2018-02-10 18:58:28 -08:00
Neil MacIntosh
9ed6ecc4e0 Made all span iterator access functions constexpr. 2018-02-10 18:25:07 -08:00
Neil MacIntosh
028925caba Removed from-smart-ptr constructors. 2018-02-10 18:05:17 -08:00
paweldac
9d65e74400 added gsl_algorithm and gsl_byte headers to main gsl header (#594) 2017-12-04 09:18:40 -08:00
Tiago
6e2e207c8d rename final_act to final_action (#579) 2017-11-28 07:20:32 -08:00
paweldac
436dbad8c6 Remove std::iterator inheritance from multi_span (#591)
In C++17 std::iterator is marked duplicated. Added handwritten usigs for traits.
2017-11-28 07:15:34 -08:00
Tiago
0d33bf6794 Applied iwyu --comment to the code base (#588) 2017-11-28 07:13:49 -08:00
bjude
7e529a47c2 Remove #pragma once (#545) (#570)
Core Guidelines SF.8 recommends using portable include guards instead.
2017-11-14 08:38:16 -08:00
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
d10ebc6555 Drop "Dummy" from enable_if in templates (#572)
Looks like this was here because of MSVC 2013 compat which is not
supported anymore
2017-11-03 16:18:59 -07:00
Anna Gringauze
9a7897915e Minimize checking in subspan (#569)
* 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();
}
2017-11-03 16:13:39 -07:00
Tiago
4862a270b9 Move GSL pointers to a separate header (#566) 2017-10-31 10:19:12 -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
Anna Gringauze
e7bcdf541b Enable vectorization of common loops using iterators with range checking enabled with GCC and Clang (#557) 2017-09-18 15:16:23 -07:00
Rian Quinn
842344e94b turning off warning (#548)
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.
2017-08-16 19:06:30 -07:00
Casey Carter
2b8d20425e Allow users to override GSL_USE_STD_BYTE (#536) 2017-07-24 17:26:21 -07:00
Neil MacIntosh
be43c79742 Removed VS2013 workarounds. (#534) 2017-07-14 04:40:27 -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
Gary Furnish
1f87ef73f1 Fix cstddef include in wrong place. (#520) 2017-06-02 08:45:42 -07:00
Vincent Zalzal
010ab921bf Fix multi_span constructor taking a const std::array. (#523)
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.
2017-06-01 21:55:25 -07:00
Neil MacIntosh
1cfb241be7 Fix bug in comparison that selects std::byte. 2017-05-31 19:08:11 -07:00
Neil MacIntosh
7731a91d75 Use std::byte when available. (#519)
* Use std::byte implementation when available with MSVC.

* Rollback the /std:c++latest flag used for testing.

* Review feedback.
2017-05-31 18:42:06 -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
Gary Furnish
d1032864aa Fix use of 0 instead of nullptr warning (#515) 2017-05-30 09:57:45 -07:00
Galik
7abfc98198 GSL_NOEXCEPT should appear before the initialization list (#514) 2017-05-30 08:09:09 -07:00
Casey Carter
39902b6ec0 span_iterator: converting constructor isn't a copy constructor (#511)
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.
2017-05-26 15:41:12 -07:00
ewoudvc
64c0ca64ce make_span for array doesn't pass N as span template parameter (#498) 2017-04-25 12:01:49 -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
Maciej T. Nowak
c2f953f2eb Add value_type to span (#425)
* 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
2017-04-13 13:55:20 -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
Casey Carter
d65660760b fail_fast should derive from logic_error (#480)
Fixes #298.
2017-04-03 11:09:47 -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
16a6a41690 gsl_assert changes: (#452)
* GSL_LIKELY/_UNLIKELY always contextually convert their argument to bool.

* Add macro GSL_ASSUME(cond) to inform the optimizer that the predicate cond must hold.

* Reimplement Expects & Ensures as expressions for flexibility and correctness. (Think about "if (cond1) Expects(cond2); else goto fail;")

* Expects and Ensures GSL_ASSUME their predicate when GSL_UNENFORCED_ON_CONTRACT_VIOLATION is defined.
2017-03-20 09:30:14 -07:00
Duncan Horn
2676e172db Updating length_func<CharT>::operator() to accept pointer-to-const. (#458) 2017-03-10 09:02:13 -08:00
Rian Quinn
f9c47dd63f add gsl::not_null operator<< (#464)
* add gsl::not_null operator<<

Hippomocks, which is a popular mocking engine for C++ uses operator<< on pointers and gets confused about gsl::not_null not having this operator.

* Update gsl
2017-03-09 12:42:18 -08:00
Casey Carter
3819df6e37 Properly qualify std::size_t (#448) 2017-02-13 12:11:45 -08:00
Casey Carter
e3fecbd1c5 not_null cleanups and improvements: (#449)
* constexpr all the things.

* remove operator=(const T&)
  * it leaves *this in an invalid state if ensure_invariant fails
  * implicitly converting the T to not_null and then assigning is in every way superior.

* simplify conversion from not_null<U> with constructor delegation.

* remove the converting assignment operator; again let the conversion constructor and self-assignment operator do the work.

* Cover the remaining pointer arithmetic operations as Wakely suggests in issue #447.

* Cleanup not_null conversions from null pointer constants:

  * replace constructor that accepts T with constructor template that accepts U convertible to T

  * remove deleted constructor that accepts int

  * Attempts to initialize with nullptr, 0, 0L, 0LL, etc. all unambiguously select the deleted nullptr_t constructor.
2017-02-13 11:40:27 -08:00
Casey Carter
6360dd1e75 Revert change to the definition of constexpr macro in gsl_byte from #446 (#450) 2017-02-11 17:38:59 -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