Commit Graph

138 Commits

Author SHA1 Message Date
Jordan Maples [MSFT]
f4c608fd39 addressing comments 2020-02-18 14:09:11 -08:00
Jordan Maples [MSFT]
41ae38f197 addressing a few more comments and adding gsl-std span compatibility tests 2020-02-14 15:24:46 -08:00
Jordan Maples [MSFT]
926aaeca56 reviewed the pr in its entirety and made some slight modifications. Removed all members and fields marked as deprecated. 2020-02-11 16:36:07 -08:00
Jordan Maples [MSFT]
cce6ee563e address issue with v140 toolset 2020-02-10 17:09:58 -08:00
Jordan Maples [MSFT]
dd78144c2e msvc and gcc work locally 2020-02-10 13:17:22 -08:00
Jordan Maples [MSFT]
d8fa68c4a5 address build failures 2020-02-07 14:40:09 -08:00
Jordan Maples [MSFT]
b81d6e40e1 constexpr the make_subspan calls. 2020-02-07 14:15:44 -08:00
Jordan Maples [MSFT]
377b2db537 almost parity with std::span 2020-02-07 14:09:57 -08:00
Jordan Maples [MSFT]
a49ff1b8df update span specialization of at, change some tests back to int i with narrowing for the comparisons. 2020-02-05 17:12:31 -08:00
Jordan Maples [MSFT]
ff5f7973a2 remove brackets around this deref for span_iterator operators 2020-02-05 14:36:34 -08:00
Jordan Maples [MSFT]
7fcc142ffc addressing travis errors 2020-02-05 14:32:08 -08:00
Jordan Maples [MSFT]
5cf1610cfe prevent overflow in size_bytes. fix compilation issue for clang 3.6 and 3.7 2020-02-05 12:58:49 -08:00
Jordan Maples [MSFT]
d7e1611137 gsl::index ptrdiff_t -> size_t. remove span::at span::operator(). 2020-02-04 16:53:43 -08:00
Jordan Maples [MSFT]
5a1e4f3953 update index_type to size_type, fix a couple Expects 2020-02-04 15:31:33 -08:00
Jordan Maples [MSFT]
61c6ef8d42 remove index_type from string_span, update comments 2020-02-04 13:30:03 -08:00
Jordan Maples [MSFT]
db2134485a Merge branch 'dev/jomaples/unsigned' of https://github.com/jordanmaples/gsl into dev/jomaples/unsigned 2020-02-04 12:01:30 -08:00
Jordan Maples [MSFT]
0c6ce424ab refactoring index_type to size_type, changing expects 2020-02-04 12:01:27 -08:00
Jordan Maples [MSFT]
e9fea77bcb
Update include/gsl/span
Co-Authored-By: Casey Carter <cartec69@gmail.com>
2020-02-03 18:31:50 -08:00
Jordan Maples [MSFT]
4ec7058b56
Update include/gsl/span
Co-Authored-By: Casey Carter <cartec69@gmail.com>
2020-02-03 18:31:21 -08:00
Jordan Maples [MSFT]
49e7ed1ebf updating comparisons 2020-02-03 18:27:09 -08:00
Jordan Maples [MSFT]
592c28c6d1 fixing spaces in gsl_suppress 2020-02-03 18:18:14 -08:00
Jordan Maples [MSFT]
2b7a8f1f2f Merge branch 'dev/jomaples/unsigned' of https://github.com/jordanmaples/gsl into dev/jomaples/unsigned 2020-02-03 18:14:52 -08:00
Jordan Maples [MSFT]
e0dc8095b3 addressing feedback 2020-02-03 18:13:14 -08:00
Jordan Maples [MSFT]
81c2a1da15 addressing feedback 2020-02-03 18:12:57 -08:00
Jordan Maples [MSFT]
827fafd32c
Update include/gsl/span
Co-Authored-By: Casey Carter <cartec69@gmail.com>
2020-02-03 18:12:32 -08:00
Jordan Maples [MSFT]
24646c6f7c
Update include/gsl/span
Co-Authored-By: Casey Carter <cartec69@gmail.com>
2020-02-03 17:51:45 -08:00
Jordan Maples [MSFT]
f4ee6ee73b
Update include/gsl/span
Co-Authored-By: Casey Carter <cartec69@gmail.com>
2020-02-03 17:51:25 -08:00
Jordan Maples [MSFT]
1815791af8 Change iterator from Span* & ptrdiff_t to pointer, pointer, pointer 2020-02-03 16:26:36 -08:00
Jordan Maples [MSFT]
d9d6ea8196 remove comparison to dynamic_extent 2020-02-03 13:53:38 -08:00
Jordan Maples [MSFT]
3e40b3fa4b Merge branch 'dev/jomaples/unsigned' of https://github.com/jordanmaples/gsl into dev/jomaples/unsigned 2020-02-03 13:52:11 -08:00
Jordan Maples [MSFT]
d0fdbdbffa fixing suppress spacing 2020-02-03 13:52:00 -08:00
Jordan Maples [MSFT]
9bb900e834
Update include/gsl/span
Co-Authored-By: Casey Carter <cartec69@gmail.com>
2020-02-03 13:46:18 -08:00
Jordan Maples [MSFT]
17e372c155
Update include/gsl/span
Co-Authored-By: Casey Carter <cartec69@gmail.com>
2020-02-03 13:45:56 -08:00
Jordan Maples [MSFT]
5b8cf5422b casting -1 for dynamic extent 2020-02-03 12:49:57 -08:00
Jordan Maples [MSFT]
eabd9358f0 addressing some comments 2020-02-03 12:46:37 -08:00
Jordan Maples [MSFT]
ad71477183 fix build breaks 2020-02-03 12:26:15 -08:00
Jordan Maples [MSFT]
8579165d0a change span from signed to unsigned to align to std 2020-02-03 10:56:31 -08:00
Kunal Tyagi
26a68c882b
Correct spelling error in docs 2020-01-17 14:32:37 +09:00
Jordan Maples [MSFT]
395a5bf550
Merge branch 'master' into dev/jomaples/add_missing_span_functions 2020-01-10 10:20:37 -08:00
Jordan Maples [MSFT]
a1e6fcbc46
Merge branch 'master' into dev/jomaples/deprecate_span_non_std_functions 2020-01-09 16:39:24 -08:00
Jordan Maples [MSFT]
2d878b94ee
Merge branch 'master' into dev/jomaples/add_missing_span_functions 2020-01-09 16:37:12 -08:00
Jordan Maples [MSFT]
cfd82aef4e deprecating span::at and span::operator() 2020-01-09 12:51:28 -08:00
Jordan Maples [MSFT]
3c0b38b777
Merge pull request #833 from JordanMaples/dev/jomaples/noexceptspan
Update noexcept in span and span_iterator
2020-01-09 12:45:17 -08:00
Jordan Maples [MSFT]
c7f9b3301a noexcepting new functions 2020-01-09 12:13:12 -08:00
Jordan Maples [MSFT]
4b823b1651 adding front and back 2020-01-09 12:03:27 -08:00
Jordan Maples [MSFT]
3bf4106a44 noexcept all of the span iterator stuff 2020-01-08 12:34:11 -08:00
Martijn Otto
b186b6cc68
Implement free-standing (c|r|cr)(begin|end) and ssize functions 2020-01-08 21:01:52 +01:00
Jordan Maples [MSFT]
b33bd4aebe updating all span functions to be noexcept 2020-01-08 11:51:15 -08:00
JACK_1729
2a1ef25406
Update span
About my Issue - https://github.com/Microsoft/GSL/issues/765
2019-02-20 20:25:50 +05:30
Anna Gringauze
6418b5f4de
Clang cl (#762)
* Added c++17 test configurations for clang5.0 and clang6.0

* Fix #739 correct cppcorecheck warnings for clang-cl

* Add clang-cl  configurations

* Corrections Appveyor;
Temporarily disable msvc compilation for faster testing (#741)

* Add path to clang-cl.exe (#741)

* Escape backslash in path (#741)

* Update vcpkg (#741)

* Check vcpkg version; try without building vcpkg; use latest clang-cl from path (#741)

* Fix blocks in ps script (#741)

* Try accessing APPVEYOR_BUILD_FOLDER variable (#471)

* Update span size() bug confirmation test for GCC 6.5 (#741)

* MSVC flags to Clang-cl; disable c++98-compat and undefined macro warnings (#741)

* Suppress clang warning on tests (missing-prototypes) (#741)

* Fix clang warning -Wnewline-eof (#741)

* Fix clang warning -Wdouble-promotion (#741)

* Set linker explicitly

* Clean condition statement

* For Clang, fallback to the AppVeyor installed version of CMake

* Fix clang warning -Wmissing-variable-declarations

* Fallback to the MSVC linker until vcpkg has been updated

* Revert "Fallback to the MSVC linker until vcpkg has been updated"

This reverts commit 7263f3289e.

* Fix clang warning -Wunused-member-function

* Fix clang warning -Wmissing-noreturn

* Fix clang warning -Winvalid-noreturn on Windows

* Add macro block end comment on large #if blocks

* Workaround: fallback to mscv link.exe

* Workaround: get msvc paths into PowerShell through intermediate file

* Workaround: fix, remove "PATH=" from text

* Workaround: try with full-path; and return user PATH

* Workaround: fix, escape backslashes

* Revert all since "Workaround: fallback to mscv link.exe" did not work on AppVeyor

This reverts the commits:
bda3d6a428
97062933ac
0f4fb04bac
1b0c19afd1
a5739ea5f0

* Suppress output of git pull; remove vcpkg from cache

* Re-enable AppVeyor builds for all platforms

* Correct typo

Co-Authored-By: Farwaykorse <Farwaykorse@users.noreply.github.com>

* Add Clang-cl 7.0.0 to the supported platforms

* Revert "Fix clang warning -Wunused-member-function"

This reverts commit 6fe1a42035.

* Fix or locally suppress clang warning -Wunused-member-function

* format touched code and correct comment

* git pull --quiet

* fix logic error in workaround

* fix missing bracket

* Suppress output of mkdir

* Replace MSBuild with Ninja

* Suppress output of 7z

* Add architecture flags for Clang

* Drop workaround for lld-link

* 7-zip Overwrite and Alternative output suppression without suppressing errors

Replaces 3c1c0794dd

* AppVeyor setup and CMake before build

* reorder compiler configuration

* remove unnecessary

* remove -fno-strict-aliasing

* remove -Wsign-conversion, since before v4.0 part of -Wconversion

* -Wctor-dtor-privacy is GCC only

* remove -Woverloaded-virtual part of -Wmost, part of -Wall

* add -Wmissing-noreturn

* remove the pragmas for -Wunused-member-function

* Re-add MSBuild generator on AppVeyor

* Print CMake commands

* Add MSBuild toolset selection

* Separate Architecture setting

* clang-cl: add -Weverything

* clang-cl -Wno-c++98-compat

* clang-cl -Wno-c++98-compat-pedantic

* clang-cl -Wno-missing-prototypes

* clang-cl C++14 -Wno-unused-member-function

* clang-cl -Wundef __GNUC__

* clang++: add -Weverything

* clang++ -Wno-c++98-compat

* clang++ -Wno-c++98-compat-pedantic

* clang++ -Wno-missing-prototypes

* clang++ -Wno-weak-vtables

* clang++ C++14 -Wno-unused-member-function

* clang++ fix -Wundef _MSC_VER

* clang++ -Wno-padded

* clang++ solve -Wdeprecated

* Add AppleClang compiler target
Since CMake v3.0 use of Clang for both is deprecated

* clang++ v5.0 C++17 -Wno-undefined-func-template

* Add VS2015 + LLVM/clang-cl to AppVeyor

* Do not disable constexpr when compiling with clang-cl on Windows

* Clean-up clang-only warnings (now under -Weverything)

* Revert "Fix clang warning -Winvalid-noreturn on Windows"

This reverts commit 2238c4760e.

* Suppress -Winvalid-noreturn for the MS STL noexception workaround

* CMake: put preprocessor definition in target_compile_definitions

* Solve compiler warning C4668: __GNUC__ not defined
2019-01-15 10:27:34 -08:00
Alex Green
7a7d025ffa Make CheckRange constexpr (#754) (#755) 2019-01-14 16:44:45 -08:00
beinhaerter
88aca1caf3 added noexcept to get rid off VC warning con.4 (#748) 2018-11-28 11:57:43 -08:00
kile0
5a7093f983 Use the c++17 constexpr if in CheckRange if possible (#753)
* change c++17 to use constexpr if in CheckRange

* remove unnecessary macro

* use the portable feature test macro rather than direct version check
2018-11-28 11:52:11 -08:00
Dave Hill
c02ddae4bc Span can be constructed from empty std::array safely (#686)
* Span std::array c'tor uses arr.data() instead of &arr[0]
- Fixes runtime issues when constructing from an empty std::array

* Construct span with std::data if C++17 detected

* Specialize span c'tor for std::array of length 0, set storage to nullptr
2018-11-05 15:39:41 -08:00
Anna Gringauze
1995e86d1a span constructor no address (#723)
* Changed &arr[0] to std::array<T, N>::data and std::address_of to protect against overloaded operator&.

* Removed the usage of `std::addressof` because it is a C++ 17 feature. Using decay for C arrays instead.

* Add unit tests for #662.

* Added c++17 test configurations for clang5.0 and clang6.0

* fixed CppCoreCheck pointer decay warning
2018-08-19 17:10:53 -07:00
Anna Gringauze
585f48ce55 better check for branch opt (#724)
* Added c++17 test configurations for clang5.0 and clang6.0

* Simplified optimization in span::operator[]
2018-08-19 16:27:30 -07:00
Anna Gringauze
5016ce4a4d
Dev/annagrin/opt neg branch (#721)
* Added c++17 test configurations for clang5.0 and clang6.0

* Added optimization that removes a branch from span::operator[]

* minor beauty fix

* added a better message for the optimization, fixed signed/unsigned warning

* better check fir wrap-around possibility
2018-08-17 11:36:06 -07:00
Anna Gringauze
cea0d0ac2b fix cppcorecheck warnings (#703)
* Added c++17 test configurations for clang5.0 and clang6.0

* Fixed CppCoreCheck warnings in GSL and tests

- Added CMakeSettings.json for VS Open Folder configuration
	- So we can easily run CppCoreCheck in VS
- Fixed CppCorecheck warnings where it made sense
- Suppressed the rest
	- Some suppression does not work due to compiler/tool bugs,
          so replaced by #pragma disable
	- CppCoreCheck has noise, suppressed those with comments
	- Catch produces many warnings, blanket-supressed them all
- Had to fix clang formatting to keep attributes in place
	- clang-format does not support attributes, so I am using
        - "CommentPragmas: '^ NO-FORMAT:'" to skip formatiting on them
- Removed GSL_NOEXCEPT macro, removed incorred noexcepts

* Ignore unknown attributes

* ignore unknown attributes in noexception mode tests

* fixed C26472 in at()

* created GSL_SUPPRESS macro to allow all compilers to parse suppression attributes

* try to fix gcc compilation problems with attributes

* ignore gsl::suppress for gcc

* move suppression to function level on return statements

clang5.0 and up does not allow attributes on return statemets in constexpr functions

* move suppression to function level on return statements

* use GSL_SUPPRESS in algorithm_tests

* Addressed PR comments
2018-08-12 21:44:17 -07:00
menete
ffdaf0fb21 fix gcc build (gcc 7) (#690)
simple solution, disable the specific warning
2018-06-08 11:41:06 -07:00
Anna Gringauze
51ae678d08
Add usage for check-and-unwrap of MS STL iterators (#687)
* Add usage for check-and-unwrap of MS STL iterators

This is Billy ONeal's PR #682 with a typo fixed.

See corresponding change here:
ca77129308
That change officially exposes the STL's range checking machinery,
available in MSVC++ "15.8"+
This change augments GSL span::iterator to call into that newly exposed
machinery.

_Verify_range(cit, cit)
Requests that the iterator type check that the parameters form a valid
[First, Last) range iterator pair. This replaces _DEBUG_RANGE and
supporting machinery. The standard library provides a version for
pointers under _IDL != 0; otherwise they are normally provided via
hidden friend functions. Note that declaring some of these hidden
friends for "wrapper" iterators like move_iterator and reverse_iterator
triggers VSO#610735.

cit._Verify_offset(difference_type _Off)
For random-access iterators, performs any asserts that would be
performed by i += _Off; except with possibly a better error message and
without moving the iterator.

cit._Unwrapped()
Returns an "unchecked" or "unwrapped" iterator which has previously been
validated. The iterator may have been validated by a call to
_Verify_range or _Verify_offset (above), or by seeking a checked
iterator to a "high water mark" point.

it._Seek_to(cit) / it._Seek_to(return value from _Unwrapped())
Moves the position of the checked iterator it to the position of the
unchecked iterator supplied. Generally not intended to perform range
checks.

* Fixed build break in VS2015

* fixed constexpr build break when using VS2015
2018-05-22 18:07:49 -07:00
Casey Carter
d6a2242d97 [span] Tell MSVC how to avoid range-checking (#664)
* [span] implement non-member + as a hidden friend

Drive-by: remove garbage `operator-(difference_type, span_iterator)`.

* [span] Use pointers for range-based-for on MSVC
2018-05-09 14:01:22 -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
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
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
314065b317 Fix span comparison ops to take arguments by-value rather than by-ref. 2018-02-11 14:22:08 -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
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
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
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
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
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
Casey Carter
3819df6e37 Properly qualify std::size_t (#448) 2017-02-13 12:11:45 -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