mirror of
https://github.com/microsoft/GSL.git
synced 2026-08-06 05:34:26 +02:00
Compare commits
50 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 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 | |||
| de053645bb | |||
| 879335cebf | |||
| 1999b48a51 | |||
| 3da256d03b | |||
| 601b55ea61 | |||
| 3a5b83db35 | |||
| 94d6a35726 | |||
| 14acdcd7a8 | |||
| 4eb554d7c2 | |||
| 70e1317ab6 | |||
| 61534ca3ad | |||
| afa2f3fd9a | |||
| fb1243d735 | |||
| 9f6a9a5807 | |||
| aeb65efada | |||
| 830b081de7 |
@@ -0,0 +1,94 @@
|
||||
name: CI
|
||||
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
|
||||
|
||||
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 {} \\\;
|
||||
+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")
|
||||
|
||||
+21
-5
@@ -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")
|
||||
@@ -89,15 +89,31 @@ install(
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
)
|
||||
# Make library importable by other projects
|
||||
install(EXPORT Microsoft.GSLConfig NAMESPACE Microsoft.GSL:: DESTINATION share/Microsoft.GSL/cmake)
|
||||
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)
|
||||
write_basic_package_version_file(
|
||||
${CMAKE_CURRENT_BINARY_DIR}/Microsoft.GSLConfigVersion.cmake
|
||||
COMPATIBILITY SameMajorVersion
|
||||
)
|
||||
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,4 +1,5 @@
|
||||
# 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).
|
||||
@@ -21,34 +22,33 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope
|
||||
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.
|
||||
|
||||
# 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:
|
||||
|
||||
+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"
|
||||
|
||||
+6
-19
@@ -30,18 +30,8 @@
|
||||
#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
|
||||
#else
|
||||
#define GSL_CONSTEXPR_NARROW 1
|
||||
#endif
|
||||
|
||||
namespace gsl
|
||||
{
|
||||
//
|
||||
@@ -96,6 +86,10 @@ 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>
|
||||
@@ -109,15 +103,13 @@ namespace details
|
||||
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) gsl::details::terminate();
|
||||
if (static_cast<U>(t) != u) throw narrowing_error{};
|
||||
if (!details::is_same_signedness<T, U>::value && ((t < T{}) != (u < U{})))
|
||||
gsl::details::terminate();
|
||||
throw narrowing_error{};
|
||||
return t;
|
||||
}
|
||||
|
||||
@@ -154,11 +146,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)
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
#include <algorithm> // for transform, lexicographical_compare
|
||||
#include <array> // for array
|
||||
#include <cstddef> // for ptrdiff_t, size_t, nullptr_t
|
||||
#include <cstddef> // for std::ptrdiff_t, size_t, nullptr_t
|
||||
#include <cstdint> // for PTRDIFF_MAX
|
||||
#include <functional> // for divides, multiplies, minus, negate, plus
|
||||
#include <initializer_list> // for initializer_list
|
||||
@@ -62,7 +62,7 @@
|
||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
||||
#endif
|
||||
|
||||
// GCC 7 does not like the signed unsigned missmatch (size_t ptrdiff_t)
|
||||
// GCC 7 does not like the signed unsigned missmatch (size_t std::ptrdiff_t)
|
||||
// While there is a conversion from signed to unsigned, it happens at
|
||||
// compiletime, so the compiler wouldn't have to warn indiscriminently, but
|
||||
// could check if the source value actually doesn't fit into the target type
|
||||
@@ -392,9 +392,9 @@ namespace details
|
||||
template <typename T, std::size_t Dim = 0>
|
||||
constexpr size_type contains(const T& arr) const
|
||||
{
|
||||
const ptrdiff_t last = this->Base::template contains<T, Dim + 1>(arr);
|
||||
const std::ptrdiff_t last = this->Base::template contains<T, Dim + 1>(arr);
|
||||
if (last == -1) return -1;
|
||||
const ptrdiff_t cur = this->Base::totalSize() * arr[Dim];
|
||||
const std::ptrdiff_t cur = this->Base::totalSize() * arr[Dim];
|
||||
return cur < m_bound ? cur + last : -1;
|
||||
}
|
||||
|
||||
@@ -462,7 +462,7 @@ namespace details
|
||||
GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
|
||||
Expects(arr[Dim] >= 0 && arr[Dim] < CurrentRange); // Index is out of range
|
||||
GSL_SUPPRESS(bounds.4) // NO-FORMAT: attribute
|
||||
const ptrdiff_t d = arr[Dim];
|
||||
const std::ptrdiff_t d = arr[Dim];
|
||||
return this->Base::totalSize() * d + this->Base::template linearize<T, Dim + 1>(arr);
|
||||
}
|
||||
|
||||
|
||||
+103
-46
@@ -19,7 +19,6 @@
|
||||
|
||||
#include <gsl/gsl_assert> // for Expects
|
||||
#include <gsl/gsl_byte> // for byte
|
||||
#include <gsl/gsl_util> // for narrow_cast, narrow
|
||||
|
||||
#include <array> // for array
|
||||
#include <cstddef> // for ptrdiff_t, size_t, nullptr_t
|
||||
@@ -39,12 +38,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
|
||||
@@ -344,17 +337,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 <>
|
||||
@@ -364,10 +358,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);
|
||||
}
|
||||
@@ -378,6 +372,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
|
||||
{
|
||||
@@ -421,18 +421,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 != gsl::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
|
||||
template <std::size_t MyExtent = Extent, std::enable_if_t<MyExtent == gsl::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 != gsl::dynamic_extent, int> = 0>
|
||||
constexpr explicit span(pointer firstElem, pointer lastElem) noexcept
|
||||
: storage_(firstElem, static_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 == gsl::dynamic_extent, int> = 0>
|
||||
constexpr span(pointer firstElem, pointer lastElem) noexcept
|
||||
: storage_(firstElem, static_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
|
||||
@@ -457,40 +467,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;
|
||||
|
||||
@@ -499,7 +543,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>
|
||||
@@ -509,7 +553,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>
|
||||
@@ -520,8 +564,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
|
||||
@@ -582,12 +626,18 @@ public:
|
||||
constexpr iterator begin() const noexcept
|
||||
{
|
||||
const auto data = storage_.data();
|
||||
// clang-format off
|
||||
GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
|
||||
// clang-format on
|
||||
return {data, data + size(), data};
|
||||
}
|
||||
|
||||
constexpr iterator end() const noexcept
|
||||
{
|
||||
const auto data = storage_.data();
|
||||
// clang-format off
|
||||
GSL_SUPPRESS(bounds.1) // NO-FORMAT: attribute
|
||||
// clang-format on
|
||||
const auto endData = data + storage_.size();
|
||||
return {data, endData, endData};
|
||||
}
|
||||
@@ -690,6 +740,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)
|
||||
@@ -723,10 +781,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,
|
||||
@@ -734,20 +794,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
|
||||
|
||||
+1
-11
@@ -36,11 +36,6 @@
|
||||
#pragma warning(disable : 26446) // TODO: bug in parser - attributes and templates
|
||||
#pragma warning(disable : 26481) // TODO: suppress does not work inside templates sometimes
|
||||
|
||||
#if _MSC_VER < 1910
|
||||
#pragma push_macro("constexpr")
|
||||
#define constexpr /*constexpr*/
|
||||
|
||||
#endif // _MSC_VER < 1910
|
||||
#endif // _MSC_VER
|
||||
|
||||
namespace gsl
|
||||
@@ -308,7 +303,7 @@ public:
|
||||
private:
|
||||
static 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>
|
||||
@@ -706,11 +701,6 @@ 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
|
||||
|
||||
#endif // GSL_STRING_SPAN_H
|
||||
|
||||
@@ -264,5 +264,4 @@ function(add_gsl_test_noexcept name)
|
||||
set_property(TARGET ${name} PROPERTY FOLDER "GSL_tests_noexcept")
|
||||
endfunction()
|
||||
|
||||
add_gsl_test_noexcept(no_exception_throw_tests)
|
||||
add_gsl_test_noexcept(no_exception_ensure_tests)
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <cstdlib> // for std::exit
|
||||
#include <gsl/gsl_assert> // for get_terminate
|
||||
#include <gsl/gsl_util> // for narrow
|
||||
|
||||
int narrow_no_throw()
|
||||
{
|
||||
const long long bigNumber = 0x0fffffffffffffff;
|
||||
return gsl::narrow<int>(bigNumber);
|
||||
}
|
||||
|
||||
[[noreturn]] void test_terminate() { std::exit(0); }
|
||||
|
||||
void setup_termination_handler() noexcept
|
||||
{
|
||||
#if defined(GSL_MSVC_USE_STL_NOEXCEPTION_WORKAROUND)
|
||||
|
||||
auto& handler = gsl::details::get_terminate_handler();
|
||||
handler = &test_terminate;
|
||||
|
||||
#else
|
||||
|
||||
std::set_terminate(test_terminate);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
setup_termination_handler();
|
||||
narrow_no_throw();
|
||||
return -1;
|
||||
}
|
||||
@@ -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};
|
||||
|
||||
+4
-15
@@ -29,7 +29,6 @@ using namespace gsl;
|
||||
|
||||
namespace
|
||||
{
|
||||
static constexpr char deathstring[] = "Expected Death";
|
||||
void f(int& i) { i += 1; }
|
||||
static int j = 0;
|
||||
void g() { j += 1; }
|
||||
@@ -104,17 +103,12 @@ TEST(utils_tests, narrow_cast)
|
||||
|
||||
TEST(utils_tests, narrow)
|
||||
{
|
||||
std::set_terminate([] {
|
||||
std::cerr << "Expected Death. narrow";
|
||||
std::abort();
|
||||
});
|
||||
|
||||
int n = 120;
|
||||
const char c = narrow<char>(n);
|
||||
EXPECT_TRUE(c == 120);
|
||||
|
||||
n = 300;
|
||||
EXPECT_DEATH(narrow<char>(n), deathstring);
|
||||
EXPECT_THROW(narrow<char>(n), narrowing_error);
|
||||
|
||||
const auto int32_max = std::numeric_limits<int32_t>::max();
|
||||
const auto int32_min = std::numeric_limits<int32_t>::min();
|
||||
@@ -123,14 +117,9 @@ TEST(utils_tests, narrow)
|
||||
EXPECT_TRUE(narrow<uint32_t>(int32_t(1)) == 1);
|
||||
EXPECT_TRUE(narrow<uint32_t>(int32_max) == static_cast<uint32_t>(int32_max));
|
||||
|
||||
EXPECT_DEATH(narrow<uint32_t>(int32_t(-1)), deathstring);
|
||||
EXPECT_DEATH(narrow<uint32_t>(int32_min), deathstring);
|
||||
EXPECT_THROW(narrow<uint32_t>(int32_t(-1)), narrowing_error);
|
||||
EXPECT_THROW(narrow<uint32_t>(int32_min), narrowing_error);
|
||||
|
||||
n = -42;
|
||||
EXPECT_DEATH(narrow<unsigned>(n), deathstring);
|
||||
|
||||
#if GSL_CONSTEXPR_NARROW
|
||||
static_assert(narrow<char>(120) == 120, "Fix GSL_CONSTEXPR_NARROW");
|
||||
#endif
|
||||
|
||||
EXPECT_THROW(narrow<unsigned>(n), narrowing_error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user