forked from microsoft/GSL
Compare commits
104 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6f4529395c | |||
| 9fa2c5d5b9 | |||
| 8009a703c2 | |||
| cfb4db0c1e | |||
| 6432f920ea | |||
| 2af9b11fe9 | |||
| dc6fdff4c0 | |||
| 2ccf36b4b9 | |||
| bd23bdc0ad | |||
| 1665f07cf6 | |||
| 3f68a0034a | |||
| 7721de88f3 | |||
| a64c489c78 | |||
| 5e773556fe | |||
| 5de956aaf0 | |||
| bd803cc7cf | |||
| e7e3bf4f5f | |||
| 21b69e5cce | |||
| d58e50c6f4 | |||
| 5fb0c8611e | |||
| 6c518638ac | |||
| 4a4bb3c13a | |||
| b6451c5db0 | |||
| 81957f6f91 | |||
| 6aa755e9ce | |||
| e426750695 | |||
| c25a7544b8 | |||
| 06c46195ee | |||
| 83ce710d6c | |||
| ec471abe44 | |||
| dad3d80c25 | |||
| a9ffcf7f65 | |||
| e09326eefd | |||
| d09f1544fd | |||
| 74968d3ef8 | |||
| 0c80f51f7c | |||
| ef714fa49e | |||
| 9355982fc5 | |||
| 4da6a264c4 | |||
| 2469db7a5a | |||
| afe824490e | |||
| 72ddfb7a40 | |||
| bf0697be71 | |||
| 97cb97c685 | |||
| 13f57a1e70 | |||
| c482c82d3a | |||
| 01eaf5bef1 | |||
| 63379b7935 | |||
| 2231d733c6 | |||
| f8d9f2e2e3 | |||
| 552eedb390 | |||
| ca3bf7710f | |||
| 559f8cfaae | |||
| f79ed1bb5c | |||
| bf6e103dfd | |||
| 4c66cea06c | |||
| 478d876951 | |||
| 853b061141 | |||
| 301030310e | |||
| be3bc0e754 | |||
| 98002ab601 | |||
| cfe9baf02e | |||
| 0f6dbc9e29 | |||
| 78744ed530 | |||
| 794d7bb69b | |||
| 72803a7ecb | |||
| 4d2090ebc4 | |||
| c4a2ce6cc8 | |||
| 9720cc552a | |||
| c143a07f61 | |||
| 6c405a1b7f | |||
| 689abc2982 | |||
| 0dbdf322fa | |||
| 283e31478f | |||
| 8cd19412b4 | |||
| 25e7af9c7d | |||
| 7e4ed8da98 | |||
| 34750814fb | |||
| 313a1121bf | |||
| 1e44481646 | |||
| ed3fea6d93 | |||
| 31604f44f6 | |||
| d3468230b1 | |||
| 552cd20472 | |||
| 2085c7acde | |||
| 33544a706e | |||
| f0160fcb1b | |||
| 2a483c1728 | |||
| 031231466d | |||
| a6d382109e | |||
| 09caa20d99 | |||
| 0843ea444f | |||
| 1e4e23738c | |||
| 839de21707 | |||
| 91858ca3f3 | |||
| 0ab350f5de | |||
| 84847041ee | |||
| 1e5f44d3ea | |||
| de053645bb | |||
| 29297e7dac | |||
| 879335cebf | |||
| f5cf01083b | |||
| 830b081de7 | |||
| 423841e965 |
@@ -0,0 +1,50 @@
|
||||
name: CI_Android
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
Android:
|
||||
runs-on: macos-latest
|
||||
defaults:
|
||||
run:
|
||||
working-directory: build
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Create build directory
|
||||
run: mkdir -p build
|
||||
working-directory: .
|
||||
|
||||
- name: Start emulator
|
||||
run: |
|
||||
echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --install 'system-images;android-24;default;x86_64'
|
||||
echo "no" | $ANDROID_HOME/tools/bin/avdmanager create avd -n xamarin_android_emulator -k 'system-images;android-24;default;x86_64' --force
|
||||
$ANDROID_HOME/emulator/emulator -list-avds
|
||||
echo "Starting emulator"
|
||||
# Start emulator in background
|
||||
nohup $ANDROID_HOME/emulator/emulator -avd xamarin_android_emulator -no-snapshot > /dev/null 2>&1 &
|
||||
echo "Emulator starting"
|
||||
|
||||
- name: Configure
|
||||
run: cmake -DCMAKE_TOOLCHAIN_FILE=$ANDROID_HOME/ndk-bundle/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=16 -DANDROID_ABI=x86_64 -DCMAKE_BUILD_TYPE=Debug ..
|
||||
|
||||
- name: Build
|
||||
run: cmake --build . --parallel
|
||||
|
||||
- name: Wait for emulator ready
|
||||
run: |
|
||||
$ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d '\r') ]]; do sleep 10; done; input keyevent 82'
|
||||
$ANDROID_HOME/platform-tools/adb devices
|
||||
$ANDROID_HOME/platform-tools/adb shell getprop ro.product.cpu.abi
|
||||
echo "Emulator started"
|
||||
|
||||
- name: Deploy tests
|
||||
run: |
|
||||
adb push tests /data/local/tmp
|
||||
adb shell find /data/local/tmp/tests -maxdepth 1 -exec chmod +x {} \\\;
|
||||
|
||||
- name: Test
|
||||
run: adb shell find /data/local/tmp/tests -name "*_tests" -maxdepth 1 -exec {} \\\;
|
||||
@@ -0,0 +1,51 @@
|
||||
name: CI_iOS
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
iOS:
|
||||
runs-on: macos-latest
|
||||
defaults:
|
||||
run:
|
||||
working-directory: build
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Create build directory
|
||||
run: mkdir -p build
|
||||
working-directory: .
|
||||
|
||||
- name: Configure
|
||||
run: |
|
||||
cmake \
|
||||
-GXcode \
|
||||
-DCMAKE_SYSTEM_NAME=iOS \
|
||||
"-DCMAKE_OSX_ARCHITECTURES=arm64;x86_64" \
|
||||
-DCMAKE_OSX_DEPLOYMENT_TARGET=8 \
|
||||
-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY \
|
||||
"-DMACOSX_BUNDLE_GUI_IDENTIFIER=GSL.\$(EXECUTABLE_NAME)" \
|
||||
-DMACOSX_BUNDLE_BUNDLE_VERSION=3.0.1 \
|
||||
-DMACOSX_BUNDLE_SHORT_VERSION_STRING=3.0.1 \
|
||||
..
|
||||
|
||||
- name: Build
|
||||
run: cmake --build . --parallel `sysctl -n hw.ncpu` --config Release -- -sdk iphonesimulator
|
||||
|
||||
- name: Start simulator
|
||||
run: |
|
||||
RUNTIME=`xcrun simctl list runtimes iOS -j|jq '.runtimes|last.identifier'`
|
||||
UDID=`xcrun simctl list devices iPhone available -j|jq -r ".devices[$RUNTIME]|last.udid"`
|
||||
xcrun simctl bootstatus $UDID -b
|
||||
|
||||
- name: Test
|
||||
run: |
|
||||
for TEST in `find tests/Release-iphonesimulator -depth 1 -name "*.app"`
|
||||
do
|
||||
xcrun simctl install booted $TEST
|
||||
TEST_ID=`plutil -convert json -o - $TEST/Info.plist|jq -r ".CFBundleIdentifier"`
|
||||
xcrun simctl launch --console booted $TEST_ID
|
||||
xcrun simctl uninstall booted $TEST_ID
|
||||
done
|
||||
+16
-230
@@ -12,9 +12,9 @@ cache:
|
||||
- ${TRAVIS_BUILD_DIR}/deps
|
||||
|
||||
stages:
|
||||
- name: Latest # build jobs to run first and always
|
||||
- name: Latest # Compiler with the latest major version
|
||||
- name: Previous # Compilers with the major version Latest - 1
|
||||
- name: Validation # run other jobs
|
||||
- name: Legacy # build with all other supported compilers
|
||||
|
||||
jobs:
|
||||
include:
|
||||
@@ -62,73 +62,11 @@ jobs:
|
||||
# AppleClang on OSX
|
||||
##########################################################################
|
||||
|
||||
# Xcode 8.3
|
||||
- name: AppleClang Xcode-8.3 C++14 Debug
|
||||
stage: Legacy
|
||||
env: BUILD_TYPE=Debug GSL_CXX_STANDARD=14
|
||||
os: osx
|
||||
osx_image: xcode8.3
|
||||
- name: AppleClang Xcode-8.3 C++14 Release
|
||||
env: BUILD_TYPE=Release GSL_CXX_STANDARD=14
|
||||
os: osx
|
||||
osx_image: xcode8.3
|
||||
|
||||
# Xcode 9.0 earliest C++17 support
|
||||
- name: AppleClang Xcode-9.0 C++17 Debug
|
||||
env: BUILD_TYPE=Debug GSL_CXX_STANDARD=17
|
||||
os: osx
|
||||
osx_image: xcode9 # AppleClang 9.1.0 same compiler in Xcode 9.0, 9.1 and 9.2
|
||||
- name: AppleClang Xcode-9.0 C++17 Release
|
||||
env: BUILD_TYPE=Release GSL_CXX_STANDARD=17
|
||||
os: osx
|
||||
osx_image: xcode9
|
||||
- name: AppleClang Xcode-9.0 C++14 Debug
|
||||
env: BUILD_TYPE=Debug GSL_CXX_STANDARD=14
|
||||
os: osx
|
||||
osx_image: xcode9
|
||||
- name: AppleClang Xcode-9.0 C++14 Release
|
||||
env: BUILD_TYPE=Release GSL_CXX_STANDARD=14
|
||||
os: osx
|
||||
osx_image: xcode9
|
||||
|
||||
# Xcode 9.4
|
||||
- name: AppleClang Xcode-9.4 C++14 Debug
|
||||
env: BUILD_TYPE=Debug GSL_CXX_STANDARD=14
|
||||
os: osx
|
||||
osx_image: xcode9.4 # AppleClang 9.1.0 same compiler as Xcode 9.3
|
||||
- name: AppleClang Xcode-9.4 C++14 Release
|
||||
env: BUILD_TYPE=Release GSL_CXX_STANDARD=14
|
||||
os: osx
|
||||
osx_image: xcode9.4
|
||||
- name: AppleClang Xcode-9.4 C++17 Debug
|
||||
env: BUILD_TYPE=Debug GSL_CXX_STANDARD=17
|
||||
os: osx
|
||||
osx_image: xcode9.4
|
||||
- name: AppleClang Xcode-9.4 C++17 Release
|
||||
env: BUILD_TYPE=Release GSL_CXX_STANDARD=17
|
||||
os: osx
|
||||
osx_image: xcode9.4
|
||||
|
||||
# Xcode 10.1
|
||||
- name: AppleClang Xcode-10.1 C++14 Debug
|
||||
env: BUILD_TYPE=Debug GSL_CXX_STANDARD=14
|
||||
os: osx
|
||||
osx_image: xcode10.1 # AppleClang 10.0.0 same compiler as Xcode 10.0
|
||||
- name: AppleClang Xcode-10.1 C++14 Release
|
||||
env: BUILD_TYPE=Release GSL_CXX_STANDARD=14
|
||||
os: osx
|
||||
osx_image: xcode10.1
|
||||
- name: AppleClang Xcode-10.1 C++17 Debug
|
||||
env: BUILD_TYPE=Debug GSL_CXX_STANDARD=17
|
||||
os: osx
|
||||
osx_image: xcode10.1
|
||||
- name: AppleClang Xcode-10.1 C++17 Release
|
||||
env: BUILD_TYPE=Release GSL_CXX_STANDARD=17
|
||||
os: osx
|
||||
osx_image: xcode10.1
|
||||
|
||||
# Xcode 10.3
|
||||
- name: AppleClang Xcode-10.3 C++14 Debug
|
||||
stage: Previous
|
||||
env: BUILD_TYPE=Debug GSL_CXX_STANDARD=14
|
||||
os: osx
|
||||
osx_image: xcode10.3 # AppleClang 10.0.1 same compiler as Xcode 10.2
|
||||
@@ -145,157 +83,33 @@ jobs:
|
||||
os: osx
|
||||
osx_image: xcode10.3
|
||||
|
||||
# Xcode 11.3
|
||||
- name: AppleClang Xcode-11.3 C++17 Debug
|
||||
|
||||
# Xcode 11.4
|
||||
- name: AppleClang Xcode-11.4 C++17 Debug
|
||||
stage: Latest
|
||||
env: BUILD_TYPE=Debug GSL_CXX_STANDARD=17
|
||||
os: osx
|
||||
osx_image: xcode11.3 # AppleClang 11.0.0 linker update / same as Xcode 11.2
|
||||
- name: AppleClang Xcode-11.3 C++17 Release
|
||||
osx_image: xcode11.4
|
||||
- name: AppleClang Xcode-11.4 C++17 Release
|
||||
env: BUILD_TYPE=Release GSL_CXX_STANDARD=17
|
||||
os: osx
|
||||
osx_image: xcode11.3
|
||||
- name: AppleClang Xcode-11.3 C++14 Debug
|
||||
osx_image: xcode11.4
|
||||
- name: AppleClang Xcode-11.4 C++14 Debug
|
||||
env: BUILD_TYPE=Debug GSL_CXX_STANDARD=14
|
||||
os: osx
|
||||
osx_image: xcode11.3
|
||||
- name: AppleClang Xcode-11.3 C++14 Release
|
||||
osx_image: xcode11.4
|
||||
- name: AppleClang Xcode-11.4 C++14 Release
|
||||
env: BUILD_TYPE=Release GSL_CXX_STANDARD=14
|
||||
os: osx
|
||||
osx_image: xcode11.3
|
||||
osx_image: xcode11.4
|
||||
|
||||
##########################################################################
|
||||
# Clang on Linux
|
||||
##########################################################################
|
||||
|
||||
# Clang 3.6
|
||||
- name: Clang-3.6 C++14 Debug
|
||||
stage: Legacy
|
||||
dist: xenial
|
||||
env: CXX=clang++-3.6 BUILD_TYPE=Debug GSL_CXX_STANDARD=14
|
||||
addons: &clang36
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.6
|
||||
- name: Clang-3.6 C++14 Release
|
||||
dist: xenial
|
||||
env: CXX=clang++-3.6 BUILD_TYPE=Release GSL_CXX_STANDARD=14
|
||||
addons: *clang36
|
||||
|
||||
# Clang 3.7
|
||||
- name: Clang-3.7 C++14 Debug
|
||||
dist: xenial
|
||||
env: CXX=clang++-3.7 BUILD_TYPE=Debug GSL_CXX_STANDARD=14
|
||||
addons: &clang37
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.7
|
||||
- name: Clang-3.7 C++14 Release
|
||||
dist: xenial
|
||||
env: CXX=clang++-3.7 BUILD_TYPE=Release GSL_CXX_STANDARD=14
|
||||
addons: *clang37
|
||||
|
||||
# Clang 3.8
|
||||
- name: Clang-3.8 C++14 Debug
|
||||
dist: xenial
|
||||
env: CXX=clang++-3.8 BUILD_TYPE=Debug GSL_CXX_STANDARD=14
|
||||
addons: &clang38
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.8
|
||||
- name: Clang-3.8 C++14 Release
|
||||
dist: xenial
|
||||
env: CXX=clang++-3.8 BUILD_TYPE=Release GSL_CXX_STANDARD=14
|
||||
addons: *clang38
|
||||
|
||||
# Clang 3.9
|
||||
- name: Clang-3.9 C++14 Debug
|
||||
env: CXX=clang++-3.9 BUILD_TYPE=Debug GSL_CXX_STANDARD=14
|
||||
addons: &clang39
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.9
|
||||
- name: Clang-3.9 C++14 Release
|
||||
env: CXX=clang++-3.9 BUILD_TYPE=Release GSL_CXX_STANDARD=14
|
||||
addons: *clang39
|
||||
|
||||
# Clang 4.0
|
||||
- name: Clang-4.0 C++14 Debug
|
||||
env: CXX=clang++-4.0 BUILD_TYPE=Debug GSL_CXX_STANDARD=14
|
||||
addons: &clang40
|
||||
apt:
|
||||
packages:
|
||||
- clang-4.0
|
||||
- name: Clang-4.0 C++14 Release
|
||||
env: CXX=clang++-4.0 BUILD_TYPE=Release GSL_CXX_STANDARD=14
|
||||
addons: *clang40
|
||||
|
||||
# Clang 5.0
|
||||
- name: Clang-5.0 C++14 Debug
|
||||
env: CXX=clang++-5.0 BUILD_TYPE=Debug GSL_CXX_STANDARD=14
|
||||
addons: &clang50
|
||||
apt:
|
||||
packages:
|
||||
- clang-5.0
|
||||
- name: Clang-5.0 C++14 Release
|
||||
env: CXX=clang++-5.0 BUILD_TYPE=Release GSL_CXX_STANDARD=14
|
||||
addons: *clang50
|
||||
- name: Clang-5.0 C++17 Debug
|
||||
env: CXX=clang++-5.0 BUILD_TYPE=Debug GSL_CXX_STANDARD=17
|
||||
addons: *clang50
|
||||
- name: Clang 5.0 C++17 Release
|
||||
env: CXX=clang++-5.0 BUILD_TYPE=Release GSL_CXX_STANDARD=17
|
||||
addons: *clang50
|
||||
|
||||
# Clang 6.0
|
||||
- name: Clang-6.0 C++14 Debug
|
||||
env: CXX=clang++-6.0 BUILD_TYPE=Debug GSL_CXX_STANDARD=14
|
||||
addons: &clang60
|
||||
apt:
|
||||
packages:
|
||||
- clang-6.0
|
||||
- name: Clang 6.0 C++14 Release
|
||||
env: CXX=clang++-6.0 BUILD_TYPE=Release GSL_CXX_STANDARD=14
|
||||
addons: *clang60
|
||||
- name: Clang-6.0 C++17 Debug
|
||||
env: CXX=clang++-6.0 BUILD_TYPE=Debug GSL_CXX_STANDARD=17
|
||||
addons: *clang60
|
||||
- name: Clang 6.0 C++17 Release
|
||||
env: CXX=clang++-6.0 BUILD_TYPE=Release GSL_CXX_STANDARD=17
|
||||
addons: *clang60
|
||||
|
||||
# Clang 7 (default on Xenial and Bionic images)
|
||||
- name: Clang-7 C++14 Debug
|
||||
env: CXX=clang++ BUILD_TYPE=Debug GSL_CXX_STANDARD=14
|
||||
- name: Clang-7 C++14 Release
|
||||
env: CXX=clang++ BUILD_TYPE=Release GSL_CXX_STANDARD=14
|
||||
- name: Clang-7 C++17 Debug
|
||||
env: CXX=clang++ BUILD_TYPE=Debug GSL_CXX_STANDARD=17
|
||||
- name: Clang-7 C++17 Release
|
||||
env: CXX=clang++ BUILD_TYPE=Release GSL_CXX_STANDARD=17
|
||||
|
||||
# Clang 8
|
||||
- name: Clang-8 C++14 Debug
|
||||
env: CXX=clang++-8 BUILD_TYPE=Debug GSL_CXX_STANDARD=14
|
||||
addons: &clang8
|
||||
apt:
|
||||
sources:
|
||||
- sourceline: 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-8 main'
|
||||
key_url: https://apt.llvm.org/llvm-snapshot.gpg.key
|
||||
packages:
|
||||
- clang-8
|
||||
- name: Clang-8 C++14 Release
|
||||
env: CXX=clang++-8 BUILD_TYPE=Release GSL_CXX_STANDARD=14
|
||||
addons: *clang8
|
||||
- name: Clang-8 C++17 Debug
|
||||
env: CXX=clang++-8 BUILD_TYPE=Debug GSL_CXX_STANDARD=17
|
||||
addons: *clang8
|
||||
- name: Clang-8 C++17 Release
|
||||
env: CXX=clang++-8 BUILD_TYPE=Release GSL_CXX_STANDARD=17
|
||||
addons: *clang8
|
||||
|
||||
# Clang 9
|
||||
- name: Clang-9 C++14 Debug
|
||||
stage: Previous
|
||||
env: CXX=clang++-9 BUILD_TYPE=Debug GSL_CXX_STANDARD=14
|
||||
addons: &clang9
|
||||
apt:
|
||||
@@ -339,37 +153,9 @@ jobs:
|
||||
# GCC on Linux
|
||||
##########################################################################
|
||||
|
||||
# GCC 5 (default on the Xenial image)
|
||||
- name: GCC-5 C++14 Debug
|
||||
stage: Legacy
|
||||
dist: xenial
|
||||
env: CXX=g++-5 BUILD_TYPE=Debug GSL_CXX_STANDARD=14
|
||||
- name: GCC-5 C++14 Release
|
||||
dist: xenial
|
||||
env: CXX=g++-5 BUILD_TYPE=Release GSL_CXX_STANDARD=14
|
||||
|
||||
# GCC 6
|
||||
- name: GCC-6 C++14 Debug
|
||||
env: CXX=g++-6 BUILD_TYPE=Debug GSL_CXX_STANDARD=14
|
||||
addons: &gcc6
|
||||
apt:
|
||||
packages: g++-6
|
||||
- name: GCC-6 C++14 Release
|
||||
env: CXX=g++-6 BUILD_TYPE=Release GSL_CXX_STANDARD=14
|
||||
addons: *gcc6
|
||||
|
||||
# GCC 7 (default on the Bionic image)
|
||||
- name: GCC-7 C++14 Debug
|
||||
env: CXX=g++-7 BUILD_TYPE=Debug GSL_CXX_STANDARD=14
|
||||
- name: GCC-7 C++14 Release
|
||||
env: CXX=g++-7 BUILD_TYPE=Release GSL_CXX_STANDARD=14
|
||||
- name: GCC-7 C++17 Debug
|
||||
env: CXX=g++-7 BUILD_TYPE=Debug GSL_CXX_STANDARD=17
|
||||
- name: GCC-7 C++17 Release
|
||||
env: CXX=g++-7 BUILD_TYPE=Release GSL_CXX_STANDARD=17
|
||||
|
||||
# GCC 8
|
||||
- name: GCC-8 C++14 Debug
|
||||
stage: Previous
|
||||
env: CXX=g++-8 BUILD_TYPE=Debug GSL_CXX_STANDARD=14
|
||||
addons: &gcc8
|
||||
apt:
|
||||
@@ -538,7 +324,7 @@ before_script:
|
||||
- |
|
||||
cd "${TRAVIS_BUILD_DIR:?}"
|
||||
mkdir build && cd build
|
||||
if [[ ${GSL_CXX_STANDARD:-} ]]; then
|
||||
if [[ ${GSL_CXX_STANDARD:-} ]]; then
|
||||
CMAKE_GEN_FLAGS=("-DGSL_CXX_STANDARD=$GSL_CXX_STANDARD")
|
||||
fi
|
||||
CMAKE_GEN_FLAGS+=("-Wdev -Werror=dev --warn-uninitialized")
|
||||
|
||||
+31
-7
@@ -1,6 +1,6 @@
|
||||
cmake_minimum_required(VERSION 3.1.3...3.16)
|
||||
|
||||
project(GSL CXX)
|
||||
project(GSL VERSION 3.1.0 LANGUAGES CXX)
|
||||
|
||||
include(ExternalProject)
|
||||
find_package(Git)
|
||||
@@ -14,7 +14,7 @@ add_library(GSL INTERFACE)
|
||||
# determine whether this is a standalone project or included by other projects
|
||||
set(GSL_STANDALONE_PROJECT OFF)
|
||||
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
||||
set(GSL_STANDALONE_PROJECT ON)
|
||||
set(GSL_STANDALONE_PROJECT ON)
|
||||
endif ()
|
||||
|
||||
set(GSL_CXX_STANDARD "14" CACHE STRING "Use c++ standard")
|
||||
@@ -70,13 +70,13 @@ endif()
|
||||
|
||||
if (CMAKE_VERSION VERSION_GREATER 3.7.8)
|
||||
if (MSVC_IDE)
|
||||
option(VS_ADD_NATIVE_VISUALIZERS "Configure project to use Visual Studio native visualizers" TRUE)
|
||||
option(GSL_VS_ADD_NATIVE_VISUALIZERS "Configure project to use Visual Studio native visualizers" TRUE)
|
||||
else()
|
||||
set(VS_ADD_NATIVE_VISUALIZERS FALSE CACHE INTERNAL "Native visualizers are Visual Studio extension" FORCE)
|
||||
set(GSL_VS_ADD_NATIVE_VISUALIZERS FALSE CACHE INTERNAL "Native visualizers are Visual Studio extension" FORCE)
|
||||
endif()
|
||||
|
||||
# add natvis file to the library so it will automatically be loaded into Visual Studio
|
||||
if(VS_ADD_NATIVE_VISUALIZERS)
|
||||
if(GSL_VS_ADD_NATIVE_VISUALIZERS)
|
||||
target_sources(GSL INTERFACE
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/GSL.natvis>
|
||||
)
|
||||
@@ -92,12 +92,36 @@ install(
|
||||
install(EXPORT Microsoft.GSLConfig NAMESPACE Microsoft.GSL:: DESTINATION ${CMAKE_INSTALL_DATADIR}/cmake/Microsoft.GSL)
|
||||
export(TARGETS GSL NAMESPACE Microsoft.GSL:: FILE Microsoft.GSLConfig.cmake)
|
||||
|
||||
# Add find_package() versioning support. The version for
|
||||
# generated Microsoft.GSLConfigVersion.cmake will be used from
|
||||
# last project() command. The version's compatibility is set between all
|
||||
# minor versions (as it was in prev. GSL releases).
|
||||
include(CMakePackageConfigHelpers)
|
||||
if(${CMAKE_VERSION} VERSION_LESS "3.14.0")
|
||||
write_basic_package_version_file(
|
||||
${CMAKE_CURRENT_BINARY_DIR}/Microsoft.GSLConfigVersion.cmake
|
||||
COMPATIBILITY SameMajorVersion
|
||||
)
|
||||
else()
|
||||
write_basic_package_version_file(
|
||||
${CMAKE_CURRENT_BINARY_DIR}/Microsoft.GSLConfigVersion.cmake
|
||||
COMPATIBILITY SameMajorVersion
|
||||
ARCH_INDEPENDENT
|
||||
)
|
||||
endif()
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Microsoft.GSLConfigVersion.cmake DESTINATION ${CMAKE_INSTALL_DATADIR}/cmake/Microsoft.GSL)
|
||||
|
||||
# Add Microsoft.GSL::GSL alias for GSL so that dependents can be agnostic about
|
||||
# whether GSL was added via `add_subdirectory` or `find_package`
|
||||
add_library(Microsoft.GSL::GSL ALIAS GSL)
|
||||
|
||||
option(GSL_TEST "Generate tests." ${GSL_STANDALONE_PROJECT})
|
||||
if (GSL_TEST)
|
||||
enable_testing()
|
||||
add_subdirectory(tests)
|
||||
enable_testing()
|
||||
if(IOS)
|
||||
add_compile_definitions(
|
||||
GTEST_HAS_DEATH_TEST=1
|
||||
)
|
||||
endif()
|
||||
add_subdirectory(tests)
|
||||
endif ()
|
||||
|
||||
+6
-45
@@ -19,9 +19,7 @@
|
||||
</Expand>
|
||||
</Type>
|
||||
|
||||
<!-- These types are from the span header. -->
|
||||
<!-- This is for dynamic_extent spans. -->
|
||||
<Type Name="gsl::span<*, -1>">
|
||||
<Type Name="gsl::span<*, *>">
|
||||
<DisplayString>{{ extent = {storage_.size_} }}</DisplayString>
|
||||
<Expand>
|
||||
<ArrayItems>
|
||||
@@ -31,43 +29,7 @@
|
||||
</Expand>
|
||||
</Type>
|
||||
|
||||
<!-- This works for constexpr size spans. -->
|
||||
<Type Name="gsl::span<*, *>">
|
||||
<DisplayString>{{ extent = {extent} }}</DisplayString>
|
||||
<Expand>
|
||||
<ArrayItems>
|
||||
<Size>extent</Size>
|
||||
<ValuePointer>storage_.data_</ValuePointer>
|
||||
</ArrayItems>
|
||||
</Expand>
|
||||
</Type>
|
||||
|
||||
<!-- This is for dynamic_extent string_spans. -->
|
||||
<Type Name="gsl::basic_string_span<*, -1>">
|
||||
<DisplayString>{span_.storage_.data_,[span_.storage_.size_]na}</DisplayString>
|
||||
<Expand>
|
||||
<Item Name="[size]">span_.storage_.size_</Item>
|
||||
<ArrayItems>
|
||||
<Size>span_.storage_.size_</Size>
|
||||
<ValuePointer>span_.storage_.data_</ValuePointer>
|
||||
</ArrayItems>
|
||||
</Expand>
|
||||
</Type>
|
||||
|
||||
<!-- This works for constexpr size string_spans. -->
|
||||
<Type Name="gsl::basic_string_span<*, *>">
|
||||
<DisplayString>{span_.storage_.data_,[span_.extent]na}</DisplayString>
|
||||
<Expand>
|
||||
<Item Name="[size]">span_.extent</Item>
|
||||
<ArrayItems>
|
||||
<Size>span_.extent</Size>
|
||||
<ValuePointer>span_.storage_.data_</ValuePointer>
|
||||
</ArrayItems>
|
||||
</Expand>
|
||||
</Type>
|
||||
|
||||
<!-- This is for dynamic_extent zstring_spans. -->
|
||||
<Type Name="gsl::basic_zstring_span<*, -1>">
|
||||
<DisplayString>{span_.storage_.data_,[span_.storage_.size_]na}</DisplayString>
|
||||
<Expand>
|
||||
<Item Name="[size]">span_.storage_.size_</Item>
|
||||
@@ -77,19 +39,18 @@
|
||||
</ArrayItems>
|
||||
</Expand>
|
||||
</Type>
|
||||
|
||||
<!-- This works for constexpr size string_spans. -->
|
||||
|
||||
<Type Name="gsl::basic_zstring_span<*, *>">
|
||||
<DisplayString>{span_.storage_.data_,[span_.extent]na}</DisplayString>
|
||||
<DisplayString>{span_.storage_.data_,[span_.storage_.size_]na}</DisplayString>
|
||||
<Expand>
|
||||
<Item Name="[size]">span_.extent</Item>
|
||||
<Item Name="[size]">span_.storage_.size_</Item>
|
||||
<ArrayItems>
|
||||
<Size>span_.extent</Size>
|
||||
<Size>span_.storage_.size_</Size>
|
||||
<ValuePointer>span_.storage_.data_</ValuePointer>
|
||||
</ArrayItems>
|
||||
</Expand>
|
||||
</Type>
|
||||
|
||||
|
||||
<!-- These types are from the gsl header. -->
|
||||
<Type Name="gsl::not_null<*>">
|
||||
<!-- We can always dereference this since it's an invariant. -->
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
# GSL: Guidelines Support Library [](https://travis-ci.org/Microsoft/GSL) [](https://ci.appveyor.com/project/neilmacintosh/GSL)
|
||||
# GSL: Guidelines Support Library
|
||||
[](https://travis-ci.org/Microsoft/GSL) [](https://ci.appveyor.com/project/neilmacintosh/GSL)
|
||||
|
||||
The Guidelines Support Library (GSL) contains functions and types that are suggested for use by the
|
||||
[C++ Core Guidelines](https://github.com/isocpp/CppCoreGuidelines) maintained by the [Standard C++ Foundation](https://isocpp.org).
|
||||
This repo contains Microsoft's implementation of GSL.
|
||||
|
||||
The library includes types like `span<T>`, `string_span`, `owner<>` and others.
|
||||
|
||||
The entire implementation is provided inline in the headers under the [gsl](./include/gsl) directory. The implementation generally assumes a platform that implements C++14 support. There are specific workarounds to support MSVC 2015.
|
||||
The entire implementation is provided inline in the headers under the [gsl](./include/gsl) directory. The implementation generally assumes a platform that implements C++14 support.
|
||||
|
||||
While some types have been broken out into their own headers (e.g. [gsl/span](./include/gsl/span)),
|
||||
it is simplest to just include [gsl/gsl](./include/gsl/gsl) and gain access to the entire library.
|
||||
@@ -20,35 +19,99 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope
|
||||
# Usage of Third Party Libraries
|
||||
This project makes use of the [Google Test](https://github.com/google/googletest) testing library. Please see the [ThirdPartyNotices.txt](./ThirdPartyNotices.txt) file for details regarding the licensing of Google Test.
|
||||
|
||||
# Supported features
|
||||
## Microsoft GSL implements the following from the C++ Core Guidelines:
|
||||
|
||||
Feature | Supported? | Description
|
||||
-----------------------------------|:----------:|-------------
|
||||
[**1. Views**][cg-views] | |
|
||||
owner | ☑ | an alias for a raw pointer
|
||||
not_null | ☑ | restricts a pointer / smart pointer to hold non-null values
|
||||
span | ☑ | a view over a contiguous sequence of memory. Based on the standardized verison of `std::span`, however `gsl::span` enforces bounds checking. See the [wiki](https://github.com/microsoft/GSL/wiki/gsl::span-and-std::span) for additional information.
|
||||
span_p | ☐ | spans a range starting from a pointer to the first place for which the predicate is true
|
||||
[**2. Owners**][cg-owners] | |
|
||||
unique_ptr | ☑ | an alias to `std::unique_ptr`
|
||||
shared_ptr | ☑ | an alias to `std::shared_ptr`
|
||||
stack_array | ☐ | a stack-allocated array
|
||||
dyn_array | ☐ | a heap-allocated array
|
||||
[**3. Assertions**][cg-assertions] | |
|
||||
Expects | ☑ | a precondition assertion; on failure it terminates
|
||||
Ensures | ☑ | a postcondition assertion; on failure it terminates
|
||||
[**4. Utilities**][cg-utilities] | |
|
||||
move_owner | ☐ | a helper function that moves one `owner` to the other
|
||||
byte | ☑ | either an alias to std::byte or a byte type
|
||||
final_action | ☑ | a RAII style class that invokes a functor on its destruction
|
||||
finally | ☑ | a helper function instantiating `final_action`
|
||||
GSL_SUPPRESS | ☑ | a macro that takes an argument and turns it into `[[gsl::suppress(x)]]` or `[[gsl::suppress("x")]]`
|
||||
[[implicit]] | ☐ | a "marker" to put on single-argument constructors to explicitly make them non-explicit
|
||||
index | ☑ | a type to use for all container and array indexing (currently an alias for std::ptrdiff_t)
|
||||
joining_thread | ☐ | a RAII style version of `std::thread` that joins
|
||||
narrow | ☑ | a checked version of narrow_cast; it can throw `narrowing_error`
|
||||
narrow_cast | ☑ | a narrowing cast for values and a synonym for static_cast
|
||||
narrowing_error | ☑ | a custom exception type thrown by `narrow()`
|
||||
[**5. Concepts**][cg-concepts] | ☐ |
|
||||
|
||||
## The following features do not exist in or have been removed from the C++ Core Guidelines:
|
||||
Feature | Supported? | Description
|
||||
-----------------------------------|:----------:|-------------
|
||||
strict_not_null | ☑ | A stricter version of `not_null` with explicit constructors
|
||||
multi_span | ☐ | Deprecated. Multi-dimensional span.
|
||||
strided_span | ☐ | Deprecated. Support for this type has been discontinued.
|
||||
basic_zstring | ☐ | Deprecated. A pointer to a C-string (zero-terminated array) with a templated char type
|
||||
zstring | ☐ | Deprecated. An alias to `basic_zstring` with a char type of char
|
||||
czstring | ☐ | Deprecated. An alias to `basic_zstring` with a char type of const char
|
||||
wzstring | ☐ | Deprecated. An alias to `basic_zstring` with a char type of wchar_t
|
||||
cwzstring | ☐ | Deprecated. An alias to `basic_zstring` with a char type of const wchar_t
|
||||
u16zstring | ☐ | Deprecated. An alias to `basic_zstring` with a char type of char16_t
|
||||
cu16zstring | ☐ | Deprecated. An alias to `basic_zstring` with a char type of const char16_t
|
||||
u32zstring | ☐ | Deprecated. An alias to `basic_zstring` with a char type of char32_t
|
||||
cu32zstring | ☐ | Deprecated. An alias to `basic_zstring` with a char type of const char32_t
|
||||
basic_string_span | ☐ | Deprecated. Like `span` but for strings with a templated char type
|
||||
string_span | ☐ | Deprecated. An alias to `basic_string_span` with a char type of char
|
||||
cstring_span | ☐ | Deprecated. An alias to `basic_string_span` with a char type of const char
|
||||
wstring_span | ☐ | Deprecated. An alias to `basic_string_span` with a char type of wchar_t
|
||||
cwstring_span | ☐ | Deprecated. An alias to `basic_string_span` with a char type of const wchar_t
|
||||
u16string_span | ☐ | Deprecated. An alias to `basic_string_span` with a char type of char16_t
|
||||
cu16string_span | ☐ | Deprecated. An alias to `basic_string_span` with a char type of const char16_t
|
||||
u32string_span | ☐ | Deprecated. An alias to `basic_string_span` with a char type of char32_t
|
||||
cu32string_span | ☐ | Deprecated. An alias to `basic_string_span` with a char type of const char32_t
|
||||
|
||||
This is based on [CppCoreGuidelines semi-specification](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#gsl-guidelines-support-library).
|
||||
|
||||
[cg-views]: https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#gslview-views
|
||||
[cg-owners]: https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#gslowner-ownership-pointers
|
||||
[cg-assertions]: https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#gslassert-assertions
|
||||
[cg-utilities]: https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#gslutil-utilities
|
||||
[cg-concepts]: https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#gslconcept-concepts
|
||||
|
||||
# Quick Start
|
||||
## Supported Platforms
|
||||
The test suite that exercises GSL has been built and passes successfully on the following platforms:<sup>1)</sup>
|
||||
## Supported Compilers
|
||||
The GSL officially supports the current and previous major release of MSVC, GCC, Clang, and XCode's Apple-Clang.
|
||||
See our latest test results for the most up-to-date list of supported configurations.
|
||||
|
||||
* Windows using Visual Studio 2015
|
||||
* Windows using Visual Studio 2017
|
||||
* Windows using Clang/LLVM 3.6
|
||||
* Windows using Clang/LLVM 7.0.0
|
||||
* Windows using GCC 5.1
|
||||
* Windows using Intel C++ Compiler 18.0
|
||||
* GNU/Linux using Clang/LLVM 3.6-3.9
|
||||
* GNU/Linux using Clang/LLVM 4.0
|
||||
* GNU/Linux using Clang/LLVM 5.0
|
||||
* GNU/Linux using Clang/LLVM 6.0
|
||||
* GNU/Linux using Clang/LLVM 7.0
|
||||
* GNU/Linux using GCC 5.1
|
||||
* OS X Mojave 10.14.4 using Apple LLVM version 10.0.0 (10.0.1.10010046)
|
||||
* OS X Mojave 10.14.3 using Apple LLVM version 10.0.0 (clang-1000.11.45.5)
|
||||
* OS X Yosemite using Xcode with Apple Clang 7.0.0.7000072
|
||||
* OS X Yosemite using GCC-5.2.0
|
||||
* OS X Sierra 10.12.4 using Apple LLVM version 8.1.0 (Clang-802.0.42)
|
||||
* OS X El Capitan (10.11) using Xcode with AppleClang 8.0.0.8000042
|
||||
* OS X High Sierra 10.13.2 (17C88) using Apple LLVM version 9.0.0 (clang-900.0.39.2)
|
||||
* FreeBSD 10.x with Clang/LLVM 3.6
|
||||
Compiler |Toolset Versions Currently Tested| Build Status
|
||||
:------- |:--|------------:
|
||||
XCode |11.4 & 10.3 | [](https://travis-ci.org/Microsoft/GSL)
|
||||
GCC |9 & 8| [](https://travis-ci.org/Microsoft/GSL)
|
||||
Clang |11 & 10| [](https://travis-ci.org/Microsoft/GSL)
|
||||
Visual Studio with MSVC | VS2017 (15.9) & VS2019 (16.4) | [](https://ci.appveyor.com/project/neilmacintosh/GSL)
|
||||
Visual Studio with LLVM | VS2017 (Clang 9) & VS2019 (Clang 10) | [](https://ci.appveyor.com/project/neilmacintosh/GSL)
|
||||
|
||||
> If you successfully port GSL to another platform, we would love to hear from you. Please submit an issue to let us know. Also please consider
|
||||
contributing any changes that were necessary back to this project to benefit the wider community.
|
||||
|
||||
<sup>1)</sup> For `gsl::byte` to work correctly with Clang and GCC you might have to use the ` -fno-strict-aliasing` compiler option.
|
||||
Note: For `gsl::byte` to work correctly with Clang and GCC you might have to use the ` -fno-strict-aliasing` compiler option.
|
||||
|
||||
---
|
||||
If you successfully port GSL to another platform, we would love to hear from you!
|
||||
- Submit an issue specifying the platform and target.
|
||||
- Consider contributing your changes by filing a pull request with any necessary changes.
|
||||
- If at all possible, add a CI/CD step and add the button to the table below!
|
||||
|
||||
Target | CI/CD Status
|
||||
:------- | -----------:
|
||||
iOS | 
|
||||
Android | 
|
||||
|
||||
Note: These CI/CD steps are run with each pull request, however failures in them are non-blocking.
|
||||
|
||||
## Building the tests
|
||||
To build the tests, you will require the following:
|
||||
@@ -65,7 +128,7 @@ These steps assume the source code of this repository has been cloned into a dir
|
||||
|
||||
2. Configure CMake to use the compiler of your choice (you can see a list by running `cmake --help`).
|
||||
|
||||
cmake -G "Visual Studio 14 2015" c:\GSL
|
||||
cmake -G "Visual Studio 15 2017" c:\GSL
|
||||
|
||||
3. Build the test suite (in this case, in the Debug configuration, Release is another good choice).
|
||||
|
||||
|
||||
+5
-19
@@ -9,7 +9,6 @@ configuration:
|
||||
- Release
|
||||
|
||||
image:
|
||||
- Visual Studio 2015
|
||||
- Visual Studio 2017
|
||||
- Visual Studio 2019
|
||||
|
||||
@@ -17,7 +16,6 @@ environment:
|
||||
NINJA_TAG: v1.8.2
|
||||
NINJA_SHA512: 9B9CE248240665FCD6404B989F3B3C27ED9682838225E6DC9B67B551774F251E4FF8A207504F941E7C811E7A8BE1945E7BCB94472A335EF15E23A0200A32E6D5
|
||||
NINJA_PATH: C:\Tools\ninja\ninja-%NINJA_TAG%
|
||||
VCVAR2015: 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat'
|
||||
VCVAR2017: 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat'
|
||||
VCVAR2019: 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat'
|
||||
matrix:
|
||||
@@ -34,14 +32,6 @@ environment:
|
||||
USE_TOOLSET: LLVM
|
||||
USE_GENERATOR: Ninja
|
||||
|
||||
matrix:
|
||||
exclude:
|
||||
- image: Visual Studio 2015
|
||||
GSL_CXX_STANDARD: 17
|
||||
- image: Visual Studio 2015
|
||||
USE_TOOLSET: LLVM
|
||||
USE_GENERATOR: MSBuild
|
||||
|
||||
cache:
|
||||
- C:\cmake-3.14.4-win32-x86
|
||||
- C:\Tools\ninja
|
||||
@@ -72,9 +62,7 @@ before_build:
|
||||
if ("$env:USE_GENERATOR" -eq "Ninja") {
|
||||
$GeneratorFlags = '-k 10'
|
||||
$Architecture = $env:PLATFORM
|
||||
if ("$env:APPVEYOR_BUILD_WORKER_IMAGE" -eq "Visual Studio 2015") {
|
||||
$env:VCVARSALL = "`"$env:VCVAR2015`" $Architecture"
|
||||
} elseif ("$env:APPVEYOR_BUILD_WORKER_IMAGE" -eq "Visual Studio 2017") {
|
||||
if ("$env:APPVEYOR_BUILD_WORKER_IMAGE" -eq "Visual Studio 2017") {
|
||||
$env:VCVARSALL = "`"$env:VCVAR2017`" $Architecture"
|
||||
} else {
|
||||
$env:VCVARSALL = "`"$env:VCVAR2019`" $Architecture"
|
||||
@@ -82,17 +70,15 @@ before_build:
|
||||
$env:CMakeGenFlags = "-G Ninja -DGSL_CXX_STANDARD=$env:GSL_CXX_STANDARD"
|
||||
} else {
|
||||
$GeneratorFlags = '/m /v:minimal'
|
||||
if ("$env:APPVEYOR_BUILD_WORKER_IMAGE" -eq "Visual Studio 2015") {
|
||||
$Generator = 'Visual Studio 14 2015'
|
||||
} elseif ("$env:APPVEYOR_BUILD_WORKER_IMAGE" -eq "Visual Studio 2017") {
|
||||
if ("$env:APPVEYOR_BUILD_WORKER_IMAGE" -eq "Visual Studio 2017") {
|
||||
$Generator = 'Visual Studio 15 2017'
|
||||
} else {
|
||||
$Generator = 'Visual Studio 16 2019'
|
||||
}
|
||||
if ("$env:PLATFORM" -eq "x86") {
|
||||
if ("$env:PLATFORM" -eq "x86") {
|
||||
$Architecture = "Win32"
|
||||
} else {
|
||||
$Architecture = "x64"
|
||||
} else {
|
||||
$Architecture = "x64"
|
||||
}
|
||||
if ("$env:USE_TOOLSET" -eq "LLVM") {
|
||||
$env:CMakeGenFlags = "-G `"$Generator`" -A $Architecture -T llvm -DGSL_CXX_STANDARD=$env:GSL_CXX_STANDARD"
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
#if defined(__clang__)
|
||||
#define GSL_SUPPRESS(x) [[gsl::suppress("x")]]
|
||||
#else
|
||||
#if defined(_MSC_VER)
|
||||
#if defined(_MSC_VER) && ! defined(__INTEL_COMPILER)
|
||||
#define GSL_SUPPRESS(x) [[gsl::suppress(x)]]
|
||||
#else
|
||||
#define GSL_SUPPRESS(x)
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#if defined(__clang__)
|
||||
#define GSL_SUPPRESS(x) [[gsl::suppress("x")]]
|
||||
#else
|
||||
#if defined(_MSC_VER)
|
||||
#if defined(_MSC_VER) && ! defined(__INTEL_COMPILER)
|
||||
#define GSL_SUPPRESS(x) [[gsl::suppress(x)]]
|
||||
#else
|
||||
#define GSL_SUPPRESS(x)
|
||||
@@ -59,8 +59,8 @@
|
||||
|
||||
#ifndef GSL_USE_STD_BYTE
|
||||
#include <cstddef> /* __cpp_lib_byte */
|
||||
// this tests if we are under GCC or Clang with enough -std:c++1z power to get us std::byte
|
||||
// also check if libc++ version is sufficient (> 5.0) or libstc++ actually contains std::byte
|
||||
// this tests if we are under GCC or Clang with enough -std=c++1z power to get us std::byte
|
||||
// also check if libc++ version is sufficient (> 5.0) or libstdc++ actually contains std::byte
|
||||
#if defined(__cplusplus) && (__cplusplus >= 201703L) && \
|
||||
(defined(__cpp_lib_byte) && (__cpp_lib_byte >= 201603) || \
|
||||
defined(_LIBCPP_VERSION) && (_LIBCPP_VERSION >= 5000))
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2015 Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// This code is licensed under the MIT License (MIT).
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef GSL_NARROW_H
|
||||
#define GSL_NARROW_H
|
||||
#include <gsl/gsl_assert> // for Expects
|
||||
#include <gsl/gsl_util> // for narrow_cast
|
||||
namespace gsl
|
||||
{
|
||||
struct narrowing_error : public std::exception
|
||||
{
|
||||
const char* what() const noexcept override
|
||||
{
|
||||
return "narrowing_error";
|
||||
}
|
||||
};
|
||||
|
||||
// narrow() : a checked version of narrow_cast() that throws if the cast changed the value
|
||||
template <class T, class U>
|
||||
GSL_SUPPRESS(type.1) // NO-FORMAT: attribute
|
||||
GSL_SUPPRESS(f.6) // NO-FORMAT: attribute // TODO: MSVC /analyze does not recognise noexcept(false)
|
||||
constexpr
|
||||
T narrow(U u) noexcept(false)
|
||||
{
|
||||
constexpr const bool is_different_signedness = (std::is_signed<T>::value != std::is_signed<U>::value);
|
||||
|
||||
const T t = narrow_cast<T>(u);
|
||||
|
||||
if (static_cast<U>(t) != u
|
||||
|| (is_different_signedness
|
||||
&& ((t < T{}) != (u < U{}))))
|
||||
{
|
||||
throw narrowing_error{};
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
}
|
||||
#endif // GSL_NARROW_H
|
||||
+8
-50
@@ -30,17 +30,13 @@
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4127) // conditional expression is constant
|
||||
|
||||
#if _MSC_VER < 1910
|
||||
#pragma push_macro("constexpr")
|
||||
#define constexpr /*constexpr*/
|
||||
#endif // _MSC_VER < 1910
|
||||
#endif // _MSC_VER
|
||||
|
||||
#if (defined(_MSC_VER) && _MSC_VER < 1910) || (!defined(__clang__) && defined(__GNUC__) && __GNUC__ < 6)
|
||||
#define GSL_CONSTEXPR_NARROW 0
|
||||
#if defined(__cplusplus) && (__cplusplus >= 201703L)
|
||||
#define GSL_NODISCARD [[nodiscard]]
|
||||
#else
|
||||
#define GSL_CONSTEXPR_NARROW 1
|
||||
#endif
|
||||
#define GSL_NODISCARD
|
||||
#endif // defined(__cplusplus) && (__cplusplus >= 201703L)
|
||||
|
||||
namespace gsl
|
||||
{
|
||||
@@ -56,6 +52,8 @@ template <class F>
|
||||
class final_action
|
||||
{
|
||||
public:
|
||||
static_assert(!std::is_reference<F>::value && !std::is_const<F>::value && !std::is_volatile<F>::value, "Final_action should store its callable by value");
|
||||
|
||||
explicit final_action(F f) noexcept : f_(std::move(f)) {}
|
||||
|
||||
final_action(final_action&& other) noexcept : f_(std::move(other.f_)), invoke_(std::exchange(other.invoke_, false)) {}
|
||||
@@ -77,15 +75,9 @@ private:
|
||||
|
||||
// finally() - convenience function to generate a final_action
|
||||
template <class F>
|
||||
final_action<F> finally(const F& f) noexcept
|
||||
GSL_NODISCARD final_action<typename std::remove_cv<typename std::remove_reference<F>::type>::type> finally(F&& f) noexcept
|
||||
{
|
||||
return final_action<F>(f);
|
||||
}
|
||||
|
||||
template <class F>
|
||||
final_action<F> finally(F&& f) noexcept
|
||||
{
|
||||
return final_action<F>(std::forward<F>(f));
|
||||
return final_action<typename std::remove_cv<typename std::remove_reference<F>::type>::type>(std::forward<F>(f));
|
||||
}
|
||||
|
||||
// narrow_cast(): a searchable way to do narrowing casts of values
|
||||
@@ -96,35 +88,6 @@ constexpr T narrow_cast(U&& u) noexcept
|
||||
return static_cast<T>(std::forward<U>(u));
|
||||
}
|
||||
|
||||
struct narrowing_error : public std::exception
|
||||
{
|
||||
};
|
||||
|
||||
namespace details
|
||||
{
|
||||
template <class T, class U>
|
||||
struct is_same_signedness
|
||||
: public std::integral_constant<bool, std::is_signed<T>::value == std::is_signed<U>::value>
|
||||
{
|
||||
};
|
||||
} // namespace details
|
||||
|
||||
// narrow() : a checked version of narrow_cast() that throws if the cast changed the value
|
||||
template <class T, class U>
|
||||
GSL_SUPPRESS(type.1) // NO-FORMAT: attribute
|
||||
GSL_SUPPRESS(f.6) // NO-FORMAT: attribute // TODO: MSVC /analyze does not recognise noexcept(false)
|
||||
#if GSL_CONSTEXPR_NARROW
|
||||
constexpr
|
||||
#endif
|
||||
T narrow(U u) noexcept(false)
|
||||
{
|
||||
T t = narrow_cast<T>(u);
|
||||
if (static_cast<U>(t) != u) throw narrowing_error{};
|
||||
if (!details::is_same_signedness<T, U>::value && ((t < T{}) != (u < U{})))
|
||||
throw narrowing_error{};
|
||||
return t;
|
||||
}
|
||||
|
||||
//
|
||||
// at() - Bounds-checked way of accessing builtin arrays, std::array, std::vector
|
||||
//
|
||||
@@ -158,11 +121,6 @@ constexpr T at(const std::initializer_list<T> cont, const index i)
|
||||
} // namespace gsl
|
||||
|
||||
#if defined(_MSC_VER) && !defined(__clang__)
|
||||
#if _MSC_VER < 1910
|
||||
#undef constexpr
|
||||
#pragma pop_macro("constexpr")
|
||||
|
||||
#endif // _MSC_VER < 1910
|
||||
|
||||
#pragma warning(pop)
|
||||
|
||||
|
||||
@@ -50,11 +50,6 @@
|
||||
#pragma warning(disable : 26465) // TODO: bug - suppression does not work on template functions
|
||||
#pragma warning(disable : 4996) // use of function or classes marked [[deprecated]]
|
||||
|
||||
#if _MSC_VER < 1910
|
||||
#pragma push_macro("constexpr")
|
||||
#define constexpr /*constexpr*/
|
||||
|
||||
#endif // _MSC_VER < 1910
|
||||
#endif // _MSC_VER
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
@@ -2252,11 +2247,6 @@ general_span_iterator<Span> operator+(typename general_span_iterator<Span>::diff
|
||||
} // namespace gsl
|
||||
|
||||
#if defined(_MSC_VER) && !defined(__clang__)
|
||||
#if _MSC_VER < 1910
|
||||
|
||||
#undef constexpr
|
||||
#pragma pop_macro("constexpr")
|
||||
#endif // _MSC_VER < 1910
|
||||
|
||||
#pragma warning(pop)
|
||||
|
||||
|
||||
+14
-28
@@ -25,12 +25,6 @@
|
||||
#include <system_error> // for hash
|
||||
#include <type_traits> // for enable_if_t, is_convertible, is_assignable
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1910 && !defined(__clang__)
|
||||
#pragma push_macro("constexpr")
|
||||
#define constexpr /*constexpr*/
|
||||
|
||||
#endif // defined(_MSC_VER) && _MSC_VER < 1910
|
||||
|
||||
namespace gsl
|
||||
{
|
||||
|
||||
@@ -69,7 +63,7 @@ template <class T>
|
||||
class not_null
|
||||
{
|
||||
public:
|
||||
static_assert(std::is_assignable<T&, std::nullptr_t>::value, "T cannot be assigned nullptr.");
|
||||
static_assert(std::is_convertible<decltype(std::declval<T>() != nullptr), bool>::value, "T cannot be compared to nullptr.");
|
||||
|
||||
template <typename U, typename = std::enable_if_t<std::is_convertible<U, T>::value>>
|
||||
constexpr not_null(U&& u) : ptr_(std::forward<U>(u))
|
||||
@@ -78,7 +72,7 @@ public:
|
||||
}
|
||||
|
||||
template <typename = std::enable_if_t<!std::is_same<std::nullptr_t, T>::value>>
|
||||
constexpr not_null(T u) : ptr_(u)
|
||||
constexpr not_null(T u) : ptr_(std::move(u))
|
||||
{
|
||||
Expects(ptr_ != nullptr);
|
||||
}
|
||||
@@ -90,15 +84,14 @@ public:
|
||||
|
||||
not_null(const not_null& other) = default;
|
||||
not_null& operator=(const not_null& other) = default;
|
||||
|
||||
constexpr T get() const
|
||||
constexpr std::conditional_t<std::is_copy_constructible<T>::value, T, const T&> get() const
|
||||
{
|
||||
Ensures(ptr_ != nullptr);
|
||||
return ptr_;
|
||||
}
|
||||
|
||||
constexpr operator T() const { return get(); }
|
||||
constexpr T operator->() const { return get(); }
|
||||
constexpr decltype(auto) operator->() const { return get(); }
|
||||
constexpr decltype(auto) operator*() const { return *get(); }
|
||||
|
||||
// prevents compilation when someone attempts to assign a null pointer constant
|
||||
@@ -119,7 +112,7 @@ private:
|
||||
};
|
||||
|
||||
template <class T>
|
||||
auto make_not_null(T&& t) {
|
||||
auto make_not_null(T&& t) noexcept {
|
||||
return not_null<std::remove_cv_t<std::remove_reference_t<T>>>{std::forward<T>(t)};
|
||||
}
|
||||
|
||||
@@ -131,37 +124,37 @@ std::ostream& operator<<(std::ostream& os, const not_null<T>& val)
|
||||
}
|
||||
|
||||
template <class T, class U>
|
||||
auto operator==(const not_null<T>& lhs, const not_null<U>& rhs) -> decltype(lhs.get() == rhs.get())
|
||||
auto operator==(const not_null<T>& lhs, const not_null<U>& rhs) noexcept(noexcept(lhs.get() == rhs.get())) -> decltype(lhs.get() == rhs.get())
|
||||
{
|
||||
return lhs.get() == rhs.get();
|
||||
}
|
||||
|
||||
template <class T, class U>
|
||||
auto operator!=(const not_null<T>& lhs, const not_null<U>& rhs) -> decltype(lhs.get() != rhs.get())
|
||||
auto operator!=(const not_null<T>& lhs, const not_null<U>& rhs) noexcept(noexcept(lhs.get() != rhs.get())) -> decltype(lhs.get() != rhs.get())
|
||||
{
|
||||
return lhs.get() != rhs.get();
|
||||
}
|
||||
|
||||
template <class T, class U>
|
||||
auto operator<(const not_null<T>& lhs, const not_null<U>& rhs) -> decltype(lhs.get() < rhs.get())
|
||||
auto operator<(const not_null<T>& lhs, const not_null<U>& rhs) noexcept(noexcept(lhs.get() < rhs.get())) -> decltype(lhs.get() < rhs.get())
|
||||
{
|
||||
return lhs.get() < rhs.get();
|
||||
}
|
||||
|
||||
template <class T, class U>
|
||||
auto operator<=(const not_null<T>& lhs, const not_null<U>& rhs) -> decltype(lhs.get() <= rhs.get())
|
||||
auto operator<=(const not_null<T>& lhs, const not_null<U>& rhs) noexcept(noexcept(lhs.get() <= rhs.get())) -> decltype(lhs.get() <= rhs.get())
|
||||
{
|
||||
return lhs.get() <= rhs.get();
|
||||
}
|
||||
|
||||
template <class T, class U>
|
||||
auto operator>(const not_null<T>& lhs, const not_null<U>& rhs) -> decltype(lhs.get() > rhs.get())
|
||||
auto operator>(const not_null<T>& lhs, const not_null<U>& rhs) noexcept(noexcept(lhs.get() > rhs.get())) -> decltype(lhs.get() > rhs.get())
|
||||
{
|
||||
return lhs.get() > rhs.get();
|
||||
}
|
||||
|
||||
template <class T, class U>
|
||||
auto operator>=(const not_null<T>& lhs, const not_null<U>& rhs) -> decltype(lhs.get() >= rhs.get())
|
||||
auto operator>=(const not_null<T>& lhs, const not_null<U>& rhs) noexcept(noexcept(lhs.get() >= rhs.get())) -> decltype(lhs.get() >= rhs.get())
|
||||
{
|
||||
return lhs.get() >= rhs.get();
|
||||
}
|
||||
@@ -183,7 +176,7 @@ namespace std
|
||||
template <class T>
|
||||
struct hash<gsl::not_null<T>>
|
||||
{
|
||||
std::size_t operator()(const gsl::not_null<T>& value) const { return hash<T>{}(value); }
|
||||
std::size_t operator()(const gsl::not_null<T>& value) const { return hash<T>{}(value.get()); }
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
@@ -267,7 +260,7 @@ template <class T>
|
||||
strict_not_null<T> operator+(std::ptrdiff_t, const strict_not_null<T>&) = delete;
|
||||
|
||||
template <class T>
|
||||
auto make_strict_not_null(T&& t) {
|
||||
auto make_strict_not_null(T&& t) noexcept {
|
||||
return strict_not_null<std::remove_cv_t<std::remove_reference_t<T>>>{std::forward<T>(t)};
|
||||
}
|
||||
|
||||
@@ -286,16 +279,9 @@ namespace std
|
||||
template <class T>
|
||||
struct hash<gsl::strict_not_null<T>>
|
||||
{
|
||||
std::size_t operator()(const gsl::strict_not_null<T>& value) const { return hash<T>{}(value); }
|
||||
std::size_t operator()(const gsl::strict_not_null<T>& value) const { return hash<T>{}(value.get()); }
|
||||
};
|
||||
|
||||
} // namespace std
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1910 && !defined(__clang__)
|
||||
|
||||
#undef constexpr
|
||||
#pragma pop_macro("constexpr")
|
||||
|
||||
#endif // defined(_MSC_VER) && _MSC_VER < 1910 && !defined(__clang__)
|
||||
|
||||
#endif // GSL_POINTERS_H
|
||||
|
||||
+101
-48
@@ -19,6 +19,7 @@
|
||||
|
||||
#include <gsl/gsl_assert> // for Expects
|
||||
#include <gsl/gsl_byte> // for byte
|
||||
#include <gsl/gsl_util> // for narrow_cast
|
||||
|
||||
#include <array> // for array
|
||||
#include <cstddef> // for ptrdiff_t, size_t, nullptr_t
|
||||
@@ -38,12 +39,6 @@
|
||||
#pragma warning(disable : 26495) // uninitalized member when constructor calls constructor
|
||||
#pragma warning(disable : 26446) // parser bug does not allow attributes on some templates
|
||||
|
||||
#if _MSC_VER < 1910
|
||||
#pragma push_macro("constexpr")
|
||||
#define constexpr /*constexpr*/
|
||||
#define GSL_USE_STATIC_CONSTEXPR_WORKAROUND
|
||||
|
||||
#endif // _MSC_VER < 1910
|
||||
#endif // _MSC_VER
|
||||
|
||||
// See if we have enough C++17 power to use a static constexpr data member
|
||||
@@ -66,7 +61,7 @@ namespace gsl
|
||||
{
|
||||
|
||||
// [views.constants], constants
|
||||
constexpr const std::size_t dynamic_extent = static_cast<std::size_t>(-1);
|
||||
constexpr const std::size_t dynamic_extent = narrow_cast<std::size_t>(-1);
|
||||
|
||||
template <class ElementType, std::size_t Extent = dynamic_extent>
|
||||
class span;
|
||||
@@ -106,7 +101,7 @@ namespace details
|
||||
|
||||
template <std::size_t From, std::size_t To>
|
||||
struct is_allowed_extent_conversion
|
||||
: std::integral_constant<bool, From == To || To == gsl::dynamic_extent>
|
||||
: std::integral_constant<bool, From == To || To == dynamic_extent>
|
||||
{
|
||||
};
|
||||
|
||||
@@ -343,17 +338,18 @@ namespace details
|
||||
|
||||
constexpr extent_type() noexcept = default;
|
||||
|
||||
template <size_type Other>
|
||||
constexpr extent_type(extent_type<Other> ext)
|
||||
{
|
||||
static_assert(Other == Ext,
|
||||
"Mismatch between fixed-size extent and size of initializing data.");
|
||||
Expects(ext.size() == Ext);
|
||||
}
|
||||
constexpr explicit extent_type(extent_type<dynamic_extent>);
|
||||
|
||||
constexpr extent_type(size_type size) { Expects(size == Ext); }
|
||||
constexpr explicit extent_type(size_type size) { Expects(size == Ext); }
|
||||
|
||||
constexpr size_type size() const noexcept { return Ext; }
|
||||
|
||||
private:
|
||||
#if defined(GSL_USE_STATIC_CONSTEXPR_WORKAROUND)
|
||||
static constexpr const size_type size_ = Ext; // static size equal to Ext
|
||||
#else
|
||||
static constexpr size_type size_ = Ext; // static size equal to Ext
|
||||
#endif
|
||||
};
|
||||
|
||||
template <>
|
||||
@@ -363,10 +359,10 @@ namespace details
|
||||
using size_type = std::size_t;
|
||||
|
||||
template <size_type Other>
|
||||
explicit constexpr extent_type(extent_type<Other> ext) : size_(ext.size())
|
||||
constexpr explicit extent_type(extent_type<Other> ext) : size_(ext.size())
|
||||
{}
|
||||
|
||||
explicit constexpr extent_type(size_type size) : size_(size)
|
||||
constexpr explicit extent_type(size_type size) : size_(size)
|
||||
{
|
||||
Expects(size != dynamic_extent);
|
||||
}
|
||||
@@ -377,6 +373,12 @@ namespace details
|
||||
size_type size_;
|
||||
};
|
||||
|
||||
template <std::size_t Ext>
|
||||
constexpr extent_type<Ext>::extent_type(extent_type<dynamic_extent> ext)
|
||||
{
|
||||
Expects(ext.size() == Ext);
|
||||
}
|
||||
|
||||
template <class ElementType, std::size_t Extent, std::size_t Offset, std::size_t Count>
|
||||
struct calculate_subspan_type
|
||||
{
|
||||
@@ -420,18 +422,28 @@ public:
|
||||
constexpr span() noexcept : storage_(nullptr, details::extent_type<0>())
|
||||
{}
|
||||
|
||||
constexpr span(pointer ptr, size_type count) noexcept : storage_(ptr, count)
|
||||
template <std::size_t MyExtent = Extent, std::enable_if_t<MyExtent != dynamic_extent, int> = 0>
|
||||
constexpr explicit span(pointer ptr, size_type count) noexcept : storage_(ptr, count)
|
||||
{
|
||||
if (Extent != dynamic_extent) Expects(count == Extent);
|
||||
Expects(count == Extent);
|
||||
}
|
||||
|
||||
constexpr span(pointer firstElem, pointer lastElem) noexcept
|
||||
: storage_(firstElem, static_cast<std::size_t>(lastElem - firstElem))
|
||||
template <std::size_t MyExtent = Extent, std::enable_if_t<MyExtent == dynamic_extent, int> = 0>
|
||||
constexpr span(pointer ptr, size_type count) noexcept : storage_(ptr, count)
|
||||
{}
|
||||
|
||||
template <std::size_t MyExtent = Extent, std::enable_if_t<MyExtent != dynamic_extent, int> = 0>
|
||||
constexpr explicit span(pointer firstElem, pointer lastElem) noexcept
|
||||
: storage_(firstElem, narrow_cast<std::size_t>(lastElem - firstElem))
|
||||
{
|
||||
if (Extent != dynamic_extent)
|
||||
{ Expects(lastElem - firstElem == static_cast<difference_type>(Extent)); }
|
||||
Expects(lastElem - firstElem == static_cast<difference_type>(Extent));
|
||||
}
|
||||
|
||||
template <std::size_t MyExtent = Extent, std::enable_if_t<MyExtent == dynamic_extent, int> = 0>
|
||||
constexpr span(pointer firstElem, pointer lastElem) noexcept
|
||||
: storage_(firstElem, narrow_cast<std::size_t>(lastElem - firstElem))
|
||||
{}
|
||||
|
||||
template <std::size_t N,
|
||||
std::enable_if_t<details::is_allowed_extent_conversion<N, Extent>::value, int> = 0>
|
||||
constexpr span(element_type (&arr)[N]) noexcept
|
||||
@@ -456,40 +468,74 @@ public:
|
||||
: storage_(KnownNotNull{arr.data()}, details::extent_type<N>())
|
||||
{}
|
||||
|
||||
// NB: the SFINAE here uses .data() as an incomplete/imperfect proxy for the requirement
|
||||
// on Container to be a contiguous sequence container.
|
||||
template <class Container,
|
||||
class = std::enable_if_t<
|
||||
// NB: the SFINAE on these constructors uses .data() as an incomplete/imperfect proxy for the
|
||||
// requirement on Container to be a contiguous sequence container.
|
||||
template <std::size_t MyExtent = Extent, class Container,
|
||||
std::enable_if_t<
|
||||
MyExtent != dynamic_extent &&
|
||||
!details::is_span<Container>::value && !details::is_std_array<Container>::value &&
|
||||
std::is_pointer<decltype(std::declval<Container&>().data())>::value &&
|
||||
std::is_convertible<
|
||||
std::remove_pointer_t<decltype(std::declval<Container&>().data())> (*)[],
|
||||
element_type (*)[]>::value>>
|
||||
element_type (*)[]>::value, int> = 0>
|
||||
constexpr explicit span(Container& cont) noexcept : span(cont.data(), cont.size())
|
||||
{}
|
||||
|
||||
template <std::size_t MyExtent = Extent, class Container,
|
||||
std::enable_if_t<
|
||||
MyExtent == dynamic_extent &&
|
||||
!details::is_span<Container>::value && !details::is_std_array<Container>::value &&
|
||||
std::is_pointer<decltype(std::declval<Container&>().data())>::value &&
|
||||
std::is_convertible<
|
||||
std::remove_pointer_t<decltype(std::declval<Container&>().data())> (*)[],
|
||||
element_type (*)[]>::value, int> = 0>
|
||||
constexpr span(Container& cont) noexcept : span(cont.data(), cont.size())
|
||||
{}
|
||||
|
||||
template <class Container,
|
||||
class = std::enable_if_t<
|
||||
template <std::size_t MyExtent = Extent, class Container,
|
||||
std::enable_if_t<
|
||||
MyExtent != dynamic_extent &&
|
||||
std::is_const<element_type>::value && !details::is_span<Container>::value &&
|
||||
!details::is_std_array<Container>::value &&
|
||||
std::is_pointer<decltype(std::declval<const Container&>().data())>::value &&
|
||||
std::is_convertible<std::remove_pointer_t<
|
||||
decltype(std::declval<const Container&>().data())> (*)[],
|
||||
element_type (*)[]>::value>>
|
||||
decltype(std::declval<const Container&>().data())> (*)[],
|
||||
element_type (*)[]>::value, int> = 0>
|
||||
constexpr explicit span(const Container& cont) noexcept : span(cont.data(), cont.size())
|
||||
{}
|
||||
|
||||
template <std::size_t MyExtent = Extent, class Container,
|
||||
std::enable_if_t<
|
||||
MyExtent == dynamic_extent &&
|
||||
std::is_const<element_type>::value && !details::is_span<Container>::value &&
|
||||
!details::is_std_array<Container>::value &&
|
||||
std::is_pointer<decltype(std::declval<const Container&>().data())>::value &&
|
||||
std::is_convertible<std::remove_pointer_t<
|
||||
decltype(std::declval<const Container&>().data())> (*)[],
|
||||
element_type (*)[]>::value, int> = 0>
|
||||
constexpr span(const Container& cont) noexcept : span(cont.data(), cont.size())
|
||||
{}
|
||||
|
||||
constexpr span(const span& other) noexcept = default;
|
||||
|
||||
template <
|
||||
class OtherElementType, std::size_t OtherExtent,
|
||||
class = std::enable_if_t<
|
||||
details::is_allowed_extent_conversion<OtherExtent, Extent>::value &&
|
||||
details::is_allowed_element_type_conversion<OtherElementType, element_type>::value>>
|
||||
class OtherElementType, std::size_t OtherExtent, std::size_t MyExtent = Extent,
|
||||
std::enable_if_t<
|
||||
(MyExtent == dynamic_extent || MyExtent == OtherExtent) &&
|
||||
details::is_allowed_element_type_conversion<OtherElementType, element_type>::value, int> = 0>
|
||||
constexpr span(const span<OtherElementType, OtherExtent>& other) noexcept
|
||||
: storage_(other.data(), details::extent_type<OtherExtent>(other.size()))
|
||||
{}
|
||||
|
||||
template <
|
||||
class OtherElementType, std::size_t OtherExtent, std::size_t MyExtent = Extent,
|
||||
std::enable_if_t<
|
||||
MyExtent != dynamic_extent && OtherExtent == dynamic_extent &&
|
||||
details::is_allowed_element_type_conversion<OtherElementType, element_type>::value, int> = 0>
|
||||
constexpr explicit span(const span<OtherElementType, OtherExtent>& other) noexcept
|
||||
: storage_(other.data(), details::extent_type<OtherExtent>(other.size()))
|
||||
{}
|
||||
|
||||
~span() noexcept = default;
|
||||
constexpr span& operator=(const span& other) noexcept = default;
|
||||
|
||||
@@ -498,7 +544,7 @@ public:
|
||||
constexpr span<element_type, Count> first() const noexcept
|
||||
{
|
||||
Expects(Count <= size());
|
||||
return {data(), Count};
|
||||
return span<element_type, Count>{data(), Count};
|
||||
}
|
||||
|
||||
template <std::size_t Count>
|
||||
@@ -508,7 +554,7 @@ public:
|
||||
constexpr span<element_type, Count> last() const noexcept
|
||||
{
|
||||
Expects(Count <= size());
|
||||
return {data() + (size() - Count), Count};
|
||||
return span<element_type, Count>{data() + (size() - Count), Count};
|
||||
}
|
||||
|
||||
template <std::size_t Offset, std::size_t Count = dynamic_extent>
|
||||
@@ -519,8 +565,8 @@ public:
|
||||
typename details::calculate_subspan_type<ElementType, Extent, Offset, Count>::type
|
||||
{
|
||||
Expects((size() >= Offset) && (Count == dynamic_extent || (Count <= size() - Offset)));
|
||||
|
||||
return {data() + Offset, Count == dynamic_extent ? size() - Offset : Count};
|
||||
using type = typename details::calculate_subspan_type<ElementType, Extent, Offset, Count>::type;
|
||||
return type{data() + Offset, Count == dynamic_extent ? size() - Offset : Count};
|
||||
}
|
||||
|
||||
constexpr span<element_type, dynamic_extent> first(size_type count) const noexcept
|
||||
@@ -695,6 +741,14 @@ span(std::array<Type, Size>&)->span<Type, Size>;
|
||||
template <class Type, std::size_t Size>
|
||||
span(const std::array<Type, Size>&)->span<const Type, Size>;
|
||||
|
||||
template <class Container,
|
||||
class Element = std::remove_pointer_t<decltype(std::declval<Container&>().data())>>
|
||||
span(Container&)->span<Element>;
|
||||
|
||||
template <class Container,
|
||||
class Element = std::remove_pointer_t<decltype(std::declval<const Container&>().data())>>
|
||||
span(const Container&)->span<Element>;
|
||||
|
||||
#endif // ( defined(__cpp_deduction_guides) && (__cpp_deduction_guides >= 201611L) )
|
||||
|
||||
#if defined(GSL_USE_STATIC_CONSTEXPR_WORKAROUND)
|
||||
@@ -728,10 +782,12 @@ template <class ElementType, std::size_t Extent>
|
||||
span<const byte, details::calculate_byte_size<ElementType, Extent>::value>
|
||||
as_bytes(span<ElementType, Extent> s) noexcept
|
||||
{
|
||||
using type = span<const byte, details::calculate_byte_size<ElementType, Extent>::value>;
|
||||
|
||||
// clang-format off
|
||||
GSL_SUPPRESS(type.1) // NO-FORMAT: attribute
|
||||
// clang-format on
|
||||
return {reinterpret_cast<const byte*>(s.data()), s.size_bytes()};
|
||||
return type{reinterpret_cast<const byte*>(s.data()), s.size_bytes()};
|
||||
}
|
||||
|
||||
template <class ElementType, std::size_t Extent,
|
||||
@@ -739,20 +795,17 @@ template <class ElementType, std::size_t Extent,
|
||||
span<byte, details::calculate_byte_size<ElementType, Extent>::value>
|
||||
as_writable_bytes(span<ElementType, Extent> s) noexcept
|
||||
{
|
||||
using type = span<byte, details::calculate_byte_size<ElementType, Extent>::value>;
|
||||
|
||||
// clang-format off
|
||||
GSL_SUPPRESS(type.1) // NO-FORMAT: attribute
|
||||
// clang-format on
|
||||
return {reinterpret_cast<byte*>(s.data()), s.size_bytes()};
|
||||
return type{reinterpret_cast<byte*>(s.data()), s.size_bytes()};
|
||||
}
|
||||
|
||||
} // namespace gsl
|
||||
|
||||
#if defined(_MSC_VER) && !defined(__clang__)
|
||||
#if _MSC_VER < 1910
|
||||
#undef constexpr
|
||||
#pragma pop_macro("constexpr")
|
||||
|
||||
#endif // _MSC_VER < 1910
|
||||
|
||||
#pragma warning(pop)
|
||||
#endif // _MSC_VER
|
||||
|
||||
+171
-102
@@ -19,14 +19,14 @@
|
||||
|
||||
#include <gsl/gsl_assert> // for Ensures, Expects
|
||||
#include <gsl/gsl_util> // for narrow_cast
|
||||
#include <gsl/span_ext> // for operator!=, operator==, dynamic_extent
|
||||
#include <gsl/span_ext> // for operator!=, operator==, dynamic_extent
|
||||
|
||||
#include <algorithm> // for equal, lexicographical_compare
|
||||
#include <array> // for array
|
||||
#include <cstddef> // for size_t, nullptr_t
|
||||
#include <cstdint> // for PTRDIFF_MAX
|
||||
#include <cstring>
|
||||
#include <string> // for basic_string, allocator, char_traits
|
||||
#include <string> // for basic_string, allocator, char_traits
|
||||
#include <type_traits> // for declval, is_convertible, enable_if_t, add_...
|
||||
|
||||
#if defined(_MSC_VER) && !defined(__clang__)
|
||||
@@ -35,13 +35,13 @@
|
||||
// Turn MSVC /analyze rules that generate too much noise. TODO: fix in the tool.
|
||||
#pragma warning(disable : 26446) // TODO: bug in parser - attributes and templates
|
||||
#pragma warning(disable : 26481) // TODO: suppress does not work inside templates sometimes
|
||||
#pragma warning(disable : 4996) // use of functions & classes marked [[deprecated]]
|
||||
#endif // _MSC_VER
|
||||
|
||||
#if _MSC_VER < 1910
|
||||
#pragma push_macro("constexpr")
|
||||
#define constexpr /*constexpr*/
|
||||
|
||||
#endif // _MSC_VER < 1910
|
||||
#endif // _MSC_VER
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
#endif
|
||||
|
||||
namespace gsl
|
||||
{
|
||||
@@ -57,36 +57,55 @@ namespace gsl
|
||||
//
|
||||
|
||||
template <typename CharT, std::size_t Extent = dynamic_extent>
|
||||
using basic_zstring = CharT*;
|
||||
using basic_zstring [[deprecated("string_span was removed from the C++ Core Guidelines. For more "
|
||||
"information, see isocpp/CppCoreGuidelines PR#1680")]] = CharT*;
|
||||
|
||||
template <std::size_t Extent = dynamic_extent>
|
||||
using czstring = basic_zstring<const char, Extent>;
|
||||
using czstring [[deprecated("string_span was removed from the C++ Core Guidelines. For more "
|
||||
"information, see isocpp/CppCoreGuidelines PR#1680")]] =
|
||||
basic_zstring<const char, Extent>;
|
||||
|
||||
template <std::size_t Extent = dynamic_extent>
|
||||
using cwzstring = basic_zstring<const wchar_t, Extent>;
|
||||
using cwzstring [[deprecated("string_span was removed from the C++ Core Guidelines. For more "
|
||||
"information, see isocpp/CppCoreGuidelines PR#1680")]] =
|
||||
basic_zstring<const wchar_t, Extent>;
|
||||
|
||||
template <std::size_t Extent = dynamic_extent>
|
||||
using cu16zstring = basic_zstring<const char16_t, Extent>;
|
||||
using cu16zstring [[deprecated("string_span was removed from the C++ Core Guidelines. For more "
|
||||
"information, see isocpp/CppCoreGuidelines PR#1680")]] =
|
||||
basic_zstring<const char16_t, Extent>;
|
||||
|
||||
template <std::size_t Extent = dynamic_extent>
|
||||
using cu32zstring = basic_zstring<const char32_t, Extent>;
|
||||
using cu32zstring [[deprecated("string_span was removed from the C++ Core Guidelines. For more "
|
||||
"information, see isocpp/CppCoreGuidelines PR#1680")]] =
|
||||
basic_zstring<const char32_t, Extent>;
|
||||
|
||||
template <std::size_t Extent = dynamic_extent>
|
||||
using zstring = basic_zstring<char, Extent>;
|
||||
using zstring [[deprecated("string_span was removed from the C++ Core Guidelines. For more "
|
||||
"information, see isocpp/CppCoreGuidelines PR#1680")]] =
|
||||
basic_zstring<char, Extent>;
|
||||
|
||||
template <std::size_t Extent = dynamic_extent>
|
||||
using wzstring = basic_zstring<wchar_t, Extent>;
|
||||
using wzstring [[deprecated("string_span was removed from the C++ Core Guidelines. For more "
|
||||
"information, see isocpp/CppCoreGuidelines PR#1680")]] =
|
||||
basic_zstring<wchar_t, Extent>;
|
||||
|
||||
template <std::size_t Extent = dynamic_extent>
|
||||
using u16zstring = basic_zstring<char16_t, Extent>;
|
||||
using u16zstring [[deprecated("string_span was removed from the C++ Core Guidelines. For more "
|
||||
"information, see isocpp/CppCoreGuidelines PR#1680")]] =
|
||||
basic_zstring<char16_t, Extent>;
|
||||
|
||||
template <std::size_t Extent = dynamic_extent>
|
||||
using u32zstring = basic_zstring<char32_t, Extent>;
|
||||
using u32zstring [[deprecated("string_span was removed from the C++ Core Guidelines. For more "
|
||||
"information, see isocpp/CppCoreGuidelines PR#1680")]] =
|
||||
basic_zstring<char32_t, Extent>;
|
||||
|
||||
namespace details
|
||||
{
|
||||
template <class CharT>
|
||||
std::size_t string_length(const CharT* str, std::size_t n)
|
||||
[[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see "
|
||||
"isocpp/CppCoreGuidelines PR#1680")]] constexpr std::size_t
|
||||
string_length(const CharT* str, std::size_t n)
|
||||
{
|
||||
if (str == nullptr || n == dynamic_extent) return 0;
|
||||
|
||||
@@ -108,73 +127,87 @@ namespace details
|
||||
// Will fail-fast if sentinel cannot be found before max elements are examined.
|
||||
//
|
||||
template <typename T, const T Sentinel>
|
||||
span<T, dynamic_extent> ensure_sentinel(T* seq,
|
||||
std::size_t max = static_cast<std::size_t>(-1))
|
||||
[[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see "
|
||||
"isocpp/CppCoreGuidelines PR#1680")]] constexpr span<T, dynamic_extent>
|
||||
ensure_sentinel(T* seq, std::size_t max = static_cast<std::size_t>(-1))
|
||||
{
|
||||
Ensures(seq != nullptr);
|
||||
|
||||
GSL_SUPPRESS(
|
||||
f.23) // NO-FORMAT: attribute // TODO: false positive // TODO: suppress does not work
|
||||
// clang-format off
|
||||
GSL_SUPPRESS(f.23) // TODO: false positive // TODO: suppress does not work
|
||||
// clang-format on
|
||||
auto cur = seq;
|
||||
Ensures(cur != nullptr); // workaround for removing the warning
|
||||
|
||||
GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute // TODO: suppress does not work
|
||||
// clang-format off
|
||||
GSL_SUPPRESS(bounds.1) // TODO: suppress does not work
|
||||
// clang-format on
|
||||
while (static_cast<std::size_t>(cur - seq) < max && *cur != Sentinel) ++cur;
|
||||
Ensures(*cur == Sentinel);
|
||||
return {seq, static_cast<std::size_t>(cur - seq)};
|
||||
}
|
||||
|
||||
//
|
||||
// ensure_z - creates a span for a zero terminated strings.
|
||||
// Will fail fast if a null-terminator cannot be found before
|
||||
// the limit of size_type.
|
||||
// ensure_z - creates a span for a zero terminated strings. The span will not contain the zero
|
||||
// termination. Will fail fast if a null-terminator cannot be found before the limit of size_type.
|
||||
//
|
||||
template <typename CharT>
|
||||
span<CharT, dynamic_extent> ensure_z(CharT* const& sz,
|
||||
std::size_t max = static_cast<std::size_t>(-1))
|
||||
[[deprecated("string_span was removed from the C++ Core Guidelines. For more information, see "
|
||||
"isocpp/CppCoreGuidelines PR#1680")]] constexpr span<CharT, dynamic_extent>
|
||||
ensure_z(CharT* const& sz, std::size_t max = static_cast<std::size_t>(-1))
|
||||
{
|
||||
return ensure_sentinel<CharT, CharT(0)>(sz, max);
|
||||
}
|
||||
|
||||
template <typename CharT, std::size_t N>
|
||||
span<CharT, dynamic_extent> ensure_z(CharT (&sz)[N])
|
||||
constexpr span<CharT, dynamic_extent> ensure_z(CharT (&sz)[N])
|
||||
{
|
||||
return ensure_z(&sz[0], N);
|
||||
}
|
||||
|
||||
template <class Cont>
|
||||
span<typename std::remove_pointer<typename Cont::pointer>::type, dynamic_extent>
|
||||
[[deprecated(
|
||||
"string_span was removed from the C++ Core Guidelines. For more information, see "
|
||||
"isocpp/CppCoreGuidelines PR#1680")]] constexpr span<typename std::
|
||||
remove_pointer<
|
||||
typename Cont::pointer>::type,
|
||||
dynamic_extent>
|
||||
ensure_z(Cont& cont)
|
||||
{
|
||||
return ensure_z(cont.data(), cont.size());
|
||||
}
|
||||
|
||||
template <typename CharT, std::size_t>
|
||||
class basic_string_span;
|
||||
class [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, "
|
||||
"see isocpp/CppCoreGuidelines PR#1680")]] basic_string_span;
|
||||
|
||||
namespace details
|
||||
{
|
||||
template <typename T>
|
||||
struct is_basic_string_span_oracle : std::false_type
|
||||
{
|
||||
};
|
||||
struct [
|
||||
[deprecated("string_span was removed from the C++ Core Guidelines. For more information, "
|
||||
"see isocpp/CppCoreGuidelines PR#1680")]] is_basic_string_span_oracle
|
||||
: std::false_type{};
|
||||
|
||||
template <typename CharT, std::size_t Extent>
|
||||
struct is_basic_string_span_oracle<basic_string_span<CharT, Extent>> : std::true_type
|
||||
{
|
||||
};
|
||||
struct [[deprecated(
|
||||
"string_span was removed from the C++ Core Guidelines. For more information, see "
|
||||
"isocpp/CppCoreGuidelines PR#1680")]] is_basic_string_span_oracle<basic_string_span<CharT,
|
||||
Extent>>
|
||||
: std::true_type{};
|
||||
|
||||
template <typename T>
|
||||
struct is_basic_string_span : is_basic_string_span_oracle<std::remove_cv_t<T>>
|
||||
{
|
||||
};
|
||||
struct [[deprecated("string_span was removed from the C++ Core Guidelines. For more "
|
||||
"information, see isocpp/CppCoreGuidelines PR#1680")]] is_basic_string_span
|
||||
: is_basic_string_span_oracle<std::remove_cv_t<T>>{};
|
||||
} // namespace details
|
||||
|
||||
//
|
||||
// string_span and relatives
|
||||
//
|
||||
template <typename CharT, std::size_t Extent = dynamic_extent>
|
||||
class basic_string_span
|
||||
class [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, "
|
||||
"see isocpp/CppCoreGuidelines PR#1680")]] basic_string_span
|
||||
{
|
||||
public:
|
||||
using element_type = CharT;
|
||||
@@ -203,11 +236,11 @@ public:
|
||||
// From static arrays - if 0-terminated, remove 0 from the view
|
||||
// All other containers allow 0s within the length, so we do not remove them
|
||||
template <std::size_t N>
|
||||
constexpr basic_string_span(element_type (&arr)[N]) : span_(remove_z(arr))
|
||||
constexpr basic_string_span(element_type(&arr)[N]) : span_(remove_z(arr))
|
||||
{}
|
||||
|
||||
template <std::size_t N, class ArrayElementType = std::remove_const_t<element_type>>
|
||||
constexpr basic_string_span(std::array<ArrayElementType, N>& arr) noexcept : span_(arr)
|
||||
constexpr basic_string_span(std::array<ArrayElementType, N> & arr) noexcept : span_(arr)
|
||||
{}
|
||||
|
||||
template <std::size_t N, class ArrayElementType = std::remove_const_t<element_type>>
|
||||
@@ -216,8 +249,8 @@ public:
|
||||
|
||||
// Container signature should work for basic_string after C++17 version exists
|
||||
template <class Traits, class Allocator>
|
||||
// GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute // TODO: parser bug
|
||||
constexpr basic_string_span(std::basic_string<element_type, Traits, Allocator>& str)
|
||||
// GSL_SUPPRESS(bounds.4) // TODO: parser bug
|
||||
constexpr basic_string_span(std::basic_string<element_type, Traits, Allocator> & str)
|
||||
: span_(&str[0], str.length())
|
||||
{}
|
||||
|
||||
@@ -233,7 +266,7 @@ public:
|
||||
std::is_convertible<typename Container::pointer, pointer>::value &&
|
||||
std::is_convertible<typename Container::pointer,
|
||||
decltype(std::declval<Container>().data())>::value>>
|
||||
constexpr basic_string_span(Container& cont) : span_(cont)
|
||||
constexpr basic_string_span(Container & cont) : span_(cont)
|
||||
{}
|
||||
|
||||
template <class Container,
|
||||
@@ -282,8 +315,8 @@ public:
|
||||
return {span_.template subspan<Offset, Count>()};
|
||||
}
|
||||
|
||||
constexpr basic_string_span<element_type, dynamic_extent>
|
||||
subspan(size_type offset, size_type count = dynamic_extent) const
|
||||
constexpr basic_string_span<element_type, dynamic_extent> subspan(
|
||||
size_type offset, size_type count = dynamic_extent) const
|
||||
{
|
||||
return {span_.subspan(offset, count)};
|
||||
}
|
||||
@@ -306,13 +339,13 @@ public:
|
||||
constexpr reverse_iterator rend() const noexcept { return span_.rend(); }
|
||||
|
||||
private:
|
||||
static impl_type remove_z(pointer const& sz, std::size_t max)
|
||||
static constexpr impl_type remove_z(pointer const& sz, std::size_t max)
|
||||
{
|
||||
return {sz, details::string_length(sz, max)};
|
||||
return impl_type(sz, details::string_length(sz, max));
|
||||
}
|
||||
|
||||
template <std::size_t N>
|
||||
static impl_type remove_z(element_type (&sz)[N])
|
||||
static constexpr impl_type remove_z(element_type(&sz)[N])
|
||||
{
|
||||
return remove_z(&sz[0], N);
|
||||
}
|
||||
@@ -321,35 +354,51 @@ private:
|
||||
};
|
||||
|
||||
template <std::size_t Extent = dynamic_extent>
|
||||
using string_span = basic_string_span<char, Extent>;
|
||||
using string_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more "
|
||||
"information, see isocpp/CppCoreGuidelines PR#1680")]] =
|
||||
basic_string_span<char, Extent>;
|
||||
|
||||
template <std::size_t Extent = dynamic_extent>
|
||||
using cstring_span = basic_string_span<const char, Extent>;
|
||||
using cstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more "
|
||||
"information, see isocpp/CppCoreGuidelines PR#1680")]] =
|
||||
basic_string_span<const char, Extent>;
|
||||
|
||||
template <std::size_t Extent = dynamic_extent>
|
||||
using wstring_span = basic_string_span<wchar_t, Extent>;
|
||||
using wstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more "
|
||||
"information, see isocpp/CppCoreGuidelines PR#1680")]] =
|
||||
basic_string_span<wchar_t, Extent>;
|
||||
|
||||
template <std::size_t Extent = dynamic_extent>
|
||||
using cwstring_span = basic_string_span<const wchar_t, Extent>;
|
||||
using cwstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more "
|
||||
"information, see isocpp/CppCoreGuidelines PR#1680")]] =
|
||||
basic_string_span<const wchar_t, Extent>;
|
||||
|
||||
template <std::size_t Extent = dynamic_extent>
|
||||
using u16string_span = basic_string_span<char16_t, Extent>;
|
||||
using u16string_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more "
|
||||
"information, see isocpp/CppCoreGuidelines PR#1680")]] =
|
||||
basic_string_span<char16_t, Extent>;
|
||||
|
||||
template <std::size_t Extent = dynamic_extent>
|
||||
using cu16string_span = basic_string_span<const char16_t, Extent>;
|
||||
using cu16string_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more "
|
||||
"information, see isocpp/CppCoreGuidelines PR#1680")]] =
|
||||
basic_string_span<const char16_t, Extent>;
|
||||
|
||||
template <std::size_t Extent = dynamic_extent>
|
||||
using u32string_span = basic_string_span<char32_t, Extent>;
|
||||
using u32string_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more "
|
||||
"information, see isocpp/CppCoreGuidelines PR#1680")]] =
|
||||
basic_string_span<char32_t, Extent>;
|
||||
|
||||
template <std::size_t Extent = dynamic_extent>
|
||||
using cu32string_span = basic_string_span<const char32_t, Extent>;
|
||||
using cu32string_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more "
|
||||
"information, see isocpp/CppCoreGuidelines PR#1680")]] =
|
||||
basic_string_span<const char32_t, Extent>;
|
||||
|
||||
//
|
||||
// to_string() allow (explicit) conversions from string_span to string
|
||||
//
|
||||
|
||||
template <typename CharT, std::size_t Extent>
|
||||
std::basic_string<typename std::remove_const<CharT>::type>
|
||||
constexpr std::basic_string<typename std::remove_const<CharT>::type>
|
||||
to_string(basic_string_span<CharT, Extent> view)
|
||||
{
|
||||
return {view.data(), narrow_cast<std::size_t>(view.length())};
|
||||
@@ -357,32 +406,38 @@ to_string(basic_string_span<CharT, Extent> view)
|
||||
|
||||
template <typename CharT, typename Traits = typename std::char_traits<CharT>,
|
||||
typename Allocator = std::allocator<CharT>, typename gCharT, std::size_t Extent>
|
||||
std::basic_string<CharT, Traits, Allocator> to_basic_string(basic_string_span<gCharT, Extent> view)
|
||||
constexpr std::basic_string<CharT, Traits, Allocator>
|
||||
to_basic_string(basic_string_span<gCharT, Extent> view)
|
||||
{
|
||||
return {view.data(), narrow_cast<std::size_t>(view.length())};
|
||||
}
|
||||
|
||||
template <class ElementType, std::size_t Extent>
|
||||
basic_string_span<const byte, details::calculate_byte_size<ElementType, Extent>::value>
|
||||
constexpr basic_string_span<const byte, details::calculate_byte_size<ElementType, Extent>::value>
|
||||
as_bytes(basic_string_span<ElementType, Extent> s) noexcept
|
||||
{
|
||||
GSL_SUPPRESS(type.1) // NO-FORMAT: attribute
|
||||
// clang-format off
|
||||
GSL_SUPPRESS(type.1)
|
||||
// clang-format on
|
||||
return {reinterpret_cast<const byte*>(s.data()), s.size_bytes()};
|
||||
}
|
||||
|
||||
template <class ElementType, std::size_t Extent,
|
||||
class = std::enable_if_t<!std::is_const<ElementType>::value>>
|
||||
basic_string_span<byte, details::calculate_byte_size<ElementType, Extent>::value>
|
||||
constexpr basic_string_span<byte, details::calculate_byte_size<ElementType, Extent>::value>
|
||||
as_writable_bytes(basic_string_span<ElementType, Extent> s) noexcept
|
||||
{
|
||||
GSL_SUPPRESS(type.1) // NO-FORMAT: attribute
|
||||
// clang-format off
|
||||
GSL_SUPPRESS(type.1)
|
||||
// clang-format on
|
||||
return {reinterpret_cast<byte*>(s.data()), s.size_bytes()};
|
||||
}
|
||||
|
||||
// zero-terminated string span, used to convert
|
||||
// zero-terminated spans to legacy strings
|
||||
template <typename CharT, std::size_t Extent = dynamic_extent>
|
||||
class basic_zstring_span
|
||||
class [[deprecated("string_span was removed from the C++ Core Guidelines. For more information, "
|
||||
"see isocpp/CppCoreGuidelines PR#1680")]] basic_zstring_span
|
||||
{
|
||||
public:
|
||||
using value_type = CharT;
|
||||
@@ -400,14 +455,15 @@ public:
|
||||
constexpr basic_zstring_span(impl_type s) : span_(s)
|
||||
{
|
||||
// expects a zero-terminated span
|
||||
Expects(s[s.size() - 1] == '\0');
|
||||
Expects(s.size() > 0);
|
||||
Expects(s[s.size() - 1] == value_type{});
|
||||
}
|
||||
|
||||
// copy
|
||||
constexpr basic_zstring_span(const basic_zstring_span& other) = default;
|
||||
|
||||
// move
|
||||
constexpr basic_zstring_span(basic_zstring_span&& other) = default;
|
||||
constexpr basic_zstring_span(basic_zstring_span && other) = default;
|
||||
|
||||
// assign
|
||||
constexpr basic_zstring_span& operator=(const basic_zstring_span& other) = default;
|
||||
@@ -415,12 +471,11 @@ public:
|
||||
// move assign
|
||||
constexpr basic_zstring_span& operator=(basic_zstring_span&& other) = default;
|
||||
|
||||
constexpr bool empty() const noexcept { return span_.size() == 0; }
|
||||
constexpr bool empty() const noexcept { return false; }
|
||||
|
||||
constexpr string_span_type as_string_span() const noexcept
|
||||
{
|
||||
const auto sz = span_.size();
|
||||
return {span_.data(), sz > 1 ? sz - 1 : 0};
|
||||
return {span_.data(), span_.size() - 1};
|
||||
}
|
||||
constexpr string_span_type ensure_z() const { return gsl::ensure_z(span_); }
|
||||
|
||||
@@ -431,28 +486,44 @@ private:
|
||||
};
|
||||
|
||||
template <std::size_t Max = dynamic_extent>
|
||||
using zstring_span = basic_zstring_span<char, Max>;
|
||||
using zstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more "
|
||||
"information, see isocpp/CppCoreGuidelines PR#1680")]] =
|
||||
basic_zstring_span<char, Max>;
|
||||
|
||||
template <std::size_t Max = dynamic_extent>
|
||||
using wzstring_span = basic_zstring_span<wchar_t, Max>;
|
||||
using wzstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more "
|
||||
"information, see isocpp/CppCoreGuidelines PR#1680")]] =
|
||||
basic_zstring_span<wchar_t, Max>;
|
||||
|
||||
template <std::size_t Max = dynamic_extent>
|
||||
using u16zstring_span = basic_zstring_span<char16_t, Max>;
|
||||
using u16zstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more "
|
||||
"information, see isocpp/CppCoreGuidelines PR#1680")]] =
|
||||
basic_zstring_span<char16_t, Max>;
|
||||
|
||||
template <std::size_t Max = dynamic_extent>
|
||||
using u32zstring_span = basic_zstring_span<char32_t, Max>;
|
||||
using u32zstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more "
|
||||
"information, see isocpp/CppCoreGuidelines PR#1680")]] =
|
||||
basic_zstring_span<char32_t, Max>;
|
||||
|
||||
template <std::size_t Max = dynamic_extent>
|
||||
using czstring_span = basic_zstring_span<const char, Max>;
|
||||
using czstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more "
|
||||
"information, see isocpp/CppCoreGuidelines PR#1680")]] =
|
||||
basic_zstring_span<const char, Max>;
|
||||
|
||||
template <std::size_t Max = dynamic_extent>
|
||||
using cwzstring_span = basic_zstring_span<const wchar_t, Max>;
|
||||
using cwzstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For more "
|
||||
"information, see isocpp/CppCoreGuidelines PR#1680")]] =
|
||||
basic_zstring_span<const wchar_t, Max>;
|
||||
|
||||
template <std::size_t Max = dynamic_extent>
|
||||
using cu16zstring_span = basic_zstring_span<const char16_t, Max>;
|
||||
using cu16zstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For "
|
||||
"more information, see isocpp/CppCoreGuidelines PR#1680")]] =
|
||||
basic_zstring_span<const char16_t, Max>;
|
||||
|
||||
template <std::size_t Max = dynamic_extent>
|
||||
using cu32zstring_span = basic_zstring_span<const char32_t, Max>;
|
||||
using cu32zstring_span [[deprecated("string_span was removed from the C++ Core Guidelines. For "
|
||||
"more information, see isocpp/CppCoreGuidelines PR#1680")]] =
|
||||
basic_zstring_span<const char32_t, Max>;
|
||||
|
||||
// operator ==
|
||||
template <class CharT, std::size_t Extent, class T,
|
||||
@@ -476,7 +547,7 @@ bool operator==(const T& one, const gsl::basic_string_span<CharT, Extent>& other
|
||||
}
|
||||
|
||||
// operator !=
|
||||
template <typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T,
|
||||
template <typename CharT, std::size_t Extent = dynamic_extent, typename T,
|
||||
typename = std::enable_if_t<std::is_convertible<
|
||||
T, gsl::basic_string_span<std::add_const_t<CharT>, Extent>>::value>>
|
||||
bool operator!=(gsl::basic_string_span<CharT, Extent> one, const T& other)
|
||||
@@ -485,7 +556,7 @@ bool operator!=(gsl::basic_string_span<CharT, Extent> one, const T& other)
|
||||
}
|
||||
|
||||
template <
|
||||
typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename CharT, std::size_t Extent = dynamic_extent, typename T,
|
||||
typename = std::enable_if_t<
|
||||
std::is_convertible<T, gsl::basic_string_span<std::add_const_t<CharT>, Extent>>::value &&
|
||||
!gsl::details::is_basic_string_span<T>::value>>
|
||||
@@ -495,7 +566,7 @@ bool operator!=(const T& one, gsl::basic_string_span<CharT, Extent> other)
|
||||
}
|
||||
|
||||
// operator<
|
||||
template <typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T,
|
||||
template <typename CharT, std::size_t Extent = dynamic_extent, typename T,
|
||||
typename = std::enable_if_t<std::is_convertible<
|
||||
T, gsl::basic_string_span<std::add_const_t<CharT>, Extent>>::value>>
|
||||
bool operator<(gsl::basic_string_span<CharT, Extent> one, const T& other)
|
||||
@@ -505,7 +576,7 @@ bool operator<(gsl::basic_string_span<CharT, Extent> one, const T& other)
|
||||
}
|
||||
|
||||
template <
|
||||
typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename CharT, std::size_t Extent = dynamic_extent, typename T,
|
||||
typename = std::enable_if_t<
|
||||
std::is_convertible<T, gsl::basic_string_span<std::add_const_t<CharT>, Extent>>::value &&
|
||||
!gsl::details::is_basic_string_span<T>::value>>
|
||||
@@ -521,7 +592,7 @@ bool operator<(const T& one, gsl::basic_string_span<CharT, Extent> other)
|
||||
// so the cases below are already covered by the previous operators
|
||||
|
||||
template <
|
||||
typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename CharT, std::size_t Extent = dynamic_extent, typename T,
|
||||
typename DataType = typename T::value_type,
|
||||
typename = std::enable_if_t<
|
||||
!gsl::details::is_span<T>::value && !gsl::details::is_basic_string_span<T>::value &&
|
||||
@@ -535,7 +606,7 @@ bool operator<(gsl::basic_string_span<CharT, Extent> one, const T& other)
|
||||
}
|
||||
|
||||
template <
|
||||
typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename CharT, std::size_t Extent = dynamic_extent, typename T,
|
||||
typename DataType = typename T::value_type,
|
||||
typename = std::enable_if_t<
|
||||
!gsl::details::is_span<T>::value && !gsl::details::is_basic_string_span<T>::value &&
|
||||
@@ -550,7 +621,7 @@ bool operator<(const T& one, gsl::basic_string_span<CharT, Extent> other)
|
||||
#endif
|
||||
|
||||
// operator <=
|
||||
template <typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T,
|
||||
template <typename CharT, std::size_t Extent = dynamic_extent, typename T,
|
||||
typename = std::enable_if_t<std::is_convertible<
|
||||
T, gsl::basic_string_span<std::add_const_t<CharT>, Extent>>::value>>
|
||||
bool operator<=(gsl::basic_string_span<CharT, Extent> one, const T& other)
|
||||
@@ -559,7 +630,7 @@ bool operator<=(gsl::basic_string_span<CharT, Extent> one, const T& other)
|
||||
}
|
||||
|
||||
template <
|
||||
typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename CharT, std::size_t Extent = dynamic_extent, typename T,
|
||||
typename = std::enable_if_t<
|
||||
std::is_convertible<T, gsl::basic_string_span<std::add_const_t<CharT>, Extent>>::value &&
|
||||
!gsl::details::is_basic_string_span<T>::value>>
|
||||
@@ -574,7 +645,7 @@ bool operator<=(const T& one, gsl::basic_string_span<CharT, Extent> other)
|
||||
// so the cases below are already covered by the previous operators
|
||||
|
||||
template <
|
||||
typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename CharT, std::size_t Extent = dynamic_extent, typename T,
|
||||
typename DataType = typename T::value_type,
|
||||
typename = std::enable_if_t<
|
||||
!gsl::details::is_span<T>::value && !gsl::details::is_basic_string_span<T>::value &&
|
||||
@@ -587,7 +658,7 @@ bool operator<=(gsl::basic_string_span<CharT, Extent> one, const T& other)
|
||||
}
|
||||
|
||||
template <
|
||||
typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename CharT, std::size_t Extent = dynamic_extent, typename T,
|
||||
typename DataType = typename T::value_type,
|
||||
typename = std::enable_if_t<
|
||||
!gsl::details::is_span<T>::value && !gsl::details::is_basic_string_span<T>::value &&
|
||||
@@ -601,7 +672,7 @@ bool operator<=(const T& one, gsl::basic_string_span<CharT, Extent> other)
|
||||
#endif
|
||||
|
||||
// operator>
|
||||
template <typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T,
|
||||
template <typename CharT, std::size_t Extent = dynamic_extent, typename T,
|
||||
typename = std::enable_if_t<std::is_convertible<
|
||||
T, gsl::basic_string_span<std::add_const_t<CharT>, Extent>>::value>>
|
||||
bool operator>(gsl::basic_string_span<CharT, Extent> one, const T& other)
|
||||
@@ -610,7 +681,7 @@ bool operator>(gsl::basic_string_span<CharT, Extent> one, const T& other)
|
||||
}
|
||||
|
||||
template <
|
||||
typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename CharT, std::size_t Extent = dynamic_extent, typename T,
|
||||
typename = std::enable_if_t<
|
||||
std::is_convertible<T, gsl::basic_string_span<std::add_const_t<CharT>, Extent>>::value &&
|
||||
!gsl::details::is_basic_string_span<T>::value>>
|
||||
@@ -625,7 +696,7 @@ bool operator>(const T& one, gsl::basic_string_span<CharT, Extent> other)
|
||||
// so the cases below are already covered by the previous operators
|
||||
|
||||
template <
|
||||
typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename CharT, std::size_t Extent = dynamic_extent, typename T,
|
||||
typename DataType = typename T::value_type,
|
||||
typename = std::enable_if_t<
|
||||
!gsl::details::is_span<T>::value && !gsl::details::is_basic_string_span<T>::value &&
|
||||
@@ -638,7 +709,7 @@ bool operator>(gsl::basic_string_span<CharT, Extent> one, const T& other)
|
||||
}
|
||||
|
||||
template <
|
||||
typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename CharT, std::size_t Extent = dynamic_extent, typename T,
|
||||
typename DataType = typename T::value_type,
|
||||
typename = std::enable_if_t<
|
||||
!gsl::details::is_span<T>::value && !gsl::details::is_basic_string_span<T>::value &&
|
||||
@@ -652,7 +723,7 @@ bool operator>(const T& one, gsl::basic_string_span<CharT, Extent> other)
|
||||
#endif
|
||||
|
||||
// operator >=
|
||||
template <typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T,
|
||||
template <typename CharT, std::size_t Extent = dynamic_extent, typename T,
|
||||
typename = std::enable_if_t<std::is_convertible<
|
||||
T, gsl::basic_string_span<std::add_const_t<CharT>, Extent>>::value>>
|
||||
bool operator>=(gsl::basic_string_span<CharT, Extent> one, const T& other)
|
||||
@@ -661,7 +732,7 @@ bool operator>=(gsl::basic_string_span<CharT, Extent> one, const T& other)
|
||||
}
|
||||
|
||||
template <
|
||||
typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename CharT, std::size_t Extent = dynamic_extent, typename T,
|
||||
typename = std::enable_if_t<
|
||||
std::is_convertible<T, gsl::basic_string_span<std::add_const_t<CharT>, Extent>>::value &&
|
||||
!gsl::details::is_basic_string_span<T>::value>>
|
||||
@@ -676,7 +747,7 @@ bool operator>=(const T& one, gsl::basic_string_span<CharT, Extent> other)
|
||||
// so the cases below are already covered by the previous operators
|
||||
|
||||
template <
|
||||
typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename CharT, std::size_t Extent = dynamic_extent, typename T,
|
||||
typename DataType = typename T::value_type,
|
||||
typename = std::enable_if_t<
|
||||
!gsl::details::is_span<T>::value && !gsl::details::is_basic_string_span<T>::value &&
|
||||
@@ -689,7 +760,7 @@ bool operator>=(gsl::basic_string_span<CharT, Extent> one, const T& other)
|
||||
}
|
||||
|
||||
template <
|
||||
typename CharT, std::size_t Extent = gsl::dynamic_extent, typename T,
|
||||
typename CharT, std::size_t Extent = dynamic_extent, typename T,
|
||||
typename DataType = typename T::value_type,
|
||||
typename = std::enable_if_t<
|
||||
!gsl::details::is_span<T>::value && !gsl::details::is_basic_string_span<T>::value &&
|
||||
@@ -706,11 +777,9 @@ bool operator>=(const T& one, gsl::basic_string_span<CharT, Extent> other)
|
||||
#if defined(_MSC_VER) && !defined(__clang__)
|
||||
#pragma warning(pop)
|
||||
|
||||
#if _MSC_VER < 1910
|
||||
#undef constexpr
|
||||
#pragma pop_macro("constexpr")
|
||||
|
||||
#endif // _MSC_VER < 1910
|
||||
#endif // _MSC_VER
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
#endif // GSL_STRING_SPAN_H
|
||||
|
||||
+32
-27
@@ -1,37 +1,42 @@
|
||||
cmake_minimum_required(VERSION 3.0.2)
|
||||
|
||||
project(GSLTests CXX)
|
||||
include(FindPkgConfig)
|
||||
|
||||
# will make visual studio generated project group files
|
||||
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||
|
||||
configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
|
||||
RESULT_VARIABLE result
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download
|
||||
)
|
||||
if(result)
|
||||
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
|
||||
pkg_search_module(GTestMain gtest_main)
|
||||
if (NOT GTestMain_FOUND)
|
||||
configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
|
||||
RESULT_VARIABLE result
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download
|
||||
)
|
||||
if(result)
|
||||
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
|
||||
endif()
|
||||
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_COMMAND} --build .
|
||||
RESULT_VARIABLE result
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download
|
||||
)
|
||||
if(result)
|
||||
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
|
||||
endif()
|
||||
|
||||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||
set(GTestMain_LIBRARIES gtest_main)
|
||||
|
||||
add_subdirectory(
|
||||
${CMAKE_CURRENT_BINARY_DIR}/googletest-src
|
||||
${CMAKE_CURRENT_BINARY_DIR}/googletest-build
|
||||
EXCLUDE_FROM_ALL
|
||||
)
|
||||
endif()
|
||||
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_COMMAND} --build .
|
||||
RESULT_VARIABLE result
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download
|
||||
)
|
||||
if(result)
|
||||
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
|
||||
endif()
|
||||
|
||||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||
|
||||
add_subdirectory(
|
||||
${CMAKE_CURRENT_BINARY_DIR}/googletest-src
|
||||
${CMAKE_CURRENT_BINARY_DIR}/googletest-build
|
||||
EXCLUDE_FROM_ALL
|
||||
)
|
||||
|
||||
if (MSVC AND (GSL_CXX_STANDARD EQUAL 17))
|
||||
set(GSL_CPLUSPLUS_OPT -Zc:__cplusplus -permissive-)
|
||||
endif()
|
||||
@@ -149,7 +154,7 @@ function(add_gsl_test name)
|
||||
target_link_libraries(${name}
|
||||
GSL
|
||||
gsl_tests_config
|
||||
gtest_main
|
||||
${GTestMain_LIBRARIES}
|
||||
)
|
||||
add_test(
|
||||
${name}
|
||||
@@ -254,7 +259,7 @@ function(add_gsl_test_noexcept name)
|
||||
target_link_libraries(${name}
|
||||
GSL
|
||||
gsl_tests_config_noexcept
|
||||
gtest_main
|
||||
${GTestMain_LIBRARIES}
|
||||
)
|
||||
add_test(
|
||||
${name}
|
||||
|
||||
@@ -846,8 +846,6 @@ static_assert(!std::is_constructible<gsl::span<int, 3>, std::array<int, 500>&>::
|
||||
"!std::is_constructible<gsl::span<int, 3>, std::array<int, 500>&>");
|
||||
static_assert(!std::is_constructible<gsl::span<int, 3>, const std::array<int, 3>&>::value,
|
||||
"!std::is_constructible<gsl::span<int, 3>, const std::array<int, 3>&>");
|
||||
static_assert(!std::is_constructible<gsl::span<int, 3>, const gsl::span<int>&>::value,
|
||||
"!std::is_constructible<gsl::span<int, 3>, const gsl::span<int>&>");
|
||||
static_assert(!std::is_constructible<gsl::span<int, 3>, const gsl::span<int, 500>&>::value,
|
||||
"!std::is_constructible<gsl::span<int, 3>, const gsl::span<int, 500>&>");
|
||||
static_assert(!std::is_constructible<gsl::span<int, 3>, const gsl::span<const int>&>::value,
|
||||
@@ -866,12 +864,8 @@ static_assert(!std::is_constructible<gsl::span<const int>, std::array<double, 3>
|
||||
static_assert(!std::is_constructible<gsl::span<const int>, const gsl::span<double, 3>&>::value,
|
||||
"!std::is_constructible<gsl::span<const int>, const gsl::span<double, 3>&>");
|
||||
|
||||
static_assert(!std::is_constructible<gsl::span<const int, 3>, const gsl::span<int>&>::value,
|
||||
"!std::is_constructible<gsl::span<const int, 3>, const gsl::span<int>&>");
|
||||
static_assert(!std::is_constructible<gsl::span<const int, 3>, const gsl::span<int, 500>&>::value,
|
||||
"!std::is_constructible<gsl::span<const int, 3>, const gsl::span<int, 500>&>");
|
||||
static_assert(!std::is_constructible<gsl::span<const int, 3>, const gsl::span<const int>&>::value,
|
||||
"!std::is_constructible<gsl::span<const int, 3>, const gsl::span<const int>&>");
|
||||
static_assert(
|
||||
!std::is_constructible<gsl::span<const int, 3>, const gsl::span<const int, 500>&>::value,
|
||||
"!std::is_constructible<gsl::span<const int, 3>, const gsl::span<const int, 500>&>");
|
||||
@@ -925,6 +919,14 @@ static_assert(!std::is_constructible<gsl::span<const Derived>, std::array<Base,
|
||||
static_assert(!std::is_constructible<gsl::span<const Derived>, const std::array<Base, 3>&>::value,
|
||||
"!std::is_constructible<gsl::span<const Derived>, const std::array<Base, 3>&>");
|
||||
|
||||
// Explicit construction enabled in P1976R2
|
||||
static_assert(std::is_constructible<gsl::span<int, 3>, const gsl::span<int>&>::value,
|
||||
"std::is_constructible<gsl::span<int, 3>, const gsl::span<int>&>");
|
||||
static_assert(std::is_constructible<gsl::span<const int, 3>, const gsl::span<int>&>::value,
|
||||
"std::is_constructible<gsl::span<const int, 3>, const gsl::span<int>&>");
|
||||
static_assert(std::is_constructible<gsl::span<const int, 3>, const gsl::span<const int>&>::value,
|
||||
"std::is_constructible<gsl::span<const int, 3>, const gsl::span<const int>&>");
|
||||
|
||||
// no throw copy constructor
|
||||
static_assert(std::is_nothrow_copy_constructible<gsl::span<int>>::value,
|
||||
"std::is_nothrow_copy_constructible<gsl::span<int>>");
|
||||
|
||||
+36
-2
@@ -31,6 +31,16 @@
|
||||
#include <vector> // for vector
|
||||
#include <utility>
|
||||
|
||||
// the string_view include and macro are used in the deduction guide verification
|
||||
#if (defined(__cpp_deduction_guides) && (__cpp_deduction_guides >= 201611L))
|
||||
#ifdef __has_include
|
||||
#if __has_include(<string_view>)
|
||||
#include <string_view>
|
||||
#define HAS_STRING_VIEW
|
||||
#endif // __has_include(<string_view>)
|
||||
#endif // __has_include
|
||||
#endif // (defined(__cpp_deduction_guides) && (__cpp_deduction_guides >= 201611L))
|
||||
|
||||
using namespace std;
|
||||
using namespace gsl;
|
||||
|
||||
@@ -1144,7 +1154,7 @@ TEST(span_test, from_array_constructor)
|
||||
|
||||
// you can convert statically
|
||||
{
|
||||
const span<int, 2> s2 = {&arr[0], 2};
|
||||
const span<int, 2> s2{&arr[0], 2};
|
||||
static_cast<void>(s2);
|
||||
}
|
||||
{
|
||||
@@ -1180,7 +1190,7 @@ TEST(span_test, from_array_constructor)
|
||||
#endif
|
||||
{
|
||||
auto f = [&]() {
|
||||
const span<int, 4> _s4 = {arr2, 2};
|
||||
const span<int, 4> _s4{arr2, 2};
|
||||
static_cast<void>(_s4);
|
||||
};
|
||||
EXPECT_DEATH(f(), deathstring);
|
||||
@@ -1227,6 +1237,30 @@ TEST(span_test, from_array_constructor)
|
||||
EXPECT_FALSE((std::is_default_constructible<span<int, 42>>::value));
|
||||
}
|
||||
|
||||
TEST(span_test, std_container_ctad)
|
||||
{
|
||||
#if (defined(__cpp_deduction_guides) && (__cpp_deduction_guides >= 201611L))
|
||||
// this test is just to verify that these compile
|
||||
{
|
||||
std::vector<int> v{1,2,3,4};
|
||||
gsl::span sp{v};
|
||||
static_assert(std::is_same<decltype(sp), gsl::span<int>>::value);
|
||||
}
|
||||
{
|
||||
std::string str{"foo"};
|
||||
gsl::span sp{str};
|
||||
static_assert(std::is_same<decltype(sp), gsl::span<char>>::value);
|
||||
}
|
||||
#ifdef HAS_STRING_VIEW
|
||||
{
|
||||
std::string_view sv{"foo"};
|
||||
gsl::span sp{sv};
|
||||
static_assert(std::is_same<decltype(sp), gsl::span<const char>>::value);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(span_test, front_back)
|
||||
{
|
||||
int arr[5] = {1,2,3,4,5};
|
||||
|
||||
+24
-6
@@ -16,8 +16,8 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <gsl/gsl_util> // for narrow, finally, narrow_cast, narrowing_e...
|
||||
|
||||
#include <gsl/gsl_util> // finally, narrow_cast
|
||||
#include <gsl/gsl_narrow> // for narrow, narrowing_error
|
||||
#include <algorithm> // for move
|
||||
#include <functional> // for reference_wrapper, _Bind_helper<>::type
|
||||
#include <limits> // for numeric_limits
|
||||
@@ -70,6 +70,28 @@ TEST(utils_tests, finally_lambda_move)
|
||||
EXPECT_TRUE(i == 1);
|
||||
}
|
||||
|
||||
TEST(utils_tests, finally_const_lvalue_lambda)
|
||||
{
|
||||
int i = 0;
|
||||
{
|
||||
const auto const_lvalue_lambda = [&]() { f(i); };
|
||||
auto _ = finally(const_lvalue_lambda);
|
||||
EXPECT_TRUE(i == 0);
|
||||
}
|
||||
EXPECT_TRUE(i == 1);
|
||||
}
|
||||
|
||||
TEST(utils_tests, finally_mutable_lvalue_lambda)
|
||||
{
|
||||
int i = 0;
|
||||
{
|
||||
auto mutable_lvalue_lambda = [&]() { f(i); };
|
||||
auto _ = finally(mutable_lvalue_lambda);
|
||||
EXPECT_TRUE(i == 0);
|
||||
}
|
||||
EXPECT_TRUE(i == 1);
|
||||
}
|
||||
|
||||
TEST(utils_tests, finally_function_with_bind)
|
||||
{
|
||||
int i = 0;
|
||||
@@ -122,8 +144,4 @@ TEST(utils_tests, narrow)
|
||||
|
||||
n = -42;
|
||||
EXPECT_THROW(narrow<unsigned>(n), narrowing_error);
|
||||
|
||||
#if GSL_CONSTEXPR_NARROW
|
||||
static_assert(narrow<char>(120) == 120, "Fix GSL_CONSTEXPR_NARROW");
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user