mirror of
https://github.com/boostorg/compat.git
synced 2026-01-20 16:32:23 +00:00
Compare commits
48 Commits
feature/in
...
boost-1.88
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
61b464c3ee | ||
|
|
c3bd40856d | ||
|
|
736b381d13 | ||
|
|
881cc909fb | ||
|
|
c9f3354cff | ||
|
|
c4924db9e5 | ||
|
|
1a8bb0b574 | ||
|
|
c18e5f2276 | ||
|
|
d2d5cbe094 | ||
|
|
c49f822b2e | ||
|
|
889d2608e6 | ||
|
|
787a5dd4d1 | ||
|
|
a6520ef2e1 | ||
|
|
0d2593326f | ||
|
|
4abae7082a | ||
|
|
d802b97ba8 | ||
|
|
e6d2faa267 | ||
|
|
9244cd17b9 | ||
|
|
37dbb81cce | ||
|
|
8ed23dd6a7 | ||
|
|
915a207fc9 | ||
|
|
2a5e8031f8 | ||
|
|
b9f5082f6e | ||
|
|
6a0f933b2e | ||
|
|
ef0f49933b | ||
|
|
438e0fbbf3 | ||
|
|
df5cd71735 | ||
|
|
6f8c2fe8c1 | ||
|
|
e5f0043abc | ||
|
|
fb5f95b3b2 | ||
|
|
cc45f3198a | ||
|
|
ef87b7c225 | ||
|
|
257ce0b4bd | ||
|
|
ea462a4363 | ||
|
|
d5cf9802bd | ||
|
|
28496a6a01 | ||
|
|
09dd50c8db | ||
|
|
f969df9b2a | ||
|
|
74d9d80471 | ||
|
|
26e3edd0af | ||
|
|
09d1a51778 | ||
|
|
f0aeb3ba95 | ||
|
|
0afd51fcd3 | ||
|
|
ed8837a4ff | ||
|
|
54c72a5033 | ||
|
|
7fc7795d6b | ||
|
|
0598dd0688 | ||
|
|
c511487e78 |
284
.drone.jsonnet
Normal file
284
.drone.jsonnet
Normal file
@@ -0,0 +1,284 @@
|
||||
# Copyright 2022 Peter Dimov
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
local library = "compat";
|
||||
|
||||
local triggers =
|
||||
{
|
||||
branch: [ "master", "develop", "feature/*" ]
|
||||
};
|
||||
|
||||
local ubsan = { UBSAN: '1', UBSAN_OPTIONS: 'print_stacktrace=1' };
|
||||
local asan = { ASAN: '1' };
|
||||
|
||||
local linux_pipeline(name, image, environment, packages = "", sources = [], arch = "amd64") =
|
||||
{
|
||||
name: name,
|
||||
kind: "pipeline",
|
||||
type: "docker",
|
||||
trigger: triggers,
|
||||
platform:
|
||||
{
|
||||
os: "linux",
|
||||
arch: arch
|
||||
},
|
||||
steps:
|
||||
[
|
||||
{
|
||||
name: "everything",
|
||||
image: image,
|
||||
environment: environment,
|
||||
commands:
|
||||
[
|
||||
'set -e',
|
||||
'uname -a',
|
||||
'echo $DRONE_STAGE_MACHINE',
|
||||
'wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -',
|
||||
] +
|
||||
(if sources != [] then [ ('apt-add-repository "' + source + '"') for source in sources ] else []) +
|
||||
(if packages != "" then [ 'apt-get update', 'apt-get -y install ' + packages ] else []) +
|
||||
[
|
||||
'export LIBRARY=' + library,
|
||||
'./.drone/drone.sh',
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
local macos_pipeline(name, environment, xcode_version = "12.2", osx_version = "catalina", arch = "amd64") =
|
||||
{
|
||||
name: name,
|
||||
kind: "pipeline",
|
||||
type: "exec",
|
||||
trigger: triggers,
|
||||
platform: {
|
||||
"os": "darwin",
|
||||
"arch": arch
|
||||
},
|
||||
node: {
|
||||
"os": osx_version
|
||||
},
|
||||
steps: [
|
||||
{
|
||||
name: "everything",
|
||||
environment: environment + { "DEVELOPER_DIR": "/Applications/Xcode-" + xcode_version + ".app/Contents/Developer" },
|
||||
commands:
|
||||
[
|
||||
'export LIBRARY=' + library,
|
||||
'./.drone/drone.sh',
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
local windows_pipeline(name, image, environment, arch = "amd64") =
|
||||
{
|
||||
name: name,
|
||||
kind: "pipeline",
|
||||
type: "docker",
|
||||
trigger: triggers,
|
||||
platform:
|
||||
{
|
||||
os: "windows",
|
||||
arch: arch
|
||||
},
|
||||
"steps":
|
||||
[
|
||||
{
|
||||
name: "everything",
|
||||
image: image,
|
||||
environment: environment,
|
||||
commands:
|
||||
[
|
||||
'cmd /C .drone\\\\drone.bat ' + library,
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
[
|
||||
linux_pipeline(
|
||||
"Linux 16.04 GCC 4.8 32/64",
|
||||
"cppalliance/droneubuntu1604:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-4.8', CXXSTD: '11', ADDRMD: '32,64' },
|
||||
"g++-4.8-multilib",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 16.04 GCC 4.9 32/64",
|
||||
"cppalliance/droneubuntu1604:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-4.9', CXXSTD: '11', ADDRMD: '32,64' },
|
||||
"g++-4.9-multilib",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 16.04 GCC 5* 32/64",
|
||||
"cppalliance/droneubuntu1604:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '11,14', ADDRMD: '32,64' },
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 18.04 GCC 7* 32/64",
|
||||
"cppalliance/droneubuntu1804:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '11,14,17', ADDRMD: '32,64' },
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 20.04 GCC 9* ARM64 UBSAN",
|
||||
"cppalliance/droneubuntu2004:multiarch",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '11,14,17,2a' } + ubsan,
|
||||
arch="arm64",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 20.04 GCC 9* ARM64 ASAN",
|
||||
"cppalliance/droneubuntu2004:multiarch",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '11,14,17,2a' } + asan,
|
||||
arch="arm64",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 20.04 GCC 9* S390x UBSAN",
|
||||
"cppalliance/droneubuntu2004:multiarch",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '11,14,17,2a' } + ubsan,
|
||||
arch="s390x",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 22.04 GCC 12 32/64",
|
||||
"cppalliance/droneubuntu2204:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-12', CXXSTD: '11,14,17,20', ADDRMD: '32,64' },
|
||||
"g++-12-multilib",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 GCC 13 32/64",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-13', CXXSTD: '11,14,17,20,2b', ADDRMD: '32,64' },
|
||||
"g++-13-multilib",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 GCC 14 32 ASAN",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-14', CXXSTD: '11,14,17,20,2b', ADDRMD: '32' } + asan,
|
||||
"g++-14-multilib",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 GCC 14 64 ASAN",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-14', CXXSTD: '11,14,17,20,2b', ADDRMD: '64' } + asan,
|
||||
"g++-14-multilib",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 GCC 14 32 UBSAN",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-14', CXXSTD: '11,14,17,20,2b', ADDRMD: '32' } + ubsan,
|
||||
"g++-14-multilib",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 GCC 14 64 UBSAN",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'gcc', COMPILER: 'g++-14', CXXSTD: '11,14,17,20,2b', ADDRMD: '64' } + ubsan,
|
||||
"g++-14-multilib",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 22.04 Clang 15",
|
||||
"cppalliance/droneubuntu2204:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-15', CXXSTD: '11,14,17,20,2b' },
|
||||
"clang-15",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 Clang 16",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-16', CXXSTD: '11,14,17,20,2b' },
|
||||
"clang-16",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 Clang 17 UBSAN",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-17', CXXSTD: '11,14,17,20,2b' } + ubsan,
|
||||
"clang-17",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 Clang 17 ASAN",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-17', CXXSTD: '11,14,17,20,2b' } + asan,
|
||||
"clang-17",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 Clang 18 UBSAN",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-18', CXXSTD: '11,14,17,20,2b' } + ubsan,
|
||||
"clang-18",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.04 Clang 18 ASAN",
|
||||
"cppalliance/droneubuntu2404:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-18', CXXSTD: '11,14,17,20,2b' } + asan,
|
||||
"clang-18",
|
||||
),
|
||||
|
||||
linux_pipeline(
|
||||
"Linux 24.10 Clang 19",
|
||||
"cppalliance/droneubuntu2410:1",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++-19', CXXSTD: '11,14,17,20,2b' },
|
||||
"clang-19",
|
||||
),
|
||||
|
||||
macos_pipeline(
|
||||
"MacOS 10.15 Xcode 12.2 UBSAN",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '11,14,1z' } + ubsan,
|
||||
),
|
||||
|
||||
macos_pipeline(
|
||||
"MacOS 10.15 Xcode 12.2 ASAN",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '11,14,1z' } + asan,
|
||||
),
|
||||
|
||||
macos_pipeline(
|
||||
"MacOS 12.4 Xcode 13.4.1 UBSAN",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '11,14,17,20,2b' } + ubsan,
|
||||
xcode_version = "13.4.1", osx_version = "monterey", arch = "arm64",
|
||||
),
|
||||
|
||||
macos_pipeline(
|
||||
"MacOS 12.4 Xcode 13.4.1 ASAN",
|
||||
{ TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '11,14,17,20,2b' } + asan,
|
||||
xcode_version = "13.4.1", osx_version = "monterey", arch = "arm64",
|
||||
),
|
||||
|
||||
windows_pipeline(
|
||||
"Windows VS2015 msvc-14.0",
|
||||
"cppalliance/dronevs2015",
|
||||
{ TOOLSET: 'msvc-14.0', CXXSTD: '14,latest', B2_DONT_EMBED_MANIFEST: '1' },
|
||||
),
|
||||
|
||||
windows_pipeline(
|
||||
"Windows VS2017 msvc-14.1",
|
||||
"cppalliance/dronevs2017",
|
||||
{ TOOLSET: 'msvc-14.1', CXXSTD: '14,17,latest' },
|
||||
),
|
||||
|
||||
windows_pipeline(
|
||||
"Windows VS2019 msvc-14.2",
|
||||
"cppalliance/dronevs2019",
|
||||
{ TOOLSET: 'msvc-14.2', CXXSTD: '14,17,20,latest' },
|
||||
),
|
||||
|
||||
windows_pipeline(
|
||||
"Windows VS2022 msvc-14.3",
|
||||
"cppalliance/dronevs2022:1",
|
||||
{ TOOLSET: 'msvc-14.3', CXXSTD: '14,17,20,latest' },
|
||||
),
|
||||
]
|
||||
25
.drone/drone.bat
Normal file
25
.drone/drone.bat
Normal file
@@ -0,0 +1,25 @@
|
||||
@REM Copyright 2022 Peter Dimov
|
||||
@REM Distributed under the Boost Software License, Version 1.0.
|
||||
@REM https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
@ECHO ON
|
||||
|
||||
set LIBRARY=%1
|
||||
set DRONE_BUILD_DIR=%CD%
|
||||
|
||||
echo %DRONE_STAGE_MACHINE%
|
||||
|
||||
set BOOST_BRANCH=develop
|
||||
if "%DRONE_BRANCH%" == "master" set BOOST_BRANCH=master
|
||||
cd ..
|
||||
git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root
|
||||
cd boost-root
|
||||
git submodule update --init tools/boostdep
|
||||
xcopy /s /e /q %DRONE_BUILD_DIR% libs\%LIBRARY%\
|
||||
python tools/boostdep/depinst/depinst.py %LIBRARY%
|
||||
cmd /c bootstrap
|
||||
b2 -d0 headers
|
||||
|
||||
if not "%CXXSTD%" == "" set CXXSTD=cxxstd=%CXXSTD%
|
||||
if not "%ADDRMD%" == "" set ADDRMD=address-model=%ADDRMD%
|
||||
b2 -j3 libs/%LIBRARY%/test toolset=%TOOLSET% %CXXSTD% %ADDRMD% variant=debug,release embed-manifest-via=linker
|
||||
31
.drone/drone.sh
Executable file
31
.drone/drone.sh
Executable file
@@ -0,0 +1,31 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright 2022 Peter Dimov
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
set -ex
|
||||
export PATH=~/.local/bin:/usr/local/bin:$PATH
|
||||
|
||||
uname -a
|
||||
echo $DRONE_STAGE_MACHINE
|
||||
command -v lscpu && lscpu
|
||||
|
||||
DRONE_BUILD_DIR=$(pwd)
|
||||
|
||||
BOOST_BRANCH=develop
|
||||
if [ "$DRONE_BRANCH" = "master" ]; then BOOST_BRANCH=master; fi
|
||||
|
||||
cd ..
|
||||
git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
|
||||
cd boost-root
|
||||
git submodule update --init tools/boostdep
|
||||
cp -r $DRONE_BUILD_DIR/* libs/$LIBRARY
|
||||
python tools/boostdep/depinst/depinst.py $LIBRARY
|
||||
CXXFLAGS= ./bootstrap.sh
|
||||
./b2 -d0 headers
|
||||
|
||||
echo "using $TOOLSET : : $COMPILER ;" > ~/user-config.jam
|
||||
./b2 -j2 libs/$LIBRARY/test toolset=$TOOLSET cxxstd=$CXXSTD variant=debug,release \
|
||||
${ADDRMD:+address-model=$ADDRMD} ${CXXFLAGS:+cxxflags=$CXXFLAGS} ${LINKFLAGS:+linkflags=$LINKFLAGS} \
|
||||
${UBSAN:+undefined-sanitizer=norecover debug-symbols=on} ${ASAN:+address-sanitizer=norecover debug-symbols=on}
|
||||
83
.github/workflows/ci.yml
vendored
83
.github/workflows/ci.yml
vendored
@@ -19,23 +19,23 @@ jobs:
|
||||
include:
|
||||
- toolset: gcc-4.8
|
||||
cxxstd: "03,11"
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:18.04
|
||||
os: ubuntu-latest
|
||||
install: g++-4.8
|
||||
- toolset: gcc-4.9
|
||||
cxxstd: "03,11"
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:16.04
|
||||
os: ubuntu-latest
|
||||
install: g++-4.9
|
||||
- toolset: gcc-5
|
||||
cxxstd: "03,11,14,1z"
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:18.04
|
||||
os: ubuntu-latest
|
||||
install: g++-5
|
||||
- toolset: gcc-6
|
||||
cxxstd: "03,11,14,1z"
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:18.04
|
||||
os: ubuntu-latest
|
||||
install: g++-6
|
||||
- toolset: gcc-7
|
||||
cxxstd: "03,11,14,17"
|
||||
@@ -54,34 +54,38 @@ jobs:
|
||||
install: g++-10
|
||||
- toolset: gcc-11
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
os: ubuntu-20.04
|
||||
install: g++-11
|
||||
os: ubuntu-22.04
|
||||
- toolset: gcc-12
|
||||
cxxstd: "03,11,14,17,20,2b"
|
||||
os: ubuntu-22.04
|
||||
install: g++-12
|
||||
- toolset: gcc-13
|
||||
cxxstd: "03,11,14,17,20,2b"
|
||||
container: ubuntu:24.04
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:23.04
|
||||
install: g++-13
|
||||
- toolset: gcc-14
|
||||
cxxstd: "03,11,14,17,20,2b"
|
||||
container: ubuntu:24.04
|
||||
os: ubuntu-latest
|
||||
install: g++-14
|
||||
- toolset: clang
|
||||
compiler: clang++-3.9
|
||||
cxxstd: "03,11,14"
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:18.04
|
||||
os: ubuntu-latest
|
||||
install: clang-3.9
|
||||
- toolset: clang
|
||||
compiler: clang++-4.0
|
||||
cxxstd: "03,11,14"
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:18.04
|
||||
os: ubuntu-latest
|
||||
install: clang-4.0
|
||||
- toolset: clang
|
||||
compiler: clang++-5.0
|
||||
cxxstd: "03,11,14,1z"
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:18.04
|
||||
os: ubuntu-latest
|
||||
install: clang-5.0
|
||||
- toolset: clang
|
||||
compiler: clang++-6.0
|
||||
@@ -139,40 +143,64 @@ jobs:
|
||||
- toolset: clang
|
||||
compiler: clang++-16
|
||||
cxxstd: "03,11,14,17,20,2b"
|
||||
container: ubuntu:23.04
|
||||
container: ubuntu:24.04
|
||||
os: ubuntu-latest
|
||||
install: clang-16
|
||||
- toolset: clang
|
||||
compiler: clang++-17
|
||||
cxxstd: "03,11,14,17,20,2b"
|
||||
container: ubuntu:23.10
|
||||
container: ubuntu:24.04
|
||||
os: ubuntu-latest
|
||||
install: clang-17
|
||||
- toolset: clang
|
||||
cxxstd: "03,11,14,17,2a"
|
||||
os: macos-11
|
||||
- toolset: clang
|
||||
compiler: clang++-18
|
||||
cxxstd: "03,11,14,17,20,2b"
|
||||
os: macos-12
|
||||
container: ubuntu:24.04
|
||||
os: ubuntu-latest
|
||||
install: clang-18
|
||||
- toolset: clang
|
||||
compiler: clang++-19
|
||||
cxxstd: "03,11,14,17,20,2b"
|
||||
container: ubuntu:24.10
|
||||
os: ubuntu-latest
|
||||
install: clang-19
|
||||
- toolset: clang
|
||||
cxxstd: "03,11,14,17,20,2b"
|
||||
os: macos-13
|
||||
- toolset: clang
|
||||
cxxstd: "03,11,14,17,20,2b"
|
||||
os: macos-14
|
||||
- toolset: clang
|
||||
cxxstd: "03,11,14,17,20,2b"
|
||||
os: macos-15
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
container: ${{matrix.container}}
|
||||
|
||||
container:
|
||||
image: ${{matrix.container}}
|
||||
volumes:
|
||||
- /node20217:/node20217:rw,rshared
|
||||
- ${{ startsWith(matrix.container, 'ubuntu:1') && '/node20217:/__e/node20:ro,rshared' || ' ' }}
|
||||
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Setup container environment
|
||||
if: matrix.container
|
||||
run: |
|
||||
apt-get update
|
||||
apt-get -y install sudo python3 git g++
|
||||
apt-get -y install sudo python3 git g++ curl xz-utils
|
||||
|
||||
- name: Install nodejs20glibc2.17
|
||||
if: ${{ startsWith( matrix.container, 'ubuntu:1' ) }}
|
||||
run: |
|
||||
curl -LO https://archives.boost.io/misc/node/node-v20.9.0-linux-x64-glibc-217.tar.xz
|
||||
tar -xf node-v20.9.0-linux-x64-glibc-217.tar.xz --strip-components 1 -C /node20217
|
||||
ldd /__e/node20/bin/node
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install packages
|
||||
if: matrix.install
|
||||
@@ -279,9 +307,10 @@ jobs:
|
||||
include:
|
||||
- os: ubuntu-20.04
|
||||
- os: ubuntu-22.04
|
||||
- os: macos-11
|
||||
- os: macos-12
|
||||
- os: ubuntu-24.04
|
||||
- os: macos-13
|
||||
- os: macos-14
|
||||
- os: macos-15
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
@@ -328,9 +357,10 @@ jobs:
|
||||
include:
|
||||
- os: ubuntu-20.04
|
||||
- os: ubuntu-22.04
|
||||
- os: macos-11
|
||||
- os: macos-12
|
||||
- os: ubuntu-24.04
|
||||
- os: macos-13
|
||||
- os: macos-14
|
||||
- os: macos-15
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
@@ -387,9 +417,10 @@ jobs:
|
||||
include:
|
||||
- os: ubuntu-20.04
|
||||
- os: ubuntu-22.04
|
||||
- os: macos-11
|
||||
- os: macos-12
|
||||
- os: ubuntu-24.04
|
||||
- os: macos-13
|
||||
- os: macos-14
|
||||
- os: macos-15
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
|
||||
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
/__build__
|
||||
/toolchain.cmake
|
||||
/compile_commands.json
|
||||
/.cache
|
||||
/.vscode
|
||||
22
build.jam
Normal file
22
build.jam
Normal file
@@ -0,0 +1,22 @@
|
||||
# Copyright 2024 René Ferdinand Rivera Morell
|
||||
# Copyright 2024 Peter Dimov
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
require-b2 5.2 ;
|
||||
|
||||
constant boost_dependencies :
|
||||
/boost/assert//boost_assert
|
||||
/boost/config//boost_config
|
||||
/boost/throw_exception//boost_throw_exception
|
||||
;
|
||||
|
||||
project /boost/compat ;
|
||||
|
||||
explicit
|
||||
[ alias boost_compat : : : : <include>include <library>$(boost_dependencies) ]
|
||||
[ alias all : boost_compat test ]
|
||||
;
|
||||
|
||||
call-if : boost-library compat
|
||||
;
|
||||
@@ -8,9 +8,14 @@ https://www.boost.org/LICENSE_1_0.txt
|
||||
# Revision History
|
||||
:idprefix: changelog_
|
||||
|
||||
## Changes in 1.87.0
|
||||
|
||||
* Added `to_array.hpp` (contributed by Ruben Perez Hidalgo.)
|
||||
|
||||
## Changes in 1.86.0
|
||||
|
||||
* Added `bind_front.hpp`, `bind_back.hpp`, `invoke.hpp`, `mem_fn.hpp`, `integer_sequence.hpp` and `type_traits.hpp`.
|
||||
* Added `function_ref.hpp`.
|
||||
|
||||
## Changes in 1.83.0
|
||||
|
||||
|
||||
200
doc/compat/function_ref.adoc
Normal file
200
doc/compat/function_ref.adoc
Normal file
@@ -0,0 +1,200 @@
|
||||
////
|
||||
Copyright 2024 Christian Mazakas
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
https://www.boost.org/LICENSE_1_0.txt
|
||||
////
|
||||
|
||||
[#function_ref]
|
||||
# <boost/compat/function_ref.hpp>
|
||||
:idprefix: ref_function_ref_
|
||||
|
||||
## Description
|
||||
|
||||
The header `<boost/compat/function_ref.hpp>` implements the {cpp}26 class
|
||||
`std::function_ref`.
|
||||
|
||||
`function_ref` is a lightweight polymorphic function wrapper that only stores a pointer to the supplied https://en.cppreference.com/w/cpp/named_req/Callable[Callable] object and a pointer to an unspecified function, meaning it does not participate in ownership of the Callable and does not allocate. All specializations of `function_ref` satisfy https://en.cppreference.com/w/cpp/named_req/TriviallyCopyable[TriviallyCopyable].
|
||||
|
||||
`function_ref` supports every combination of `const` and `noexcept` and is useful for writing higher-order functions as
|
||||
it can avoid a template parameter or an allocation (as `std::function` is known for).
|
||||
|
||||
## Example
|
||||
|
||||
```cpp
|
||||
int add(int x, int y) noexcept { return x * 10 + y; }
|
||||
|
||||
auto add2 = [](int x, int y) { return x * 100 + y; };
|
||||
|
||||
std::vector<boost::compat::function_ref<int(int, int)>> fns;
|
||||
fns.push_back({add});
|
||||
fns.push_back({add2});
|
||||
|
||||
for (auto fn : fns) {
|
||||
std::cout << fn(1, 2) << std::endl;
|
||||
}
|
||||
```
|
||||
|
||||
## Synopsis
|
||||
|
||||
```cpp
|
||||
namespace boost
|
||||
{
|
||||
namespace compat
|
||||
{
|
||||
|
||||
template <class... S>
|
||||
struct function_ref;
|
||||
|
||||
// cv is either `const` or empty
|
||||
// noex is either `true` or `false`
|
||||
template<class R, class... ArgTypes>
|
||||
class function_ref<R(ArgTypes...) cv noexcept(noex)> {
|
||||
public:
|
||||
template<class F> function_ref(F*) noexcept;
|
||||
template<class F> function_ref(F&&) noexcept;
|
||||
template<auto f> function_ref(nontype_t<f>) noexcept;
|
||||
template<auto f, class U> function_ref(nontype_t<f>, U&&) noexcept;
|
||||
template<auto f, class T> function_ref(nontype_t<f>, cv T*) noexcept;
|
||||
|
||||
function_ref(const function_ref&) noexcept = default;
|
||||
function_ref& operator=(const function_ref&) noexcept = default;
|
||||
template<class T> function_ref& operator=(T) = delete;
|
||||
|
||||
R operator()(ArgTypes...) const noexcept(noex);
|
||||
};
|
||||
|
||||
} // namespace compat
|
||||
} // namespace boost
|
||||
```
|
||||
|
||||
## Constructors
|
||||
|
||||
### Function Pointer Constructor
|
||||
|
||||
```cpp
|
||||
template<class F> function_ref(F* fn) noexcept;
|
||||
```
|
||||
|
||||
[horizontal]
|
||||
Preconditions:: `fn` != `nullptr`.
|
||||
Effects::
|
||||
Constructs a `function_ref` which uses the supplied function pointer as its Callable. +
|
||||
+
|
||||
Calling the `function_ref` is expression-equivalent to `invoke_r<R>(f, call-args...)`.
|
||||
|
||||
|
||||
### Object Constructor
|
||||
|
||||
```cpp
|
||||
template<class F> function_ref(F&& fn) noexcept;
|
||||
```
|
||||
|
||||
[horizontal]
|
||||
Effects:;; Constructs a `function_ref` that stores the address of the supplied Callable object `fn`. This overload only
|
||||
participates in resolution when `fn` is not a pointer-to-member or pointer-to-member-function. +
|
||||
+
|
||||
Calling the `function_ref` is expression-equivalent to: + `invoke_r<R>(static_cast<cv T&>(f), call-args...)`.
|
||||
|
||||
### Pointer to Member Function Constructor
|
||||
|
||||
```cpp
|
||||
template<auto f> function_ref(nontype_t<f>) noexcept;
|
||||
```
|
||||
|
||||
[horizontal]
|
||||
Effects:;; Constructs a `function_ref` using the supplied pointer to member function. This overload only participates
|
||||
in resolution when `f` is a pointer to member or pointer to member function. +
|
||||
+
|
||||
Calling the `function_ref` is express-equivalent to: `invoke_r<R>(f, class-args)`.
|
||||
Example:;;
|
||||
+
|
||||
--
|
||||
```cpp
|
||||
struct point { int x = 1, y = 2; };
|
||||
|
||||
point p;
|
||||
compat::function_ref<int(point const&)> f(compat::nontype_t<&point::x>{});
|
||||
|
||||
BOOST_TEST_EQ(f(p), 1);
|
||||
```
|
||||
--
|
||||
|
||||
### Bound Object Constructor
|
||||
|
||||
```cpp
|
||||
template<auto f, class U> function_ref(nontype_t<f>, U&&) noexcept;
|
||||
```
|
||||
|
||||
[horizontal]
|
||||
Effects:;; Constructs a `function_ref` using the supplied pointer to member or pointer to member function and a reference
|
||||
to an object to bind it to. +
|
||||
+
|
||||
This overload only participates in resolution if `is_rvalue_reference_v<U&&>` is false.
|
||||
Example:;;
|
||||
+
|
||||
--
|
||||
```cpp
|
||||
struct point { int x = 1, y = 2; };
|
||||
|
||||
point p;
|
||||
compat::function_ref<int()> f(compat::nontype_t<&point::x>{}, p);
|
||||
|
||||
BOOST_TEST_EQ(f(), 1);
|
||||
```
|
||||
--
|
||||
|
||||
### Bound Pointer Constructor
|
||||
|
||||
```cpp
|
||||
template<auto f, class T> function_ref(nontype_t<f>, cv T*) noexcept;
|
||||
```
|
||||
|
||||
[horizontal]
|
||||
Effects:;; Constructs a `function_ref` using the supplied pointer to member or pointer to member function and a pointer
|
||||
to an object.
|
||||
Example:;;
|
||||
+
|
||||
--
|
||||
```cpp
|
||||
struct point { int x = 1, y = 2; };
|
||||
|
||||
point p;
|
||||
compat::function_ref<int()> f(compat::nontype_t<&point::x>{}, &p);
|
||||
|
||||
BOOST_TEST_EQ(f(), 1);
|
||||
```
|
||||
--
|
||||
|
||||
### Copy Constructor
|
||||
|
||||
```cpp
|
||||
function_ref(const function_ref&) noexcept = default;
|
||||
```
|
||||
|
||||
[horizontal]
|
||||
Effects:;; `function_ref` is a TriviallyCopyable type.
|
||||
|
||||
## Member Functions
|
||||
|
||||
### call operator
|
||||
|
||||
```cpp
|
||||
R operator()(ArgTypes...) const noexcept(noex);
|
||||
```
|
||||
|
||||
[horizontal]
|
||||
Effects:;; Invokes the underlying Callable object by forwarding the supplied arguments.
|
||||
|
||||
## Assignment
|
||||
|
||||
### Copy Assignment
|
||||
|
||||
```cpp
|
||||
function_ref& operator=(const function_ref&) noexcept = default;
|
||||
template<class T> function_ref& operator=(T) = delete;
|
||||
```
|
||||
|
||||
[horizontal]
|
||||
Effects:;; `operator=(T)` participates in overload resolution if:
|
||||
* `T` is not the same as `function_ref`
|
||||
* `is_pointer_v<T>` is `false`.
|
||||
@@ -11,14 +11,17 @@ https://www.boost.org/LICENSE_1_0.txt
|
||||
## Description
|
||||
|
||||
The header `<boost/compat/invoke.hpp>` implements the {cpp}17 function
|
||||
`std::invoke` and the associated utilities `invoke_result_t`, `is_invocable`,
|
||||
and `is_nothrow_invocable`.
|
||||
`std::invoke`, the {cpp}23 function `std::invoke_r`, and the associated
|
||||
utilities `invoke_result_t`, `is_invocable`, `is_invocable_r`,
|
||||
`is_nothrow_invocable`, and `is_nothrow_invocable_r`.
|
||||
|
||||
`invoke(f, a...)` generally returns `f(a...)`, but when `f` is a pointer to
|
||||
member, it invokes it as if by returning `mem_fn(f)(a...)`. This allows
|
||||
functions, function objects, and pointers to members to be treated uniformly
|
||||
by components such as `bind_front`.
|
||||
|
||||
`invoke_r<R>(f, a...)` returns `invoke(f, a...)`, converted to `R`.
|
||||
|
||||
## Example
|
||||
|
||||
```
|
||||
@@ -50,6 +53,12 @@ template<class F, class... A> struct is_invocable;
|
||||
|
||||
template<class F, class... A> struct is_nothrow_invocable;
|
||||
|
||||
template<class R, class F, class... A> R invoke_r(F&& f, A&&... a);
|
||||
|
||||
template<class R, class F, class... A> struct is_invocable_r;
|
||||
|
||||
template<class R, class F, class... A> struct is_nothrow_invocable_r;
|
||||
|
||||
} // namespace compat
|
||||
} // namespace boost
|
||||
```
|
||||
@@ -57,7 +66,7 @@ template<class F, class... A> struct is_nothrow_invocable;
|
||||
## invoke
|
||||
|
||||
```
|
||||
template<class F, class... A> auto invoke(F&& f, A&&... a) noexcept(/*...*/);
|
||||
template<class F, class... A> auto invoke(F&& f, A&&... a) noexcept(/*...*/) -> /*...*/;
|
||||
```
|
||||
|
||||
[horizontal]
|
||||
@@ -65,7 +74,7 @@ Returns:;;
|
||||
* `std::forward<F>(f)(std::forward<A>(a)...)`, when `f` is not a pointer to member;
|
||||
* `mem_fn(f)(std::forward<A>(a)...)`, otherwise.
|
||||
Constraints:;; the return expression must be valid.
|
||||
Remarks:;; The `noexcept` clause is `noexcept(noexcept(r))`, where `r` is the return expression.
|
||||
Remarks:;; The return type is `decltype(r)`, and the `noexcept` clause is `noexcept(noexcept(r))`, where `r` is the return expression.
|
||||
|
||||
## invoke_result_t
|
||||
|
||||
@@ -90,3 +99,32 @@ template<class F, class... A> struct is_nothrow_invocable: public /*...*/;
|
||||
|
||||
The base class of `is_nothrow_invocable<F, A...>` is `std::false_type` when `is_invocable<F, A...>::value` is `false`, `std::integral_constant<bool, noexcept(invoke(std::declval<F>(), std::declval<A>()...))>` otherwise.
|
||||
|
||||
## invoke_r
|
||||
|
||||
```
|
||||
template<class R, class F, class... A> R invoke_r(F&& f, A&&... a) noexcept(/*...*/);
|
||||
```
|
||||
|
||||
[horizontal]
|
||||
Returns:;;
|
||||
* `static_cast<R>(invoke(std::forward<F>(f), std::forward<A>(a)...))`, when `R` is (possibly cv-qualified) `void`;
|
||||
* `invoke(std::forward<F>(f), std::forward<A>(a)...)`, implicitly converted to `R`, otherwise.
|
||||
Constraints:;; `is_invocable<F, A...>::value` must be `true` and, if `R` is not cv `void`, `std::is_convertible<invoke_result_t<F, A...>, R>::value` must be `true`.
|
||||
Remarks:;; The `noexcept` clause is `noexcept(noexcept(static_cast<R>(invoke(std::forward<F>(f), std::forward<A>(a)...))))`.
|
||||
|
||||
## is_invocable_r
|
||||
|
||||
```
|
||||
template<class R, class F, class... A> struct is_invocable: public /*...*/;
|
||||
```
|
||||
|
||||
The base class of `is_invocable_r<R, F, A...>` is `std::true_type` when `invoke_r<R>(std::declval<F>(), std::declval<A>()...)` is a valid expression, `std::false_type` otherwise.
|
||||
|
||||
## is_nothrow_invocable_r
|
||||
|
||||
```
|
||||
template<class R, class F, class... A> struct is_nothrow_invocable: public /*...*/;
|
||||
```
|
||||
|
||||
The base class of `is_nothrow_invocable<R, F, A...>` is `std::false_type` when `is_invocable_r<R, F, A...>::value` is `false`, `std::integral_constant<bool, noexcept(invoke_r<R>(std::declval<F>(), std::declval<A>()...))>` otherwise.
|
||||
|
||||
|
||||
@@ -6,9 +6,11 @@ https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
include::bind_back.adoc[]
|
||||
include::bind_front.adoc[]
|
||||
include::function_ref.adoc[]
|
||||
include::integer_sequence.adoc[]
|
||||
include::invoke.adoc[]
|
||||
include::latch.adoc[]
|
||||
include::mem_fn.adoc[]
|
||||
include::shared_lock.adoc[]
|
||||
include::to_array.adoc[]
|
||||
include::type_traits.adoc[]
|
||||
|
||||
72
doc/compat/to_array.adoc
Normal file
72
doc/compat/to_array.adoc
Normal file
@@ -0,0 +1,72 @@
|
||||
////
|
||||
Copyright 2024 Ruben Perez Hidalgo
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
https://www.boost.org/LICENSE_1_0.txt
|
||||
////
|
||||
|
||||
[#to_array]
|
||||
# <boost/compat/to_array.hpp>
|
||||
:idprefix: ref_to_array_
|
||||
|
||||
## Description
|
||||
|
||||
The header `<boost/compat/to_array.hpp>` implements, in a portable way, the C++20
|
||||
`std::to_array` function, present in the `<array>` header.
|
||||
|
||||
`to_array` creates a `std::array` from a single-dimensional C array,
|
||||
performing an element-wise copy or move.
|
||||
|
||||
## Example
|
||||
|
||||
```cpp
|
||||
int input [] = {1, 2, 3};
|
||||
std::array<int, 3> output = boost::compat::to_array(input);
|
||||
assert((
|
||||
output == std::array<int, 3>{{1, 2, 3}}
|
||||
));
|
||||
```
|
||||
|
||||
## Synopsis
|
||||
|
||||
```cpp
|
||||
namespace boost
|
||||
{
|
||||
namespace compat
|
||||
{
|
||||
|
||||
template <class T, std::size_t N>
|
||||
constexpr std::array<remove_cv_t<T>, N> to_array(T (&a)[N]);
|
||||
|
||||
template <class T, std::size_t N>
|
||||
constexpr std::array<remove_cv_t<T>, N> to_array(T (&&a)[N]);
|
||||
|
||||
} // namespace compat
|
||||
} // namespace boost
|
||||
```
|
||||
|
||||
## to_array
|
||||
|
||||
```cpp
|
||||
template <class T, std::size_t N>
|
||||
constexpr std::array<remove_cv_t<T>, N> to_array(T (&&a)[N]);
|
||||
```
|
||||
|
||||
[horizontal]
|
||||
Effects:;; Creates an array of `N` elements by copying elements in `a`.
|
||||
For every `i` in `0, ..., N-1`, copy-initializes the i-th element
|
||||
in the output array from `a[i]`.
|
||||
Type requirements:;; `std::is_constructible_v<remove_cv_t<T>, T&> && !std::is_array_v<T>`.
|
||||
Otherwise, the overload is ill-formed.
|
||||
|
||||
|
||||
```cpp
|
||||
template <class T, std::size_t N>
|
||||
constexpr std::array<remove_cvref_t<T>, N> to_array(T (&a)[N]);
|
||||
```
|
||||
|
||||
[horizontal]
|
||||
Effects:;; Creates an array of `N` elements by moving elements in `a`.
|
||||
For every `i` in `0, ..., N-1`, move-initializes the i-th element
|
||||
in the output array from `std::move(a[i])`.
|
||||
Type requirements:;; `std::is_constructible_v<remove_cv_t<T>, T&&> && !std::is_array_v<T>`.
|
||||
Otherwise, the overload is ill-formed.
|
||||
314
include/boost/compat/function_ref.hpp
Normal file
314
include/boost/compat/function_ref.hpp
Normal file
@@ -0,0 +1,314 @@
|
||||
#ifndef BOOST_COMPAT_FUNCTION_REF_HPP_INCLUDED
|
||||
#define BOOST_COMPAT_FUNCTION_REF_HPP_INCLUDED
|
||||
|
||||
// Copyright 2024 Christian Mazakas.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/compat/invoke.hpp>
|
||||
#include <boost/compat/type_traits.hpp>
|
||||
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
#if defined(__cpp_nontype_template_parameter_auto) && __cpp_nontype_template_parameter_auto >= 201606L
|
||||
#define BOOST_COMPAT_HAS_AUTO_NTTP
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
namespace compat {
|
||||
|
||||
template <class... S>
|
||||
struct function_ref;
|
||||
|
||||
#if defined(BOOST_COMPAT_HAS_AUTO_NTTP)
|
||||
|
||||
template <auto V>
|
||||
struct nontype_t {
|
||||
explicit nontype_t() = default;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <bool NoEx>
|
||||
union thunk_storage {
|
||||
void* pobj_;
|
||||
void (*pfn_)() noexcept(NoEx);
|
||||
};
|
||||
|
||||
template <bool NoEx, class Fp, class R, class... Args>
|
||||
struct invoke_function_holder {
|
||||
static R invoke_function(thunk_storage<NoEx> s, Args&&... args) noexcept(NoEx) {
|
||||
auto f = reinterpret_cast<Fp>(s.pfn_);
|
||||
return compat::invoke_r<R>(f, std::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
|
||||
template <bool Const, bool NoEx, class F, class R, class... Args>
|
||||
struct invoke_object_holder {
|
||||
static R invoke_object(thunk_storage<NoEx> s, Args&&... args) noexcept(NoEx) {
|
||||
using T = remove_reference_t<F>;
|
||||
using cv_T = conditional_t<Const, add_const_t<T>, T>;
|
||||
return compat::invoke_r<R>(*static_cast<cv_T*>(s.pobj_), std::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
|
||||
#if defined(BOOST_COMPAT_HAS_AUTO_NTTP)
|
||||
|
||||
template <auto f, bool Const, bool NoEx, class R, class... Args>
|
||||
struct invoke_mem_fn_holder {
|
||||
static R invoke_mem_fn(thunk_storage<NoEx> /* s */, Args&&... args) noexcept(NoEx) {
|
||||
return compat::invoke_r<R>(f, std::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
|
||||
template <auto f, class U, bool Const, bool NoEx, class R, class... Args>
|
||||
struct invoke_target_mem_fn_holder {
|
||||
static R invoke_mem_fn(thunk_storage<NoEx> s, Args&&... args) noexcept(NoEx) {
|
||||
using T = remove_reference_t<U>;
|
||||
using cv_T = conditional_t<Const, add_const_t<T>, T>;
|
||||
return compat::invoke_r<R>(f, *static_cast<cv_T*>(s.pobj_), std::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
|
||||
template <auto f, class T, bool Const, bool NoEx, class R, class... Args>
|
||||
struct invoke_ptr_mem_fn_holder {
|
||||
static R invoke_mem_fn(thunk_storage<NoEx> s, Args&&... args) noexcept(NoEx) {
|
||||
using cv_T = conditional_t<Const, add_const_t<T>, T>;
|
||||
return compat::invoke_r<R>(f, static_cast<cv_T*>(s.pobj_), std::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
template <bool Const, bool NoEx, class R, class... Args>
|
||||
struct function_ref_base {
|
||||
private:
|
||||
thunk_storage<NoEx> thunk_ = nullptr;
|
||||
R (*invoke_)(thunk_storage<NoEx>, Args&&...) noexcept(NoEx) = nullptr;
|
||||
|
||||
public:
|
||||
struct fp_tag {};
|
||||
struct obj_tag {};
|
||||
struct mem_fn_tag {};
|
||||
|
||||
template <class F>
|
||||
function_ref_base(fp_tag, F* fn) noexcept
|
||||
: thunk_{}, invoke_(&invoke_function_holder<NoEx, F*, R, Args...>::invoke_function) {
|
||||
thunk_.pfn_ = reinterpret_cast<decltype(thunk_.pfn_)>(fn);
|
||||
}
|
||||
|
||||
template <class F>
|
||||
function_ref_base(obj_tag, F&& fn) noexcept
|
||||
: thunk_{}, invoke_(&invoke_object_holder<Const, NoEx, F, R, Args...>::invoke_object) {
|
||||
thunk_.pobj_ = const_cast<void*>(static_cast<void const*>(std::addressof(fn)));
|
||||
}
|
||||
|
||||
#if defined(BOOST_COMPAT_HAS_AUTO_NTTP)
|
||||
|
||||
template <auto f, class F = decltype(f)>
|
||||
function_ref_base(mem_fn_tag, nontype_t<f>)
|
||||
: thunk_{}, invoke_(&invoke_mem_fn_holder<F{f}, Const, NoEx, R, Args...>::invoke_mem_fn) {
|
||||
thunk_.pobj_ = nullptr;
|
||||
}
|
||||
|
||||
template <auto f, class U, class F = decltype(f)>
|
||||
function_ref_base(mem_fn_tag, nontype_t<f>, U&& obj)
|
||||
: thunk_{}, invoke_(&invoke_target_mem_fn_holder<F{f}, U, Const, NoEx, R, Args...>::invoke_mem_fn) {
|
||||
thunk_.pobj_ = const_cast<void*>(static_cast<void const*>(std::addressof(obj)));
|
||||
}
|
||||
|
||||
template <auto f, class T, class F = decltype(f)>
|
||||
function_ref_base(mem_fn_tag, nontype_t<f>, T* obj)
|
||||
: thunk_{}, invoke_(&invoke_ptr_mem_fn_holder<F{f}, T, Const, NoEx, R, Args...>::invoke_mem_fn) {
|
||||
thunk_.pobj_ = const_cast<void*>(static_cast<void const*>(obj));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
function_ref_base(const function_ref_base&) noexcept = default;
|
||||
function_ref_base& operator=(const function_ref_base&) noexcept = default;
|
||||
|
||||
R operator()(Args... args) const noexcept(NoEx) { return this->invoke_(thunk_, std::forward<Args>(args)...); }
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template <class R, class... Args>
|
||||
struct function_ref<R(Args...)> : public detail::function_ref_base<false, false, R, Args...> {
|
||||
private:
|
||||
using base_type = detail::function_ref_base<false, false, R, Args...>;
|
||||
using typename base_type::fp_tag;
|
||||
using typename base_type::mem_fn_tag;
|
||||
using typename base_type::obj_tag;
|
||||
|
||||
template <class... T>
|
||||
using is_invocable_using = boost::compat::is_invocable_r<R, T..., Args...>;
|
||||
|
||||
public:
|
||||
template <class F, enable_if_t<std::is_function<F>::value && is_invocable_using<F>::value, int> = 0>
|
||||
function_ref(F* fn) noexcept : base_type(fp_tag{}, fn) {}
|
||||
|
||||
template <class F, class T = remove_reference_t<F>,
|
||||
enable_if_t<!std::is_same<remove_cvref_t<F>, function_ref>::value && !std::is_member_pointer<T>::value &&
|
||||
is_invocable_using<T&>::value,
|
||||
int> = 0>
|
||||
function_ref(F&& fn) noexcept : base_type(obj_tag{}, fn) {}
|
||||
|
||||
#if defined(BOOST_COMPAT_HAS_AUTO_NTTP)
|
||||
|
||||
template <auto f, class F = decltype(f), enable_if_t<is_invocable_using<F>::value, int> = 0>
|
||||
function_ref(nontype_t<f> x) noexcept : base_type(mem_fn_tag{}, x) {}
|
||||
|
||||
template <auto f, class U, class T = remove_reference_t<U>, class F = decltype(f),
|
||||
enable_if_t<!std::is_rvalue_reference_v<U&&> && is_invocable_using<F, T&>::value, int> = 0>
|
||||
function_ref(nontype_t<f> x, U&& obj) noexcept : base_type(mem_fn_tag{}, x, std::forward<U>(obj)) {}
|
||||
|
||||
template <auto f, class T, class F = decltype(f), enable_if_t<is_invocable_using<F, T*>::value, int> = 0>
|
||||
function_ref(nontype_t<f> x, T* obj) noexcept : base_type(mem_fn_tag{}, x, obj) {}
|
||||
|
||||
#endif
|
||||
|
||||
function_ref(const function_ref&) noexcept = default;
|
||||
function_ref& operator=(const function_ref&) noexcept = default;
|
||||
|
||||
template <class T, enable_if_t<!std::is_same<T, function_ref>::value && !std::is_pointer<T>::value, int> = 0>
|
||||
function_ref& operator=(T) = delete;
|
||||
};
|
||||
|
||||
template <class R, class... Args>
|
||||
struct function_ref<R(Args...) const> : public detail::function_ref_base<true, false, R, Args...> {
|
||||
private:
|
||||
using base_type = detail::function_ref_base<true, false, R, Args...>;
|
||||
using typename base_type::fp_tag;
|
||||
using typename base_type::mem_fn_tag;
|
||||
using typename base_type::obj_tag;
|
||||
|
||||
template <class... T>
|
||||
using is_invocable_using = boost::compat::is_invocable_r<R, T..., Args...>;
|
||||
|
||||
public:
|
||||
template <class F, enable_if_t<std::is_function<F>::value && is_invocable_using<F>::value, int> = 0>
|
||||
function_ref(F* fn) noexcept : base_type(fp_tag{}, fn) {}
|
||||
|
||||
template <class F, class T = remove_reference_t<F>,
|
||||
enable_if_t<!std::is_same<remove_cvref_t<F>, function_ref>::value && !std::is_member_pointer<T>::value &&
|
||||
is_invocable_using<T const&>::value,
|
||||
int> = 0>
|
||||
function_ref(F&& fn) noexcept : base_type(obj_tag{}, fn) {}
|
||||
|
||||
#if defined(BOOST_COMPAT_HAS_AUTO_NTTP)
|
||||
|
||||
template <auto f, class F = decltype(f), enable_if_t<is_invocable_using<F>::value, int> = 0>
|
||||
function_ref(nontype_t<f> x) noexcept : base_type(mem_fn_tag{}, x) {}
|
||||
|
||||
template <auto f, class U, class T = remove_reference_t<U>, class F = decltype(f),
|
||||
enable_if_t<!std::is_rvalue_reference_v<U&&> && is_invocable_using<F, T const&>::value, int> = 0>
|
||||
function_ref(nontype_t<f> x, U&& obj) noexcept : base_type(mem_fn_tag{}, x, std::forward<U>(obj)) {}
|
||||
|
||||
template <auto f, class T, class F = decltype(f), enable_if_t<is_invocable_using<F, T const*>::value, int> = 0>
|
||||
function_ref(nontype_t<f> x, T const* obj) noexcept : base_type(mem_fn_tag{}, x, obj) {}
|
||||
|
||||
#endif
|
||||
|
||||
function_ref(const function_ref&) noexcept = default;
|
||||
function_ref& operator=(const function_ref&) noexcept = default;
|
||||
|
||||
template <class T, enable_if_t<!std::is_same<T, function_ref>::value && !std::is_pointer<T>::value, int> = 0>
|
||||
function_ref& operator=(T) = delete;
|
||||
};
|
||||
|
||||
#if defined(__cpp_noexcept_function_type)
|
||||
|
||||
template <class R, class... Args>
|
||||
struct function_ref<R(Args...) noexcept> : public detail::function_ref_base<false, true, R, Args...> {
|
||||
private:
|
||||
using base_type = detail::function_ref_base<false, true, R, Args...>;
|
||||
using typename base_type::fp_tag;
|
||||
using typename base_type::mem_fn_tag;
|
||||
using typename base_type::obj_tag;
|
||||
|
||||
template <class... T>
|
||||
using is_invocable_using = boost::compat::is_nothrow_invocable_r<R, T..., Args...>;
|
||||
|
||||
public:
|
||||
template <class F, enable_if_t<std::is_function<F>::value && is_invocable_using<F>::value, int> = 0>
|
||||
function_ref(F* fn) noexcept : base_type(fp_tag{}, fn) {}
|
||||
|
||||
template <class F, class T = remove_reference_t<F>,
|
||||
enable_if_t<!std::is_same<remove_cvref_t<F>, function_ref>::value && !std::is_member_pointer<T>::value &&
|
||||
is_invocable_using<T&>::value,
|
||||
int> = 0>
|
||||
function_ref(F&& fn) noexcept : base_type(obj_tag{}, fn) {}
|
||||
|
||||
#if defined(BOOST_COMPAT_HAS_AUTO_NTTP)
|
||||
|
||||
template <auto f, class F = decltype(f), enable_if_t<is_invocable_using<F>::value, int> = 0>
|
||||
function_ref(nontype_t<f> x) noexcept : base_type(mem_fn_tag{}, x) {}
|
||||
|
||||
template <auto f, class U, class T = remove_reference_t<U>, class F = decltype(f),
|
||||
enable_if_t<!std::is_rvalue_reference_v<U&&> && is_invocable_using<F, T&>::value, int> = 0>
|
||||
function_ref(nontype_t<f> x, U&& obj) noexcept : base_type(mem_fn_tag{}, x, std::forward<U>(obj)) {}
|
||||
|
||||
template <auto f, class T, class F = decltype(f), enable_if_t<is_invocable_using<F, T*>::value, int> = 0>
|
||||
function_ref(nontype_t<f> x, T* obj) noexcept : base_type(mem_fn_tag{}, x, obj) {}
|
||||
|
||||
#endif
|
||||
|
||||
function_ref(const function_ref&) noexcept = default;
|
||||
function_ref& operator=(const function_ref&) noexcept = default;
|
||||
|
||||
template <class T, enable_if_t<!std::is_same<T, function_ref>::value && !std::is_pointer<T>::value, int> = 0>
|
||||
function_ref& operator=(T) = delete;
|
||||
};
|
||||
|
||||
template <class R, class... Args>
|
||||
struct function_ref<R(Args...) const noexcept> : public detail::function_ref_base<true, true, R, Args...> {
|
||||
private:
|
||||
using base_type = detail::function_ref_base<true, true, R, Args...>;
|
||||
using typename base_type::fp_tag;
|
||||
using typename base_type::mem_fn_tag;
|
||||
using typename base_type::obj_tag;
|
||||
|
||||
template <class... T>
|
||||
using is_invocable_using = boost::compat::is_nothrow_invocable_r<R, T..., Args...>;
|
||||
|
||||
public:
|
||||
template <class F, enable_if_t<std::is_function<F>::value && is_invocable_using<F>::value, int> = 0>
|
||||
function_ref(F* fn) noexcept : base_type(fp_tag{}, fn) {}
|
||||
|
||||
template <class F, class T = remove_reference_t<F>,
|
||||
enable_if_t<!std::is_same<remove_cvref_t<F>, function_ref>::value && !std::is_member_pointer<T>::value &&
|
||||
is_invocable_using<T const&>::value,
|
||||
int> = 0>
|
||||
function_ref(F&& fn) noexcept : base_type(obj_tag{}, fn) {}
|
||||
|
||||
#if defined(BOOST_COMPAT_HAS_AUTO_NTTP)
|
||||
|
||||
template <auto f, class F = decltype(f), enable_if_t<is_invocable_using<F>::value, int> = 0>
|
||||
function_ref(nontype_t<f> x) noexcept : base_type(mem_fn_tag{}, x) {}
|
||||
|
||||
template <auto f, class U, class T = remove_reference_t<U>, class F = decltype(f),
|
||||
enable_if_t<!std::is_rvalue_reference_v<U&&> && is_invocable_using<F, T const&>::value, int> = 0>
|
||||
function_ref(nontype_t<f> x, U&& obj) noexcept : base_type(mem_fn_tag{}, x, std::forward<U>(obj)) {}
|
||||
|
||||
template <auto f, class T, class F = decltype(f), enable_if_t<is_invocable_using<F, T const*>::value, int> = 0>
|
||||
function_ref(nontype_t<f> x, T const* obj) noexcept : base_type(mem_fn_tag{}, x, obj) {}
|
||||
|
||||
#endif
|
||||
|
||||
function_ref(const function_ref&) noexcept = default;
|
||||
function_ref& operator=(const function_ref&) noexcept = default;
|
||||
|
||||
template <class T, enable_if_t<!std::is_same<T, function_ref>::value && !std::is_pointer<T>::value, int> = 0>
|
||||
function_ref& operator=(T) = delete;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace compat
|
||||
} // namespace boost
|
||||
|
||||
#endif // #ifndef BOOST_COMPAT_FUNCTION_REF_HPP_INCLUDED
|
||||
60
include/boost/compat/to_array.hpp
Normal file
60
include/boost/compat/to_array.hpp
Normal file
@@ -0,0 +1,60 @@
|
||||
#ifndef BOOST_COMPAT_TO_ARRAY_HPP_INCLUDED
|
||||
#define BOOST_COMPAT_TO_ARRAY_HPP_INCLUDED
|
||||
|
||||
// Copyright 2024 Ruben Perez Hidalgo
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/compat/integer_sequence.hpp>
|
||||
#include <boost/compat/type_traits.hpp>
|
||||
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
namespace boost {
|
||||
namespace compat {
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <class T, std::size_t N, std::size_t... I>
|
||||
constexpr std::array<remove_cv_t<T>, N> to_array_lvalue(T (&a)[N], index_sequence<I...>)
|
||||
{
|
||||
return {{a[I]...}};
|
||||
}
|
||||
|
||||
template <class T, std::size_t N, std::size_t... I>
|
||||
constexpr std::array<remove_cv_t<T>, N> to_array_rvalue(T (&&a)[N], index_sequence<I...>)
|
||||
{
|
||||
return {{std::move(a[I])...}};
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template <class T, std::size_t N>
|
||||
constexpr std::array<remove_cv_t<T>, N> to_array(T (&a)[N])
|
||||
{
|
||||
static_assert(
|
||||
std::is_constructible<remove_cv_t<T>, T&>::value,
|
||||
"This overload requires the resulting element type to be constructible from T&"
|
||||
);
|
||||
static_assert(!std::is_array<T>::value, "to_array does not work for multi-dimensional C arrays");
|
||||
return detail::to_array_lvalue(a, make_index_sequence<N>{});
|
||||
}
|
||||
|
||||
template <class T, std::size_t N>
|
||||
constexpr std::array<remove_cv_t<T>, N> to_array(T (&&a)[N])
|
||||
{
|
||||
static_assert(
|
||||
std::is_constructible<remove_cv_t<T>, T&&>::value,
|
||||
"This overload requires the resulting element type to be constructible from T&&"
|
||||
);
|
||||
static_assert(!std::is_array<T>::value, "to_array does not work for multi-dimensional C arrays");
|
||||
return detail::to_array_rvalue(static_cast<T(&&)[N]>(a), make_index_sequence<N>{});
|
||||
}
|
||||
|
||||
} // namespace compat
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_COMPAT_TO_ARRAY_HPP_INCLUDED
|
||||
@@ -2,6 +2,7 @@
|
||||
#define BOOST_COMPAT_TYPE_TRAITS_HPP_INCLUDED
|
||||
|
||||
// Copyright 2024 Peter Dimov
|
||||
// Copyright 2024 Christian Mazakas
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
@@ -32,6 +33,8 @@ template<class...> struct make_void
|
||||
|
||||
template<class... T> using void_t = typename detail::make_void<T...>::type;
|
||||
|
||||
template<class T> using add_const_t = typename std::add_const<T>::type;
|
||||
|
||||
} // namespace compat
|
||||
} // namespace boost
|
||||
|
||||
|
||||
23
test/Jamfile
23
test/Jamfile
@@ -4,7 +4,8 @@
|
||||
# https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
import testing ;
|
||||
import ../../config/checks/config : requires ;
|
||||
import-search /boost/config/checks ;
|
||||
import config : requires ;
|
||||
|
||||
project
|
||||
: default-build
|
||||
@@ -20,6 +21,15 @@ project
|
||||
<toolset>msvc:<warnings-as-errors>on
|
||||
<toolset>gcc:<warnings-as-errors>on
|
||||
<toolset>clang:<warnings-as-errors>on
|
||||
|
||||
<library>/boost/core//boost_core
|
||||
<library>/boost/mp11//boost_mp11
|
||||
|
||||
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81601
|
||||
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91146
|
||||
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92397
|
||||
<toolset>gcc,<undefined-sanitizer>norecover:<cxxflags>"-Wno-array-bounds"
|
||||
<toolset>gcc,<address-sanitizer>norecover:<cxxflags>"-Wno-array-bounds"
|
||||
;
|
||||
|
||||
run quick.cpp ;
|
||||
@@ -94,3 +104,14 @@ compile invoke_r_md_constexpr_test.cpp
|
||||
|
||||
run is_invocable_r_test.cpp ;
|
||||
run is_nothrow_invocable_r_test.cpp ;
|
||||
|
||||
run function_ref_fn_test.cpp ;
|
||||
run function_ref_obj_test.cpp ;
|
||||
run function_ref_mfn_test.cpp ;
|
||||
|
||||
run function_ref_fn_noexcept_test.cpp ;
|
||||
run function_ref_mfn_noexcept_test.cpp ;
|
||||
run function_ref_obj_noexcept_test.cpp ;
|
||||
|
||||
run to_array_lvalue_test.cpp ;
|
||||
run to_array_rvalue_test.cpp ;
|
||||
|
||||
@@ -39,7 +39,7 @@ int main()
|
||||
BOOST_TEST_EQ( boost::compat::bind_back( &X::m, &x )(), -1 );
|
||||
}
|
||||
|
||||
#if !BOOST_WORKAROUND(BOOST_MSVC, >= 1920 && BOOST_MSVC < 1940)
|
||||
#if !BOOST_WORKAROUND(BOOST_MSVC, >= 1920 && BOOST_MSVC < 1950)
|
||||
|
||||
{
|
||||
BOOST_TEST_EQ( boost::compat::bind_back( &X::m, Y() )(), -1 );
|
||||
|
||||
@@ -39,7 +39,7 @@ int main()
|
||||
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, &x )(), -1 );
|
||||
}
|
||||
|
||||
#if !BOOST_WORKAROUND(BOOST_MSVC, >= 1920 && BOOST_MSVC < 1940)
|
||||
#if !BOOST_WORKAROUND(BOOST_MSVC, >= 1920 && BOOST_MSVC < 1950)
|
||||
|
||||
{
|
||||
BOOST_TEST_EQ( boost::compat::bind_front( &X::m, Y() )(), -1 );
|
||||
|
||||
@@ -14,4 +14,4 @@ target_link_libraries(quick Boost::compat)
|
||||
enable_testing()
|
||||
add_test(quick quick)
|
||||
|
||||
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>)
|
||||
add_custom_target(check VERBATIM COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>)
|
||||
|
||||
@@ -18,4 +18,4 @@ target_link_libraries(quick Boost::compat)
|
||||
enable_testing()
|
||||
add_test(quick quick)
|
||||
|
||||
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>)
|
||||
add_custom_target(check VERBATIM COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>)
|
||||
|
||||
165
test/function_ref_fn_noexcept_test.cpp
Normal file
165
test/function_ref_fn_noexcept_test.cpp
Normal file
@@ -0,0 +1,165 @@
|
||||
// Copyright 2024 Christian Mazakas
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if !defined(__cpp_noexcept_function_type)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("Test skipped, __cpp_noexcept_function_type is not defined")
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/compat/function_ref.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
|
||||
int f0() { return -1; }
|
||||
|
||||
int f1(int x1) noexcept { return x1; }
|
||||
int g1(int x1) noexcept { return x1 * 2; }
|
||||
|
||||
int f2(int x1, int x2) { return 10 * x1 + x2; }
|
||||
|
||||
int f3(int x1, int x2, int x3) noexcept { return 100 * x1 + 10 * x2 + x3; }
|
||||
|
||||
int g(std::unique_ptr<int> p, std::unique_ptr<int> q) { return 10 * *p + *q; }
|
||||
|
||||
struct X {
|
||||
int v = 0;
|
||||
|
||||
X() = default;
|
||||
X(int v_) noexcept : v{v_} {}
|
||||
};
|
||||
|
||||
struct Y {
|
||||
int v = 0;
|
||||
|
||||
Y() = default;
|
||||
explicit Y(int v_) : v{v_} {}
|
||||
};
|
||||
|
||||
struct Z {
|
||||
int v = 0;
|
||||
|
||||
Z() = default;
|
||||
Z(int v_) : v{v_} {}
|
||||
};
|
||||
|
||||
namespace compat = boost::compat;
|
||||
|
||||
int main() {
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_trivially_copyable<compat::function_ref<int() noexcept>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_trivially_copyable<compat::function_ref<int() const noexcept>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_trivially_copyable<compat::function_ref<int(int) noexcept>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_trivially_copyable<compat::function_ref<int(int) const noexcept>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_trivially_copyable<compat::function_ref<int(int, int) noexcept>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_trivially_copyable<compat::function_ref<int(int, int) const noexcept>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_trivially_copyable<compat::function_ref<int(int, int, int) noexcept>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_trivially_copyable<compat::function_ref<int(int, int, int) const noexcept>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_trivially_copyable<compat::function_ref<X(int, int, int) noexcept>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_trivially_copyable<compat::function_ref<X(int, int, int) const noexcept>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_trivially_copyable<compat::function_ref<void(int, int, int) noexcept>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_trivially_copyable<compat::function_ref<void(int, int, int) const noexcept>>));
|
||||
|
||||
struct W {
|
||||
int w_;
|
||||
};
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_assignable<compat::function_ref<int() noexcept>, W>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_assignable<compat::function_ref<int() const noexcept>, W>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_assignable<compat::function_ref<int() noexcept>, compat::function_ref<int()>>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_assignable<compat::function_ref<int()>, compat::function_ref<int() noexcept>>));
|
||||
BOOST_TEST_TRAIT_FALSE(
|
||||
(std::is_assignable<compat::function_ref<int() const noexcept>, compat::function_ref<int() const>>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE(
|
||||
(std::is_assignable<compat::function_ref<int() noexcept>, compat::function_ref<int(int) noexcept>>));
|
||||
BOOST_TEST_TRAIT_FALSE(
|
||||
(std::is_assignable<compat::function_ref<int(int) noexcept>, compat::function_ref<int() noexcept>>));
|
||||
|
||||
// f0
|
||||
{
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<int() noexcept>, decltype(f0)>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<int() const noexcept>, decltype(f0)>));
|
||||
}
|
||||
|
||||
// f1
|
||||
{
|
||||
compat::function_ref<int(int) noexcept> fv1(f1);
|
||||
BOOST_TEST_EQ(fv1(1), 1);
|
||||
|
||||
compat::function_ref<int(int) const noexcept> fv2(f1);
|
||||
BOOST_TEST_EQ(fv2(1), 1);
|
||||
}
|
||||
|
||||
// f2
|
||||
{
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<int(int, int) noexcept>, decltype(f2)>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<int(int, int) const noexcept>, decltype(f2)>));
|
||||
}
|
||||
|
||||
// f3
|
||||
{
|
||||
compat::function_ref<int(int, int, int) noexcept> fv1(f3);
|
||||
BOOST_TEST_EQ(fv1(1, 2, 3), 123);
|
||||
|
||||
compat::function_ref<int(int, int, int) const noexcept> fv2(f3);
|
||||
BOOST_TEST_EQ(fv2(1, 2, 3), 123);
|
||||
}
|
||||
|
||||
// g
|
||||
{
|
||||
BOOST_TEST_TRAIT_FALSE(
|
||||
(std::is_constructible<compat::function_ref<int(std::unique_ptr<int>, std::unique_ptr<int>) noexcept>,
|
||||
decltype(g)>));
|
||||
BOOST_TEST_TRAIT_FALSE(
|
||||
(std::is_constructible<compat::function_ref<int(std::unique_ptr<int>, std::unique_ptr<int>) const noexcept>,
|
||||
decltype(g)>));
|
||||
}
|
||||
|
||||
// invoke_r
|
||||
{
|
||||
compat::function_ref<X(int, int, int) noexcept> fv1(f3);
|
||||
BOOST_TEST_EQ(fv1(1, 2, 3).v, 123);
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<Y(int, int, int) noexcept>, decltype(f3)>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<Z(int, int, int) noexcept>, decltype(f3)>));
|
||||
|
||||
compat::function_ref<X(int, int, int) const noexcept> fv2(f3);
|
||||
BOOST_TEST_EQ(fv2(1, 2, 3).v, 123);
|
||||
BOOST_TEST_TRAIT_FALSE(
|
||||
(std::is_constructible<compat::function_ref<Y(int, int, int) const noexcept>, decltype(f3)>));
|
||||
BOOST_TEST_TRAIT_FALSE(
|
||||
(std::is_constructible<compat::function_ref<Z(int, int, int) const noexcept>, decltype(f3)>));
|
||||
|
||||
compat::function_ref<void(int, int, int) noexcept> fv3(f3);
|
||||
fv3(1, 2, 3);
|
||||
|
||||
compat::function_ref<void(int, int, int) const noexcept> fv4(f3);
|
||||
fv4(1, 2, 3);
|
||||
}
|
||||
|
||||
// copy construct, copy assign
|
||||
{
|
||||
compat::function_ref<int(int) noexcept> fv(f1);
|
||||
compat::function_ref<int(int) noexcept> fv2(fv);
|
||||
BOOST_TEST_EQ(fv(42), fv2(42));
|
||||
|
||||
fv2 = g1;
|
||||
BOOST_TEST_EQ(fv2(12), 24);
|
||||
|
||||
compat::function_ref<int(int) const noexcept> cfv(f1);
|
||||
compat::function_ref<int(int) const noexcept> cfv2(cfv);
|
||||
BOOST_TEST_EQ(cfv(42), cfv2(42));
|
||||
|
||||
cfv2 = g1;
|
||||
BOOST_TEST_EQ(cfv2(24), 48);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#endif
|
||||
184
test/function_ref_fn_test.cpp
Normal file
184
test/function_ref_fn_test.cpp
Normal file
@@ -0,0 +1,184 @@
|
||||
// Copyright 2024 Christian Mazakas
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ == 7
|
||||
#pragma GCC diagnostic ignored "-Wnoexcept-type"
|
||||
#endif
|
||||
|
||||
#include <boost/compat/function_ref.hpp>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
#include <boost/config/workaround.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
|
||||
int f0() { return -1; }
|
||||
int g0() { return 7331; }
|
||||
|
||||
int f1(int x1) noexcept { return x1; }
|
||||
|
||||
int f2(int x1, int x2) { return 10 * x1 + x2; }
|
||||
|
||||
int f3(int x1, int x2, int x3) noexcept { return 100 * x1 + 10 * x2 + x3; }
|
||||
|
||||
int g(std::unique_ptr<int> p, std::unique_ptr<int> q) { return 10 * *p + *q; }
|
||||
|
||||
struct X {
|
||||
int v = 0;
|
||||
|
||||
X() = default;
|
||||
X(int v_) noexcept : v{v_} {}
|
||||
};
|
||||
|
||||
struct Y {
|
||||
int v = 0;
|
||||
|
||||
Y() = default;
|
||||
explicit Y(int v_) : v{v_} {}
|
||||
};
|
||||
|
||||
struct Z {
|
||||
int v = 0;
|
||||
|
||||
Z() = default;
|
||||
Z(int v_) : v{v_} {}
|
||||
};
|
||||
|
||||
namespace compat = boost::compat;
|
||||
|
||||
int main() {
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS)
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_trivially_copyable<compat::function_ref<int()>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_trivially_copyable<compat::function_ref<int() const>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_trivially_copyable<compat::function_ref<int(int)>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_trivially_copyable<compat::function_ref<int(int) const>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_trivially_copyable<compat::function_ref<int(int, int)>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_trivially_copyable<compat::function_ref<int(int, int) const>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_trivially_copyable<compat::function_ref<int(int, int, int)>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_trivially_copyable<compat::function_ref<int(int, int, int) const>>));
|
||||
BOOST_TEST_TRAIT_TRUE(
|
||||
(std::is_trivially_copyable<compat::function_ref<int(std::unique_ptr<int>, std::unique_ptr<int>)>>));
|
||||
BOOST_TEST_TRAIT_TRUE(
|
||||
(std::is_trivially_copyable<compat::function_ref<int(std::unique_ptr<int>, std::unique_ptr<int>) const>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_trivially_copyable<compat::function_ref<X(int, int, int)>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_trivially_copyable<compat::function_ref<X(int, int, int) const>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_trivially_copyable<compat::function_ref<void(int, int, int)>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_trivially_copyable<compat::function_ref<void(int, int, int) const>>));
|
||||
|
||||
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1910)
|
||||
struct W {
|
||||
int w_;
|
||||
};
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_assignable<compat::function_ref<int()>, W>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_assignable<compat::function_ref<int() const>, W>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_assignable<compat::function_ref<int()>, compat::function_ref<int() const>>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_assignable<compat::function_ref<int() const>, compat::function_ref<int()>>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_assignable<compat::function_ref<int()>, compat::function_ref<int(int)>>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_assignable<compat::function_ref<int(int)>, compat::function_ref<int()>>));
|
||||
#endif
|
||||
|
||||
#else
|
||||
BOOST_PRAGMA_MESSAGE("<type_traits> is incomplete, skipping is_trivially_copyable checks")
|
||||
#endif
|
||||
|
||||
// f0
|
||||
{
|
||||
compat::function_ref<int()> fv1(f0);
|
||||
BOOST_TEST_EQ(fv1(), -1);
|
||||
|
||||
compat::function_ref<int() const> fv2(f0);
|
||||
BOOST_TEST_EQ(fv2(), -1);
|
||||
}
|
||||
|
||||
// f1
|
||||
{
|
||||
int x = 1;
|
||||
compat::function_ref<int(int)> fv1(f1);
|
||||
BOOST_TEST_EQ(fv1(x), 1);
|
||||
|
||||
compat::function_ref<int(int) const> fv2(f1);
|
||||
BOOST_TEST_EQ(fv2(1), 1);
|
||||
}
|
||||
|
||||
// f2
|
||||
{
|
||||
compat::function_ref<int(int, int)> fv1(f2);
|
||||
BOOST_TEST_EQ(fv1(1, 2), 12);
|
||||
|
||||
compat::function_ref<int(int, int) const> fv2(f2);
|
||||
BOOST_TEST_EQ(fv2(1, 2), 12);
|
||||
}
|
||||
|
||||
// f3
|
||||
{
|
||||
compat::function_ref<int(int, int, int)> fv1(f3);
|
||||
BOOST_TEST_EQ(fv1(1, 2, 3), 123);
|
||||
|
||||
compat::function_ref<int(int, int, int) const> fv2(f3);
|
||||
BOOST_TEST_EQ(fv2(1, 2, 3), 123);
|
||||
}
|
||||
|
||||
// g
|
||||
{
|
||||
using S1 = int(std::unique_ptr<int>, std::unique_ptr<int>);
|
||||
using S2 = int(std::unique_ptr<int>, std::unique_ptr<int>) const;
|
||||
|
||||
compat::function_ref<S1> fv1(g);
|
||||
{
|
||||
auto p = std::unique_ptr<int>(new int{1});
|
||||
auto q = std::unique_ptr<int>(new int{2});
|
||||
BOOST_TEST_EQ(fv1(std::move(p), std::move(q)), 12);
|
||||
}
|
||||
|
||||
compat::function_ref<S2> fv2(g);
|
||||
{
|
||||
auto p = std::unique_ptr<int>(new int{130});
|
||||
auto q = std::unique_ptr<int>(new int{37});
|
||||
BOOST_TEST_EQ(fv1(std::move(p), std::move(q)), 1337);
|
||||
}
|
||||
}
|
||||
|
||||
// invoke_r
|
||||
{
|
||||
compat::function_ref<X(int, int, int)> fv1(f3);
|
||||
BOOST_TEST_EQ(fv1(1, 2, 3).v, 123);
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<Y(int, int, int)>, decltype(f3)>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<Z(int, int, int)>, decltype(f3)>));
|
||||
|
||||
compat::function_ref<X(int, int, int) const> fv2(f3);
|
||||
BOOST_TEST_EQ(fv2(1, 2, 3).v, 123);
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<Y(int, int, int) const>, decltype(f3)>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<Z(int, int, int) const>, decltype(f3)>));
|
||||
|
||||
compat::function_ref<void(int, int, int)> fv3(f3);
|
||||
fv3(1, 2, 3);
|
||||
|
||||
compat::function_ref<void(int, int, int) const> fv4(f3);
|
||||
fv4(1, 2, 3);
|
||||
}
|
||||
|
||||
// copy construct, copy assign
|
||||
{
|
||||
compat::function_ref<int()> fv(f0);
|
||||
compat::function_ref<int()> fv2(fv);
|
||||
BOOST_TEST_EQ(fv(), fv2());
|
||||
|
||||
fv2 = g0;
|
||||
BOOST_TEST_EQ(fv2(), 7331);
|
||||
|
||||
compat::function_ref<int() const> cfv(f0);
|
||||
compat::function_ref<int() const> cfv2(cfv);
|
||||
BOOST_TEST_EQ(cfv(), cfv2());
|
||||
|
||||
cfv2 = g0;
|
||||
BOOST_TEST_EQ(cfv2(), 7331);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
164
test/function_ref_mfn_noexcept_test.cpp
Normal file
164
test/function_ref_mfn_noexcept_test.cpp
Normal file
@@ -0,0 +1,164 @@
|
||||
// Copyright 2024 Christian Mazakas
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ == 7
|
||||
#pragma GCC diagnostic ignored "-Wnoexcept-type"
|
||||
#endif
|
||||
|
||||
#include <boost/compat/function_ref.hpp>
|
||||
|
||||
#if !defined(BOOST_COMPAT_HAS_AUTO_NTTP)
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
BOOST_PRAGMA_MESSAGE("no support for placeholder NTTPs detected, skipping this test")
|
||||
int main() {}
|
||||
#else
|
||||
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
struct F1 {
|
||||
std::unique_ptr<int> p_;
|
||||
|
||||
F1() : p_(new int(1)) {}
|
||||
|
||||
int m1() { return *p_ + -1; }
|
||||
int m2(int x1) noexcept { return 10 * *p_ + x1; }
|
||||
int m3(int x1, int x2) const { return 100 * *p_ + 10 * x1 + x2; }
|
||||
int m4(int x1, int x2, int x3) const noexcept { return 1000 * *p_ + 100 * x1 + 10 * x2 + x3; }
|
||||
};
|
||||
|
||||
namespace compat = boost::compat;
|
||||
|
||||
int main() {
|
||||
{
|
||||
BOOST_TEST_TRAIT_FALSE(
|
||||
(std::is_constructible<compat::function_ref<int(F1&) noexcept>, compat::nontype_t<&F1::m1>>));
|
||||
BOOST_TEST_TRAIT_TRUE(
|
||||
(std::is_constructible<compat::function_ref<int(F1&, int) noexcept>, compat::nontype_t<&F1::m2>>));
|
||||
BOOST_TEST_TRAIT_FALSE(
|
||||
(std::is_constructible<compat::function_ref<int(F1&, int, int) noexcept>, compat::nontype_t<&F1::m3>>));
|
||||
BOOST_TEST_TRAIT_TRUE(
|
||||
(std::is_constructible<compat::function_ref<int(F1&, int, int, int) noexcept>, compat::nontype_t<&F1::m4>>));
|
||||
}
|
||||
|
||||
{
|
||||
F1 f1;
|
||||
|
||||
compat::function_ref<int(F1&, int) noexcept> fn2(compat::nontype_t<&F1::m2>{});
|
||||
BOOST_TEST_EQ(fn2(f1, 2), 12);
|
||||
|
||||
compat::function_ref<int(F1&, int, int, int) noexcept> fn4(compat::nontype_t<&F1::m4>{});
|
||||
BOOST_TEST_EQ(fn4(f1, 2, 3, 4), 1234);
|
||||
}
|
||||
|
||||
{
|
||||
BOOST_TEST_TRAIT_FALSE(
|
||||
(std::is_constructible<compat::function_ref<int(F1&) const noexcept>, compat::nontype_t<&F1::m1>>));
|
||||
BOOST_TEST_TRAIT_FALSE(
|
||||
(std::is_constructible<compat::function_ref<int(F1&, int, int) const noexcept>, compat::nontype_t<&F1::m3>>));
|
||||
|
||||
F1 f1;
|
||||
|
||||
compat::function_ref<int(F1&, int) const noexcept> fn2(compat::nontype_t<&F1::m2>{});
|
||||
BOOST_TEST_EQ(fn2(f1, 2), 12);
|
||||
|
||||
compat::function_ref<int(F1&, int, int, int) const noexcept> fn4(compat::nontype_t<&F1::m4>{});
|
||||
BOOST_TEST_EQ(fn4(f1, 2, 3, 4), 1234);
|
||||
}
|
||||
|
||||
{
|
||||
BOOST_TEST_TRAIT_FALSE(
|
||||
(std::is_constructible<compat::function_ref<int(F1 const&) noexcept>, compat::nontype_t<&F1::m1>>));
|
||||
BOOST_TEST_TRAIT_FALSE(
|
||||
(std::is_constructible<compat::function_ref<int(F1 const&, int) noexcept>, compat::nontype_t<&F1::m2>>));
|
||||
BOOST_TEST_TRAIT_FALSE(
|
||||
(std::is_constructible<compat::function_ref<int(F1 const&, int, int) noexcept>, compat::nontype_t<&F1::m3>>));
|
||||
|
||||
F1 f1;
|
||||
|
||||
compat::function_ref<int(F1 const&, int, int, int) noexcept> fn4(compat::nontype_t<&F1::m4>{});
|
||||
BOOST_TEST_EQ(fn4(f1, 2, 3, 4), 1234);
|
||||
}
|
||||
|
||||
{
|
||||
BOOST_TEST_TRAIT_FALSE(
|
||||
(std::is_constructible<compat::function_ref<int() noexcept>, compat::nontype_t<&F1::m1>, F1&>));
|
||||
BOOST_TEST_TRAIT_TRUE(
|
||||
(std::is_constructible<compat::function_ref<int(int) noexcept>, compat::nontype_t<&F1::m2>, F1&>));
|
||||
BOOST_TEST_TRAIT_FALSE(
|
||||
(std::is_constructible<compat::function_ref<int(int, int) noexcept>, compat::nontype_t<&F1::m3>, F1&>));
|
||||
BOOST_TEST_TRAIT_TRUE(
|
||||
(std::is_constructible<compat::function_ref<int(int, int, int) noexcept>, compat::nontype_t<&F1::m4>, F1&>));
|
||||
|
||||
F1 f1;
|
||||
|
||||
compat::function_ref<int(int) noexcept> fn2(compat::nontype_t<&F1::m2>{}, f1);
|
||||
BOOST_TEST_EQ(fn2(2), 12);
|
||||
|
||||
compat::function_ref<int(int, int, int) noexcept> fn4(compat::nontype_t<&F1::m4>{}, f1);
|
||||
BOOST_TEST_EQ(fn4(2, 3, 4), 1234);
|
||||
}
|
||||
|
||||
{
|
||||
BOOST_TEST_TRAIT_FALSE(
|
||||
(std::is_constructible<compat::function_ref<int() const noexcept>, compat::nontype_t<&F1::m1>, F1 const&>));
|
||||
BOOST_TEST_TRAIT_FALSE(
|
||||
(std::is_constructible<compat::function_ref<int(int) const noexcept>, compat::nontype_t<&F1::m2>, F1 const&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<int(int, int) const noexcept>,
|
||||
compat::nontype_t<&F1::m3>, F1 const&>));
|
||||
|
||||
F1 f1;
|
||||
|
||||
compat::function_ref<int(int, int, int) const noexcept> fn4(compat::nontype_t<&F1::m4>{}, f1);
|
||||
BOOST_TEST_EQ(fn4(2, 3, 4), 1234);
|
||||
|
||||
auto const& f1_2 = f1;
|
||||
compat::function_ref<int(int, int, int) const noexcept> fn4_2(compat::nontype_t<&F1::m4>{}, f1_2);
|
||||
BOOST_TEST_EQ(fn4_2(2, 3, 4), 1234);
|
||||
}
|
||||
|
||||
{
|
||||
BOOST_TEST_TRAIT_FALSE(
|
||||
(std::is_constructible<compat::function_ref<int() noexcept>, compat::nontype_t<&F1::m1>, F1*>));
|
||||
BOOST_TEST_TRAIT_TRUE(
|
||||
(std::is_constructible<compat::function_ref<int(int) noexcept>, compat::nontype_t<&F1::m2>, F1*>));
|
||||
BOOST_TEST_TRAIT_FALSE(
|
||||
(std::is_constructible<compat::function_ref<int(int, int) noexcept>, compat::nontype_t<&F1::m3>, F1*>));
|
||||
BOOST_TEST_TRAIT_TRUE(
|
||||
(std::is_constructible<compat::function_ref<int(int, int, int) noexcept>, compat::nontype_t<&F1::m4>, F1*>));
|
||||
|
||||
F1 f1;
|
||||
|
||||
compat::function_ref<int(int) noexcept> fn2(compat::nontype_t<&F1::m2>{}, &f1);
|
||||
BOOST_TEST_EQ(fn2(2), 12);
|
||||
|
||||
compat::function_ref<int(int, int, int) noexcept> fn4(compat::nontype_t<&F1::m4>{}, &f1);
|
||||
BOOST_TEST_EQ(fn4(2, 3, 4), 1234);
|
||||
}
|
||||
|
||||
{
|
||||
BOOST_TEST_TRAIT_FALSE(
|
||||
(std::is_constructible<compat::function_ref<int() const noexcept>, compat::nontype_t<&F1::m1>, F1 const*>));
|
||||
BOOST_TEST_TRAIT_FALSE(
|
||||
(std::is_constructible<compat::function_ref<int(int) const noexcept>, compat::nontype_t<&F1::m2>, F1 const*>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<int(int, int) const noexcept>,
|
||||
compat::nontype_t<&F1::m3>, F1 const*>));
|
||||
|
||||
F1 const f1;
|
||||
|
||||
compat::function_ref<int(int, int, int) const noexcept> fn4(compat::nontype_t<&F1::m4>{}, &f1);
|
||||
BOOST_TEST_EQ(fn4(2, 3, 4), 1234);
|
||||
|
||||
auto const& f1_2 = f1;
|
||||
compat::function_ref<int(int, int, int) const noexcept> fn4_2(compat::nontype_t<&F1::m4>{}, &f1_2);
|
||||
BOOST_TEST_EQ(fn4_2(2, 3, 4), 1234);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#endif
|
||||
177
test/function_ref_mfn_test.cpp
Normal file
177
test/function_ref_mfn_test.cpp
Normal file
@@ -0,0 +1,177 @@
|
||||
// Copyright 2024 Christian Mazakas
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ == 7
|
||||
#pragma GCC diagnostic ignored "-Wnoexcept-type"
|
||||
#endif
|
||||
|
||||
#include <boost/compat/function_ref.hpp>
|
||||
|
||||
#if !defined(BOOST_COMPAT_HAS_AUTO_NTTP)
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
BOOST_PRAGMA_MESSAGE("no support for placeholder NTTPs detected, skipping this test")
|
||||
int main() {}
|
||||
#else
|
||||
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
struct F1 {
|
||||
std::unique_ptr<int> p_;
|
||||
int q_ = 1337;
|
||||
|
||||
F1() : p_(new int(1)) {}
|
||||
|
||||
int m1() { return *p_ + -1; }
|
||||
int m2(int x1) noexcept { return 10 * *p_ + x1; }
|
||||
int m3(int x1, int x2) const { return 100 * *p_ + 10 * x1 + x2; }
|
||||
int m4(int x1, int x2, int x3) const noexcept { return 1000 * *p_ + 100 * x1 + 10 * x2 + x3; }
|
||||
};
|
||||
|
||||
namespace compat = boost::compat;
|
||||
|
||||
int main() {
|
||||
{
|
||||
F1 f1;
|
||||
|
||||
compat::function_ref<int(F1&)> fn1(compat::nontype_t<&F1::m1>{});
|
||||
BOOST_TEST_EQ(fn1(f1), 0);
|
||||
|
||||
int x = 2;
|
||||
compat::function_ref<int(F1&, int)> fn2(compat::nontype_t<&F1::m2>{});
|
||||
BOOST_TEST_EQ(fn2(f1, x), 12);
|
||||
|
||||
compat::function_ref<int(F1&, int, int)> fn3(compat::nontype_t<&F1::m3>{});
|
||||
BOOST_TEST_EQ(fn3(f1, 2, 3), 123);
|
||||
|
||||
compat::function_ref<int(F1&, int, int, int)> fn4(compat::nontype_t<&F1::m4>{});
|
||||
BOOST_TEST_EQ(fn4(f1, 2, 3, 4), 1234);
|
||||
|
||||
compat::function_ref<int(F1&)> a1(compat::nontype_t<&F1::q_>{});
|
||||
BOOST_TEST_EQ(a1(f1), 1337);
|
||||
}
|
||||
|
||||
{
|
||||
F1 f1;
|
||||
|
||||
compat::function_ref<int(F1&) const> fn1(compat::nontype_t<&F1::m1>{});
|
||||
BOOST_TEST_EQ(fn1(f1), 0);
|
||||
|
||||
compat::function_ref<int(F1&, int) const> fn2(compat::nontype_t<&F1::m2>{});
|
||||
BOOST_TEST_EQ(fn2(f1, 2), 12);
|
||||
|
||||
compat::function_ref<int(F1&, int, int) const> fn3(compat::nontype_t<&F1::m3>{});
|
||||
BOOST_TEST_EQ(fn3(f1, 2, 3), 123);
|
||||
|
||||
compat::function_ref<int(F1&, int, int, int) const> fn4(compat::nontype_t<&F1::m4>{});
|
||||
BOOST_TEST_EQ(fn4(f1, 2, 3, 4), 1234);
|
||||
}
|
||||
|
||||
{
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<int(F1 const&)>, compat::nontype_t<&F1::m1>>));
|
||||
BOOST_TEST_TRAIT_FALSE(
|
||||
(std::is_constructible<compat::function_ref<int(F1 const&, int)>, compat::nontype_t<&F1::m2>>));
|
||||
|
||||
F1 f1;
|
||||
|
||||
compat::function_ref<int(F1 const&, int, int) const> fn3(compat::nontype_t<&F1::m3>{});
|
||||
BOOST_TEST_EQ(fn3(f1, 2, 3), 123);
|
||||
|
||||
compat::function_ref<int(F1 const&, int, int, int) const> fn4(compat::nontype_t<&F1::m4>{});
|
||||
BOOST_TEST_EQ(fn4(f1, 2, 3, 4), 1234);
|
||||
|
||||
auto const& f2 = f1;
|
||||
|
||||
compat::function_ref<int(F1 const&, int, int) const> fn23(compat::nontype_t<&F1::m3>{});
|
||||
BOOST_TEST_EQ(fn3(f2, 2, 3), 123);
|
||||
|
||||
compat::function_ref<int(F1 const&, int, int, int) const> fn24(compat::nontype_t<&F1::m4>{});
|
||||
BOOST_TEST_EQ(fn4(f2, 2, 3, 4), 1234);
|
||||
}
|
||||
|
||||
{
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<int(int)>, compat::nontype_t<&F1::m2>, F1&>));
|
||||
BOOST_TEST_TRAIT_FALSE(
|
||||
(std::is_constructible<compat::function_ref<int(int)>, compat::nontype_t<&F1::m2>, F1 const&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<int(int)>, compat::nontype_t<&F1::m2>, F1&&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<int(int)>, compat::nontype_t<&F1::m2>, F1>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE(
|
||||
(std::is_constructible<compat::function_ref<int(int, int) const>, compat::nontype_t<&F1::m3>, F1&>));
|
||||
BOOST_TEST_TRAIT_TRUE(
|
||||
(std::is_constructible<compat::function_ref<int(int, int) const>, compat::nontype_t<&F1::m3>, F1 const&>));
|
||||
BOOST_TEST_TRAIT_FALSE(
|
||||
(std::is_constructible<compat::function_ref<int(int, int) const>, compat::nontype_t<&F1::m3>, F1&&>));
|
||||
BOOST_TEST_TRAIT_FALSE(
|
||||
(std::is_constructible<compat::function_ref<int(int, int) const>, compat::nontype_t<&F1::m3>, F1>));
|
||||
}
|
||||
|
||||
{
|
||||
F1 f1;
|
||||
|
||||
compat::function_ref<int()> fn1(compat::nontype_t<&F1::m1>{}, f1);
|
||||
BOOST_TEST_EQ(fn1(), 0);
|
||||
|
||||
compat::function_ref<int(int)> fn2(compat::nontype_t<&F1::m2>{}, f1);
|
||||
BOOST_TEST_EQ(fn2(2), 12);
|
||||
|
||||
compat::function_ref<int(int, int)> fn3(compat::nontype_t<&F1::m3>{}, f1);
|
||||
BOOST_TEST_EQ(fn3(2, 3), 123);
|
||||
|
||||
compat::function_ref<int(int, int, int)> fn4(compat::nontype_t<&F1::m4>{}, f1);
|
||||
BOOST_TEST_EQ(fn4(2, 3, 4), 1234);
|
||||
}
|
||||
|
||||
{
|
||||
F1 const f1;
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<int() const>, compat::nontype_t<&F1::m1>, F1&>));
|
||||
BOOST_TEST_TRAIT_FALSE(
|
||||
(std::is_constructible<compat::function_ref<int(int) const>, compat::nontype_t<&F1::m2>, F1&>));
|
||||
|
||||
compat::function_ref<int(int, int) const> fn3(compat::nontype_t<&F1::m3>{}, f1);
|
||||
BOOST_TEST_EQ(fn3(2, 3), 123);
|
||||
|
||||
compat::function_ref<int(int, int, int) const> fn4(compat::nontype_t<&F1::m4>{}, f1);
|
||||
BOOST_TEST_EQ(fn4(2, 3, 4), 1234);
|
||||
}
|
||||
|
||||
{
|
||||
F1 f1;
|
||||
|
||||
compat::function_ref<int()> fn1(compat::nontype_t<&F1::m1>{}, &f1);
|
||||
BOOST_TEST_EQ(fn1(), 0);
|
||||
|
||||
compat::function_ref<int(int)> fn2(compat::nontype_t<&F1::m2>{}, &f1);
|
||||
BOOST_TEST_EQ(fn2(2), 12);
|
||||
|
||||
compat::function_ref<int(int, int)> fn3(compat::nontype_t<&F1::m3>{}, &f1);
|
||||
BOOST_TEST_EQ(fn3(2, 3), 123);
|
||||
|
||||
compat::function_ref<int(int, int, int)> fn4(compat::nontype_t<&F1::m4>{}, &f1);
|
||||
BOOST_TEST_EQ(fn4(2, 3, 4), 1234);
|
||||
}
|
||||
|
||||
{
|
||||
F1 const f1;
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE(
|
||||
(std::is_constructible<compat::function_ref<int() const>, compat::nontype_t<&F1::m1>, F1 const*>));
|
||||
BOOST_TEST_TRAIT_FALSE(
|
||||
(std::is_constructible<compat::function_ref<int(int) const>, compat::nontype_t<&F1::m2>, F1 const*>));
|
||||
|
||||
compat::function_ref<int(int, int) const> fn3(compat::nontype_t<&F1::m3>{}, &f1);
|
||||
BOOST_TEST_EQ(fn3(2, 3), 123);
|
||||
|
||||
compat::function_ref<int(int, int, int) const> fn4(compat::nontype_t<&F1::m4>{}, &f1);
|
||||
BOOST_TEST_EQ(fn4(2, 3, 4), 1234);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#endif
|
||||
228
test/function_ref_obj_noexcept_test.cpp
Normal file
228
test/function_ref_obj_noexcept_test.cpp
Normal file
@@ -0,0 +1,228 @@
|
||||
// Copyright 2024 Christian Mazakas
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if !defined(__cpp_noexcept_function_type)
|
||||
|
||||
BOOST_PRAGMA_MESSAGE("Test skipped, __cpp_noexcept_function_type is not defined")
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
#include <boost/compat/function_ref.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
|
||||
struct F1 {
|
||||
int operator()() { return -1; }
|
||||
|
||||
int operator()(int x1) noexcept { return x1; }
|
||||
|
||||
int operator()(int x1, int x2) const { return 10 * x1 + x2; }
|
||||
|
||||
int operator()(int x1, int x2, int x3) const noexcept { return 100 * x1 + 10 * x2 + x3; }
|
||||
};
|
||||
|
||||
struct F2 {
|
||||
int operator()(int x1, int x2) & { return 100 * x1 + 10 * x2 + 1; }
|
||||
int operator()(int x1, int x2) const& { return 100 * x1 + 10 * x2 + 2; }
|
||||
int operator()(int x1, int x2) && { return 100 * x1 + 10 * x2 + 3; }
|
||||
int operator()(int x1, int x2) const&& { return 100 * x1 + 10 * x2 + 4; }
|
||||
};
|
||||
|
||||
struct X {
|
||||
int v = 0;
|
||||
|
||||
X() = default;
|
||||
X(int v_) noexcept : v{v_} {}
|
||||
};
|
||||
|
||||
struct Y {
|
||||
int v = 0;
|
||||
|
||||
Y() = default;
|
||||
explicit Y(int v_) : v{v_} {}
|
||||
};
|
||||
|
||||
struct Z {
|
||||
int v = 0;
|
||||
|
||||
Z() = default;
|
||||
Z(int v_) : v{v_} {}
|
||||
};
|
||||
|
||||
namespace compat = boost::compat;
|
||||
|
||||
int main() {
|
||||
{
|
||||
F1 f1;
|
||||
{
|
||||
using S1 = int() noexcept;
|
||||
using S2 = int(int) noexcept;
|
||||
using S3 = int(int, int) noexcept;
|
||||
using S4 = int(int, int, int) noexcept;
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S1>, F1>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S1>, F1&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S1>, F1&&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S1>, F1 const>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S1>, F1 const&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S1>, F1 const&&>));
|
||||
|
||||
compat::function_ref<S2> fv2(f1);
|
||||
|
||||
BOOST_TEST_EQ(fv2(1), 1);
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S2>, F1 const>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S2>, F1 const&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S2>, F1 const&&>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S3>, F1>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S3>, F1&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S3>, F1&&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S3>, F1 const>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S3>, F1 const&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S3>, F1 const&&>));
|
||||
|
||||
compat::function_ref<S4> fv4(f1);
|
||||
|
||||
BOOST_TEST_EQ(fv4(1, 2, 3), 123);
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<S4>, F1>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<S4>, F1&>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<S4>, F1&&>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<S4>, F1 const>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<S4>, F1 const&>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<S4>, F1 const&&>));
|
||||
}
|
||||
{
|
||||
using S1 = int() const noexcept;
|
||||
using S2 = int(int) const noexcept;
|
||||
using S3 = int(int, int) const noexcept;
|
||||
using S4 = int(int, int, int) const noexcept;
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S1>, F1>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S1>, F1&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S1>, F1&&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S1>, F1 const>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S1>, F1 const&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S1>, F1 const&&>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S2>, F1>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S2>, F1&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S2>, F1&&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S2>, F1 const>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S2>, F1 const&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S2>, F1 const&&>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S3>, F1>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S3>, F1&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S3>, F1&&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S3>, F1 const>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S3>, F1 const&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S3>, F1 const&&>));
|
||||
|
||||
compat::function_ref<S4> fv4(f1);
|
||||
|
||||
BOOST_TEST_EQ(fv4(1, 2, 3), 123);
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<S4>, F1>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<S4>, F1&>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<S4>, F1&&>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<S4>, F1 const>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<S4>, F1 const&>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<S4>, F1 const&&>));
|
||||
}
|
||||
|
||||
{
|
||||
using S2 = int(int) noexcept;
|
||||
using S4 = int(int, int, int) noexcept;
|
||||
|
||||
auto& fref = f1;
|
||||
|
||||
compat::function_ref<S2> fv2(fref);
|
||||
BOOST_TEST_EQ(fv2(1), 1);
|
||||
|
||||
auto const& cfref = f1;
|
||||
compat::function_ref<S4> fv4(cfref);
|
||||
BOOST_TEST_EQ(fv4(1, 2, 3), 123);
|
||||
}
|
||||
|
||||
{
|
||||
using S4 = int(int, int, int) const noexcept;
|
||||
|
||||
auto const& cfref = f1;
|
||||
compat::function_ref<S4> fv4(cfref);
|
||||
BOOST_TEST_EQ(fv4(1, 2, 3), 123);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
using S1 = int(int, int) noexcept;
|
||||
using S2 = int(int, int) const noexcept;
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S1>, F2>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S1>, F2&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S1>, F2&&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S1>, F2 const>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S1>, F2 const&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S1>, F2 const&&>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S2>, F2>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S2>, F2&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S2>, F2&&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S2>, F2 const>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S2>, F2 const&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S2>, F2 const&&>));
|
||||
}
|
||||
|
||||
// invoke_r
|
||||
{
|
||||
F1 f;
|
||||
|
||||
compat::function_ref<X(int, int, int) noexcept> fv1(f);
|
||||
BOOST_TEST_EQ(fv1(1, 2, 3).v, 123);
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<Y(int, int, int) noexcept>, F1>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<Z(int, int, int) noexcept>, F1>));
|
||||
|
||||
compat::function_ref<X(int, int, int) const noexcept> fv2(f);
|
||||
BOOST_TEST_EQ(fv2(1, 2, 3).v, 123);
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<Y(int, int, int) const noexcept>, F1>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<Z(int, int, int) const noexcept>, F1>));
|
||||
|
||||
compat::function_ref<void(int, int, int) noexcept> fv3(f);
|
||||
fv3(1, 2, 3);
|
||||
|
||||
compat::function_ref<void(int, int, int) const noexcept> fv4(f);
|
||||
fv4(1, 2, 3);
|
||||
}
|
||||
|
||||
// copy construct, copy assign
|
||||
{
|
||||
F1 f;
|
||||
|
||||
auto id = [](int x) noexcept { return x + 7331; };
|
||||
|
||||
compat::function_ref<int(int) noexcept> fv(f);
|
||||
compat::function_ref<int(int) noexcept> fv2(fv);
|
||||
BOOST_TEST_EQ(fv(12), fv2(12));
|
||||
|
||||
fv2 = compat::function_ref<int(int) noexcept>(id);
|
||||
BOOST_TEST_EQ(fv2(1), 7332);
|
||||
|
||||
auto add = [](int x, int y, int z) noexcept { return x + y + z; };
|
||||
compat::function_ref<int(int, int, int) const noexcept> cfv(f);
|
||||
compat::function_ref<int(int, int, int) const noexcept> cfv2(cfv);
|
||||
BOOST_TEST_EQ(cfv(1, 2, 3), cfv2(1, 2, 3));
|
||||
|
||||
cfv2 = compat::function_ref<int(int, int, int) const noexcept>(add);
|
||||
BOOST_TEST_EQ(cfv2(1, 2, 3), 6);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#endif
|
||||
260
test/function_ref_obj_test.cpp
Normal file
260
test/function_ref_obj_test.cpp
Normal file
@@ -0,0 +1,260 @@
|
||||
// Copyright 2024 Christian Mazakas
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/compat/function_ref.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
|
||||
struct F1 {
|
||||
int operator()() { return -1; }
|
||||
|
||||
int operator()(int x1) noexcept { return x1; }
|
||||
|
||||
int operator()(int x1, int x2) const { return 10 * x1 + x2; }
|
||||
|
||||
int operator()(int x1, int x2, int x3) const noexcept { return 100 * x1 + 10 * x2 + x3; }
|
||||
};
|
||||
|
||||
struct F2 {
|
||||
int operator()(int x1, int x2) & { return 100 * x1 + 10 * x2 + 1; }
|
||||
int operator()(int x1, int x2) const& { return 100 * x1 + 10 * x2 + 2; }
|
||||
int operator()(int x1, int x2) && { return 100 * x1 + 10 * x2 + 3; }
|
||||
int operator()(int x1, int x2) const&& { return 100 * x1 + 10 * x2 + 4; }
|
||||
};
|
||||
|
||||
struct X {
|
||||
int v = 0;
|
||||
|
||||
X() = default;
|
||||
X(int v_) noexcept : v{v_} {}
|
||||
};
|
||||
|
||||
struct Y {
|
||||
int v = 0;
|
||||
|
||||
Y() = default;
|
||||
explicit Y(int v_) : v{v_} {}
|
||||
};
|
||||
|
||||
struct Z {
|
||||
int v = 0;
|
||||
|
||||
Z() = default;
|
||||
Z(int v_) : v{v_} {}
|
||||
};
|
||||
|
||||
namespace compat = boost::compat;
|
||||
|
||||
int main() {
|
||||
{
|
||||
F1 f;
|
||||
{
|
||||
using S1 = int();
|
||||
using S2 = int(int);
|
||||
using S3 = int(int, int);
|
||||
using S4 = int(int, int, int);
|
||||
|
||||
compat::function_ref<S1> fv1(f);
|
||||
|
||||
BOOST_TEST_EQ(fv1(), -1);
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S1>, F1 const>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S1>, F1 const&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S1>, F1 const&&>));
|
||||
|
||||
compat::function_ref<S2> fv2(f);
|
||||
int x = 1;
|
||||
BOOST_TEST_EQ(fv2(x), 1);
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S2>, F1 const>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S2>, F1 const&>));
|
||||
|
||||
compat::function_ref<S3> fv3(f);
|
||||
|
||||
BOOST_TEST_EQ(fv3(1, 2), 12);
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<S3>, F1>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<S3>, F1&>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<S3>, F1&&>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<S3>, F1 const>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<S3>, F1 const&>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<S3>, F1 const&&>));
|
||||
|
||||
compat::function_ref<S4> fv4(f);
|
||||
|
||||
BOOST_TEST_EQ(fv4(1, 2, 3), 123);
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<S4>, F1>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<S4>, F1&>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<S4>, F1&&>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<S4>, F1 const>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<S4>, F1 const&>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<S4>, F1 const&&>));
|
||||
}
|
||||
|
||||
{
|
||||
using S1 = int() const;
|
||||
using S2 = int(int) const;
|
||||
using S3 = int(int, int) const;
|
||||
using S4 = int(int, int, int) const;
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S1>, F1>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S1>, F1&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S1>, F1&&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S1>, F1 const>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S1>, F1 const&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S1>, F1 const&&>));
|
||||
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S2>, F1>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S2>, F1&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S2>, F1&&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S2>, F1 const>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S2>, F1 const&>));
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<S2>, F1 const&&>));
|
||||
|
||||
compat::function_ref<S3> fv3(f);
|
||||
|
||||
BOOST_TEST_EQ(fv3(1, 2), 12);
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<S3>, F1>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<S3>, F1&>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<S3>, F1&&>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<S3>, F1 const>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<S3>, F1 const&>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<S3>, F1 const&&>));
|
||||
|
||||
compat::function_ref<S4> fv4(f);
|
||||
|
||||
BOOST_TEST_EQ(fv4(1, 2, 3), 123);
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<S4>, F1>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<S4>, F1&>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<S4>, F1&&>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<S4>, F1 const>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<S4>, F1 const&>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<S4>, F1 const&&>));
|
||||
}
|
||||
|
||||
{
|
||||
using S1 = int();
|
||||
using S2 = int(int);
|
||||
|
||||
auto& fref = f;
|
||||
|
||||
compat::function_ref<S1> fv1(fref);
|
||||
BOOST_TEST_EQ(fv1(), -1);
|
||||
|
||||
compat::function_ref<S2> fv2(fref);
|
||||
BOOST_TEST_EQ(fv2(1), 1);
|
||||
}
|
||||
|
||||
{
|
||||
using S1 = int();
|
||||
using S2 = int(int);
|
||||
|
||||
compat::function_ref<S1> fv1(std::move(f));
|
||||
BOOST_TEST_EQ(fv1(), -1);
|
||||
|
||||
compat::function_ref<S2> fv2(std::move(f));
|
||||
BOOST_TEST_EQ(fv2(1), 1);
|
||||
}
|
||||
|
||||
{
|
||||
using S3 = int(int, int) const;
|
||||
using S4 = int(int, int, int) const;
|
||||
|
||||
auto const& fref = f;
|
||||
|
||||
compat::function_ref<S3> fv3(fref);
|
||||
BOOST_TEST_EQ(fv3(1, 2), 12);
|
||||
|
||||
compat::function_ref<S4> fv4(fref);
|
||||
BOOST_TEST_EQ(fv4(1, 2, 3), 123);
|
||||
}
|
||||
|
||||
{
|
||||
using S3 = int(int, int) const;
|
||||
using S4 = int(int, int, int) const;
|
||||
|
||||
auto const&& fref = std::move(f);
|
||||
|
||||
compat::function_ref<S3> fv3(fref);
|
||||
BOOST_TEST_EQ(fv3(1, 2), 12);
|
||||
|
||||
compat::function_ref<S4> fv4(fref);
|
||||
BOOST_TEST_EQ(fv4(1, 2, 3), 123);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
F2 g;
|
||||
{
|
||||
compat::function_ref<int(int, int)> fv1(g);
|
||||
BOOST_TEST_EQ(fv1(3, 2), 321);
|
||||
|
||||
auto& gref = g;
|
||||
compat::function_ref<int(int, int)> rfv1(gref);
|
||||
BOOST_TEST_EQ(rfv1(3, 2), 321);
|
||||
|
||||
compat::function_ref<int(int, int)> fv2(std::move(g));
|
||||
BOOST_TEST_EQ(fv2(3, 2), 321);
|
||||
|
||||
compat::function_ref<int(int, int) const> fv3(g);
|
||||
BOOST_TEST_EQ(fv3(3, 2), 322);
|
||||
|
||||
auto const& gcref = g;
|
||||
compat::function_ref<int(int, int) const> crfv3(gcref);
|
||||
BOOST_TEST_EQ(fv3(3, 2), 322);
|
||||
|
||||
compat::function_ref<int(int, int) const> fv4(std::move(g));
|
||||
BOOST_TEST_EQ(fv4(3, 2), 322);
|
||||
}
|
||||
}
|
||||
|
||||
// invoke_r
|
||||
{
|
||||
F1 f;
|
||||
|
||||
compat::function_ref<X(int, int, int)> fv1(f);
|
||||
BOOST_TEST_EQ(fv1(1, 2, 3).v, 123);
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<Y(int, int, int)>, F1>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<Z(int, int, int)>, F1>));
|
||||
|
||||
compat::function_ref<X(int, int, int) const> fv2(f);
|
||||
BOOST_TEST_EQ(fv2(1, 2, 3).v, 123);
|
||||
BOOST_TEST_TRAIT_FALSE((std::is_constructible<compat::function_ref<Y(int, int, int) const>, F1>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_constructible<compat::function_ref<Z(int, int, int) const>, F1>));
|
||||
|
||||
compat::function_ref<void(int, int, int)> fv3(f);
|
||||
fv3(1, 2, 3);
|
||||
|
||||
compat::function_ref<void(int, int, int) const> fv4(f);
|
||||
fv4(1, 2, 3);
|
||||
}
|
||||
|
||||
// copy construct, copy assign
|
||||
{
|
||||
F1 f;
|
||||
|
||||
auto id = [] { return 7331; };
|
||||
|
||||
compat::function_ref<int()> fv(f);
|
||||
compat::function_ref<int()> fv2(fv);
|
||||
BOOST_TEST_EQ(fv(), fv2());
|
||||
|
||||
fv2 = compat::function_ref<int()>(id);
|
||||
BOOST_TEST_EQ(fv2(), 7331);
|
||||
|
||||
auto add = [](int x, int y) { return x + y; };
|
||||
compat::function_ref<int(int, int) const> cfv(f);
|
||||
compat::function_ref<int(int, int) const> cfv2(cfv);
|
||||
BOOST_TEST_EQ(cfv(1, 2), cfv2(1, 2));
|
||||
|
||||
cfv2 = compat::function_ref<int(int, int) const>(add);
|
||||
BOOST_TEST_EQ(cfv2(1, 2), 3);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
@@ -29,7 +29,7 @@ int main()
|
||||
BOOST_TEST_EQ( boost::compat::invoke( &X::m, &x ), -1 );
|
||||
}
|
||||
|
||||
#if !BOOST_WORKAROUND(BOOST_MSVC, >= 1920 && BOOST_MSVC < 1940)
|
||||
#if !BOOST_WORKAROUND(BOOST_MSVC, >= 1920 && BOOST_MSVC < 1950)
|
||||
{
|
||||
BOOST_TEST_EQ( boost::compat::invoke( &X::m, Y() ), -1 );
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ int main()
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !BOOST_WORKAROUND(BOOST_MSVC, >= 1920 && BOOST_MSVC < 1940)
|
||||
#if !BOOST_WORKAROUND(BOOST_MSVC, >= 1920 && BOOST_MSVC < 1950)
|
||||
{
|
||||
constexpr Y y = {};
|
||||
|
||||
|
||||
60
test/to_array_lvalue_test.cpp
Normal file
60
test/to_array_lvalue_test.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
// Copyright 2024 Ruben Perez Hidalgo.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/compat/to_array.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
#include <array>
|
||||
#include <vector>
|
||||
|
||||
namespace compat = boost::compat;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
// regular C array
|
||||
int input[] = {1, 2};
|
||||
auto output = compat::to_array(input);
|
||||
static_assert(std::is_same<decltype(output), std::array<int, 2>>::value, "");
|
||||
BOOST_TEST_EQ(output[0], 1);
|
||||
BOOST_TEST_EQ(output[1], 2);
|
||||
}
|
||||
{
|
||||
// regular C array, const
|
||||
const int input[] = {1, 2};
|
||||
auto output = compat::to_array(input);
|
||||
static_assert(std::is_same<decltype(output), std::array<int, 2>>::value, "");
|
||||
BOOST_TEST_EQ(output[0], 1);
|
||||
BOOST_TEST_EQ(output[1], 2);
|
||||
}
|
||||
{
|
||||
// values not moved
|
||||
const std::vector<int> vec{1, 2};
|
||||
std::vector<int> input[]{vec};
|
||||
auto output = compat::to_array(input);
|
||||
static_assert(std::is_same<decltype(output), std::array<std::vector<int>, 1>>::value, "");
|
||||
BOOST_TEST_ALL_EQ(output[0].begin(), output[0].end(), vec.begin(), vec.end());
|
||||
BOOST_TEST_ALL_EQ(input[0].begin(), input[0].end(), vec.begin(), vec.end()); // input not modified
|
||||
}
|
||||
{
|
||||
// const values work
|
||||
const std::vector<int> vec{1, 2};
|
||||
const std::vector<int> input[]{vec};
|
||||
auto output = compat::to_array(input);
|
||||
static_assert(std::is_same<decltype(output), std::array<std::vector<int>, 1>>::value, "");
|
||||
BOOST_TEST_ALL_EQ(output[0].begin(), output[0].end(), vec.begin(), vec.end());
|
||||
BOOST_TEST_ALL_EQ(input[0].begin(), input[0].end(), vec.begin(), vec.end()); // input not modified
|
||||
}
|
||||
{
|
||||
// constexpr check
|
||||
constexpr int input[] = {1, 2, 3};
|
||||
constexpr auto output = compat::to_array(input);
|
||||
static_assert(std::is_same<decltype(output), const std::array<int, 3>>::value, "");
|
||||
BOOST_TEST_EQ(output[0], 1);
|
||||
BOOST_TEST_EQ(output[1], 2);
|
||||
BOOST_TEST_EQ(output[2], 3);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
88
test/to_array_rvalue_test.cpp
Normal file
88
test/to_array_rvalue_test.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
// Copyright 2024 Ruben Perez Hidalgo.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/compat/to_array.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/workaround.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#if defined(BOOST_MSVC) && BOOST_MSVC < 1910
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Test skipped because BOOST_MSVC < 1910" )
|
||||
int main() {}
|
||||
|
||||
#else
|
||||
|
||||
namespace compat = boost::compat;
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
// regular C array
|
||||
int input[] = {5, 6};
|
||||
auto output = compat::to_array(std::move(input));
|
||||
static_assert(std::is_same<decltype(output), std::array<int, 2>>::value, "");
|
||||
BOOST_TEST_EQ(output[0], 5);
|
||||
BOOST_TEST_EQ(output[1], 6);
|
||||
}
|
||||
{
|
||||
// regular C array, const
|
||||
const int input[] = {5, 6};
|
||||
auto output = compat::to_array(std::move(input));
|
||||
static_assert(std::is_same<decltype(output), std::array<int, 2>>::value, "");
|
||||
BOOST_TEST_EQ(output[0], 5);
|
||||
BOOST_TEST_EQ(output[1], 6);
|
||||
}
|
||||
{
|
||||
// values moved
|
||||
const std::vector<int> vec{1, 2};
|
||||
std::vector<int> input[]{vec};
|
||||
auto output = compat::to_array(std::move(input));
|
||||
static_assert(std::is_same<decltype(output), std::array<std::vector<int>, 1>>::value, "");
|
||||
BOOST_TEST_ALL_EQ(output[0].begin(), output[0].end(), vec.begin(), vec.end());
|
||||
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1920)
|
||||
BOOST_TEST(input[0].empty()); // input left in a moved-from state
|
||||
#endif
|
||||
}
|
||||
{
|
||||
// const values work (although they don't result in an effective move)
|
||||
const std::vector<int> vec{1, 2};
|
||||
const std::vector<int> input[]{vec};
|
||||
auto output = compat::to_array(std::move(input));
|
||||
static_assert(std::is_same<decltype(output), std::array<std::vector<int>, 1>>::value, "");
|
||||
BOOST_TEST_ALL_EQ(output[0].begin(), output[0].end(), vec.begin(), vec.end());
|
||||
BOOST_TEST_ALL_EQ(input[0].begin(), input[0].end(), vec.begin(), vec.end()); // input not modified
|
||||
}
|
||||
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1920)
|
||||
{
|
||||
// move-only types work
|
||||
std::unique_ptr<int> input[] = {std::unique_ptr<int>{new int(42)}};
|
||||
int* ptr = input[0].get();
|
||||
auto output = compat::to_array(std::move(input));
|
||||
static_assert(std::is_same<decltype(output), std::array<std::unique_ptr<int>, 1>>::value, "");
|
||||
BOOST_TEST_EQ(output[0].get(), ptr);
|
||||
BOOST_TEST_EQ(input[0].get(), nullptr); // input left in a moved-from state
|
||||
}
|
||||
#endif
|
||||
|
||||
{
|
||||
// constexpr check
|
||||
constexpr int input[] = {1, 2, 3};
|
||||
constexpr auto output = compat::to_array(std::move(input));
|
||||
static_assert(std::is_same<decltype(output), const std::array<int, 3>>::value, "");
|
||||
BOOST_TEST_EQ(output[0], 1);
|
||||
BOOST_TEST_EQ(output[1], 2);
|
||||
BOOST_TEST_EQ(output[2], 3);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user