mirror of
https://github.com/boostorg/utility.git
synced 2025-06-25 12:01:38 +02:00
Compare commits
248 Commits
boost-1.62
...
develop
Author | SHA1 | Date | |
---|---|---|---|
211570f2b9 | |||
7f1b54c3cc | |||
4c85489e91 | |||
fdd6586aa6 | |||
49cd132374 | |||
67d8cbd243 | |||
ec297bfdfb | |||
3a5e8f4aba | |||
9939ea24d1 | |||
171647fb3e | |||
8f6116ada4 | |||
2a37aaaeb4 | |||
79c293351f | |||
a481266238 | |||
2aa26c9e84 | |||
31de9279d8 | |||
6d870ad5e3 | |||
80ede74e8c | |||
12c95c48cf | |||
336c00b659 | |||
bf21064bfd | |||
2a8ce8e081 | |||
e0ecf92764 | |||
bff26e4fa1 | |||
9abd1fc78d | |||
3829fcbef4 | |||
21d6434320 | |||
2ac19511c2 | |||
217f7346f6 | |||
85b5594f32 | |||
a95a4f6580 | |||
076f050e9a | |||
e06b6dd788 | |||
219ee9855d | |||
cea4262e62 | |||
52e3e64a34 | |||
eb721609af | |||
b32d95a887 | |||
656b5397c5 | |||
65b40cbf99 | |||
3aa25c9dd7 | |||
46a785e32d | |||
a1231d1ff4 | |||
3fe40554df | |||
c869f8a9fa | |||
5d39709ef0 | |||
028a90b29d | |||
581654e408 | |||
06548cf5fa | |||
932973fe39 | |||
c63d36cf5b | |||
0106ffda5f | |||
0c1d01d30a | |||
7ac95c156c | |||
eb29d71245 | |||
fe417f6237 | |||
d5c33889b9 | |||
11cff46019 | |||
f11a56c2a7 | |||
69f6588d7c | |||
6950023bca | |||
c3aab6a184 | |||
7717dac7bc | |||
63aadf3f0f | |||
0feb28b467 | |||
78f1b38930 | |||
e6edd4eb91 | |||
9d1284ef6d | |||
aa0ccfa65e | |||
c21d2818c7 | |||
5ae025b56a | |||
f3f7c3c041 | |||
bdc983b804 | |||
a1583e3072 | |||
30caa722c1 | |||
96169c9fc6 | |||
b6119df27f | |||
9941e831bb | |||
a8cdbe516d | |||
485a160dde | |||
2b0441e95f | |||
de106bf696 | |||
b9a91970be | |||
73bccf50db | |||
f7c17df050 | |||
51104850f6 | |||
301ad68447 | |||
5f5aa500d0 | |||
fede5878c3 | |||
a3ec92334d | |||
d186ad3539 | |||
1d6d44c1c4 | |||
0171af0f77 | |||
703a4bf752 | |||
05e0d1688d | |||
dcaf2c0e3b | |||
71107238eb | |||
28c90abaf0 | |||
2cc83cc7d5 | |||
e8fc7cc2a1 | |||
09d24c0516 | |||
3f51807f24 | |||
a04a0d9531 | |||
449a03e13d | |||
dc59afafdb | |||
e845ae6752 | |||
375382e1e6 | |||
6cca23a63a | |||
9ad7e51912 | |||
601f80e8c1 | |||
c960bef6ef | |||
6ab27d5689 | |||
3e2f0199cf | |||
9c2aa8d193 | |||
601fc9371f | |||
7aafdf92a0 | |||
a7570d7608 | |||
37168a3f4b | |||
e56171989a | |||
f00a5bf0d3 | |||
a4feaf4f24 | |||
688628f764 | |||
8faf831bd1 | |||
25cb7aa122 | |||
0ae5cebc7f | |||
1caa002121 | |||
691f3238d7 | |||
8b6da499a3 | |||
6e6d0777e8 | |||
64fffa0f97 | |||
5da340a2a4 | |||
9a4cff038b | |||
0c059a50ad | |||
bdc5b5cf3a | |||
86e7caefea | |||
7953ba56ba | |||
46f72656b3 | |||
e3a2a06011 | |||
a4752e066d | |||
957aeba2e9 | |||
2b436d7d50 | |||
882c9c86c4 | |||
c81d8e3990 | |||
75276a055d | |||
309e6a1b31 | |||
9eeb7f85c5 | |||
62c34f51f6 | |||
6a1917ceec | |||
47c9f69ffe | |||
7b74d2d494 | |||
57da5f0c18 | |||
dabf53a703 | |||
ff56b3649e | |||
31e0ae4c37 | |||
5fe9df91c0 | |||
f03b681d01 | |||
e120a83d1e | |||
424fea5881 | |||
53d9aa9d2f | |||
6b62dcc504 | |||
91ebdcd1dd | |||
e8d2b2ba76 | |||
ce64b13846 | |||
32c50e0814 | |||
05dda09fd3 | |||
a4cafcc75d | |||
796fb965be | |||
08da98a551 | |||
57b027f1cd | |||
db05c11f50 | |||
3d2a7f0c17 | |||
8858bad352 | |||
fc135e0d72 | |||
ebe44296ca | |||
bdf55e0b6f | |||
d4170ccdb5 | |||
e2d115db97 | |||
15cfa44937 | |||
473be2e4c1 | |||
6ad6bc005c | |||
7709f0e430 | |||
eacea4664d | |||
1fe5af5264 | |||
d2fb06e6a0 | |||
73baeb7a63 | |||
56f13625b1 | |||
ac4e8da91d | |||
426836d860 | |||
82df2b82fc | |||
f8a243bcff | |||
51f7f7f53e | |||
5f535a151c | |||
c88936800d | |||
96fbce5759 | |||
9d46de1578 | |||
976a4d2fc1 | |||
ea81279b35 | |||
7d101d420c | |||
d8acfef27b | |||
d7ae336915 | |||
b74f49f1e5 | |||
5977f11be8 | |||
ad0fc7c9d3 | |||
a6c175e2c3 | |||
874ca2307b | |||
5220260145 | |||
2f5a6fbcf1 | |||
51ba9f1b45 | |||
5cef1403b0 | |||
81ce4693f6 | |||
fb2f110eb4 | |||
2ed5ee9588 | |||
88c36c1941 | |||
0b2409a942 | |||
62b39548be | |||
2722fdcda3 | |||
792d0538d2 | |||
06ae661775 | |||
d9d076874e | |||
e25d85446e | |||
5bc9e47688 | |||
ec50f22b8b | |||
592382dc61 | |||
6cf9c22cf1 | |||
33475f87e4 | |||
21261a8630 | |||
7d60e8e378 | |||
10ff4d4fcd | |||
89bf74beee | |||
bfdcce0f97 | |||
330b49d602 | |||
68b26cddbe | |||
6c4ab93573 | |||
0876da45db | |||
00f02167e3 | |||
9960d9f395 | |||
ccfd741c0a | |||
c5c479d49c | |||
3e8f73c6ac | |||
38121f2af3 | |||
38b536ff05 | |||
9ae6492af9 | |||
816607e212 | |||
a3ab942bc2 | |||
0f1f793caf | |||
ff445c0ece | |||
9fae8be166 | |||
b90a28f0e1 |
611
.github/workflows/ci.yml
vendored
Normal file
611
.github/workflows/ci.yml
vendored
Normal file
@ -0,0 +1,611 @@
|
||||
# Copyright 2021-2025 Andrey Semashev
|
||||
#
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
|
||||
name: CI
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- develop
|
||||
- feature/**
|
||||
|
||||
concurrency:
|
||||
group: ${{format('{0}:{1}', github.repository, github.ref)}}
|
||||
cancel-in-progress: true
|
||||
|
||||
env:
|
||||
GIT_FETCH_JOBS: 8
|
||||
NET_RETRY_COUNT: 5
|
||||
DEFAULT_BUILD_VARIANT: debug,release
|
||||
|
||||
jobs:
|
||||
posix:
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
# Linux, gcc
|
||||
- toolset: gcc-4.7
|
||||
cxxstd: "11"
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:16.04
|
||||
install:
|
||||
- g++-4.7
|
||||
- toolset: gcc-4.8
|
||||
cxxstd: "11"
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:18.04
|
||||
install:
|
||||
- g++-4.8
|
||||
- toolset: gcc-4.9
|
||||
cxxstd: "11"
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:16.04
|
||||
install:
|
||||
- g++-4.9
|
||||
- toolset: gcc-5
|
||||
cxxstd: "11,14,1z"
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:16.04
|
||||
install:
|
||||
- g++-5
|
||||
- toolset: gcc-6
|
||||
cxxstd: "11,14,1z"
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:18.04
|
||||
install:
|
||||
- g++-6
|
||||
- toolset: gcc-7
|
||||
cxxstd: "11,14,17"
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:18.04
|
||||
install:
|
||||
- g++-7
|
||||
- toolset: gcc-8
|
||||
cxxstd: "11,14,17,2a"
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:18.04
|
||||
install:
|
||||
- g++-8
|
||||
- toolset: gcc-9
|
||||
cxxstd: "11,14,17,2a"
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:20.04
|
||||
install:
|
||||
- g++-9
|
||||
- toolset: gcc-10
|
||||
cxxstd: "11,14,17,20"
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:20.04
|
||||
install:
|
||||
- g++-10
|
||||
- toolset: gcc-11
|
||||
cxxstd: "11,14,17,20,23"
|
||||
os: ubuntu-22.04
|
||||
install:
|
||||
- g++-11
|
||||
- toolset: gcc-12
|
||||
cxxstd: "11,14,17,20,23"
|
||||
os: ubuntu-22.04
|
||||
install:
|
||||
- g++-12
|
||||
- toolset: gcc-13
|
||||
cxxstd: "11,14,17,20,23"
|
||||
os: ubuntu-24.04
|
||||
install:
|
||||
- g++-13
|
||||
- toolset: gcc-14
|
||||
cxxstd: "11,14,17,20,23,26"
|
||||
os: ubuntu-24.04
|
||||
install:
|
||||
- g++-14
|
||||
- toolset: gcc-15
|
||||
cxxstd: "11,14,17,20,23,26"
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:25.04
|
||||
install:
|
||||
- g++-15
|
||||
- name: UBSAN
|
||||
toolset: gcc-13
|
||||
cxxstd: "11,14,17,20,23"
|
||||
ubsan: 1
|
||||
build_variant: debug
|
||||
os: ubuntu-24.04
|
||||
install:
|
||||
- g++-13
|
||||
|
||||
# Linux, clang
|
||||
- toolset: clang
|
||||
compiler: clang++-3.5
|
||||
cxxstd: "11"
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:16.04
|
||||
install:
|
||||
- clang-3.5
|
||||
- toolset: clang
|
||||
compiler: clang++-3.6
|
||||
cxxstd: "11,14"
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:16.04
|
||||
install:
|
||||
- clang-3.6
|
||||
- toolset: clang
|
||||
compiler: clang++-3.7
|
||||
cxxstd: "11,14"
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:16.04
|
||||
install:
|
||||
- clang-3.7
|
||||
- toolset: clang
|
||||
compiler: clang++-3.8
|
||||
cxxstd: "11,14"
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:16.04
|
||||
install:
|
||||
- clang-3.8
|
||||
- toolset: clang
|
||||
compiler: clang++-3.9
|
||||
cxxstd: "11,14"
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:18.04
|
||||
install:
|
||||
- clang-3.9
|
||||
- toolset: clang
|
||||
compiler: clang++-4.0
|
||||
cxxstd: "11,14"
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:18.04
|
||||
install:
|
||||
- clang-4.0
|
||||
- toolset: clang
|
||||
compiler: clang++-5.0
|
||||
cxxstd: "11,14,1z"
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:18.04
|
||||
install:
|
||||
- clang-5.0
|
||||
- toolset: clang
|
||||
compiler: clang++-6.0
|
||||
cxxstd: "11,14,17"
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:18.04
|
||||
install:
|
||||
- clang-6.0
|
||||
- toolset: clang
|
||||
compiler: clang++-7
|
||||
cxxstd: "11,14,17"
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:18.04
|
||||
install:
|
||||
- clang-7
|
||||
# Note: clang-8 does not fully support C++20, so it is not compatible with libstdc++-8 in this mode
|
||||
- toolset: clang
|
||||
compiler: clang++-8
|
||||
cxxstd: "11,14,17,2a"
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:18.04
|
||||
install:
|
||||
- clang-8
|
||||
- g++-7
|
||||
gcc_toolchain: 7
|
||||
- toolset: clang
|
||||
compiler: clang++-9
|
||||
cxxstd: "11,14,17,2a"
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:20.04
|
||||
install:
|
||||
- clang-9
|
||||
- toolset: clang
|
||||
compiler: clang++-10
|
||||
cxxstd: "11,14,17,20"
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:20.04
|
||||
install:
|
||||
- clang-10
|
||||
- toolset: clang
|
||||
compiler: clang++-11
|
||||
cxxstd: "11,14,17,20"
|
||||
os: ubuntu-22.04
|
||||
install:
|
||||
- clang-11
|
||||
- toolset: clang
|
||||
compiler: clang++-12
|
||||
cxxstd: "11,14,17,20,2b"
|
||||
os: ubuntu-22.04
|
||||
install:
|
||||
- clang-12
|
||||
- g++-11
|
||||
gcc_toolchain: 11
|
||||
- toolset: clang
|
||||
compiler: clang++-13
|
||||
cxxstd: "11,14,17,20,2b"
|
||||
os: ubuntu-22.04
|
||||
install:
|
||||
- clang-13
|
||||
- g++-11
|
||||
gcc_toolchain: 11
|
||||
- toolset: clang
|
||||
compiler: clang++-14
|
||||
cxxstd: "11,14,17,20,2b"
|
||||
os: ubuntu-22.04
|
||||
install:
|
||||
- clang-14
|
||||
- g++-11
|
||||
gcc_toolchain: 11
|
||||
- toolset: clang
|
||||
compiler: clang++-15
|
||||
cxxstd: "11,14,17,20,2b"
|
||||
os: ubuntu-22.04
|
||||
install:
|
||||
- clang-15
|
||||
- g++-11
|
||||
gcc_toolchain: 11
|
||||
- toolset: clang
|
||||
compiler: clang++-16
|
||||
cxxstd: "11,14,17,20,2b"
|
||||
os: ubuntu-24.04
|
||||
install:
|
||||
- clang-16
|
||||
- g++-11
|
||||
gcc_toolchain: 11
|
||||
- toolset: clang
|
||||
compiler: clang++-17
|
||||
cxxstd: "11,14,17,20,23"
|
||||
os: ubuntu-24.04
|
||||
install:
|
||||
- clang-17
|
||||
- g++-11
|
||||
gcc_toolchain: 11
|
||||
- toolset: clang
|
||||
compiler: clang++-18
|
||||
cxxstd: "11,14,17,20,23,26"
|
||||
os: ubuntu-24.04
|
||||
install:
|
||||
- clang-18
|
||||
- g++-13
|
||||
- toolset: clang
|
||||
compiler: clang++-19
|
||||
cxxstd: "11,14,17,20,23,26"
|
||||
os: ubuntu-24.04
|
||||
install:
|
||||
- clang-19
|
||||
- toolset: clang
|
||||
compiler: clang++-20
|
||||
cxxstd: "11,14,17,20,23,26"
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:25.04
|
||||
install:
|
||||
- clang-20
|
||||
- toolset: clang
|
||||
compiler: clang++-20
|
||||
cxxstd: "11,14,17,20,23,26"
|
||||
os: ubuntu-latest
|
||||
container: ubuntu:25.04
|
||||
install:
|
||||
- clang-20
|
||||
- libc++-20-dev
|
||||
- libc++abi-20-dev
|
||||
cxxflags: -stdlib=libc++
|
||||
linkflags: -stdlib=libc++
|
||||
- name: UBSAN
|
||||
toolset: clang
|
||||
compiler: clang++-18
|
||||
cxxstd: "11,14,17,20,23"
|
||||
cxxflags: -stdlib=libc++
|
||||
linkflags: "-stdlib=libc++ -lubsan"
|
||||
ubsan: 1
|
||||
build_variant: debug
|
||||
os: ubuntu-24.04
|
||||
install:
|
||||
- clang-18
|
||||
- libc++-18-dev
|
||||
- libc++abi-18-dev
|
||||
|
||||
- toolset: clang
|
||||
cxxstd: "11,14,17,20,2b"
|
||||
os: macos-13
|
||||
- toolset: clang
|
||||
cxxstd: "11,14,17,20,2b"
|
||||
os: macos-14
|
||||
|
||||
timeout-minutes: 15
|
||||
runs-on: ${{matrix.os}}
|
||||
container: ${{matrix.container}}
|
||||
|
||||
steps:
|
||||
- name: Setup environment
|
||||
run: |
|
||||
if [ -f "/etc/debian_version" ]
|
||||
then
|
||||
echo "DEBIAN_FRONTEND=noninteractive" >> $GITHUB_ENV
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
fi
|
||||
if [ -n "${{matrix.container}}" ]
|
||||
then
|
||||
echo "GHA_CONTAINER=${{matrix.container}}" >> $GITHUB_ENV
|
||||
if [ -f "/etc/debian_version" ]
|
||||
then
|
||||
# Use Azure APT mirrors in containers to avoid HTTP errors due to DDoS filters triggered by lots of CI jobs launching concurrently.
|
||||
# Note that not all Ubuntu versions support "mirror+file:..." URIs in APT sources, so just use Azure mirrors exclusively.
|
||||
# Note also that on recent Ubuntu versions DEB822 format is used for source files.
|
||||
APT_SOURCES=()
|
||||
if [ -d "/etc/apt/sources.list.d" ]
|
||||
then
|
||||
readarray -t APT_SOURCES < <(find "/etc/apt/sources.list.d" -type f -name '*.sources' -print)
|
||||
fi
|
||||
if [ -f "/etc/apt/sources.list" ]
|
||||
then
|
||||
APT_SOURCES+=("/etc/apt/sources.list")
|
||||
fi
|
||||
if [ "${#APT_SOURCES[@]}" -gt 0 ]
|
||||
then
|
||||
sed -i -E -e 's!([^ ]+) (http|https)://(archive|security)\.ubuntu\.com/ubuntu[^ ]*(.*)!\1 http://azure.archive.ubuntu.com/ubuntu/\4!' "${APT_SOURCES[@]}"
|
||||
fi
|
||||
apt-get -o Acquire::Retries=$NET_RETRY_COUNT update
|
||||
if [ "$(apt-cache search "^python-is-python3$" | wc -l)" -ne 0 ]
|
||||
then
|
||||
PYTHON_PACKAGE="python-is-python3"
|
||||
else
|
||||
PYTHON_PACKAGE="python"
|
||||
fi
|
||||
apt-get -o Acquire::Retries=$NET_RETRY_COUNT install -y sudo software-properties-common tzdata wget curl apt-transport-https ca-certificates make build-essential g++ $PYTHON_PACKAGE python3 perl git cmake
|
||||
fi
|
||||
fi
|
||||
git config --global pack.threads 0
|
||||
|
||||
- name: Install packages
|
||||
if: matrix.install
|
||||
run: |
|
||||
declare -a SOURCE_KEYS SOURCES
|
||||
if [ -n "${{join(matrix.source_keys, ' ')}}" ]
|
||||
then
|
||||
SOURCE_KEYS=("${{join(matrix.source_keys, '" "')}}")
|
||||
fi
|
||||
if [ -n "${{join(matrix.sources, ' ')}}" ]
|
||||
then
|
||||
SOURCES=("${{join(matrix.sources, '" "')}}")
|
||||
fi
|
||||
for key in "${SOURCE_KEYS[@]}"
|
||||
do
|
||||
for i in {1..$NET_RETRY_COUNT}
|
||||
do
|
||||
echo "Adding key: $key"
|
||||
wget -O - "$key" | sudo apt-key add - && break || sleep 2
|
||||
done
|
||||
done
|
||||
if [ ${#SOURCES[@]} -gt 0 ]
|
||||
then
|
||||
APT_ADD_REPO_COMMON_ARGS=("-y")
|
||||
APT_ADD_REPO_SUPPORTED_ARGS="$(apt-add-repository --help | perl -ne 'if (/^\s*-n/) { print "n"; } elsif (/^\s*-P/) { print "P"; } elsif (/^\s*-S/) { print "S"; } elsif (/^\s*-U/) { print "U"; }')"
|
||||
if [ -n "$APT_ADD_REPO_SUPPORTED_ARGS" -a -z "${APT_ADD_REPO_SUPPORTED_ARGS##*n*}" ]
|
||||
then
|
||||
APT_ADD_REPO_COMMON_ARGS+=("-n")
|
||||
fi
|
||||
APT_ADD_REPO_HAS_SOURCE_ARGS="$([ -n "$APT_ADD_REPO_SUPPORTED_ARGS" -a -z "${APT_ADD_REPO_SUPPORTED_ARGS##*P*}" -a -z "${APT_ADD_REPO_SUPPORTED_ARGS##*S*}" -a -z "${APT_ADD_REPO_SUPPORTED_ARGS##*U*}" ] && echo 1 || echo 0)"
|
||||
for source in "${SOURCES[@]}"
|
||||
do
|
||||
for i in {1..$NET_RETRY_COUNT}
|
||||
do
|
||||
APT_ADD_REPO_ARGS=("${APT_ADD_REPO_COMMON_ARGS[@]}")
|
||||
if [ $APT_ADD_REPO_HAS_SOURCE_ARGS -ne 0 ]
|
||||
then
|
||||
case "$source" in
|
||||
"ppa:"*)
|
||||
APT_ADD_REPO_ARGS+=("-P")
|
||||
;;
|
||||
"deb "*)
|
||||
APT_ADD_REPO_ARGS+=("-S")
|
||||
;;
|
||||
*)
|
||||
APT_ADD_REPO_ARGS+=("-U")
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
APT_ADD_REPO_ARGS+=("$source")
|
||||
echo "apt-add-repository ${APT_ADD_REPO_ARGS[@]}"
|
||||
sudo -E apt-add-repository "${APT_ADD_REPO_ARGS[@]}" && break || sleep 2
|
||||
done
|
||||
done
|
||||
fi
|
||||
sudo apt-get -o Acquire::Retries=$NET_RETRY_COUNT update
|
||||
sudo apt-get -o Acquire::Retries=$NET_RETRY_COUNT install -y ${{join(matrix.install, ' ')}}
|
||||
|
||||
- name: Setup GCC Toolchain
|
||||
if: matrix.gcc_toolchain
|
||||
run: |
|
||||
GCC_TOOLCHAIN_ROOT="$HOME/gcc-toolchain"
|
||||
echo "GCC_TOOLCHAIN_ROOT=\"$GCC_TOOLCHAIN_ROOT\"" >> $GITHUB_ENV
|
||||
MULTIARCH_TRIPLET="$(dpkg-architecture -qDEB_HOST_MULTIARCH)"
|
||||
mkdir -p "$GCC_TOOLCHAIN_ROOT"
|
||||
ln -s /usr/include "$GCC_TOOLCHAIN_ROOT/include"
|
||||
ln -s /usr/bin "$GCC_TOOLCHAIN_ROOT/bin"
|
||||
mkdir -p "$GCC_TOOLCHAIN_ROOT/lib/gcc/$MULTIARCH_TRIPLET"
|
||||
ln -s "/usr/lib/gcc/$MULTIARCH_TRIPLET/${{matrix.gcc_toolchain}}" "$GCC_TOOLCHAIN_ROOT/lib/gcc/$MULTIARCH_TRIPLET/${{matrix.gcc_toolchain}}"
|
||||
|
||||
- name: Setup Boost
|
||||
run: |
|
||||
echo GITHUB_REPOSITORY: $GITHUB_REPOSITORY
|
||||
LIBRARY=${GITHUB_REPOSITORY#*/}
|
||||
echo LIBRARY: $LIBRARY
|
||||
echo "LIBRARY=$LIBRARY" >> $GITHUB_ENV
|
||||
echo GITHUB_BASE_REF: $GITHUB_BASE_REF
|
||||
echo GITHUB_REF: $GITHUB_REF
|
||||
REF=${GITHUB_BASE_REF:-$GITHUB_REF}
|
||||
REF=${REF#refs/heads/}
|
||||
echo REF: $REF
|
||||
BOOST_BRANCH=develop && [ "$REF" = "master" ] && BOOST_BRANCH=master || true
|
||||
echo BOOST_BRANCH: $BOOST_BRANCH
|
||||
BUILD_JOBS=$((nproc || sysctl -n hw.ncpu) 2> /dev/null)
|
||||
echo "BUILD_JOBS=$BUILD_JOBS" >> $GITHUB_ENV
|
||||
echo "CMAKE_BUILD_PARALLEL_LEVEL=$BUILD_JOBS" >> $GITHUB_ENV
|
||||
DEPINST_ARGS=()
|
||||
GIT_VERSION="$(git --version | sed -e 's/git version //')"
|
||||
GIT_HAS_JOBS=1
|
||||
if [ -f "/etc/debian_version" ]
|
||||
then
|
||||
if $(dpkg --compare-versions "$GIT_VERSION" lt 2.8.0)
|
||||
then
|
||||
GIT_HAS_JOBS=0
|
||||
fi
|
||||
else
|
||||
declare -a GIT_VER=(${GIT_VERSION//./ })
|
||||
declare -a GIT_MIN_VER=(2 8 0)
|
||||
for ((i=0; i<${#GIT_VER[@]}; i++))
|
||||
do
|
||||
if [ -z "${GIT_MIN_VER[i]}" ]
|
||||
then
|
||||
GIT_MIN_VER[i]=0
|
||||
fi
|
||||
if [ "${GIT_VER[i]}" -lt "${GIT_MIN_VER[i]}" ]
|
||||
then
|
||||
GIT_HAS_JOBS=0
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
if [ "$GIT_HAS_JOBS" -ne 0 ]
|
||||
then
|
||||
DEPINST_ARGS+=("--git_args" "--jobs $GIT_FETCH_JOBS")
|
||||
fi
|
||||
mkdir -p snapshot
|
||||
cd snapshot
|
||||
echo "Downloading library snapshot: https://github.com/${GITHUB_REPOSITORY}/archive/${GITHUB_SHA}.tar.gz"
|
||||
curl -L --retry "$NET_RETRY_COUNT" -o "${LIBRARY}-${GITHUB_SHA}.tar.gz" "https://github.com/${GITHUB_REPOSITORY}/archive/${GITHUB_SHA}.tar.gz"
|
||||
tar -xf "${LIBRARY}-${GITHUB_SHA}.tar.gz"
|
||||
if [ ! -d "${LIBRARY}-${GITHUB_SHA}" ]
|
||||
then
|
||||
echo "Library snapshot does not contain the library directory ${LIBRARY}-${GITHUB_SHA}:"
|
||||
ls -la
|
||||
exit 1
|
||||
fi
|
||||
rm -f "${LIBRARY}-${GITHUB_SHA}.tar.gz"
|
||||
cd ..
|
||||
git clone -b "$BOOST_BRANCH" --depth 1 "https://github.com/boostorg/boost.git" "boost-root"
|
||||
cd boost-root
|
||||
mkdir -p libs
|
||||
rm -rf "libs/$LIBRARY"
|
||||
mv -f "../snapshot/${LIBRARY}-${GITHUB_SHA}" "libs/$LIBRARY"
|
||||
rm -rf "../snapshot"
|
||||
git submodule update --init tools/boostdep
|
||||
DEPINST_ARGS+=("$LIBRARY")
|
||||
python tools/boostdep/depinst/depinst.py "${DEPINST_ARGS[@]}"
|
||||
if [ -z "${{matrix.cmake_tests}}" ]
|
||||
then
|
||||
./bootstrap.sh
|
||||
./b2 headers
|
||||
if [ -n "${{matrix.compiler}}" -o -n "$GCC_TOOLCHAIN_ROOT" ]
|
||||
then
|
||||
echo -n "using ${{matrix.toolset}} : : ${{matrix.compiler}}" > ~/user-config.jam
|
||||
if [ -n "$GCC_TOOLCHAIN_ROOT" ]
|
||||
then
|
||||
echo -n " : <compileflags>\"--gcc-toolchain=$GCC_TOOLCHAIN_ROOT\" <linkflags>\"--gcc-toolchain=$GCC_TOOLCHAIN_ROOT\"" >> ~/user-config.jam
|
||||
fi
|
||||
echo " ;" >> ~/user-config.jam
|
||||
fi
|
||||
fi
|
||||
|
||||
- name: Run tests
|
||||
if: matrix.cmake_tests == ''
|
||||
run: |
|
||||
cd boost-root
|
||||
B2_ARGS=("-j" "$BUILD_JOBS" "toolset=${{matrix.toolset}}" "cxxstd=${{matrix.cxxstd}}")
|
||||
if [ -n "${{matrix.build_variant}}" ]
|
||||
then
|
||||
B2_ARGS+=("variant=${{matrix.build_variant}}")
|
||||
else
|
||||
B2_ARGS+=("variant=$DEFAULT_BUILD_VARIANT")
|
||||
fi
|
||||
if [ -n "${{matrix.threading}}" ]
|
||||
then
|
||||
B2_ARGS+=("threading=${{matrix.threading}}")
|
||||
fi
|
||||
if [ -n "${{matrix.ubsan}}" ]
|
||||
then
|
||||
export UBSAN_OPTIONS="print_stacktrace=1"
|
||||
B2_ARGS+=("cxxflags=-fsanitize=undefined -fno-sanitize-recover=undefined" "linkflags=-fsanitize=undefined -fuse-ld=gold" "define=UBSAN=1" "debug-symbols=on" "visibility=global")
|
||||
fi
|
||||
if [ -n "${{matrix.cxxflags}}" ]
|
||||
then
|
||||
B2_ARGS+=("cxxflags=${{matrix.cxxflags}}")
|
||||
fi
|
||||
if [ -n "${{matrix.linkflags}}" ]
|
||||
then
|
||||
B2_ARGS+=("linkflags=${{matrix.linkflags}}")
|
||||
fi
|
||||
B2_ARGS+=("libs/$LIBRARY/test")
|
||||
./b2 "${B2_ARGS[@]}"
|
||||
|
||||
windows:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- toolset: msvc-14.3
|
||||
cxxstd: "14,17,20,latest"
|
||||
addrmd: 32,64
|
||||
os: windows-2022
|
||||
- toolset: clang-win
|
||||
cxxstd: "14,17,latest"
|
||||
addrmd: 32,64
|
||||
os: windows-2022
|
||||
- toolset: gcc
|
||||
cxxstd: "11,14,17,20,23"
|
||||
addrmd: 64
|
||||
os: windows-2022
|
||||
|
||||
timeout-minutes: 15
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
steps:
|
||||
- name: Setup Boost
|
||||
shell: cmd
|
||||
run: |
|
||||
echo GITHUB_REPOSITORY: %GITHUB_REPOSITORY%
|
||||
for /f %%i in ("%GITHUB_REPOSITORY%") do set LIBRARY=%%~nxi
|
||||
echo LIBRARY: %LIBRARY%
|
||||
echo LIBRARY=%LIBRARY%>>%GITHUB_ENV%
|
||||
echo GITHUB_BASE_REF: %GITHUB_BASE_REF%
|
||||
echo GITHUB_REF: %GITHUB_REF%
|
||||
if "%GITHUB_BASE_REF%" == "" set GITHUB_BASE_REF=%GITHUB_REF%
|
||||
set BOOST_BRANCH=develop
|
||||
for /f %%i in ("%GITHUB_BASE_REF%") do if "%%~nxi" == "master" set BOOST_BRANCH=master
|
||||
echo BOOST_BRANCH: %BOOST_BRANCH%
|
||||
mkdir snapshot
|
||||
cd snapshot
|
||||
echo Downloading library snapshot: https://github.com/%GITHUB_REPOSITORY%/archive/%GITHUB_SHA%.zip
|
||||
curl -L --retry %NET_RETRY_COUNT% -o "%LIBRARY%-%GITHUB_SHA%.zip" "https://github.com/%GITHUB_REPOSITORY%/archive/%GITHUB_SHA%.zip"
|
||||
tar -xf "%LIBRARY%-%GITHUB_SHA%.zip"
|
||||
if not exist "%LIBRARY%-%GITHUB_SHA%\" (
|
||||
echo Library snapshot does not contain the library directory %LIBRARY%-%GITHUB_SHA%:
|
||||
dir
|
||||
exit /b 1
|
||||
)
|
||||
del /f "%LIBRARY%-%GITHUB_SHA%.zip"
|
||||
cd ..
|
||||
git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root
|
||||
cd boost-root
|
||||
if not exist "libs\" mkdir libs
|
||||
if exist "libs\%LIBRARY%\" rmdir /s /q "libs\%LIBRARY%"
|
||||
move /Y "..\snapshot\%LIBRARY%-%GITHUB_SHA%" "libs\%LIBRARY%"
|
||||
rmdir /s /q "..\snapshot"
|
||||
git submodule update --init tools/boostdep
|
||||
python tools/boostdep/depinst/depinst.py --git_args "--jobs %GIT_FETCH_JOBS%" %LIBRARY%
|
||||
cmd /c bootstrap
|
||||
b2 -d0 headers
|
||||
|
||||
- name: Run tests
|
||||
shell: cmd
|
||||
run: |
|
||||
cd boost-root
|
||||
if not "${{matrix.cxxstd}}" == "" set CXXSTD=cxxstd=${{matrix.cxxstd}}
|
||||
if not "${{matrix.addrmd}}" == "" set ADDRMD=address-model=${{matrix.addrmd}}
|
||||
if not "${{matrix.build_variant}}" == "" (set BUILD_VARIANT=variant=${{matrix.build_variant}}) else (set BUILD_VARIANT=variant=%DEFAULT_BUILD_VARIANT%)
|
||||
b2 -j %NUMBER_OF_PROCESSORS% libs/%LIBRARY%/test toolset=${{matrix.toolset}} %CXXSTD% %ADDRMD% %BUILD_VARIANT% embed-manifest-via=linker
|
24
CMakeLists.txt
Normal file
24
CMakeLists.txt
Normal file
@ -0,0 +1,24 @@
|
||||
# Copyright 2018 Peter Dimov
|
||||
# Copyright 2018 Andrey Semashev
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
cmake_minimum_required(VERSION 3.5...3.20)
|
||||
|
||||
project(boost_utility VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)
|
||||
|
||||
add_library(boost_utility INTERFACE)
|
||||
add_library(Boost::utility ALIAS boost_utility)
|
||||
|
||||
target_include_directories(boost_utility INTERFACE include)
|
||||
|
||||
target_link_libraries(boost_utility
|
||||
INTERFACE
|
||||
Boost::config
|
||||
Boost::core
|
||||
Boost::io
|
||||
Boost::preprocessor
|
||||
Boost::static_assert
|
||||
Boost::throw_exception
|
||||
Boost::type_traits
|
||||
)
|
26
README.md
Normal file
26
README.md
Normal file
@ -0,0 +1,26 @@
|
||||
# 
|
||||
|
||||
Boost.Utility, part of collection of the [Boost C++ Libraries](https://github.com/boostorg), provides a number of smaller components, too small to be called libraries in their own right. See the documentation for the list of components.
|
||||
|
||||
### Directories
|
||||
|
||||
* **doc** - Documentation sources
|
||||
* **include** - Interface headers of Boost.Utility
|
||||
* **test** - Boost.Utility unit tests
|
||||
|
||||
### More information
|
||||
|
||||
* [Documentation](https://boost.org/libs/utility)
|
||||
* [Report bugs](https://github.com/boostorg/utility/issues/new). Be sure to mention Boost version, Boost.Utility component, platform and compiler you're using. A small compilable code sample to reproduce the problem is always good as well.
|
||||
* Submit your patches as pull requests against **develop** branch. Note that by submitting patches you agree to license your modifications under the [Boost Software License, Version 1.0](https://www.boost.org/LICENSE_1_0.txt).
|
||||
|
||||
### Build status
|
||||
|
||||
Branch | GitHub Actions | AppVeyor | Test Matrix | Dependencies |
|
||||
:-------------: | -------------- | -------- | ----------- | ------------ |
|
||||
[`master`](https://github.com/boostorg/utility/tree/master) | [](https://github.com/boostorg/utility/actions?query=branch%3Amaster) | [](https://ci.appveyor.com/project/Lastique/utility/branch/master) | [](http://www.boost.org/development/tests/master/developer/utility.html) | [](https://pdimov.github.io/boostdep-report/master/utility.html)
|
||||
[`develop`](https://github.com/boostorg/utility/tree/develop) | [](https://github.com/boostorg/utility/actions?query=branch%3Adevelop) | [](https://ci.appveyor.com/project/Lastique/utility/branch/develop) | [](http://www.boost.org/development/tests/develop/developer/utility.html) | [](https://pdimov.github.io/boostdep-report/develop/utility.html)
|
||||
|
||||
### License
|
||||
|
||||
Distributed under the [Boost Software License, Version 1.0](https://www.boost.org/LICENSE_1_0.txt).
|
88
appveyor.yml
Normal file
88
appveyor.yml
Normal file
@ -0,0 +1,88 @@
|
||||
# Copyright 2016-2019 Peter Dimov
|
||||
# Copyright 2019, 2022 Andrey Semashev
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
|
||||
version: 1.0.{build}-{branch}
|
||||
|
||||
shallow_clone: true
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- develop
|
||||
- /feature\/.*/
|
||||
|
||||
environment:
|
||||
matrix:
|
||||
- TOOLSET: msvc-14.0
|
||||
ADDRMD: 32,64
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
- TOOLSET: msvc-14.1
|
||||
CXXSTD: 14,17,latest
|
||||
ADDRMD: 32,64
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
- TOOLSET: msvc-14.2
|
||||
ADDRMD: 32,64
|
||||
CXXSTD: 14,17,20,latest
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
||||
- TOOLSET: msvc-14.3
|
||||
ADDRMD: 32,64
|
||||
CXXSTD: 14,17,20,latest
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022
|
||||
- TOOLSET: clang-win
|
||||
ADDRMD: 32
|
||||
CXXSTD: 14,17,latest
|
||||
ENV_SCRIPT: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars32.bat
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
||||
- TOOLSET: clang-win
|
||||
ADDRMD: 64
|
||||
CXXSTD: 14,17,latest
|
||||
ENV_SCRIPT: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
||||
- TOOLSET: gcc
|
||||
CXXSTD: 11,14,1z
|
||||
ADDPATH: C:\cygwin\bin;
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
- TOOLSET: gcc
|
||||
CXXSTD: 11,14,1z
|
||||
ADDPATH: C:\cygwin64\bin;
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
- TOOLSET: gcc
|
||||
CXXSTD: 11,14,1z
|
||||
ADDPATH: C:\mingw\bin;
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
- TOOLSET: gcc
|
||||
CXXSTD: 11,14,1z
|
||||
ADDPATH: C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin;
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
- TOOLSET: gcc
|
||||
CXXSTD: 11,14,17
|
||||
ADDPATH: C:\mingw-w64\x86_64-7.3.0-posix-seh-rt_v5-rev0\mingw64\bin;
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
- TOOLSET: gcc
|
||||
CXXSTD: 11,14,17,2a
|
||||
ADDPATH: C:\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin;
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
|
||||
install:
|
||||
- set GIT_FETCH_JOBS=8
|
||||
- set BOOST_BRANCH=develop
|
||||
- if "%APPVEYOR_REPO_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 %APPVEYOR_BUILD_FOLDER% libs\utility
|
||||
- python tools/boostdep/depinst/depinst.py %DEPINST_ARG_INCLUDE_EXAMPLES% --git_args "--jobs %GIT_FETCH_JOBS%" utility
|
||||
- cmd /c bootstrap
|
||||
- b2 headers
|
||||
|
||||
build: off
|
||||
|
||||
test_script:
|
||||
- PATH=%ADDPATH%%PATH%
|
||||
- if not "%ENV_SCRIPT%" == "" call "%ENV_SCRIPT%"
|
||||
- if not "%CXXSTD%" == "" set CXXSTD=cxxstd=%CXXSTD%
|
||||
- if not "%ADDRMD%" == "" set ADDRMD=address-model=%ADDRMD%
|
||||
- b2 -j %NUMBER_OF_PROCESSORS% libs/utility/test toolset=%TOOLSET% %CXXSTD% %ADDRMD% variant=debug,release
|
29
build.jam
Normal file
29
build.jam
Normal file
@ -0,0 +1,29 @@
|
||||
# Copyright René Ferdinand Rivera Morell 2023-2024
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
require-b2 5.2 ;
|
||||
|
||||
constant boost_dependencies :
|
||||
/boost/assert//boost_assert
|
||||
/boost/config//boost_config
|
||||
/boost/core//boost_core
|
||||
/boost/io//boost_io
|
||||
/boost/preprocessor//boost_preprocessor
|
||||
/boost/throw_exception//boost_throw_exception
|
||||
/boost/type_traits//boost_type_traits ;
|
||||
|
||||
project /boost/utility
|
||||
: common-requirements
|
||||
<include>include
|
||||
;
|
||||
|
||||
explicit
|
||||
[ alias boost_utility : : : : <library>$(boost_dependencies) ]
|
||||
[ alias all : boost_utility test ]
|
||||
;
|
||||
|
||||
call-if : boost-library utility
|
||||
;
|
||||
|
762
call_traits.htm
762
call_traits.htm
@ -1,755 +1,19 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Type"
|
||||
content="text/html; charset=iso-8859-1">
|
||||
<meta name="Template"
|
||||
content="C:\PROGRAM FILES\MICROSOFT OFFICE\OFFICE\html.dot">
|
||||
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
|
||||
<title>Call Traits</title>
|
||||
<title>Boost.CallTraits</title>
|
||||
<meta http-equiv="refresh" content="0; URL=./doc/html/utility/utilities/call_traits.html">
|
||||
</head>
|
||||
|
||||
<body bgcolor="#FFFFFF" text="#000000" link="#0000FF"
|
||||
vlink="#800080">
|
||||
|
||||
<h1><img src="../../boost.png" width="276" height="86">Header
|
||||
<<a href="../../boost/detail/call_traits.hpp">boost/call_traits.hpp</a>></h1>
|
||||
|
||||
<p>All of the contents of <boost/call_traits.hpp> are
|
||||
defined inside namespace boost.</p>
|
||||
|
||||
<p>The template class call_traits<T> encapsulates the
|
||||
"best" method to pass a parameter of some type T to or
|
||||
from a function, and consists of a collection of typedefs defined
|
||||
as in the table below. The purpose of call_traits is to ensure
|
||||
that problems like "<a href="#refs">references to references</a>"
|
||||
never occur, and that parameters are passed in the most efficient
|
||||
manner possible (see <a href="#examples">examples</a>). In each
|
||||
case if your existing practice is to use the type defined on the
|
||||
left, then replace it with the call_traits defined type on the
|
||||
right. </p>
|
||||
|
||||
<p>Note that for compilers that do not support either partial
|
||||
specialization or member templates, no benefit will occur from
|
||||
using call_traits: the call_traits defined types will always be
|
||||
the same as the existing practice in this case. In addition if
|
||||
only member templates and not partial template specialisation is
|
||||
support by the compiler (for example Visual C++ 6) then
|
||||
call_traits can not be used with array types (although it can be
|
||||
used to solve the reference to reference problem).</p>
|
||||
|
||||
<table border="0" cellpadding="7" cellspacing="1" width="797">
|
||||
<tr>
|
||||
<td valign="top" width="17%" bgcolor="#008080"><p
|
||||
align="center">Existing practice</p>
|
||||
</td>
|
||||
<td valign="top" width="35%" bgcolor="#008080"><p
|
||||
align="center">call_traits equivalent</p>
|
||||
</td>
|
||||
<td valign="top" width="32%" bgcolor="#008080"><p
|
||||
align="center">Description</p>
|
||||
</td>
|
||||
<td valign="top" width="16%" bgcolor="#008080"><p
|
||||
align="center">Notes</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top" width="17%"><p align="center">T<br>
|
||||
(return by value)</p>
|
||||
</td>
|
||||
<td valign="top" width="35%"><p align="center"><code>call_traits<T>::value_type</code></p>
|
||||
</td>
|
||||
<td valign="top" width="32%">Defines a type that
|
||||
represents the "value" of type T. Use this for
|
||||
functions that return by value, or possibly for stored
|
||||
values of type T.</td>
|
||||
<td valign="top" width="16%"><p align="center">2</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top" width="17%"><p align="center">T&<br>
|
||||
(return value)</p>
|
||||
</td>
|
||||
<td valign="top" width="35%"><p align="center"><code>call_traits<T>::reference</code></p>
|
||||
</td>
|
||||
<td valign="top" width="32%">Defines a type that
|
||||
represents a reference to type T. Use for functions that
|
||||
would normally return a T&.</td>
|
||||
<td valign="top" width="16%"><p align="center">1</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top" width="17%"><p align="center">const
|
||||
T&<br>
|
||||
(return value)</p>
|
||||
</td>
|
||||
<td valign="top" width="35%"><p align="center"><code>call_traits<T>::const_reference</code></p>
|
||||
</td>
|
||||
<td valign="top" width="32%">Defines a type that
|
||||
represents a constant reference to type T. Use for
|
||||
functions that would normally return a const T&.</td>
|
||||
<td valign="top" width="16%"><p align="center">1</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top" width="17%"><p align="center">const
|
||||
T&<br>
|
||||
(function parameter)</p>
|
||||
</td>
|
||||
<td valign="top" width="35%"><p align="center"><code>call_traits<T>::param_type</code></p>
|
||||
</td>
|
||||
<td valign="top" width="32%">Defines a type that
|
||||
represents the "best" way to pass a parameter
|
||||
of type T to a function.</td>
|
||||
<td valign="top" width="16%"><p align="center">1,3</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<p>Notes:</p>
|
||||
|
||||
<ol>
|
||||
<li>If T is already reference type, then call_traits is
|
||||
defined such that <a href="#refs">references to
|
||||
references</a> do not occur (requires partial
|
||||
specialization).</li>
|
||||
<li>If T is an array type, then call_traits defines <code>value_type</code>
|
||||
as a "constant pointer to type" rather than an
|
||||
"array of type" (requires partial
|
||||
specialization). Note that if you are using value_type as
|
||||
a stored value then this will result in storing a "constant
|
||||
pointer to an array" rather than the array itself.
|
||||
This may or may not be a good thing depending upon what
|
||||
you actually need (in other words take care!).</li>
|
||||
<li>If T is a small built in type or a pointer, then <code>param_type</code>
|
||||
is defined as <code>T const</code>, instead of <code>T
|
||||
const&</code>. This can improve the ability of the
|
||||
compiler to optimize loops in the body of the function if
|
||||
they depend upon the passed parameter, the semantics of
|
||||
the passed parameter is otherwise unchanged (requires
|
||||
partial specialization).</li>
|
||||
</ol>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<h3>Copy constructibility</h3>
|
||||
|
||||
<p>The following table defines which call_traits types can always
|
||||
be copy-constructed from which other types, those entries marked
|
||||
with a '?' are true only if and only if T is copy constructible:</p>
|
||||
|
||||
<table border="0" cellpadding="7" cellspacing="1" width="766">
|
||||
<tr>
|
||||
<td valign="top" width="17%"> </td>
|
||||
<td valign="top" colspan="5" width="85%"
|
||||
bgcolor="#008080"><p align="center">To:</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top" width="17%" bgcolor="#008080">From:</td>
|
||||
<td valign="top" width="17%" bgcolor="#C0C0C0"><p
|
||||
align="center">T</p>
|
||||
</td>
|
||||
<td valign="top" width="17%" bgcolor="#C0C0C0"><p
|
||||
align="center">value_type</p>
|
||||
</td>
|
||||
<td valign="top" width="17%" bgcolor="#C0C0C0"><p
|
||||
align="center">reference</p>
|
||||
</td>
|
||||
<td valign="top" width="17%" bgcolor="#C0C0C0"><p
|
||||
align="center">const_reference</p>
|
||||
</td>
|
||||
<td valign="top" width="17%" bgcolor="#C0C0C0"><p
|
||||
align="center">param_type</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top" width="17%" bgcolor="#C0C0C0">T</td>
|
||||
<td valign="top" width="17%"><p align="center">?</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">?</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">Y</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">Y</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">Y</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top" width="17%" bgcolor="#C0C0C0">value_type</td>
|
||||
<td valign="top" width="17%"><p align="center">?</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">?</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">N</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">N</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">Y</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top" width="17%" bgcolor="#C0C0C0">reference</td>
|
||||
<td valign="top" width="17%"><p align="center">?</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">?</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">Y</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">Y</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">Y</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top" width="17%" bgcolor="#C0C0C0">const_reference</td>
|
||||
<td valign="top" width="17%"><p align="center">?</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">N</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">N</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">Y</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">Y</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top" width="17%" bgcolor="#C0C0C0">param_type</td>
|
||||
<td valign="top" width="17%"><p align="center">?</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">?</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">N</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">N</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">Y</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p>If T is an assignable type the following assignments are
|
||||
possible:</p>
|
||||
|
||||
<table border="0" cellpadding="7" cellspacing="1" width="766">
|
||||
<tr>
|
||||
<td valign="top" width="17%"> </td>
|
||||
<td valign="top" colspan="5" width="85%"
|
||||
bgcolor="#008080"><p align="center">To:</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top" width="17%" bgcolor="#008080">From:</td>
|
||||
<td valign="top" width="17%" bgcolor="#C0C0C0"><p
|
||||
align="center">T</p>
|
||||
</td>
|
||||
<td valign="top" width="17%" bgcolor="#C0C0C0"><p
|
||||
align="center">value_type</p>
|
||||
</td>
|
||||
<td valign="top" width="17%" bgcolor="#C0C0C0"><p
|
||||
align="center">reference</p>
|
||||
</td>
|
||||
<td valign="top" width="17%" bgcolor="#C0C0C0"><p
|
||||
align="center">const_reference</p>
|
||||
</td>
|
||||
<td valign="top" width="17%" bgcolor="#C0C0C0"><p
|
||||
align="center">param_type</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top" width="17%" bgcolor="#C0C0C0">T</td>
|
||||
<td valign="top" width="17%"><p align="center">Y</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">Y</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">-</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">-</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top" width="17%" bgcolor="#C0C0C0">value_type</td>
|
||||
<td valign="top" width="17%"><p align="center">Y</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">Y</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">-</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">-</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top" width="17%" bgcolor="#C0C0C0">reference</td>
|
||||
<td valign="top" width="17%"><p align="center">Y</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">Y</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">-</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">-</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top" width="17%" bgcolor="#C0C0C0">const_reference</td>
|
||||
<td valign="top" width="17%"><p align="center">Y</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">Y</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">-</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">-</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">-</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top" width="17%" bgcolor="#C0C0C0">param_type</td>
|
||||
<td valign="top" width="17%"><p align="center">Y</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">Y</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">-</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">-</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">-</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<h3><a name="examples"></a>Examples</h3>
|
||||
|
||||
<p>The following table shows the effect that call_traits has on
|
||||
various types, the table assumes that the compiler supports
|
||||
partial specialization: if it doesn't then all types behave in
|
||||
the same way as the entry for "myclass", and
|
||||
call_traits can not be used with reference or array types.</p>
|
||||
|
||||
<table border="0" cellpadding="7" cellspacing="1" width="766">
|
||||
<tr>
|
||||
<td valign="top" width="17%"> </td>
|
||||
<td valign="top" colspan="5" width="85%"
|
||||
bgcolor="#008080"><p align="center">Call_traits type:</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top" width="17%" bgcolor="#008080"><p
|
||||
align="center">Original type T</p>
|
||||
</td>
|
||||
<td valign="top" width="17%" bgcolor="#C0C0C0"><p
|
||||
align="center">value_type</p>
|
||||
</td>
|
||||
<td valign="top" width="17%" bgcolor="#C0C0C0"><p
|
||||
align="center">reference</p>
|
||||
</td>
|
||||
<td valign="top" width="17%" bgcolor="#C0C0C0"><p
|
||||
align="center">const_reference</p>
|
||||
</td>
|
||||
<td valign="top" width="17%" bgcolor="#C0C0C0"><p
|
||||
align="center">param_type</p>
|
||||
</td>
|
||||
<td valign="top" width="17%" bgcolor="#C0C0C0"><p
|
||||
align="center">Applies to:</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top" width="17%" bgcolor="#C0C0C0"><p
|
||||
align="center">myclass</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">myclass</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">myclass&</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">const
|
||||
myclass&</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">myclass
|
||||
const&</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">All user
|
||||
defined types.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top" width="17%" bgcolor="#C0C0C0"><p
|
||||
align="center">int</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">int</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">int&</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">const
|
||||
int&</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">int const</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">All small
|
||||
built-in types.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top" width="17%" bgcolor="#C0C0C0"><p
|
||||
align="center">int*</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">int*</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">int*&</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">int*const&</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">int* const</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">All
|
||||
pointer types.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top" width="17%" bgcolor="#C0C0C0"><p
|
||||
align="center">int&</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">int&</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">int&</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">const
|
||||
int&</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">int&</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">All
|
||||
reference types.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top" width="17%" bgcolor="#C0C0C0"><p
|
||||
align="center">const int&</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">const
|
||||
int&</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">const
|
||||
int&</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">const
|
||||
int&</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">const
|
||||
int&</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">All
|
||||
constant-references.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top" width="17%" bgcolor="#C0C0C0"><p
|
||||
align="center">int[3]</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">const int*</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">int(&)[3]</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">const int(&)[3]</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">const int*
|
||||
const</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">All array
|
||||
types.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top" width="17%" bgcolor="#C0C0C0"><p
|
||||
align="center">const int[3]</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">const int*</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">const int(&)[3]</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">const int(&)[3]</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">const int*
|
||||
const</p>
|
||||
</td>
|
||||
<td valign="top" width="17%"><p align="center">All
|
||||
constant-array types.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<h4>Example 1:</h4>
|
||||
|
||||
<p>The following class is a trivial class that stores some type T
|
||||
by value (see the <a href="call_traits_test.cpp">call_traits_test.cpp</a>
|
||||
file), the aim is to illustrate how each of the available
|
||||
call_traits typedefs may be used:</p>
|
||||
|
||||
<pre>template <class T>
|
||||
struct contained
|
||||
{
|
||||
// define our typedefs first, arrays are stored by value
|
||||
// so value_type is not the same as result_type:
|
||||
typedef typename boost::call_traits<T>::param_type param_type;
|
||||
typedef typename boost::call_traits<T>::reference reference;
|
||||
typedef typename boost::call_traits<T>::const_reference const_reference;
|
||||
typedef T value_type;
|
||||
typedef typename boost::call_traits<T>::value_type result_type;
|
||||
|
||||
// stored value:
|
||||
value_type v_;
|
||||
|
||||
// constructors:
|
||||
contained() {}
|
||||
contained(param_type p) : v_(p){}
|
||||
// return byval:
|
||||
result_type value() { return v_; }
|
||||
// return by_ref:
|
||||
reference get() { return v_; }
|
||||
const_reference const_get()const { return v_; }
|
||||
// pass value:
|
||||
void call(param_type p){}
|
||||
|
||||
};</pre>
|
||||
|
||||
<h4><a name="refs"></a>Example 2 (the reference to reference
|
||||
problem):</h4>
|
||||
|
||||
<p>Consider the definition of std::binder1st:</p>
|
||||
|
||||
<pre>template <class Operation>
|
||||
class binder1st :
|
||||
public unary_function<typename Operation::second_argument_type, typename Operation::result_type>
|
||||
{
|
||||
protected:
|
||||
Operation op;
|
||||
typename Operation::first_argument_type value;
|
||||
public:
|
||||
binder1st(const Operation& x, const typename Operation::first_argument_type& y);
|
||||
typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const;
|
||||
}; </pre>
|
||||
|
||||
<p>Now consider what happens in the relatively common case that
|
||||
the functor takes its second argument as a reference, that
|
||||
implies that <code>Operation::second_argument_type</code> is a
|
||||
reference type, <code>operator()</code> will now end up taking a
|
||||
reference to a reference as an argument, and that is not
|
||||
currently legal. The solution here is to modify <code>operator()</code>
|
||||
to use call_traits:</p>
|
||||
|
||||
<pre>typename Operation::result_type operator()(typename call_traits<typename Operation::second_argument_type>::param_type x) const;</pre>
|
||||
|
||||
<p>Now in the case that <code>Operation::second_argument_type</code>
|
||||
is a reference type, the argument is passed as a reference, and
|
||||
the no "reference to reference" occurs.</p>
|
||||
|
||||
<h4><a name="ex3"></a>Example 3 (the make_pair problem):</h4>
|
||||
|
||||
<p>If we pass the name of an array as one (or both) arguments to <code>std::make_pair</code>,
|
||||
then template argument deduction deduces the passed parameter as
|
||||
"const reference to array of T", this also applies to
|
||||
string literals (which are really array literals). Consequently
|
||||
instead of returning a pair of pointers, it tries to return a
|
||||
pair of arrays, and since an array type is not copy-constructible
|
||||
the code fails to compile. One solution is to explicitly cast the
|
||||
arguments to make_pair to pointers, but call_traits provides a
|
||||
better (i.e. automatic) solution (and one that works safely even
|
||||
in generic code where the cast might do the wrong thing):</p>
|
||||
|
||||
<pre>template <class T1, class T2>
|
||||
std::pair<
|
||||
typename boost::call_traits<T1>::value_type,
|
||||
typename boost::call_traits<T2>::value_type>
|
||||
make_pair(const T1& t1, const T2& t2)
|
||||
{
|
||||
return std::pair<
|
||||
typename boost::call_traits<T1>::value_type,
|
||||
typename boost::call_traits<T2>::value_type>(t1, t2);
|
||||
}</pre>
|
||||
|
||||
<p>Here, the deduced argument types will be automatically
|
||||
degraded to pointers if the deduced types are arrays, similar
|
||||
situations occur in the standard binders and adapters: in
|
||||
principle in any function that "wraps" a temporary
|
||||
whose type is deduced. Note that the function arguments to
|
||||
make_pair are not expressed in terms of call_traits: doing so
|
||||
would prevent template argument deduction from functioning.</p>
|
||||
|
||||
<h4><a name="ex4"></a>Example 4 (optimising fill):</h4>
|
||||
|
||||
<p>The call_traits template will "optimize" the passing
|
||||
of a small built-in type as a function parameter, this mainly has
|
||||
an effect when the parameter is used within a loop body. In the
|
||||
following example (see <a
|
||||
href="../type_traits/examples/fill_example.cpp">fill_example.cpp</a>),
|
||||
a version of std::fill is optimized in two ways: if the type
|
||||
passed is a single byte built-in type then std::memset is used to
|
||||
effect the fill, otherwise a conventional C++ implemention is
|
||||
used, but with the passed parameter "optimized" using
|
||||
call_traits:</p>
|
||||
|
||||
<pre>namespace detail{
|
||||
|
||||
template <bool opt>
|
||||
struct filler
|
||||
{
|
||||
template <typename I, typename T>
|
||||
static void do_fill(I first, I last, typename boost::call_traits<T>::param_type val)
|
||||
{
|
||||
while(first != last)
|
||||
{
|
||||
*first = val;
|
||||
++first;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct filler<true>
|
||||
{
|
||||
template <typename I, typename T>
|
||||
static void do_fill(I first, I last, T val)
|
||||
{
|
||||
memset(first, val, last-first);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
template <class I, class T>
|
||||
inline void fill(I first, I last, const T& val)
|
||||
{
|
||||
enum{ can_opt = boost::is_pointer<I>::value
|
||||
&& boost::is_arithmetic<T>::value
|
||||
&& (sizeof(T) == 1) };
|
||||
typedef detail::filler<can_opt> filler_t;
|
||||
filler_t::template do_fill<I,T>(first, last, val);
|
||||
}</pre>
|
||||
|
||||
<p>Footnote: the reason that this is "optimal" for
|
||||
small built-in types is that with the value passed as "T
|
||||
const" instead of "const T&" the compiler is
|
||||
able to tell both that the value is constant and that it is free
|
||||
of aliases. With this information the compiler is able to cache
|
||||
the passed value in a register, unroll the loop, or use
|
||||
explicitly parallel instructions: if any of these are supported.
|
||||
Exactly how much mileage you will get from this depends upon your
|
||||
compiler - we could really use some accurate benchmarking
|
||||
software as part of boost for cases like this.</p>
|
||||
|
||||
<p>Note that the function arguments to fill are not expressed in
|
||||
terms of call_traits: doing so would prevent template argument
|
||||
deduction from functioning. Instead fill acts as a "thin
|
||||
wrapper" that is there to perform template argument
|
||||
deduction, the compiler will optimise away the call to fill all
|
||||
together, replacing it with the call to filler<>::do_fill,
|
||||
which does use call_traits.</p>
|
||||
|
||||
<h3>Rationale</h3>
|
||||
|
||||
<p>The following notes are intended to briefly describe the
|
||||
rational behind choices made in call_traits.</p>
|
||||
|
||||
<p>All user-defined types follow "existing practice"
|
||||
and need no comment.</p>
|
||||
|
||||
<p>Small built-in types (what the standard calls fundamental
|
||||
types [3.9.1]) differ from existing practice only in the <i>param_type</i>
|
||||
typedef. In this case passing "T const" is compatible
|
||||
with existing practice, but may improve performance in some cases
|
||||
(see <a href="#ex4">Example 4</a>), in any case this should never
|
||||
be any worse than existing practice.</p>
|
||||
|
||||
<p>Pointers follow the same rational as small built-in types.</p>
|
||||
|
||||
<p>For reference types the rational follows <a href="#refs">Example
|
||||
2</a> - references to references are not allowed, so the
|
||||
call_traits members must be defined such that these problems do
|
||||
not occur. There is a proposal to modify the language such that
|
||||
"a reference to a reference is a reference" (issue #106,
|
||||
submitted by Bjarne Stroustrup), call_traits<T>::value_type
|
||||
and call_traits<T>::param_type both provide the same effect
|
||||
as that proposal, without the need for a language change (in
|
||||
other words it's a workaround).</p>
|
||||
|
||||
<p>For array types, a function that takes an array as an argument
|
||||
will degrade the array type to a pointer type: this means that
|
||||
the type of the actual parameter is different from its declared
|
||||
type, something that can cause endless problems in template code
|
||||
that relies on the declared type of a parameter. For example:</p>
|
||||
|
||||
<pre>template <class T>
|
||||
struct A
|
||||
{
|
||||
void foo(T t);
|
||||
};</pre>
|
||||
|
||||
<p><font face="Times New Roman">In this case if we instantiate
|
||||
A<int[2]> then the declared type of the parameter passed to
|
||||
member function foo is int[2], but it's actual type is const int*,
|
||||
if we try to use the type T within the function body, then there
|
||||
is a strong likelyhood that our code will not compile:</font></p>
|
||||
|
||||
<pre>template <class T>
|
||||
void A<T>::foo(T t)
|
||||
{
|
||||
T dup(t); // doesn't compile for case that T is an array.
|
||||
}</pre>
|
||||
|
||||
<p>By using call_traits the degradation from array to pointer is
|
||||
explicit, and the type of the parameter is the same as it's
|
||||
declared type:</p>
|
||||
|
||||
<pre>template <class T>
|
||||
struct A
|
||||
{
|
||||
void foo(typename call_traits<T>::value_type t);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
void A<T>::foo(typename call_traits<T>::value_type t)
|
||||
{
|
||||
typename call_traits<T>::value_type dup(t); // OK even if T is an array type.
|
||||
}</pre>
|
||||
|
||||
<p>For value_type (return by value), again only a pointer may be
|
||||
returned, not a copy of the whole array, and again call_traits
|
||||
makes the degradation explicit. The value_type member is useful
|
||||
whenever an array must be explicitly degraded to a pointer - <a
|
||||
href="#ex3">Example 3</a> provides the test case (Footnote: the
|
||||
array specialisation for call_traits is the least well understood
|
||||
of all the call_traits specialisations, if the given semantics
|
||||
cause specific problems for you, or don't solve a particular
|
||||
array-related problem, then I would be interested to hear about
|
||||
it. Most people though will probably never need to use this
|
||||
specialisation).</p>
|
||||
|
||||
<body>
|
||||
Automatic redirection failed, please go to
|
||||
<a href="./doc/html/utility/utilities/call_traits.html">./doc/html/utility/utilities/call_traits.html</a>
|
||||
<hr>
|
||||
|
||||
<p>Revised 01 September 2000</p>
|
||||
|
||||
<p>
|
||||
Copyright 2000 Steve Cleary, Beman Dawes, Howard
|
||||
Hinnant and John Maddock. <br/>
|
||||
Use, modification and distribution are subject to the
|
||||
Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt
|
||||
or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">
|
||||
http://www.boost.org/LICENSE_1_0.txt
|
||||
</a>).
|
||||
</p>
|
||||
<tt>
|
||||
Boost.CallTraits<br>
|
||||
<br>
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
<a href=http://www.boost.org/LICENSE_1_0.txt>http://www.boost.org/LICENSE_1_0.txt</a>) <br>
|
||||
<br>
|
||||
</tt>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
@ -1,15 +1,19 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv=refresh content="0; URL=../core/doc/html/core/checked_delete.html">
|
||||
<title>Automatic redirection</title>
|
||||
<title>Boost.Utility</title>
|
||||
<meta http-equiv="refresh" content="0; URL=../core/doc/html/core/checked_delete.html">
|
||||
</head>
|
||||
<body>
|
||||
Automatic redirection failed, please go to
|
||||
<a href="../core/doc/html/core/checked_delete.html">checked_delete.html</a>. <hr>
|
||||
<p><EFBFBD> Copyright Beman Dawes, 2001</p>
|
||||
<p>Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy
|
||||
at <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</p>
|
||||
<a href="../core/doc/html/core/checked_delete.html">../core/doc/html/core/checked_delete.html</a>
|
||||
<hr>
|
||||
<tt>
|
||||
Boost.Utility<br>
|
||||
<br>
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
<a href=http://www.boost.org/LICENSE_1_0.txt>http://www.boost.org/LICENSE_1_0.txt</a>) <br>
|
||||
<br>
|
||||
</tt>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -1,16 +1,19 @@
|
||||
|
||||
<!--
|
||||
Copyright 2014 Daniel James.
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
-->
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0; URL=doc/html/compressed_pair.html">
|
||||
<title>Boost.Utility</title>
|
||||
<meta http-equiv="refresh" content="0; URL=./doc/html/utility/utilities/compressed_pair.html">
|
||||
</head>
|
||||
<body>
|
||||
Automatic redirection failed, please go to
|
||||
<a href="doc/html/compressed_pair.html">doc/html/compressed_pair.html</a>
|
||||
<a href="./doc/html/utility/utilities/compressed_pair.html">./doc/html/utility/utilities/compressed_pair.html</a>
|
||||
<hr>
|
||||
<tt>
|
||||
Boost.Utility<br>
|
||||
<br>
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
<a href=http://www.boost.org/LICENSE_1_0.txt>http://www.boost.org/LICENSE_1_0.txt</a>) <br>
|
||||
<br>
|
||||
</tt>
|
||||
</body>
|
||||
</html>
|
||||
|
4
doc/.gitignore
vendored
Normal file
4
doc/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
html
|
||||
xml
|
||||
temp
|
||||
out.txt
|
80
doc/BOOST_BINARY.qbk
Normal file
80
doc/BOOST_BINARY.qbk
Normal file
@ -0,0 +1,80 @@
|
||||
[/
|
||||
/ Copyright (c) 2012 Marshall Clow
|
||||
/ Copyright (c) 2021, Alan Freitas
|
||||
/ Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
/ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
/]
|
||||
|
||||
[/===============]
|
||||
[section:BOOST_BINARY Binary Integer Literals]
|
||||
[/===============]
|
||||
|
||||
[section Introduction]
|
||||
|
||||
The macro `BOOST_BINARY` is used for the representation of binary
|
||||
literals. It takes as an argument a binary number arranged as an
|
||||
arbitrary amount of 1s and 0s in groupings of length 1 to 8, with
|
||||
groups separated by spaces. The macro serves as a replacement for
|
||||
[@https://en.cppreference.com/w/cpp/language/integer_literal binary integer literals],
|
||||
adopted in C++14.
|
||||
|
||||
The type of the literal yielded is determined by the same rules as
|
||||
those of [@https://en.cppreference.com/w/cpp/language/integer_literal hex and octal literals].
|
||||
By implementation, this macro expands directly to an octal literal during preprocessing, so
|
||||
there is no overhead at runtime and the result is usable in any place that an octal literal
|
||||
would be.
|
||||
|
||||
In order to directly support binary literals with suffixes,
|
||||
additional macros of the form `BOOST_BINARY_XXX` are also
|
||||
provided, where `XXX` is a standard integer suffix in all capital
|
||||
letters.
|
||||
|
||||
In addition, LL and ULL suffixes may be used for representing
|
||||
`long long` and `unsigned long long` types in compilers which provide
|
||||
them as an extension.
|
||||
|
||||
The `BOOST_BINARY` family of macros resides in the header
|
||||
[@../../../../boost/utility/binary.hpp <boost/utility/binary.hpp>].
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Example]
|
||||
|
||||
```
|
||||
void foo( int );
|
||||
|
||||
void foo( unsigned long );
|
||||
|
||||
void bar()
|
||||
{
|
||||
int value1 = BOOST_BINARY( 100 111000 01 1 110 );
|
||||
|
||||
unsigned long value2 = BOOST_BINARY_UL( 100 001 ); // unsigned long
|
||||
|
||||
long long value3 = BOOST_BINARY_LL( 11 000 ); // long long if supported
|
||||
|
||||
__assert__( BOOST_BINARY( 10010 )
|
||||
& BOOST_BINARY( 11000 )
|
||||
== BOOST_BINARY( 10000 )
|
||||
);
|
||||
|
||||
foo( BOOST_BINARY( 1010 ) ); // calls the first foo
|
||||
|
||||
foo( BOOST_BINARY_LU( 1010 ) ); // calls the second foo
|
||||
}
|
||||
```
|
||||
|
||||
[endsect]
|
||||
|
||||
[/===============]
|
||||
[xinclude tmp/boost_binary_reference.xml]
|
||||
[/===============]
|
||||
|
||||
|
||||
[section Acknowledgments]
|
||||
|
||||
Contributed by Matt Calabrese.
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
511
doc/Jamfile.v2
511
doc/Jamfile.v2
@ -1,119 +1,422 @@
|
||||
|
||||
# Copyright John Maddock 2005. Use, modification, and distribution are
|
||||
# subject to the Boost Software License, Version 1.0. (See accompanying
|
||||
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
project : requirements
|
||||
# Path for links to Boost:
|
||||
<xsl:param>boost.root=../../../..
|
||||
import project ;
|
||||
import doxygen ;
|
||||
import quickbook ;
|
||||
|
||||
# Some general style settings:
|
||||
<xsl:param>table.footnote.number.format=1
|
||||
<xsl:param>footnote.number.format=1
|
||||
|
||||
# HTML options first:
|
||||
# Use graphics not text for navigation:
|
||||
<xsl:param>navig.graphics=1
|
||||
# PDF Options:
|
||||
# TOC Generation: this is needed for FOP-0.9 and later:
|
||||
<xsl:param>fop1.extensions=0
|
||||
<xsl:param>xep.extensions=1
|
||||
# TOC generation: this is needed for FOP 0.2, but must not be set to zero for FOP-0.9!
|
||||
<xsl:param>fop.extensions=0
|
||||
# No indent on body text:
|
||||
<xsl:param>body.start.indent=0pt
|
||||
# Margin size:
|
||||
<xsl:param>page.margin.inner=0.5in
|
||||
# Margin size:
|
||||
<xsl:param>page.margin.outer=0.5in
|
||||
# Paper type = A4
|
||||
<xsl:param>paper.type=A4
|
||||
# Yes, we want graphics for admonishments:
|
||||
<xsl:param>admon.graphics=1
|
||||
# Set this one for PDF generation *only*:
|
||||
# default pnd graphics are awful in PDF form,
|
||||
# better use SVG's instead:
|
||||
<format>pdf:<xsl:param>admon.graphics.extension=".svg"
|
||||
<format>pdf:<xsl:param>admon.graphics.path=$(boost-images)/
|
||||
<format>pdf:<xsl:param>boost.url.prefix=http://www.boost.org/doc/libs/release/libs/utility/doc/html
|
||||
;
|
||||
|
||||
using quickbook ;
|
||||
project boost/libs/utility/doc ;
|
||||
|
||||
path-constant INCLUDES : ../include ;
|
||||
path-constant boost-images : ../../../doc/src/images ;
|
||||
|
||||
xml base_from_member : base_from_member.qbk ;
|
||||
boostbook standalone_base_from_member
|
||||
# Generate XML doxygen reference for base_from_member component in base_from_member_reference.xml
|
||||
doxygen base_from_member_reference
|
||||
:
|
||||
$(INCLUDES)/boost/utility/base_from_member.hpp
|
||||
:
|
||||
<location>tmp
|
||||
<doxygen:param>ENABLE_PREPROCESSING=YES
|
||||
<doxygen:param>EXPAND_ONLY_PREDEF=YES
|
||||
<doxygen:param>EXTRACT_ALL=NO
|
||||
<doxygen:param>EXTRACT_PRIVATE=NO
|
||||
<doxygen:param>HIDE_UNDOC_MEMBERS=YES
|
||||
<doxygen:param>MACRO_EXPANSION=YES
|
||||
<doxygen:param>"PREDEFINED= \\
|
||||
BOOST_UTILITY_DOCS \\
|
||||
BOOST_SYMBOL_VISIBLE= \\
|
||||
BOOST_FORCEINLINE=inline \\
|
||||
BOOST_GPU_ENABLED= \\
|
||||
BOOST_STATIC_ASSERT(x)= \\
|
||||
BOOST_STATIC_ASSERT_MSG(x,y)= \\
|
||||
BOOST_STATIC_CONSTANT(x,y)=\"static constexpr x y\" \\
|
||||
BOOST_RV_REF(x)=\"x&&\" \\
|
||||
BOOST_NESTED_TEMPLATE=template \\
|
||||
BOOST_CONSTEXPR=constexpr \\
|
||||
BOOST_CXX14_CONSTEXPR=constexpr \\
|
||||
BOOST_OPERATORS_CONSTEXPR=constexpr \\
|
||||
BOOST_CONSTEXPR_OR_CONST=constexpr \\
|
||||
BOOST_NOEXCEPT=noexcept \\
|
||||
BOOST_NOEXCEPT_IF(x)=noexcept(x) \\
|
||||
BOOST_NOEXCEPT_EXPR(x)=noexcept(x) \\
|
||||
BOOST_NOEXCEPT_OR_NOTHROW=noexcept \\
|
||||
BOOST_COPY_ASSIGN_REF(x)=\"x const&\" \\
|
||||
BOOST_DEFAULTED_FUNCTION(x,y)=\"x = default;\" \\
|
||||
BOOST_DELETED_FUNCTION(x)=\"x = delete;\" \\
|
||||
BOOST_EXPLICIT_OPERATOR_BOOL()=\"explicit operator bool() const;\" \\
|
||||
BOOST_REF_CONST=const"
|
||||
<doxygen:param>"EXCLUDE_SYMBOLS= \\
|
||||
detail \\
|
||||
F \\
|
||||
result_of_has_result_type_impl \\
|
||||
conditional \\
|
||||
boost::operators_impl"
|
||||
<xsl:param>"boost.doxygen.reftitle=Reference"
|
||||
<xsl:param>"boost.doxygen.refid=base_from_member.reference"
|
||||
;
|
||||
|
||||
# Generate XML doxygen reference for boost_binary component in boost_binary_reference.xml
|
||||
doxygen boost_binary_reference
|
||||
:
|
||||
$(INCLUDES)/boost/utility/binary.hpp
|
||||
:
|
||||
<location>tmp
|
||||
<doxygen:param>ENABLE_PREPROCESSING=YES
|
||||
<doxygen:param>EXPAND_ONLY_PREDEF=YES
|
||||
<doxygen:param>EXTRACT_ALL=NO
|
||||
<doxygen:param>EXTRACT_PRIVATE=NO
|
||||
<doxygen:param>HIDE_UNDOC_MEMBERS=YES
|
||||
<doxygen:param>MACRO_EXPANSION=YES
|
||||
<doxygen:param>"PREDEFINED= \\
|
||||
BOOST_UTILITY_DOCS \\
|
||||
BOOST_SYMBOL_VISIBLE= \\
|
||||
BOOST_FORCEINLINE=inline \\
|
||||
BOOST_GPU_ENABLED= \\
|
||||
BOOST_STATIC_ASSERT(x)= \\
|
||||
BOOST_STATIC_ASSERT_MSG(x,y)= \\
|
||||
BOOST_STATIC_CONSTANT(x,y)=\"static constexpr x y\" \\
|
||||
BOOST_RV_REF(x)=\"x&&\" \\
|
||||
BOOST_NESTED_TEMPLATE=template \\
|
||||
BOOST_CONSTEXPR=constexpr \\
|
||||
BOOST_CXX14_CONSTEXPR=constexpr \\
|
||||
BOOST_OPERATORS_CONSTEXPR=constexpr \\
|
||||
BOOST_CONSTEXPR_OR_CONST=constexpr \\
|
||||
BOOST_NOEXCEPT=noexcept \\
|
||||
BOOST_NOEXCEPT_IF(x)=noexcept(x) \\
|
||||
BOOST_NOEXCEPT_EXPR(x)=noexcept(x) \\
|
||||
BOOST_NOEXCEPT_OR_NOTHROW=noexcept \\
|
||||
BOOST_COPY_ASSIGN_REF(x)=\"x const&\" \\
|
||||
BOOST_DEFAULTED_FUNCTION(x,y)=\"x = default;\" \\
|
||||
BOOST_DELETED_FUNCTION(x)=\"x = delete;\" \\
|
||||
BOOST_EXPLICIT_OPERATOR_BOOL()=\"explicit operator bool() const;\" \\
|
||||
BOOST_REF_CONST=const"
|
||||
<doxygen:param>"EXCLUDE_SYMBOLS= \\
|
||||
detail \\
|
||||
F \\
|
||||
result_of_has_result_type_impl \\
|
||||
conditional \\
|
||||
boost::operators_impl"
|
||||
<xsl:param>"boost.doxygen.reftitle=Reference"
|
||||
<xsl:param>"boost.doxygen.refid=boost_binary.reference"
|
||||
;
|
||||
|
||||
# Generate XML doxygen reference for call_traits component in call_traits_reference.xml
|
||||
doxygen call_traits_reference
|
||||
:
|
||||
$(INCLUDES)/boost/call_traits.hpp
|
||||
$(INCLUDES)/boost/detail/call_traits.hpp
|
||||
:
|
||||
<location>tmp
|
||||
<doxygen:param>ENABLE_PREPROCESSING=YES
|
||||
<doxygen:param>EXPAND_ONLY_PREDEF=YES
|
||||
<doxygen:param>EXTRACT_ALL=NO
|
||||
<doxygen:param>EXTRACT_PRIVATE=NO
|
||||
<doxygen:param>HIDE_UNDOC_MEMBERS=YES
|
||||
<doxygen:param>MACRO_EXPANSION=YES
|
||||
<doxygen:param>"PREDEFINED= \\
|
||||
BOOST_UTILITY_DOCS \\
|
||||
BOOST_SYMBOL_VISIBLE= \\
|
||||
BOOST_FORCEINLINE=inline \\
|
||||
BOOST_GPU_ENABLED= \\
|
||||
BOOST_STATIC_ASSERT(x)= \\
|
||||
BOOST_STATIC_ASSERT_MSG(x,y)= \\
|
||||
BOOST_STATIC_CONSTANT(x,y)=\"static constexpr x y\" \\
|
||||
BOOST_RV_REF(x)=\"x&&\" \\
|
||||
BOOST_NESTED_TEMPLATE=template \\
|
||||
BOOST_CONSTEXPR=constexpr \\
|
||||
BOOST_CXX14_CONSTEXPR=constexpr \\
|
||||
BOOST_OPERATORS_CONSTEXPR=constexpr \\
|
||||
BOOST_CONSTEXPR_OR_CONST=constexpr \\
|
||||
BOOST_NOEXCEPT=noexcept \\
|
||||
BOOST_NOEXCEPT_IF(x)=noexcept(x) \\
|
||||
BOOST_NOEXCEPT_EXPR(x)=noexcept(x) \\
|
||||
BOOST_NOEXCEPT_OR_NOTHROW=noexcept \\
|
||||
BOOST_COPY_ASSIGN_REF(x)=\"x const&\" \\
|
||||
BOOST_DEFAULTED_FUNCTION(x,y)=\"x = default;\" \\
|
||||
BOOST_DELETED_FUNCTION(x)=\"x = delete;\" \\
|
||||
BOOST_EXPLICIT_OPERATOR_BOOL()=\"explicit operator bool() const;\" \\
|
||||
BOOST_REF_CONST=const"
|
||||
<doxygen:param>"EXCLUDE_SYMBOLS= \\
|
||||
detail \\
|
||||
F \\
|
||||
result_of_has_result_type_impl \\
|
||||
conditional \\
|
||||
boost::operators_impl"
|
||||
<xsl:param>"boost.doxygen.reftitle=Reference"
|
||||
<xsl:param>"boost.doxygen.refid=call_traits.reference"
|
||||
;
|
||||
|
||||
# Generate XML doxygen reference for compressed_pair component in compressed_pair_reference.xml
|
||||
doxygen compressed_pair_reference
|
||||
:
|
||||
$(INCLUDES)/boost/compressed_pair.hpp
|
||||
$(INCLUDES)/boost/detail/compressed_pair.hpp
|
||||
:
|
||||
<location>tmp
|
||||
<doxygen:param>ENABLE_PREPROCESSING=YES
|
||||
<doxygen:param>EXPAND_ONLY_PREDEF=YES
|
||||
<doxygen:param>EXTRACT_ALL=NO
|
||||
<doxygen:param>EXTRACT_PRIVATE=NO
|
||||
<doxygen:param>HIDE_UNDOC_MEMBERS=YES
|
||||
<doxygen:param>MACRO_EXPANSION=YES
|
||||
<doxygen:param>"PREDEFINED= \\
|
||||
BOOST_UTILITY_DOCS \\
|
||||
BOOST_SYMBOL_VISIBLE= \\
|
||||
BOOST_FORCEINLINE=inline \\
|
||||
BOOST_GPU_ENABLED= \\
|
||||
BOOST_STATIC_ASSERT(x)= \\
|
||||
BOOST_STATIC_ASSERT_MSG(x,y)= \\
|
||||
BOOST_STATIC_CONSTANT(x,y)=\"static constexpr x y\" \\
|
||||
BOOST_RV_REF(x)=\"x&&\" \\
|
||||
BOOST_NESTED_TEMPLATE=template \\
|
||||
BOOST_CONSTEXPR=constexpr \\
|
||||
BOOST_CXX14_CONSTEXPR=constexpr \\
|
||||
BOOST_OPERATORS_CONSTEXPR=constexpr \\
|
||||
BOOST_CONSTEXPR_OR_CONST=constexpr \\
|
||||
BOOST_NOEXCEPT=noexcept \\
|
||||
BOOST_NOEXCEPT_IF(x)=noexcept(x) \\
|
||||
BOOST_NOEXCEPT_EXPR(x)=noexcept(x) \\
|
||||
BOOST_NOEXCEPT_OR_NOTHROW=noexcept \\
|
||||
BOOST_COPY_ASSIGN_REF(x)=\"x const&\" \\
|
||||
BOOST_DEFAULTED_FUNCTION(x,y)=\"x = default;\" \\
|
||||
BOOST_DELETED_FUNCTION(x)=\"x = delete;\" \\
|
||||
BOOST_EXPLICIT_OPERATOR_BOOL()=\"explicit operator bool() const;\" \\
|
||||
BOOST_REF_CONST=const"
|
||||
<doxygen:param>"EXCLUDE_SYMBOLS= \\
|
||||
detail \\
|
||||
F \\
|
||||
result_of_has_result_type_impl \\
|
||||
conditional \\
|
||||
boost::operators_impl"
|
||||
<xsl:param>"boost.doxygen.reftitle=Reference"
|
||||
<xsl:param>"boost.doxygen.refid=compressed_pair.reference"
|
||||
;
|
||||
|
||||
# Generate XML doxygen reference for in_place_factory component in in_place_factory_reference.xml
|
||||
doxygen in_place_factory_reference
|
||||
:
|
||||
$(INCLUDES)/boost/utility/in_place_factory.hpp
|
||||
$(INCLUDES)/boost/utility/typed_in_place_factory.hpp
|
||||
:
|
||||
<location>tmp
|
||||
<doxygen:param>ENABLE_PREPROCESSING=YES
|
||||
<doxygen:param>EXPAND_ONLY_PREDEF=YES
|
||||
<doxygen:param>EXTRACT_ALL=NO
|
||||
<doxygen:param>EXTRACT_PRIVATE=NO
|
||||
<doxygen:param>HIDE_UNDOC_MEMBERS=YES
|
||||
<doxygen:param>MACRO_EXPANSION=YES
|
||||
<doxygen:param>"PREDEFINED= \\
|
||||
BOOST_UTILITY_DOCS \\
|
||||
BOOST_SYMBOL_VISIBLE= \\
|
||||
BOOST_FORCEINLINE=inline \\
|
||||
BOOST_GPU_ENABLED= \\
|
||||
BOOST_STATIC_ASSERT(x)= \\
|
||||
BOOST_STATIC_ASSERT_MSG(x,y)= \\
|
||||
BOOST_STATIC_CONSTANT(x,y)=\"static constexpr x y\" \\
|
||||
BOOST_RV_REF(x)=\"x&&\" \\
|
||||
BOOST_NESTED_TEMPLATE=template \\
|
||||
BOOST_CONSTEXPR=constexpr \\
|
||||
BOOST_CXX14_CONSTEXPR=constexpr \\
|
||||
BOOST_OPERATORS_CONSTEXPR=constexpr \\
|
||||
BOOST_CONSTEXPR_OR_CONST=constexpr \\
|
||||
BOOST_NOEXCEPT=noexcept \\
|
||||
BOOST_NOEXCEPT_IF(x)=noexcept(x) \\
|
||||
BOOST_NOEXCEPT_EXPR(x)=noexcept(x) \\
|
||||
BOOST_NOEXCEPT_OR_NOTHROW=noexcept \\
|
||||
BOOST_COPY_ASSIGN_REF(x)=\"x const&\" \\
|
||||
BOOST_DEFAULTED_FUNCTION(x,y)=\"x = default;\" \\
|
||||
BOOST_DELETED_FUNCTION(x)=\"x = delete;\" \\
|
||||
BOOST_EXPLICIT_OPERATOR_BOOL()=\"explicit operator bool() const;\" \\
|
||||
BOOST_REF_CONST=const"
|
||||
<doxygen:param>"EXCLUDE_SYMBOLS= \\
|
||||
detail \\
|
||||
F \\
|
||||
result_of_has_result_type_impl \\
|
||||
conditional \\
|
||||
boost::operators_impl"
|
||||
<xsl:param>"boost.doxygen.reftitle=Reference"
|
||||
<xsl:param>"boost.doxygen.refid=in_place_factory.reference"
|
||||
;
|
||||
|
||||
# Generate XML doxygen reference for operators component in operators_reference.xml
|
||||
# we skip operators_reference because operators.hpp is not adapted for doxygen
|
||||
|
||||
# Generate XML doxygen reference for result_of component in result_of_reference.xml
|
||||
doxygen result_of_reference
|
||||
:
|
||||
$(INCLUDES)/boost/utility/result_of.hpp
|
||||
:
|
||||
<location>tmp
|
||||
<doxygen:param>ENABLE_PREPROCESSING=YES
|
||||
<doxygen:param>EXPAND_ONLY_PREDEF=YES
|
||||
<doxygen:param>EXTRACT_ALL=NO
|
||||
<doxygen:param>EXTRACT_PRIVATE=NO
|
||||
<doxygen:param>HIDE_UNDOC_MEMBERS=YES
|
||||
<doxygen:param>MACRO_EXPANSION=YES
|
||||
<doxygen:param>"PREDEFINED= \\
|
||||
BOOST_UTILITY_DOCS \\
|
||||
BOOST_SYMBOL_VISIBLE= \\
|
||||
BOOST_FORCEINLINE=inline \\
|
||||
BOOST_GPU_ENABLED= \\
|
||||
BOOST_STATIC_ASSERT(x)= \\
|
||||
BOOST_STATIC_ASSERT_MSG(x,y)= \\
|
||||
BOOST_STATIC_CONSTANT(x,y)=\"static constexpr x y\" \\
|
||||
BOOST_RV_REF(x)=\"x&&\" \\
|
||||
BOOST_NESTED_TEMPLATE=template \\
|
||||
BOOST_CONSTEXPR=constexpr \\
|
||||
BOOST_CXX14_CONSTEXPR=constexpr \\
|
||||
BOOST_OPERATORS_CONSTEXPR=constexpr \\
|
||||
BOOST_CONSTEXPR_OR_CONST=constexpr \\
|
||||
BOOST_NOEXCEPT=noexcept \\
|
||||
BOOST_NOEXCEPT_IF(x)=noexcept(x) \\
|
||||
BOOST_NOEXCEPT_EXPR(x)=noexcept(x) \\
|
||||
BOOST_NOEXCEPT_OR_NOTHROW=noexcept \\
|
||||
BOOST_COPY_ASSIGN_REF(x)=\"x const&\" \\
|
||||
BOOST_DEFAULTED_FUNCTION(x,y)=\"x = default;\" \\
|
||||
BOOST_DELETED_FUNCTION(x)=\"x = delete;\" \\
|
||||
BOOST_EXPLICIT_OPERATOR_BOOL()=\"explicit operator bool() const;\" \\
|
||||
BOOST_REF_CONST=const"
|
||||
<doxygen:param>"EXCLUDE_SYMBOLS= \\
|
||||
detail \\
|
||||
F \\
|
||||
result_of_has_result_type_impl \\
|
||||
conditional \\
|
||||
boost::operators_impl"
|
||||
<xsl:param>"boost.doxygen.reftitle=Reference"
|
||||
<xsl:param>"boost.doxygen.refid=result_of.reference"
|
||||
;
|
||||
|
||||
# Generate XML doxygen reference for string_view component in string_view_reference.xml
|
||||
doxygen string_view_reference
|
||||
:
|
||||
$(INCLUDES)/boost/utility/string_view.hpp
|
||||
$(INCLUDES)/boost/utility/string_ref.hpp
|
||||
:
|
||||
<location>tmp
|
||||
<doxygen:param>ENABLE_PREPROCESSING=YES
|
||||
<doxygen:param>EXPAND_ONLY_PREDEF=YES
|
||||
<doxygen:param>EXTRACT_ALL=NO
|
||||
<doxygen:param>EXTRACT_PRIVATE=NO
|
||||
<doxygen:param>HIDE_UNDOC_MEMBERS=YES
|
||||
<doxygen:param>MACRO_EXPANSION=YES
|
||||
<doxygen:param>"PREDEFINED= \\
|
||||
BOOST_UTILITY_DOCS \\
|
||||
BOOST_SYMBOL_VISIBLE= \\
|
||||
BOOST_FORCEINLINE=inline \\
|
||||
BOOST_GPU_ENABLED= \\
|
||||
BOOST_STATIC_ASSERT(x)= \\
|
||||
BOOST_STATIC_ASSERT_MSG(x,y)= \\
|
||||
BOOST_STATIC_CONSTANT(x,y)=\"static constexpr x y\" \\
|
||||
BOOST_RV_REF(x)=\"x&&\" \\
|
||||
BOOST_NESTED_TEMPLATE=template \\
|
||||
BOOST_CONSTEXPR=constexpr \\
|
||||
BOOST_CXX14_CONSTEXPR=constexpr \\
|
||||
BOOST_OPERATORS_CONSTEXPR=constexpr \\
|
||||
BOOST_CONSTEXPR_OR_CONST=constexpr \\
|
||||
BOOST_NOEXCEPT=noexcept \\
|
||||
BOOST_NOEXCEPT_IF(x)=noexcept(x) \\
|
||||
BOOST_NOEXCEPT_EXPR(x)=noexcept(x) \\
|
||||
BOOST_NOEXCEPT_OR_NOTHROW=noexcept \\
|
||||
BOOST_COPY_ASSIGN_REF(x)=\"x const&\" \\
|
||||
BOOST_DEFAULTED_FUNCTION(x,y)=\"x = default;\" \\
|
||||
BOOST_DELETED_FUNCTION(x)=\"x = delete;\" \\
|
||||
BOOST_EXPLICIT_OPERATOR_BOOL()=\"explicit operator bool() const;\" \\
|
||||
BOOST_REF_CONST=const"
|
||||
<doxygen:param>"EXCLUDE_SYMBOLS= \\
|
||||
detail \\
|
||||
F \\
|
||||
result_of_has_result_type_impl \\
|
||||
conditional \\
|
||||
boost::operators_impl"
|
||||
<xsl:param>"boost.doxygen.reftitle=Reference"
|
||||
<xsl:param>"boost.doxygen.refid=string_view.reference"
|
||||
;
|
||||
|
||||
# Generate XML doxygen reference for value_init component in value_init_reference.xml
|
||||
doxygen value_init_reference
|
||||
:
|
||||
$(INCLUDES)/boost/utility/value_init.hpp
|
||||
:
|
||||
<location>tmp
|
||||
<doxygen:param>ENABLE_PREPROCESSING=YES
|
||||
<doxygen:param>EXPAND_ONLY_PREDEF=YES
|
||||
<doxygen:param>EXTRACT_ALL=NO
|
||||
<doxygen:param>EXTRACT_PRIVATE=NO
|
||||
<doxygen:param>HIDE_UNDOC_MEMBERS=YES
|
||||
<doxygen:param>MACRO_EXPANSION=YES
|
||||
<doxygen:param>"PREDEFINED= \\
|
||||
BOOST_UTILITY_DOCS \\
|
||||
BOOST_SYMBOL_VISIBLE= \\
|
||||
BOOST_FORCEINLINE=inline \\
|
||||
BOOST_GPU_ENABLED= \\
|
||||
BOOST_STATIC_ASSERT(x)= \\
|
||||
BOOST_STATIC_ASSERT_MSG(x,y)= \\
|
||||
BOOST_STATIC_CONSTANT(x,y)=\"static constexpr x y\" \\
|
||||
BOOST_RV_REF(x)=\"x&&\" \\
|
||||
BOOST_NESTED_TEMPLATE=template \\
|
||||
BOOST_CONSTEXPR=constexpr \\
|
||||
BOOST_CXX14_CONSTEXPR=constexpr \\
|
||||
BOOST_OPERATORS_CONSTEXPR=constexpr \\
|
||||
BOOST_CONSTEXPR_OR_CONST=constexpr \\
|
||||
BOOST_NOEXCEPT=noexcept \\
|
||||
BOOST_NOEXCEPT_IF(x)=noexcept(x) \\
|
||||
BOOST_NOEXCEPT_EXPR(x)=noexcept(x) \\
|
||||
BOOST_NOEXCEPT_OR_NOTHROW=noexcept \\
|
||||
BOOST_COPY_ASSIGN_REF(x)=\"x const&\" \\
|
||||
BOOST_DEFAULTED_FUNCTION(x,y)=\"x = default;\" \\
|
||||
BOOST_DELETED_FUNCTION(x)=\"x = delete;\" \\
|
||||
BOOST_EXPLICIT_OPERATOR_BOOL()=\"explicit operator bool() const;\" \\
|
||||
BOOST_REF_CONST=const"
|
||||
<doxygen:param>"EXCLUDE_SYMBOLS= \\
|
||||
detail \\
|
||||
F \\
|
||||
result_of_has_result_type_impl \\
|
||||
conditional \\
|
||||
boost::operators_impl"
|
||||
<xsl:param>"boost.doxygen.reftitle=Reference"
|
||||
<xsl:param>"boost.doxygen.refid=value_init.reference"
|
||||
;
|
||||
|
||||
# Generate main.xml boostbook documentation from main.qbk quickbook documentation
|
||||
xml main : main.qbk ;
|
||||
|
||||
# Generate ./html documentation from main.xml boostbook documentation
|
||||
# Each doxygen reference in quickbook files with [xinclude tmp/<component>_reference.xml] becomes:
|
||||
# <xi:include href="../../../../libs/utility/doc/tmp/<component>_reference.xml"/>
|
||||
# in boostbook.
|
||||
# All of these <xi:include> commands give the reference the id "utility.reference"
|
||||
boostbook standalone_main
|
||||
:
|
||||
base_from_member
|
||||
main
|
||||
:
|
||||
<dependency>base_from_member_reference
|
||||
<dependency>boost_binary_reference
|
||||
<dependency>call_traits_reference
|
||||
<dependency>compressed_pair_reference
|
||||
<dependency>in_place_factory_reference
|
||||
<dependency>result_of_reference
|
||||
<dependency>string_view_reference
|
||||
<dependency>value_init_reference
|
||||
# File name of HTML output:
|
||||
<xsl:param>root.filename=base_from_member
|
||||
# How far down we chunk nested sections, basically all of them:
|
||||
<xsl:param>chunk.section.depth=0
|
||||
# <xsl:param>root.filename=main
|
||||
<xsl:param>boost.root=../../../..
|
||||
<format>pdf:<xsl:param>"boost.url.prefix=http://www.boost.org/doc/libs/release/libs/utility/doc/html"
|
||||
# How far down we chunk nested sections: no more than two so utility component pages include their reference
|
||||
<xsl:param>chunk.section.depth=2 # 8
|
||||
# Don't put the first section on the same page as the TOC:
|
||||
<xsl:param>chunk.first.sections=0
|
||||
# How far down sections get TOC's
|
||||
<xsl:param>toc.section.depth=1
|
||||
# Max depth in each TOC:
|
||||
<xsl:param>toc.max.depth=1
|
||||
# How far down we go with TOC's
|
||||
<xsl:param>generate.section.toc.level=1
|
||||
<xsl:param>chunk.first.sections=1 # 1
|
||||
# How far down sections get TOC: 2 so we show each Utility component in main page but no more than that
|
||||
<xsl:param>toc.section.depth=2 # 2
|
||||
# Max depth in each TOC: 2 so we show each Utility component in main page but no more than that
|
||||
<xsl:param>toc.max.depth=2 # 2
|
||||
# How far down we go with TOC's in main page: 2 so each Utility component page has 1 level TOC
|
||||
<xsl:param>generate.section.toc.level=2 # 2
|
||||
;
|
||||
|
||||
xml compressed_pair : compressed_pair.qbk ;
|
||||
boostbook standalone_compressed_pair
|
||||
:
|
||||
compressed_pair
|
||||
:
|
||||
# File name of HTML output:
|
||||
<xsl:param>root.filename=compressed_pair
|
||||
# How far down we chunk nested sections, basically all of them:
|
||||
<xsl:param>chunk.section.depth=0
|
||||
# Don't put the first section on the same page as the TOC:
|
||||
<xsl:param>chunk.first.sections=0
|
||||
# How far down sections get TOC's
|
||||
<xsl:param>toc.section.depth=1
|
||||
# Max depth in each TOC:
|
||||
<xsl:param>toc.max.depth=1
|
||||
# How far down we go with TOC's
|
||||
<xsl:param>generate.section.toc.level=1
|
||||
;
|
||||
###############################################################################
|
||||
alias boostdoc ;
|
||||
explicit boostdoc ;
|
||||
|
||||
xml declval : declval.qbk ;
|
||||
boostbook standalone_declval
|
||||
:
|
||||
declval
|
||||
:
|
||||
# File name of HTML output:
|
||||
<xsl:param>root.filename=declval
|
||||
# How far down we chunk nested sections, basically all of them:
|
||||
<xsl:param>chunk.section.depth=0
|
||||
# Don't put the first section on the same page as the TOC:
|
||||
<xsl:param>chunk.first.sections=0
|
||||
# How far down sections get TOC's
|
||||
<xsl:param>toc.section.depth=1
|
||||
# Max depth in each TOC:
|
||||
<xsl:param>toc.max.depth=1
|
||||
# How far down we go with TOC's
|
||||
<xsl:param>generate.section.toc.level=1
|
||||
;
|
||||
|
||||
xml string_ref : string_ref.qbk ;
|
||||
boostbook standalone_string_ref
|
||||
:
|
||||
string_ref
|
||||
:
|
||||
# File name of HTML output:
|
||||
<xsl:param>root.filename=string_ref
|
||||
# How far down we chunk nested sections, basically all of them:
|
||||
<xsl:param>chunk.section.depth=0
|
||||
# Don't put the first section on the same page as the TOC:
|
||||
<xsl:param>chunk.first.sections=0
|
||||
# How far down sections get TOC's
|
||||
<xsl:param>toc.section.depth=1
|
||||
# Max depth in each TOC:
|
||||
<xsl:param>toc.max.depth=1
|
||||
# How far down we go with TOC's
|
||||
<xsl:param>generate.section.toc.level=1
|
||||
;
|
||||
alias boostrelease : standalone_main ;
|
||||
explicit boostrelease ;
|
||||
|
@ -1,5 +1,6 @@
|
||||
[/
|
||||
Copyright 2001, 2003, 2004, 2012 Daryle Walker.
|
||||
Copyright (c) 2021, Alan Freitas
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
|
||||
@ -7,48 +8,43 @@
|
||||
or copy at http://boost.org/LICENSE_1_0.txt
|
||||
]
|
||||
|
||||
[article Base_From_Member
|
||||
[quickbook 1.5]
|
||||
[authors [Walker, Daryle]]
|
||||
[copyright 2001, 2003, 2004, 2012 Daryle Walker]
|
||||
[license
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
[@http://www.boost.org/LICENSE_1_0.txt])
|
||||
]
|
||||
]
|
||||
[section:base_from_member Base from Member]
|
||||
[block'''<?dbhtml stop-chunking?>''']
|
||||
|
||||
[section Rationale]
|
||||
[section Introduction]
|
||||
|
||||
The class templates __base_from_member__ support the base-from-member idiom.
|
||||
When developing a class, sometimes a base class needs to be initialized
|
||||
with a member of the current class. As a na\u00EFve example:
|
||||
|
||||
#include <streambuf> /* for std::streambuf */
|
||||
#include <ostream> /* for std::ostream */
|
||||
```
|
||||
#include <streambuf> /* for std::streambuf */
|
||||
#include <ostream> /* for std::ostream */
|
||||
|
||||
class fdoutbuf
|
||||
: public std::streambuf
|
||||
{
|
||||
public:
|
||||
explicit fdoutbuf( int fd );
|
||||
//...
|
||||
};
|
||||
class fdoutbuf
|
||||
: public __std_streambuf__
|
||||
{
|
||||
public:
|
||||
explicit fdoutbuf( int fd );
|
||||
//...
|
||||
};
|
||||
|
||||
class fdostream
|
||||
: public std::ostream
|
||||
{
|
||||
protected:
|
||||
fdoutbuf buf;
|
||||
public:
|
||||
explicit fdostream( int fd )
|
||||
: buf( fd ), std::ostream( &buf ) {}
|
||||
//...
|
||||
};
|
||||
class fdostream
|
||||
: public __std_ostream__
|
||||
{
|
||||
protected:
|
||||
fdoutbuf buf;
|
||||
public:
|
||||
explicit fdostream( int fd )
|
||||
: buf( fd ), __std_ostream__( &buf ) {}
|
||||
//...
|
||||
};
|
||||
```
|
||||
|
||||
This is undefined because C++'s initialization order mandates that the base
|
||||
class is initialized before the member it uses. [@http://www.moocat.org R.
|
||||
Samuel Klatchko] developed a way around this by using the initialization
|
||||
order in his favor. Base classes are intialized in order of declaration, so
|
||||
order in his favor. Base classes are initialized in order of declaration, so
|
||||
moving the desired member to another base class, that is initialized before
|
||||
the desired base class, can ensure proper initialization.
|
||||
|
||||
@ -58,7 +54,7 @@ A custom base class can be made for this idiom:
|
||||
#include <ostream> /* for std::ostream */
|
||||
|
||||
class fdoutbuf
|
||||
: public std::streambuf
|
||||
: public __std_streambuf__
|
||||
{
|
||||
public:
|
||||
explicit fdoutbuf( int fd );
|
||||
@ -75,10 +71,10 @@ A custom base class can be made for this idiom:
|
||||
|
||||
class fdostream
|
||||
: private fdostream_pbase
|
||||
, public std::ostream
|
||||
, public __std_ostream__
|
||||
{
|
||||
typedef fdostream_pbase pbase_type;
|
||||
typedef std::ostream base_type;
|
||||
typedef __std_ostream__ base_type;
|
||||
|
||||
public:
|
||||
explicit fdostream( int fd )
|
||||
@ -104,6 +100,7 @@ parameter, an integer, that exists solely to provide type differentiation.
|
||||
This parameter has a default value so a single use of a particular member
|
||||
type does not need to concern itself with the integer.
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Synopsis]
|
||||
@ -115,41 +112,41 @@ type does not need to concern itself with the integer.
|
||||
#endif
|
||||
|
||||
template < typename MemberType, int UniqueID = 0 >
|
||||
class boost::base_from_member
|
||||
class __base_from_member__
|
||||
{
|
||||
protected:
|
||||
MemberType member;
|
||||
|
||||
#if ``['C++11 is in use]``
|
||||
template< typename ...T >
|
||||
explicit constexpr base_from_member( T&& ...x )
|
||||
noexcept( std::is_nothrow_constructible<MemberType, T...>::value );
|
||||
explicit constexpr __base_from_member__( T&& ...x )
|
||||
noexcept( __std_is_nothrow_constructible__<MemberType, T...>::value );
|
||||
#else
|
||||
base_from_member();
|
||||
__base_from_member__();
|
||||
|
||||
template< typename T1 >
|
||||
explicit base_from_member( T1 x1 );
|
||||
explicit __base_from_member__( T1 x1 );
|
||||
|
||||
template< typename T1, typename T2 >
|
||||
base_from_member( T1 x1, T2 x2 );
|
||||
__base_from_member__( T1 x1, T2 x2 );
|
||||
|
||||
//...
|
||||
|
||||
template< typename T1, typename T2, typename T3, typename T4,
|
||||
typename T5, typename T6, typename T7, typename T8, typename T9,
|
||||
typename T10 >
|
||||
base_from_member( T1 x1, T2 x2, T3 x3, T4 x4, T5 x5, T6 x6, T7 x7,
|
||||
__base_from_member__( T1 x1, T2 x2, T3 x3, T4 x4, T5 x5, T6 x6, T7 x7,
|
||||
T8 x8, T9 x9, T10 x10 );
|
||||
#endif
|
||||
};
|
||||
|
||||
template < typename MemberType, int UniqueID >
|
||||
class base_from_member<MemberType&, UniqueID>
|
||||
class __base_from_member__<MemberType&, UniqueID>
|
||||
{
|
||||
protected:
|
||||
MemberType& member;
|
||||
|
||||
explicit constexpr base_from_member( MemberType& x )
|
||||
explicit constexpr __base_from_member__( MemberType& x )
|
||||
noexcept;
|
||||
};
|
||||
|
||||
@ -158,21 +155,21 @@ the type of the based-member. It has a last template parameter `UniqueID`,
|
||||
that is an `int`, to differentiate between multiple base classes that use
|
||||
the same based-member type. The last template parameter has a default value
|
||||
of zero if it is omitted. The class template has a protected data member
|
||||
called `member` that the derived class can use for later base classes (or
|
||||
itself).
|
||||
called `member` that the derived class can use for later base classes or
|
||||
itself.
|
||||
|
||||
If the appropriate features of C++11 are present, there will be a single
|
||||
constructor template. It implements ['perfect forwarding] to the best
|
||||
constructor call of `member` (if any). The constructor template is marked
|
||||
constructor call of `member` if any. The constructor template is marked
|
||||
both `constexpr` and `explicit`. The former will be ignored if the
|
||||
corresponding inner constructor call (of `member`) does not have the marker.
|
||||
corresponding inner constructor call of `member` does not have the marker.
|
||||
The latter binds the other way; always taking effect, even when the inner
|
||||
constructor call does not have the marker. The constructor template
|
||||
propagates the `noexcept` status of the inner constructor call. (The
|
||||
propagates the `noexcept` status of the inner constructor call. The
|
||||
constructor template has a trailing parameter with a default value that
|
||||
disables the template when its signature is too close to the signatures of
|
||||
the automatically-defined non-template copy- and/or move-constructors of
|
||||
`base_from_member`.)
|
||||
__base_from_member__.
|
||||
|
||||
On earlier-standard compilers, there is a default constructor and several
|
||||
constructor member templates. These constructor templates can take as many
|
||||
@ -197,167 +194,183 @@ constructors.) This constant is ignored when C++11 features are present.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Usage]
|
||||
[section Basic Usage]
|
||||
|
||||
With the starting example, the `fdoutbuf` sub-object needs to be
|
||||
encapsulated in a base class that is inheirited before `std::ostream`.
|
||||
encapsulated in a base class that is inherited before `__std_ostream__`.
|
||||
|
||||
#include <boost/utility/base_from_member.hpp>
|
||||
```
|
||||
#include <boost/utility/base_from_member.hpp>
|
||||
|
||||
#include <streambuf> // for std::streambuf
|
||||
#include <ostream> // for std::ostream
|
||||
#include <streambuf> // for std::streambuf
|
||||
#include <ostream> // for __std_ostream__
|
||||
|
||||
class fdoutbuf
|
||||
: public std::streambuf
|
||||
{
|
||||
public:
|
||||
explicit fdoutbuf( int fd );
|
||||
//...
|
||||
};
|
||||
class fdoutbuf
|
||||
: public __std_streambuf__
|
||||
{
|
||||
public:
|
||||
explicit fdoutbuf( int fd );
|
||||
//...
|
||||
};
|
||||
|
||||
class fdostream
|
||||
: private boost::base_from_member<fdoutbuf>
|
||||
, public std::ostream
|
||||
{
|
||||
// Helper typedef's
|
||||
typedef boost::base_from_member<fdoutbuf> pbase_type;
|
||||
typedef std::ostream base_type;
|
||||
class fdostream
|
||||
: private __boost_base_from_member__<fdoutbuf>
|
||||
, public __std_ostream__
|
||||
{
|
||||
// Helper typedef's
|
||||
typedef __boost_base_from_member__<fdoutbuf> pbase_type;
|
||||
typedef __std_ostream__ base_type;
|
||||
|
||||
public:
|
||||
explicit fdostream( int fd )
|
||||
: pbase_type( fd ), base_type( &member ){}
|
||||
//...
|
||||
};
|
||||
public:
|
||||
explicit fdostream( int fd )
|
||||
: pbase_type( fd ), base_type( &member ){}
|
||||
//...
|
||||
};
|
||||
```
|
||||
|
||||
The base-from-member idiom is an implementation detail, so it should not
|
||||
be visible to the clients (or any derived classes) of `fdostream`. Due to
|
||||
the initialization order, the `fdoutbuf` sub-object will get initialized
|
||||
before the `std::ostream` sub-object does, making the former sub-object
|
||||
before the `__std_ostream__` sub-object does, making the former sub-object
|
||||
safe to use in the latter sub-object's construction. Since the `fdoutbuf`
|
||||
sub-object of the final type is the only sub-object with the name `member`
|
||||
that name can be used unqualified within the final class.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Example]
|
||||
[section Multiple Sub-Objects]
|
||||
|
||||
The base-from-member class templates should commonly involve only one
|
||||
base-from-member sub-object, usually for attaching a stream-buffer to an
|
||||
I/O stream. The next example demonstrates how to use multiple
|
||||
base-from-member sub-objects and the resulting qualification issues.
|
||||
|
||||
#include <boost/utility/base_from_member.hpp>
|
||||
```
|
||||
#include <boost/utility/base_from_member.hpp>
|
||||
|
||||
#include <cstddef> /* for NULL */
|
||||
#include <cstddef> /* for NULL */
|
||||
|
||||
struct an_int
|
||||
{
|
||||
int y;
|
||||
struct an_int
|
||||
{
|
||||
int y;
|
||||
|
||||
an_int( float yf );
|
||||
};
|
||||
an_int( float yf );
|
||||
};
|
||||
|
||||
class switcher
|
||||
{
|
||||
public:
|
||||
switcher();
|
||||
switcher( double, int * );
|
||||
//...
|
||||
};
|
||||
class switcher
|
||||
{
|
||||
public:
|
||||
switcher();
|
||||
switcher( double, int * );
|
||||
//...
|
||||
};
|
||||
|
||||
class flow_regulator
|
||||
{
|
||||
public:
|
||||
flow_regulator( switcher &, switcher & );
|
||||
//...
|
||||
};
|
||||
class flow_regulator
|
||||
{
|
||||
public:
|
||||
flow_regulator( switcher &, switcher & );
|
||||
//...
|
||||
};
|
||||
|
||||
template < unsigned Size >
|
||||
class fan
|
||||
{
|
||||
public:
|
||||
explicit fan( switcher );
|
||||
//...
|
||||
};
|
||||
template < unsigned Size >
|
||||
class fan
|
||||
{
|
||||
public:
|
||||
explicit fan( switcher );
|
||||
//...
|
||||
};
|
||||
|
||||
class system
|
||||
: private boost::base_from_member<an_int>
|
||||
, private boost::base_from_member<switcher>
|
||||
, private boost::base_from_member<switcher, 1>
|
||||
, private boost::base_from_member<switcher, 2>
|
||||
, protected flow_regulator
|
||||
, public fan<6>
|
||||
{
|
||||
// Helper typedef's
|
||||
typedef boost::base_from_member<an_int> pbase0_type;
|
||||
typedef boost::base_from_member<switcher> pbase1_type;
|
||||
typedef boost::base_from_member<switcher, 1> pbase2_type;
|
||||
typedef boost::base_from_member<switcher, 2> pbase3_type;
|
||||
class system
|
||||
: private __boost_base_from_member__<an_int>
|
||||
, private __boost_base_from_member__<switcher>
|
||||
, private __boost_base_from_member__<switcher, 1>
|
||||
, private __boost_base_from_member__<switcher, 2>
|
||||
, protected flow_regulator
|
||||
, public fan<6>
|
||||
{
|
||||
// Helper typedef's
|
||||
typedef __boost_base_from_member__<an_int> pbase0_type;
|
||||
typedef __boost_base_from_member__<switcher> pbase1_type;
|
||||
typedef __boost_base_from_member__<switcher, 1> pbase2_type;
|
||||
typedef __boost_base_from_member__<switcher, 2> pbase3_type;
|
||||
|
||||
typedef flow_regulator base1_type;
|
||||
typedef fan<6> base2_type;
|
||||
typedef flow_regulator base1_type;
|
||||
typedef fan<6> base2_type;
|
||||
|
||||
public:
|
||||
system( double x );
|
||||
//...
|
||||
};
|
||||
public:
|
||||
system( double x );
|
||||
//...
|
||||
};
|
||||
|
||||
system::system( double x )
|
||||
: pbase0_type( 0.2 )
|
||||
, pbase1_type()
|
||||
, pbase2_type( -16, &this->pbase0_type::member.y )
|
||||
, pbase3_type( x, static_cast<int *>(NULL) )
|
||||
, base1_type( pbase3_type::member, pbase1_type::member )
|
||||
, base2_type( pbase2_type::member )
|
||||
{
|
||||
//...
|
||||
}
|
||||
system::system( double x )
|
||||
: pbase0_type( 0.2 )
|
||||
, pbase1_type()
|
||||
, pbase2_type( -16, &this->pbase0_type::member.y )
|
||||
, pbase3_type( x, static_cast<int *>(NULL) )
|
||||
, base1_type( pbase3_type::member, pbase1_type::member )
|
||||
, base2_type( pbase2_type::member )
|
||||
{
|
||||
//...
|
||||
}
|
||||
```
|
||||
|
||||
The final class has multiple sub-objects with the name `member`, so any
|
||||
use of that name needs qualification by a name of the appropriate base
|
||||
type. (Using `typedef`s ease mentioning the base types.) However, the fix
|
||||
introduces a new problem when a pointer is needed. Using the address
|
||||
operator with a sub-object qualified with its class's name results in a
|
||||
pointer-to-member (here, having a type of `an_int boost::base_from_member<
|
||||
an_int, 0> :: *`) instead of a pointer to the member (having a type of
|
||||
`an_int *`). The new problem is fixed by qualifying the sub-object with
|
||||
`this->` and is needed just for pointers, and not for references or values.
|
||||
type. Using `typedef`s ease mentioning the base types.
|
||||
|
||||
However, the fix introduces a new problem when a pointer is needed. Using the
|
||||
address operator with a sub-object qualified with its class's name results in a
|
||||
pointer-to-member (here, having a type of `an_int __boost_base_from_member__<an_int, 0>::*`)
|
||||
instead of a pointer to the member (having a type of `an_int*`).
|
||||
The new problem is fixed by qualifying the sub-object with `this->` and is needed
|
||||
just for pointers, and not for references or values.
|
||||
|
||||
There are some argument conversions in the initialization. The constructor
|
||||
argument for `pbase0_type` is converted from `double` to `float`. The first
|
||||
constructor argument for `pbase2_type` is converted from `int` to `double`.
|
||||
|
||||
The second constructor argument for `pbase3_type` is a special case of
|
||||
necessary conversion; all forms of the null-pointer literal in C++ (except
|
||||
`nullptr` from C++11) also look like compile-time integral expressions, so
|
||||
C++ always interprets such code as an integer when it has overloads that can
|
||||
take either an integer or a pointer. The last conversion is necessary for the
|
||||
compiler to call a constructor form with the exact pointer type used in
|
||||
`switcher`'s constructor. (If C++11's `nullptr` is used, it still needs a
|
||||
conversion if multiple pointer types can be accepted in a constructor call
|
||||
but `std::nullptr_t` cannot.)
|
||||
take either an integer or a pointer.
|
||||
|
||||
The last conversion is necessary for the compiler to call a constructor form
|
||||
with the exact pointer type used in `switcher`'s constructor. (If C++11's
|
||||
__nullptr__ is used, it still needs a conversion if multiple pointer types can
|
||||
be accepted in a constructor call but `__std_nullptr_t__` cannot.)
|
||||
|
||||
[endsect]
|
||||
|
||||
[/===============]
|
||||
[xinclude tmp/base_from_member_reference.xml]
|
||||
[/===============]
|
||||
|
||||
[section Acknowledgments]
|
||||
|
||||
Author: Walker, Daryle
|
||||
|
||||
Copyright 2001, 2003, 2004, 2012 Daryle Walker
|
||||
|
||||
* [@http://www.boost.org/people/ed_brey.htm Ed Brey] suggested some interface
|
||||
changes.
|
||||
changes.
|
||||
|
||||
* [@http://www.moocat.org R. Samuel Klatchko] ([@mailto:rsk@moocat.org
|
||||
rsk@moocat.org], [@mailto:rsk@brightmail.com rsk@brightmail.com]) invented
|
||||
the idiom of how to use a class member for initializing a base class.
|
||||
rsk@moocat.org], [@mailto:rsk@brightmail.com rsk@brightmail.com]) invented
|
||||
the idiom of how to use a class member for initializing a base class.
|
||||
|
||||
* [@http://www.boost.org/people/dietmar_kuehl.htm Dietmar Kuehl] popularized the
|
||||
base-from-member idiom in his [@http://www.informatik.uni-konstanz.de/~kuehl/c++/iostream/
|
||||
base-from-member idiom in his [@http://www.informatik.uni-konstanz.de/~kuehl/c++/iostream/
|
||||
IOStream example classes].
|
||||
|
||||
* Jonathan Turkanis supplied an implementation of generating the constructor
|
||||
templates that can be controlled and automated with macros. The
|
||||
implementation uses the [@../../../preprocessor/index.html Preprocessor library].
|
||||
templates that can be controlled and automated with macros. The
|
||||
implementation uses the [@boost:/libs/preprocessor/index.html Preprocessor library].
|
||||
|
||||
* [@http://www.boost.org/people/daryle_walker.html">Daryle Walker] started the
|
||||
library. Contributed the test file [@../../base_from_member_test.cpp
|
||||
base_from_member_test.cpp].
|
||||
library. Contributed the test file [@../../../test/base_from_member_test.cpp
|
||||
base_from_member_test.cpp].
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
|
439
doc/call_traits.qbk
Normal file
439
doc/call_traits.qbk
Normal file
@ -0,0 +1,439 @@
|
||||
[/
|
||||
/ Copyright (c) 2012 Marshall Clow
|
||||
/ Copyright (c) 2021, Alan Freitas
|
||||
/
|
||||
/ Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
/ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
/]
|
||||
|
||||
[/===============]
|
||||
[section:call_traits Call Traits]
|
||||
[/===============]
|
||||
|
||||
[section Introduction]
|
||||
|
||||
All of the contents of [@../../../../boost/call_traits.hpp `<boost/call_traits.hpp>`] are
|
||||
defined inside `namespace boost`.
|
||||
|
||||
The template class __call_traits_T__ encapsulates the
|
||||
"best" method to pass a parameter of some type `T` to or
|
||||
from a function, and consists of a collection of `typedef`s defined
|
||||
as in the table below. The purpose of __call_traits__ is to ensure
|
||||
that problems like [link utility.utilities.call_traits.examples.refs "references to references"]
|
||||
never occur, and that parameters are passed in the most efficient
|
||||
manner possible, as in the [link utility.utilities.call_traits.examples examples]. In each
|
||||
case, if your existing practice is to use the type defined on the
|
||||
left, then replace it with the __call_traits__ defined type on the
|
||||
right.
|
||||
|
||||
Note that for compilers that do not support either partial
|
||||
specialization or member templates, no benefit will occur from
|
||||
using __call_traits__: the __call_traits__ defined types will always be
|
||||
the same as the existing practice in this case. In addition if
|
||||
only member templates and not partial template specialisation is
|
||||
support by the compiler (for example Visual C++ 6) then
|
||||
__call_traits__ cannot be used with array types, although it can still be
|
||||
used to solve the reference to reference problem.
|
||||
|
||||
[table __call_traits__ types
|
||||
[[Existing practice] [__call_traits__ equivalent] [Description] [Notes]]
|
||||
[
|
||||
[`T`
|
||||
|
||||
(return by value)
|
||||
]
|
||||
[
|
||||
__call_traits_T__`::value_type`
|
||||
]
|
||||
[
|
||||
Defines a type that represents the "value" of type `T`.
|
||||
|
||||
Use this for functions that return by value, or possibly for stored values of type `T`.
|
||||
]
|
||||
[2]
|
||||
]
|
||||
[
|
||||
[`T&`
|
||||
|
||||
(return value)
|
||||
]
|
||||
[
|
||||
__call_traits_T__`::reference`
|
||||
]
|
||||
[
|
||||
Defines a type that represents a reference to type `T`.
|
||||
|
||||
Use for functions that would normally return a `T&`.
|
||||
]
|
||||
[1]
|
||||
]
|
||||
[
|
||||
[`const T&`
|
||||
|
||||
(return value)
|
||||
]
|
||||
[
|
||||
__call_traits_T__`::const_reference`
|
||||
]
|
||||
[
|
||||
Defines a type that represents a constant reference to type `T`.
|
||||
|
||||
Use for functions that would normally return a `const T&`.
|
||||
]
|
||||
[1]
|
||||
]
|
||||
[
|
||||
[`const T&`
|
||||
|
||||
(function parameter)
|
||||
]
|
||||
[
|
||||
__call_traits_T__`::param_type`
|
||||
]
|
||||
[
|
||||
Defines a type that represents the "best" way to pass a parameter of type `T` to a function.
|
||||
]
|
||||
[1,3]
|
||||
]
|
||||
]
|
||||
|
||||
Notes:
|
||||
|
||||
# If `T` is already reference type, then __call_traits__ is
|
||||
defined such that [link utility.utilities.call_traits.examples.refs "references to references"]
|
||||
do not occur (requires partial specialization).
|
||||
# If `T` is an array type, then __call_traits__ defines `value_type`
|
||||
as a "constant pointer to type" rather than an
|
||||
"array of type" (requires partial specialization).
|
||||
Note that if you are using `value_type` as a stored value
|
||||
then this will result in storing a "constant pointer to
|
||||
an array" rather than the array itself. This may or may
|
||||
not be a good thing depending upon what you actually
|
||||
need (in other words take care!).
|
||||
# If `T` is a small built in type or a pointer, then `param_type`
|
||||
is defined as `T const`, instead of `T const&`. This can
|
||||
improve the ability of the compiler to optimize loops in
|
||||
the body of the function if they depend upon the passed
|
||||
parameter, the semantics of the passed parameter is
|
||||
otherwise unchanged (requires partial specialization).
|
||||
|
||||
|
||||
[endsect]
|
||||
[section Copy constructibility]
|
||||
|
||||
The following table defines which __call_traits__ types can always
|
||||
be copy-constructed from which other types:
|
||||
|
||||
[table Which __call_traits__ types can always be copy-constructed from which other types
|
||||
[[] [To `T`] [To `value_type`] [To `reference`] [To `const_reference`] [To `param_type`]]
|
||||
[[From `T`] [iff `T` is copy constructible] [iff `T` is copy constructible] [Yes] [Yes] [Yes]]
|
||||
[[From `value_type`] [iff `T` is copy constructible] [iff `T` is copy constructible] [No] [No] [Yes]]
|
||||
[[From `reference`] [iff `T` is copy constructible] [iff `T` is copy constructible] [Yes] [Yes] [Yes]]
|
||||
[[From `const_reference`] [iff `T` is copy constructible] [No] [No] [Yes] [Yes]]
|
||||
[[From `param_type`] [iff `T` is copy constructible] [iff `T` is copy constructible] [No] [No] [Yes]]
|
||||
]
|
||||
|
||||
If `T` is an assignable type the following assignments are possible:
|
||||
|
||||
[table Which __call_traits__ types are assignable from which other types
|
||||
[[] [To `T`] [To `value_type`] [To `reference`] [To `const_reference`] [To `param_type`]]
|
||||
[[From `T`] [Yes] [Yes] [-] [-] [-]]
|
||||
[[From `value_type`] [Yes] [Yes] [-] [-] [-]]
|
||||
[[From `reference`] [Yes] [Yes] [-] [-] [-]]
|
||||
[[From `const_reference`] [Yes] [Yes] [-] [-] [-]]
|
||||
[[From `param_type`] [Yes] [Yes] [-] [-] [-]]
|
||||
]
|
||||
[endsect]
|
||||
|
||||
[section:examples Examples]
|
||||
|
||||
The following table shows the effect that __call_traits__ has on
|
||||
various types.
|
||||
|
||||
[table Examples of __call_traits__ types
|
||||
[[] [__call_traits__::`value_type`] [__call_traits__::`reference`] [__call_traits__::`const_reference`] [__call_traits__::`param_type`] [Applies to:]]
|
||||
[[From `my_class`] [`my_class`] [`my_class&`] [`const my_class&`] [`my_class const&`] [All user-defined types]]
|
||||
[[From `int`] [`int`] [`int&`] [`const int&`] [`int const`] [All small built-in types]]
|
||||
[[From `int*`] [`int*`] [`int*&`] [`int* const &`] [`int* const`] [All pointer types]]
|
||||
[[From `int&`] [`int&`] [`int&`] [`const int&`] [`int&`] [All reference types]]
|
||||
[[From `const int&`] [`const int&`] [`const int&`] [`const int&`] [`const int&`] [All constant reference types]]
|
||||
[[From `int[3]`] [`const int*`] [`int(&)[3]`] [`const int(&)[3]`] [`const int* const`] [All array types]]
|
||||
[[From `const int[3]`] [`const int*`] [`const int(&)[3]`] [`const int(&)[3]`] [`const int* const`] [All constant array types]]
|
||||
]
|
||||
|
||||
The table assumes the compiler supports partial
|
||||
specialization: if it does not then all types behave in
|
||||
the same way as the entry for "`my_class`", and
|
||||
__call_traits__ can not be used with reference or array types.
|
||||
|
||||
[section Example 1:]
|
||||
|
||||
The following class is a trivial class that stores some type `T`
|
||||
by value (see the [@../../../test/call_traits_test.cpp `call_traits_test.cpp`]
|
||||
file). The aim is to illustrate how each of the available
|
||||
__call_traits__ `typedef`s may be used:
|
||||
|
||||
```
|
||||
template <class T>
|
||||
struct contained
|
||||
{
|
||||
// define our typedefs first, arrays are stored by value
|
||||
// so value_type is not the same as result_type:
|
||||
typedef typename __boost_call_traits__<T>::param_type param_type;
|
||||
typedef typename __boost_call_traits__<T>::reference reference;
|
||||
typedef typename __boost_call_traits__<T>::const_reference const_reference;
|
||||
typedef T value_type;
|
||||
typedef typename __boost_call_traits__<T>::value_type result_type;
|
||||
|
||||
// stored value:
|
||||
value_type v_;
|
||||
|
||||
// constructors:
|
||||
contained() {}
|
||||
contained(param_type p) : v_(p){}
|
||||
// return byval:
|
||||
result_type value() { return v_; }
|
||||
// return by_ref:
|
||||
reference get() { return v_; }
|
||||
const_reference const_get()const { return v_; }
|
||||
// pass value:
|
||||
void call(param_type p){}
|
||||
|
||||
};
|
||||
```
|
||||
[endsect]
|
||||
|
||||
[section:refs Example 2 (the reference to reference problem):]
|
||||
|
||||
Consider the definition of __std_binder1st__:
|
||||
|
||||
```
|
||||
template <class Operation>
|
||||
class binder1st :
|
||||
public __std_unary_function__<typename Operation::second_argument_type, typename Operation::result_type>
|
||||
{
|
||||
protected:
|
||||
Operation op;
|
||||
typename Operation::first_argument_type value;
|
||||
public:
|
||||
binder1st(const Operation& x, const typename Operation::first_argument_type& y);
|
||||
typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const;
|
||||
};
|
||||
```
|
||||
|
||||
Now consider what happens in the relatively common case that
|
||||
the functor takes its second argument as a reference, that
|
||||
implies that `Operation::second_argument_type` is a
|
||||
reference type, `operator()` will now end up taking a
|
||||
reference to a reference as an argument, and that is not
|
||||
currently legal. The solution here is to modify `operator()`
|
||||
to use __call_traits__:
|
||||
|
||||
```
|
||||
typename Operation::result_type operator()(typename __call_traits__<typename Operation::second_argument_type>::param_type x) const;
|
||||
```
|
||||
|
||||
Now in the case that `Operation::second_argument_type`
|
||||
is a reference type, the argument is passed as a reference, and
|
||||
the no "reference to reference" occurs.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:example3 Example 3 (the `make_pair` problem):]
|
||||
|
||||
If we pass the name of an array as one (or both) arguments to `__std_make_pair__`,
|
||||
then template argument deduction deduces the passed parameter as
|
||||
"const reference to array of `T`", this also applies to
|
||||
string literals (which are really array literals). Consequently
|
||||
instead of returning a pair of pointers, it tries to return a
|
||||
pair of arrays, and since an array type is not copy-constructible
|
||||
the code fails to compile. One solution is to explicitly cast the
|
||||
arguments to __std_make_pair__ to pointers, but __call_traits__ provides a
|
||||
better automatic solution that works safely even in generic code where the
|
||||
cast might do the wrong thing:
|
||||
|
||||
```
|
||||
template <class T1, class T2>
|
||||
__std_pair__<
|
||||
typename __boost_call_traits__<T1>::value_type,
|
||||
typename __boost_call_traits__<T2>::value_type>
|
||||
make_pair(const T1& t1, const T2& t2)
|
||||
{
|
||||
return __std_pair__<
|
||||
typename __boost_call_traits__<T1>::value_type,
|
||||
typename __boost_call_traits__<T2>::value_type>(t1, t2);
|
||||
}
|
||||
```
|
||||
|
||||
Here, the deduced argument types will be automatically
|
||||
degraded to pointers if the deduced types are arrays, similar
|
||||
situations occur in the standard binders and adapters: in
|
||||
principle in any function that "wraps" a temporary
|
||||
whose type is deduced. Note that the function arguments to
|
||||
__std_make_pair__ are not expressed in terms of __call_traits__: doing so
|
||||
would prevent template argument deduction from functioning.
|
||||
[endsect]
|
||||
|
||||
[section:example4 Example 4 (optimising fill):]
|
||||
|
||||
The __call_traits__ template will "optimize" the passing
|
||||
of a small built-in type as a function parameter. This mainly has
|
||||
an effect when the parameter is used within a loop body.
|
||||
|
||||
In the following example (see [@boost:/libs/type_traits/examples/fill_example.cpp `fill_example.cpp`]),
|
||||
a version of __std_fill__ is optimized in two ways: if the type
|
||||
passed is a single byte built-in type then __std_memset__ is used to
|
||||
effect the fill, otherwise a conventional C++ implementation is
|
||||
used, but with the passed parameter "optimized" using
|
||||
__call_traits__:
|
||||
|
||||
```
|
||||
template <bool opt>
|
||||
struct filler
|
||||
{
|
||||
template <typename I, typename T>
|
||||
static void do_fill(I first, I last, typename __boost_call_traits__<T>::param_type val)
|
||||
{
|
||||
while(first != last)
|
||||
{
|
||||
*first = val;
|
||||
++first;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct filler<true>
|
||||
{
|
||||
template <typename I, typename T>
|
||||
static void do_fill(I first, I last, T val)
|
||||
{
|
||||
__std_memset__(first, val, last-first);
|
||||
}
|
||||
};
|
||||
|
||||
template <class I, class T>
|
||||
inline void fill(I first, I last, const T& val)
|
||||
{
|
||||
enum { can_opt = boost::is_pointer<I>::value
|
||||
&& boost::is_arithmetic<T>::value
|
||||
&& (sizeof(T) == 1) };
|
||||
typedef filler<can_opt> filler_t;
|
||||
filler_t::template do_fill<I,T>(first, last, val);
|
||||
}
|
||||
```
|
||||
|
||||
The reason that this is "optimal" for small built-in types is that
|
||||
with the value passed as `T const` instead of `const T&` the compiler is
|
||||
able to tell both that the value is constant and that it is free
|
||||
of aliases. With this information the compiler is able to cache
|
||||
the passed value in a register, unroll the loop, or use
|
||||
explicitly parallel instructions: if any of these are supported.
|
||||
Exactly how much mileage you will get from this depends upon your
|
||||
compiler - we could really use some accurate benchmarking
|
||||
software as part of boost for cases like this.
|
||||
|
||||
Note that the function arguments to fill are not expressed in
|
||||
terms of __call_traits__: doing so would prevent template argument
|
||||
deduction from functioning. Instead fill acts as a "thin
|
||||
wrapper" that is there to perform template argument
|
||||
deduction, the compiler will optimise away the call to fill all
|
||||
together, replacing it with the call to `filler<>::do_fill`,
|
||||
which does use __call_traits__.
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
||||
[section Rationale]
|
||||
|
||||
The following notes are intended to briefly describe the
|
||||
rationale behind choices made in __call_traits__.
|
||||
|
||||
All user-defined types follow "existing practice" and need no comment.
|
||||
|
||||
Small built-in types, what the standard calls [@https://en.cppreference.com/w/cpp/language/types fundamental
|
||||
types], differ from existing practice only in the `param_type`
|
||||
`typedef`. In this case passing `T const` is compatible
|
||||
with existing practice, but may improve performance in some cases
|
||||
(see [link utility.utilities.call_traits.examples.example4 Example 4]). In any case this should never
|
||||
be any worse than existing practice.
|
||||
|
||||
Pointers follow the same rationale as small built-in types.
|
||||
|
||||
For reference types the rationale follows [link utility.utilities.call_traits.examples.refs Example 2]
|
||||
- references to references are not allowed, so the __call_traits__
|
||||
members must be defined such that these problems do
|
||||
not occur. There is a proposal to modify the language such that
|
||||
"a reference to a reference is a reference" (issue #106,
|
||||
submitted by Bjarne Stroustrup). __call_traits_T__`::value_type`
|
||||
and __call_traits_T__`::param_type` both provide the same effect
|
||||
as that proposal, without the need for a language change. In
|
||||
other words, it's a workaround.
|
||||
|
||||
For array types, a function that takes an array as an argument
|
||||
will degrade the array type to a pointer type: this means that
|
||||
the type of the actual parameter is different from its declared
|
||||
type, something that can cause endless problems in template code
|
||||
that relies on the declared type of a parameter.
|
||||
|
||||
For example:
|
||||
|
||||
```
|
||||
template <class T>
|
||||
struct A
|
||||
{
|
||||
void foo(T t);
|
||||
};
|
||||
```
|
||||
|
||||
In this case if we instantiate `A<int[2]>` then the declared type of
|
||||
the parameter passed to member function `foo` is `int[2]`, but its
|
||||
actual type is `const int*`. If we try to use the type `T` within the
|
||||
function body, then there is a strong likelihood that our code will not compile:
|
||||
|
||||
```
|
||||
template <class T>
|
||||
void A<T>::foo(T t)
|
||||
{
|
||||
T dup(t); // doesn't compile for case that T is an array.
|
||||
}
|
||||
```
|
||||
|
||||
By using __call_traits__ the degradation from array to pointer is
|
||||
explicit, and the type of the parameter is the same as it's
|
||||
declared type:
|
||||
|
||||
```
|
||||
template <class T>
|
||||
struct A
|
||||
{
|
||||
void foo(typename __call_traits__<T>::value_type t);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
void A<T>::foo(typename __call_traits__<T>::value_type t)
|
||||
{
|
||||
typename __call_traits__<T>::value_type dup(t); // OK even if T is an array type.
|
||||
}
|
||||
```
|
||||
|
||||
For `value_type` (return by value), again only a pointer may be
|
||||
returned, not a copy of the whole array, and again __call_traits__
|
||||
makes the degradation explicit. The `value_type` member is useful
|
||||
whenever an array must be explicitly degraded to a pointer -
|
||||
[link utility.utilities.call_traits.examples.example3 Example 3] provides the test case.
|
||||
|
||||
Footnote: the array specialisation for __call_traits__ is the least
|
||||
well understood of all the __call_traits__ specialisations. If the given
|
||||
semantics cause specific problems for you, or does not solve a particular
|
||||
array-related problem, then I would be interested to hear about
|
||||
it. Most people though will probably never need to use this
|
||||
specialisation.
|
||||
|
||||
[endsect]
|
||||
|
||||
[/===============]
|
||||
[xinclude tmp/call_traits_reference.xml]
|
||||
[/===============]
|
||||
|
||||
[endsect]
|
@ -1,5 +1,6 @@
|
||||
[/
|
||||
Copyright 2000 Beman Dawes & John Maddock.
|
||||
Copyright (c) 2021, Alan Freitas
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
|
||||
@ -7,80 +8,72 @@
|
||||
or copy at http://boost.org/LICENSE_1_0.txt
|
||||
]
|
||||
|
||||
[article Compressed_Pair
|
||||
[quickbook 1.5]
|
||||
[authors [Cleary, Steve]]
|
||||
[authors [Dawes, Beman]]
|
||||
[authors [Hinnant, Howard]]
|
||||
[authors [Maddock, John]]
|
||||
[copyright 2000 Steve Cleary, Beman Dawes, Howard Hinnant & John Maddock]
|
||||
[license
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
[@http://www.boost.org/LICENSE_1_0.txt])
|
||||
]
|
||||
]
|
||||
[section:compressed_pair Compressed Pair]
|
||||
|
||||
[section Overview]
|
||||
[section Introduction]
|
||||
|
||||
All of the contents of `<boost/compressed_pair.hpp>` are defined inside
|
||||
All of the contents of [@../../../../boost/compressed_pair.hpp `<boost/compressed_pair.hpp>`] are defined inside
|
||||
`namespace boost`.
|
||||
|
||||
The class `compressed_pair` is very similar to `std::pair`, but if either of
|
||||
the template arguments are empty classes, then the ['empty base-class
|
||||
optimisation] is applied to compress the size of the pair.
|
||||
The class __compressed_pair__ is very similar to __std_pair__. However, if either of
|
||||
the template arguments are empty classes, then the
|
||||
[@https://en.cppreference.com/w/cpp/language/ebo ['empty base-class optimisation]]
|
||||
is applied to compress the size of the pair.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Synopsis]
|
||||
|
||||
template <class T1, class T2>
|
||||
class compressed_pair
|
||||
{
|
||||
public:
|
||||
typedef T1 first_type;
|
||||
typedef T2 second_type;
|
||||
typedef typename call_traits<first_type>::param_type first_param_type;
|
||||
typedef typename call_traits<second_type>::param_type second_param_type;
|
||||
typedef typename call_traits<first_type>::reference first_reference;
|
||||
typedef typename call_traits<second_type>::reference second_reference;
|
||||
typedef typename call_traits<first_type>::const_reference first_const_reference;
|
||||
typedef typename call_traits<second_type>::const_reference second_const_reference;
|
||||
```cpp
|
||||
template <class T1, class T2>
|
||||
class __compressed_pair__
|
||||
{
|
||||
public:
|
||||
typedef T1 first_type;
|
||||
typedef T2 second_type;
|
||||
typedef typename __call_traits__<first_type>::param_type first_param_type;
|
||||
typedef typename __call_traits__<second_type>::param_type second_param_type;
|
||||
typedef typename __call_traits__<first_type>::reference first_reference;
|
||||
typedef typename __call_traits__<second_type>::reference second_reference;
|
||||
typedef typename __call_traits__<first_type>::const_reference first_const_reference;
|
||||
typedef typename __call_traits__<second_type>::const_reference second_const_reference;
|
||||
|
||||
compressed_pair() : base() {}
|
||||
compressed_pair(first_param_type x, second_param_type y);
|
||||
explicit compressed_pair(first_param_type x);
|
||||
explicit compressed_pair(second_param_type y);
|
||||
compressed_pair() : base() {}
|
||||
compressed_pair(first_param_type x, second_param_type y);
|
||||
explicit compressed_pair(first_param_type x);
|
||||
explicit compressed_pair(second_param_type y);
|
||||
|
||||
compressed_pair& operator=(const compressed_pair&);
|
||||
compressed_pair& operator=(const compressed_pair&);
|
||||
|
||||
first_reference first();
|
||||
first_const_reference first() const;
|
||||
first_reference first();
|
||||
first_const_reference first() const;
|
||||
|
||||
second_reference second();
|
||||
second_const_reference second() const;
|
||||
second_reference second();
|
||||
second_const_reference second() const;
|
||||
|
||||
void swap(compressed_pair& y);
|
||||
};
|
||||
void swap(compressed_pair& y);
|
||||
};
|
||||
```
|
||||
|
||||
The two members of the pair can be accessed using the member functions
|
||||
`first()` and `second()`. Note that not all member functions can be
|
||||
instantiated for all template parameter types. In particular
|
||||
`compressed_pair` can be instantiated for reference and array types,
|
||||
however in these cases the range of constructors that can be used are
|
||||
__compressed_pair__ can be instantiated for reference and array types,
|
||||
however in these cases the range of constructors that can be used is
|
||||
limited. If types `T1` and `T2` are the same type, then there is only
|
||||
one version of the single-argument constructor, and this constructor
|
||||
initialises both values in the pair to the passed value.
|
||||
|
||||
Note that if either member is a POD type, then that member is not
|
||||
zero-initialized by the `compressed_pair` default constructor: it's up
|
||||
to you to supply an initial value for these types if you want them to have
|
||||
Note that if either member is a [@https://en.cppreference.com/w/cpp/named_req/PODType POD]
|
||||
type, then that member is not zero-initialized by the __compressed_pair__ default constructor:
|
||||
it is up to you to supply an initial value for these types if you want them to have
|
||||
a default value.
|
||||
|
||||
Note that `compressed_pair` can not be instantiated if either of the
|
||||
Note that __compressed_pair__ can not be instantiated if either of the
|
||||
template arguments is a union type, unless there is compiler support for
|
||||
`boost::is_union`, or if `boost::is_union` is specialised for the union
|
||||
type.
|
||||
[@boost:/libs/type_traits/index.html `boost::is_union`], or
|
||||
if [@boost:/libs/type_traits/index.html `boost::is_union`] is
|
||||
specialised for the union type.
|
||||
|
||||
Finally, a word of caution for Visual C++ 6 users: if either argument is an
|
||||
empty type, then assigning to that member will produce memory corruption,
|
||||
@ -89,6 +82,10 @@ is due to a bug in the way VC6 generates implicit assignment operators.
|
||||
|
||||
[endsect]
|
||||
|
||||
[/===============]
|
||||
[xinclude tmp/compressed_pair_reference.xml]
|
||||
[/===============]
|
||||
|
||||
[section Acknowledgments]
|
||||
|
||||
Based on contributions by Steve Cleary, Beman Dawes, Howard Hinnant and
|
||||
@ -97,3 +94,5 @@ John Maddock.
|
||||
Maintained by [@mailto:john@johnmaddock.co.uk John Maddock].
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
|
114
doc/declval.qbk
114
doc/declval.qbk
@ -1,114 +0,0 @@
|
||||
[/
|
||||
/ Copyright (c) 2008 Howard Hinnant
|
||||
/ Copyright (c) 2009-20012 Vicente J. Botet Escriba
|
||||
/
|
||||
/ Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
/ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
/]
|
||||
|
||||
[article Declval
|
||||
[quickbook 1.5]
|
||||
[authors [Hinnant, Howard]]
|
||||
[authors [Botet Escriba, Vicente J.]]
|
||||
[copyright 2008 Howard Hinnant]
|
||||
[copyright 2009-2012 Vicente J. Botet Escriba]
|
||||
[license
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
[@http://www.boost.org/LICENSE_1_0.txt])
|
||||
]
|
||||
]
|
||||
|
||||
[/===============]
|
||||
[section Overview]
|
||||
[/===============]
|
||||
|
||||
The motivation for `declval` was introduced in [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2958.html#Value N2958:
|
||||
Moving Swap Forward]. Here follows a rewording of this chapter.
|
||||
|
||||
With the provision of decltype, late-specified return types, and default template-arguments for function templates a
|
||||
new generation of SFINAE patterns will emerge to at least partially compensate the lack of concepts on the C++0x timescale.
|
||||
Using this technique, it is sometimes necessary to obtain an object of a known type in a non-using context, e.g. given the declaration
|
||||
|
||||
template<class T>
|
||||
T&& declval(); // not used
|
||||
|
||||
as part of the function template declaration
|
||||
|
||||
template<class To, class From>
|
||||
decltype(static_cast<To>(declval<From>())) convert(From&&);
|
||||
|
||||
or as part of a class template definition
|
||||
|
||||
template<class> class result_of;
|
||||
|
||||
template<class Fn, class... ArgTypes>
|
||||
struct result_of<Fn(ArgTypes...)>
|
||||
{
|
||||
typedef decltype(declval<Fn>()(declval<ArgTypes>()...)) type;
|
||||
};
|
||||
|
||||
The role of the function template declval() is a transformation of a type T into a value without using or evaluating this function.
|
||||
The name is supposed to direct the reader's attention to the fact that the expression `declval<T>()` is an lvalue if and only if
|
||||
T is an lvalue-reference, otherwise an rvalue. To extend the domain of this function we can do a bit better by changing its declaration to
|
||||
|
||||
template<class T>
|
||||
typename std::add_rvalue_reference<T>::type declval(); // not used
|
||||
|
||||
which ensures that we can also use cv void as template parameter. The careful reader might have noticed that `declval()`
|
||||
already exists under the name create() as part of the definition of the semantics of the type trait is_convertible in the C++0x standard.
|
||||
|
||||
The provision of a new library component that allows the production of values in unevaluated expressions is considered
|
||||
important to realize constrained templates in C++0x where concepts are not available.
|
||||
This extremely light-weight function is expected to be part of the daily tool-box of the C++0x programmer.
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[/=================]
|
||||
[section:reference Reference ]
|
||||
[/=================]
|
||||
|
||||
`#include <boost/utility/declval.hpp>`
|
||||
|
||||
namespace boost {
|
||||
|
||||
template <typename T>
|
||||
typename add_rvalue_reference<T>::type declval() noexcept; // as unevaluated operand
|
||||
|
||||
} // namespace boost
|
||||
|
||||
|
||||
The library provides the function template declval to simplify the definition of expressions which occur as unevaluated operands.
|
||||
|
||||
template <typename T>
|
||||
typename add_rvalue_reference<T>::type declval();
|
||||
|
||||
[*Remarks:] If this function is used, the program is ill-formed.
|
||||
|
||||
[*Remarks:] The template parameter T of declval may be an incomplete type.
|
||||
|
||||
[*Example:]
|
||||
|
||||
template <class To, class From>
|
||||
decltype(static_cast<To>(declval<From>())) convert(From&&);
|
||||
|
||||
Declares a function template convert which only participates in overloading if the type From can be explicitly converted to type To.
|
||||
|
||||
[endsect]
|
||||
|
||||
[/===============]
|
||||
[section History]
|
||||
[/===============]
|
||||
|
||||
[heading boost 1.50]
|
||||
|
||||
Fixes:
|
||||
|
||||
* [@http://svn.boost.org/trac/boost/ticket/6570 #6570] Adding noexcept to boost::declval.
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
|
||||
|
306
doc/in_place_factory.qbk
Normal file
306
doc/in_place_factory.qbk
Normal file
@ -0,0 +1,306 @@
|
||||
[/
|
||||
/ Copyright (c) 2012 Marshall Clow
|
||||
/ Copyright (c) 2021, Alan Freitas
|
||||
/
|
||||
/ Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
/ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
/]
|
||||
|
||||
[/===============]
|
||||
[section:in_place_factory In-place Factory]
|
||||
[/===============]
|
||||
|
||||
[section Introduction]
|
||||
|
||||
Suppose we have a class
|
||||
|
||||
```
|
||||
struct X
|
||||
{
|
||||
X ( int, __std_string__ ) ;
|
||||
};
|
||||
```
|
||||
|
||||
And a container for it which supports an empty state. That is, a container which can contain zero objects:
|
||||
|
||||
```
|
||||
struct C
|
||||
{
|
||||
C() : contained_(0) {}
|
||||
~C() { delete contained_ ; }
|
||||
X* contained_ ;
|
||||
};
|
||||
```
|
||||
|
||||
A container designed to support an empty state typically does not require the contained type to be
|
||||
__DefaultConstructible__, but it typically requires it to be __CopyConstructible__ as a mechanism to
|
||||
initialize the object to store:
|
||||
|
||||
```
|
||||
struct C
|
||||
{
|
||||
C() : contained_(0) {}
|
||||
C ( X const& v ) : contained_ ( new X(v) ) {}
|
||||
~C() { delete contained_ ; }
|
||||
X* contained_ ;
|
||||
};
|
||||
```
|
||||
|
||||
There is a subtle problem with this: since the mechanism used to initialize the stored object is copy construction,
|
||||
there must exist a previously constructed source object to copy from. This object is likely to be temporary and serve
|
||||
no purpose besides being the source:
|
||||
|
||||
```
|
||||
void foo()
|
||||
{
|
||||
// Temporary object created.
|
||||
C c( X(123,"hello") ) ;
|
||||
}
|
||||
```
|
||||
|
||||
A solution to this problem is to support direct construction of the contained
|
||||
object right in the container's storage.
|
||||
|
||||
In this scheme, the user supplies the arguments for the `X` constructor
|
||||
directly to the container:
|
||||
|
||||
```
|
||||
struct C
|
||||
{
|
||||
C() : contained_(0) {}
|
||||
C ( X const& v ) : contained_ ( new X(v) ) {}
|
||||
C ( int a0, __std_string__ a1 ) : contained_ ( new X(a0,a1) ) {}
|
||||
~C() { delete contained_ ; }
|
||||
X* contained_ ;
|
||||
};
|
||||
```
|
||||
|
||||
```
|
||||
void foo()
|
||||
{
|
||||
// Wrapped object constructed in-place
|
||||
// No temporary created.
|
||||
C c(123,"hello");
|
||||
}
|
||||
```
|
||||
|
||||
Clearly, this solution does not scale well since the container must duplicate all the constructor overloads
|
||||
from the contained type, or at least all those which are to be supported directly in the container.
|
||||
|
||||
[endsect]
|
||||
[section Framework]
|
||||
|
||||
This library proposes a framework to allow some containers to directly construct contained objects in-place without requiring
|
||||
the entire set of constructor overloads from the contained type. It also allows the container to remove the __CopyConstructible__
|
||||
requirement from the contained type since objects can be directly constructed in-place without need of a copy.
|
||||
|
||||
The only requirement on the container is that it must provide proper storage. That is, the container should be
|
||||
correctly aligned and sized. Naturally, the container will typically support uninitialized storage to avoid the
|
||||
in-place construction to override a fully-constructed object, as this would defeat the purpose of in-place construction.
|
||||
|
||||
For this purpose, the framework provides two concepts called: InPlaceFactories and TypedInPlaceFactories.
|
||||
Helpers to declare these classes are declared in [@../../../../boost/utility/in_place_factory.hpp `<boost/utility/in_place_factory.hpp>`]
|
||||
and [@../../../../boost/utility/typed_in_place_factory.hpp `<boost/utility/typed_in_place_factory.hpp>`].
|
||||
|
||||
Essentially, these classes hold a sequence of actual parameters and a method to construct an object in place using these parameters.
|
||||
Each member of the family differs only in the number and type of the parameter list. The first family
|
||||
takes the type of the object to construct directly in method provided for that
|
||||
purpose, whereas the second family incorporates that type in the factory class
|
||||
itself. From the container point of view, using the framework amounts to calling the
|
||||
factory's method to contruct the object in place. From the user point of view, it amounts to creating
|
||||
the right factory object to hold the parameters and pass it to the container.
|
||||
|
||||
The following simplified example shows the basic idea. A complete example follows the formal specification of the framework:
|
||||
|
||||
```
|
||||
struct C
|
||||
{
|
||||
template <class InPlaceFactory>
|
||||
C ( InPlaceFactory const& aFactory )
|
||||
:
|
||||
contained_ ( uninitialized_storage() )
|
||||
{
|
||||
aFactory.template apply<X>(contained_);
|
||||
}
|
||||
|
||||
~C()
|
||||
{
|
||||
contained_ -> X::~X();
|
||||
delete[] contained_ ;
|
||||
}
|
||||
|
||||
char* uninitialized_storage() { return new char[sizeof(X)] ; }
|
||||
|
||||
char* contained_ ;
|
||||
};
|
||||
|
||||
void foo()
|
||||
{
|
||||
C c( in_place(123,"hello") ) ;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
[endsect]
|
||||
[section Specification]
|
||||
|
||||
The following is the first member of the family of `InPlaceFactory` classes, along with its corresponding helper template function.
|
||||
The rest of the family varies only in the number and type of template and constructor parameters.
|
||||
|
||||
|
||||
```
|
||||
namespace boost {
|
||||
|
||||
struct __in_place_factory_base__ {};
|
||||
|
||||
template<class A0>
|
||||
class in_place_factory : public __in_place_factory_base__
|
||||
{
|
||||
public:
|
||||
in_place_factory ( A0 const& a0 ) : m_a0(a0) {}
|
||||
|
||||
template< class T >
|
||||
void apply ( void* address ) const
|
||||
{
|
||||
new (address) T(m_a0);
|
||||
}
|
||||
|
||||
private:
|
||||
A0 const& m_a0 ;
|
||||
};
|
||||
|
||||
template<class A0>
|
||||
in_place_factory<A0> in_place ( A0 const& a0 )
|
||||
{
|
||||
return in_place_factory<A0>(a0);
|
||||
}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
Similarly, the following is the first member of the family of `typed_in_place_factory` classes, along with its corresponding
|
||||
helper template function. The rest of the family varies only in the number and type of template and constructor parameters.
|
||||
|
||||
```
|
||||
namespace boost {
|
||||
|
||||
struct __typed_in_place_factory_base__ {};
|
||||
|
||||
template<class T, class A0>
|
||||
class typed_in_place_factory : public __typed_in_place_factory_base__
|
||||
{
|
||||
public:
|
||||
typed_in_place_factory ( A0 const& a0 ) : m_a0(a0) {}
|
||||
|
||||
void apply ( void* address ) const
|
||||
{
|
||||
new (address) T(m_a0);
|
||||
}
|
||||
|
||||
private:
|
||||
A0 const& m_a0 ;
|
||||
};
|
||||
|
||||
template<class T, class A0>
|
||||
typed_in_place_factory<A0> in_place ( A0 const& a0 )
|
||||
{
|
||||
return typed_in_place_factory<T,A0>(a0);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
As you can see, the `in_place_factory` and `typed_in_place_factory` template classes vary only in the way they specify
|
||||
the target type: in the first family, the type is given as a template argument to the apply member function while in the
|
||||
second it is given directly as part of the factory class.
|
||||
|
||||
When the container holds a unique non-polymorphic type, such as the case of [@boost:/libs/optional/index.html Boost.Optional],
|
||||
it knows the exact dynamic-type of the contained object and can pass it to the `apply()` method of a non-typed factory.
|
||||
In this case, end users can use an `in_place_factory` instance which can be constructed without the type of the object to construct.
|
||||
|
||||
However, if the container holds heterogeneous or polymorphic objects, such as the case of [@boost:/libs/variant/index.html Boost.Variant],
|
||||
the dynamic-type of the object to be constructed must be known by the factory. In this case, end users must use a `typed_in_place_factory`
|
||||
instead.
|
||||
|
||||
[endsect]
|
||||
[section Container-side Usage]
|
||||
|
||||
As shown in the introductory simplified example, the container class must contain methods that accept an instance of
|
||||
these factories and pass the object's storage to the factory's apply method.
|
||||
|
||||
However, the type of the factory class cannot be completely specified in the container class because that would
|
||||
defeat the whole purpose of the factories which is to allow the container to accept a variadic argument list
|
||||
for the constructor of its contained object.
|
||||
|
||||
The correct function overload must be based on the only distinctive and common
|
||||
characteristic of all the classes in each family: the base class.
|
||||
|
||||
Depending on the container class, you can use `enable_if` to generate the right overload, or use the following
|
||||
dispatch technique, which is used in the [@boost:/libs/optional/index.html Boost.Optional] class:
|
||||
|
||||
|
||||
```
|
||||
struct C
|
||||
{
|
||||
C() : contained_(0) {}
|
||||
C ( X const& v ) : contained_ ( new X(v) ) {}
|
||||
|
||||
template <class Expr>
|
||||
C ( Expr const& expr )
|
||||
:
|
||||
contained_ ( uninitialized_storage() )
|
||||
{
|
||||
construct(expr,&expr);
|
||||
}
|
||||
|
||||
~C() { delete contained_ ; }
|
||||
|
||||
template<class InPlaceFactory>
|
||||
void construct ( InPlaceFactory const& aFactory, const boost::__in_place_factory_base__* )
|
||||
{
|
||||
aFactory.template apply<X>(contained_);
|
||||
}
|
||||
|
||||
template<class TypedInPlaceFactory>
|
||||
void construct ( TypedInPlaceFactory const& aFactory, const boost::__typed_in_place_factory_base__* )
|
||||
{
|
||||
aFactory.apply(contained_);
|
||||
}
|
||||
|
||||
X* uninitialized_storage() { return static_cast<X*>(new char[sizeof(X)]) ; }
|
||||
|
||||
X* contained_ ;
|
||||
};
|
||||
```
|
||||
|
||||
[endsect]
|
||||
[section User-side Usage]
|
||||
|
||||
End users pass to the container an instance of a factory object holding the actual parameters needed to construct the
|
||||
contained object directly within the container. For this, the helper template function `in_place` is used.
|
||||
|
||||
The call `in_place(a0,a1,a2,...,an)` constructs a (non-typed) `in_place_factory` instance with the given argument list.
|
||||
|
||||
The call `in_place<T>(a0,a1,a2,...,an)` constructs a `typed_in_place_factory` instance with the given argument list for the
|
||||
type `T`.
|
||||
|
||||
```
|
||||
void foo()
|
||||
{
|
||||
C a( in_place(123, "hello") ) ; // in_place_factory passed
|
||||
C b( in_place<X>(456, "world") ) ; // typed_in_place_factory passed
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
[endsect]
|
||||
|
||||
[/===============]
|
||||
[xinclude tmp/in_place_factory_reference.xml]
|
||||
[/===============]
|
||||
|
||||
[section Acknowledgments]
|
||||
|
||||
Copyright Fernando Luis Cacciola Carballal, 2004
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
BIN
doc/logo.png
Normal file
BIN
doc/logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 10 KiB |
539
doc/logo.svg
Normal file
539
doc/logo.svg
Normal file
@ -0,0 +1,539 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
width="744.09448819"
|
||||
height="1052.3622047"
|
||||
id="svg6858"
|
||||
version="1.1"
|
||||
inkscape:version="0.48.4 r9939"
|
||||
sodipodi:docname="utility.svg">
|
||||
<defs
|
||||
id="defs6860">
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient4453-7-8-6-7-3-5"
|
||||
id="linearGradient10687-2-5"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x1="753.02301"
|
||||
y1="3132.0801"
|
||||
x2="1146.25"
|
||||
y2="3132.0801" />
|
||||
<linearGradient
|
||||
id="linearGradient4453-7-8-6-7-3-5">
|
||||
<stop
|
||||
style="stop-color:#aac4dd;stop-opacity:1;"
|
||||
offset="0"
|
||||
id="stop4455-61-8-7-1-2-8" />
|
||||
<stop
|
||||
style="stop-color:#c2dbe9;stop-opacity:1;"
|
||||
offset="1"
|
||||
id="stop4457-4-1-9-1-12-1" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient4453-7-8-6-7-3-5"
|
||||
id="linearGradient10685-2-2"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x1="753.02301"
|
||||
y1="3132.0801"
|
||||
x2="1146.25"
|
||||
y2="3132.0801" />
|
||||
<linearGradient
|
||||
id="linearGradient6749">
|
||||
<stop
|
||||
style="stop-color:#aac4dd;stop-opacity:1;"
|
||||
offset="0"
|
||||
id="stop6751" />
|
||||
<stop
|
||||
style="stop-color:#c2dbe9;stop-opacity:1;"
|
||||
offset="1"
|
||||
id="stop6753" />
|
||||
</linearGradient>
|
||||
<clipPath
|
||||
clipPathUnits="userSpaceOnUse"
|
||||
id="clipPath3387-3-6-4-2-8-4">
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
d="m 862.109,3289.75 -109.086,-190.45 69.122,-124.42 164.511,-0.47 c 0,0 111.044,188.28 116.564,197.63 7.66,0 43.03,0 43.03,0 l -67.03,117.71 -217.111,0 z"
|
||||
id="path3389-2-0-7-7-8-9" />
|
||||
</clipPath>
|
||||
<linearGradient
|
||||
y2="3132.0801"
|
||||
x2="1146.25"
|
||||
y1="3132.0801"
|
||||
x1="753.02301"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="linearGradient4492-8-8"
|
||||
xlink:href="#linearGradient4453-7-8-6-7-3-5"
|
||||
inkscape:collect="always" />
|
||||
<linearGradient
|
||||
id="linearGradient6758">
|
||||
<stop
|
||||
style="stop-color:#aac4dd;stop-opacity:1;"
|
||||
offset="0"
|
||||
id="stop6760" />
|
||||
<stop
|
||||
style="stop-color:#c2dbe9;stop-opacity:1;"
|
||||
offset="1"
|
||||
id="stop6762" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient4453-7-8-6-7-3-5"
|
||||
id="linearGradient10691-7-8"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x1="1026.6899"
|
||||
y1="2937.73"
|
||||
x2="1463.14"
|
||||
y2="2937.73" />
|
||||
<linearGradient
|
||||
id="linearGradient6765">
|
||||
<stop
|
||||
style="stop-color:#aac4dd;stop-opacity:1;"
|
||||
offset="0"
|
||||
id="stop6767" />
|
||||
<stop
|
||||
style="stop-color:#c2dbe9;stop-opacity:1;"
|
||||
offset="1"
|
||||
id="stop6769" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient4453-7-8-6-7-3-5"
|
||||
id="linearGradient10689-4-2"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x1="1026.6899"
|
||||
y1="2937.73"
|
||||
x2="1463.14"
|
||||
y2="2937.73" />
|
||||
<linearGradient
|
||||
id="linearGradient6772">
|
||||
<stop
|
||||
style="stop-color:#aac4dd;stop-opacity:1;"
|
||||
offset="0"
|
||||
id="stop6774" />
|
||||
<stop
|
||||
style="stop-color:#c2dbe9;stop-opacity:1;"
|
||||
offset="1"
|
||||
id="stop6776" />
|
||||
</linearGradient>
|
||||
<clipPath
|
||||
clipPathUnits="userSpaceOnUse"
|
||||
id="clipPath3369-1-5-6-1-0-7">
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
d="m 1131.64,3128.5 -104.95,-181.12 116.38,-200.42 208.05,0.94 112.02,191.63 -112.08,188.97 -219.42,0 z"
|
||||
id="path3371-89-4-1-6-0-1" />
|
||||
</clipPath>
|
||||
<linearGradient
|
||||
y2="2937.73"
|
||||
x2="1463.14"
|
||||
y1="2937.73"
|
||||
x1="1026.6899"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="linearGradient4498-5-7"
|
||||
xlink:href="#linearGradient4453-7-8-6-7-3-5"
|
||||
inkscape:collect="always" />
|
||||
<linearGradient
|
||||
id="linearGradient6781">
|
||||
<stop
|
||||
style="stop-color:#aac4dd;stop-opacity:1;"
|
||||
offset="0"
|
||||
id="stop6783" />
|
||||
<stop
|
||||
style="stop-color:#c2dbe9;stop-opacity:1;"
|
||||
offset="1"
|
||||
id="stop6785" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient4459-1-2-8-9-9-5"
|
||||
id="linearGradient10695-9-9"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x1="646.55499"
|
||||
y1="2736.25"
|
||||
x2="1088.27"
|
||||
y2="2736.25" />
|
||||
<linearGradient
|
||||
id="linearGradient4459-1-2-8-9-9-5">
|
||||
<stop
|
||||
id="stop4461-2-1-5-2-5-0"
|
||||
offset="0"
|
||||
style="stop-color:#839bc2;stop-opacity:1;" />
|
||||
<stop
|
||||
id="stop4463-3-2-8-7-30-3"
|
||||
offset="1"
|
||||
style="stop-color:#9fb6d4;stop-opacity:1;" />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient4459-1-2-8-9-9-5"
|
||||
id="linearGradient10693-9-4"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x1="646.55499"
|
||||
y1="2736.25"
|
||||
x2="1088.27"
|
||||
y2="2736.25" />
|
||||
<linearGradient
|
||||
id="linearGradient6792">
|
||||
<stop
|
||||
id="stop6794"
|
||||
offset="0"
|
||||
style="stop-color:#839bc2;stop-opacity:1;" />
|
||||
<stop
|
||||
id="stop6796"
|
||||
offset="1"
|
||||
style="stop-color:#9fb6d4;stop-opacity:1;" />
|
||||
</linearGradient>
|
||||
<clipPath
|
||||
clipPathUnits="userSpaceOnUse"
|
||||
id="clipPath3351-4-7-3-5-95-0">
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
d="m 757.242,2926.25 -110.687,-189.11 110.656,-190.89 219.437,0 111.622,189.1 -111.59,190.9 -219.438,0 z"
|
||||
id="path3353-1-9-3-4-1-1" />
|
||||
</clipPath>
|
||||
<linearGradient
|
||||
y2="2736.25"
|
||||
x2="1088.27"
|
||||
y1="2736.25"
|
||||
x1="646.55499"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="linearGradient4510-1-5"
|
||||
xlink:href="#linearGradient4459-1-2-8-9-9-5"
|
||||
inkscape:collect="always" />
|
||||
<linearGradient
|
||||
id="linearGradient6801">
|
||||
<stop
|
||||
id="stop6803"
|
||||
offset="0"
|
||||
style="stop-color:#839bc2;stop-opacity:1;" />
|
||||
<stop
|
||||
id="stop6805"
|
||||
offset="1"
|
||||
style="stop-color:#9fb6d4;stop-opacity:1;" />
|
||||
</linearGradient>
|
||||
<radialGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#radialGradient3327-8-4-8-0-2-4"
|
||||
id="radialGradient10699-1-3"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
cx="997.46997"
|
||||
cy="2896.25"
|
||||
fx="997.46997"
|
||||
fy="2896.25"
|
||||
r="583.73999" />
|
||||
<radialGradient
|
||||
fx="0"
|
||||
fy="0"
|
||||
cx="0"
|
||||
cy="0"
|
||||
r="1"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
gradientTransform="matrix(58.375,0,0,-58.375,99.75,289.625)"
|
||||
spreadMethod="pad"
|
||||
id="radialGradient3327-8-4-8-0-2-4">
|
||||
<stop
|
||||
style="stop-opacity:1;stop-color:#aeaeb3"
|
||||
offset="0"
|
||||
id="stop3329-7-0-1-0-33-2" />
|
||||
<stop
|
||||
style="stop-opacity:1;stop-color:#ffffff"
|
||||
offset="0.949438"
|
||||
id="stop3331-4-3-0-0-97-3" />
|
||||
<stop
|
||||
style="stop-opacity:1;stop-color:#ffffff"
|
||||
offset="1"
|
||||
id="stop3333-2-4-9-7-2-2" />
|
||||
</radialGradient>
|
||||
<radialGradient
|
||||
r="583.73999"
|
||||
fy="2896.25"
|
||||
fx="997.46997"
|
||||
cy="2896.25"
|
||||
cx="997.46997"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="radialGradient13050"
|
||||
xlink:href="#radialGradient3327-8-4-8-0-2-4"
|
||||
inkscape:collect="always" />
|
||||
<radialGradient
|
||||
fx="0"
|
||||
fy="0"
|
||||
cx="0"
|
||||
cy="0"
|
||||
r="1"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
gradientTransform="matrix(58.375,0,0,-58.375,99.75,289.625)"
|
||||
spreadMethod="pad"
|
||||
id="radialGradient6813">
|
||||
<stop
|
||||
style="stop-opacity:1;stop-color:#aeaeb3"
|
||||
offset="0"
|
||||
id="stop6815" />
|
||||
<stop
|
||||
style="stop-opacity:1;stop-color:#ffffff"
|
||||
offset="0.949438"
|
||||
id="stop6817" />
|
||||
<stop
|
||||
style="stop-opacity:1;stop-color:#ffffff"
|
||||
offset="1"
|
||||
id="stop6819" />
|
||||
</radialGradient>
|
||||
<clipPath
|
||||
clipPathUnits="userSpaceOnUse"
|
||||
id="clipPath3323-7-2-4-5-3-4">
|
||||
<path
|
||||
inkscape:connector-curvature="0"
|
||||
d="m 997.469,2312.51 c -322.379,0 -583.739,261.36 -583.739,583.74 0,322.38 261.36,583.74 583.739,583.74 322.381,0 583.741,-261.36 583.741,-583.74 0,-322.38 -261.36,-583.74 -583.741,-583.74"
|
||||
id="path3325-9-2-9-5-04-9" />
|
||||
</clipPath>
|
||||
<radialGradient
|
||||
r="583.73999"
|
||||
fy="2896.25"
|
||||
fx="997.46997"
|
||||
cy="2896.25"
|
||||
cx="997.46997"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="radialGradient4516-8-2"
|
||||
xlink:href="#radialGradient3327-8-4-8-0-2-4"
|
||||
inkscape:collect="always" />
|
||||
<radialGradient
|
||||
fx="0"
|
||||
fy="0"
|
||||
cx="0"
|
||||
cy="0"
|
||||
r="1"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
gradientTransform="matrix(58.375,0,0,-58.375,99.75,289.625)"
|
||||
spreadMethod="pad"
|
||||
id="radialGradient6824">
|
||||
<stop
|
||||
style="stop-opacity:1;stop-color:#aeaeb3"
|
||||
offset="0"
|
||||
id="stop6826" />
|
||||
<stop
|
||||
style="stop-opacity:1;stop-color:#ffffff"
|
||||
offset="0.949438"
|
||||
id="stop6828" />
|
||||
<stop
|
||||
style="stop-opacity:1;stop-color:#ffffff"
|
||||
offset="1"
|
||||
id="stop6830" />
|
||||
</radialGradient>
|
||||
<radialGradient
|
||||
r="583.73999"
|
||||
fy="2896.25"
|
||||
fx="997.46997"
|
||||
cy="2896.25"
|
||||
cx="997.46997"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
id="radialGradient6856"
|
||||
xlink:href="#radialGradient3327-8-4-8-0-2-4"
|
||||
inkscape:collect="always" />
|
||||
</defs>
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="1.4"
|
||||
inkscape:cx="234.05635"
|
||||
inkscape:cy="581.46313"
|
||||
inkscape:document-units="px"
|
||||
inkscape:current-layer="layer1"
|
||||
showgrid="false"
|
||||
inkscape:window-width="1680"
|
||||
inkscape:window-height="982"
|
||||
inkscape:window-x="-8"
|
||||
inkscape:window-y="-8"
|
||||
inkscape:window-maximized="1">
|
||||
<inkscape:grid
|
||||
type="xygrid"
|
||||
id="grid3066" />
|
||||
</sodipodi:namedview>
|
||||
<metadata
|
||||
id="metadata6863">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title />
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1">
|
||||
<g
|
||||
id="g3319-1-2-5-1-4-4"
|
||||
transform="matrix(0.10419818,0,0,-0.10419818,137.10955,897.00327)"
|
||||
style="fill:url(#radialGradient10699-1-3);fill-opacity:1"
|
||||
inkscape:export-filename="C:\Users\Adam\Desktop\bg_logo1.png"
|
||||
inkscape:export-xdpi="63.625523"
|
||||
inkscape:export-ydpi="63.625523">
|
||||
<g
|
||||
clip-path="url(#clipPath3323-7-2-4-5-3-4)"
|
||||
id="g3321-9-2-7-4-3-9"
|
||||
style="fill:url(#radialGradient6856);fill-opacity:1">
|
||||
<path
|
||||
id="path3335-8-7-3-8-92-0"
|
||||
style="fill:url(#radialGradient4516-8-2);fill-opacity:1;fill-rule:nonzero;stroke:none"
|
||||
d="m 997.469,2312.51 c -322.379,0 -583.739,261.36 -583.739,583.74 0,322.38 261.36,583.74 583.739,583.74 322.381,0 583.741,-261.36 583.741,-583.74 0,-322.38 -261.36,-583.74 -583.741,-583.74"
|
||||
inkscape:connector-curvature="0" />
|
||||
</g>
|
||||
</g>
|
||||
<g
|
||||
id="g3347-6-8-3-7-4-4"
|
||||
transform="matrix(0.125,0,0,-0.125,112.08304,959.82207)"
|
||||
style="fill:url(#linearGradient10695-9-9);fill-opacity:1"
|
||||
inkscape:export-filename="C:\Users\Adam\Desktop\bg_logo1.png"
|
||||
inkscape:export-xdpi="63.625523"
|
||||
inkscape:export-ydpi="63.625523">
|
||||
<g
|
||||
clip-path="url(#clipPath3351-4-7-3-5-95-0)"
|
||||
id="g3349-5-5-4-7-9-4"
|
||||
style="fill:url(#linearGradient10693-9-4);fill-opacity:1">
|
||||
<path
|
||||
id="path3361-0-8-2-9-0-9"
|
||||
style="fill:url(#linearGradient4510-1-5);fill-opacity:1;fill-rule:nonzero;stroke:none"
|
||||
d="m 757.242,2926.25 -110.687,-189.11 110.656,-190.89 219.437,0 111.622,189.1 -111.59,190.9 -219.438,0"
|
||||
inkscape:connector-curvature="0" />
|
||||
</g>
|
||||
</g>
|
||||
<path
|
||||
id="path3363-6-9-0-1-5-8"
|
||||
style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"
|
||||
d="m 194.34816,617.68335 13.106,-22.3925 25.99649,0 13.21487,22.60874 -13.21487,22.39125 -25.99649,0 -13.106,-22.60749 z m 40.53761,-24.8925 -28.86524,0 -0.72412,1.23749 -13.106,22.39251 -0.73575,1.25625 0.73087,1.26 13.106,22.60744 0.72263,1.24634 28.86374,0 0.72512,-1.22884 13.215,-22.39119 0.74625,-1.265 -0.74,-1.26751 -13.21537,-22.60875 -0.72313,-1.23874"
|
||||
inkscape:connector-curvature="0"
|
||||
inkscape:export-filename="C:\Users\Adam\Desktop\bg_logo1.png"
|
||||
inkscape:export-xdpi="63.625523"
|
||||
inkscape:export-ydpi="63.625523" />
|
||||
<g
|
||||
id="g3365-0-4-1-9-7-5"
|
||||
transform="matrix(0.125,0,0,-0.125,112.08304,959.82207)"
|
||||
style="fill:url(#linearGradient10691-7-8);fill-opacity:1"
|
||||
inkscape:export-filename="C:\Users\Adam\Desktop\bg_logo1.png"
|
||||
inkscape:export-xdpi="63.625523"
|
||||
inkscape:export-ydpi="63.625523">
|
||||
<g
|
||||
clip-path="url(#clipPath3369-1-5-6-1-0-7)"
|
||||
id="g3367-2-4-2-8-4-3"
|
||||
style="fill:url(#linearGradient10689-4-2);fill-opacity:1">
|
||||
<path
|
||||
id="path3379-4-6-7-6-7-2"
|
||||
style="fill:url(#linearGradient4498-5-7);fill-opacity:1;fill-rule:nonzero;stroke:none"
|
||||
d="m 1131.64,3128.5 -104.95,-181.12 116.38,-200.42 208.05,0.94 112.02,191.63 -112.08,188.97 -219.42,0"
|
||||
inkscape:connector-curvature="0" />
|
||||
</g>
|
||||
</g>
|
||||
<path
|
||||
id="path3381-6-8-0-0-66-3"
|
||||
style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"
|
||||
d="m 241.86427,591.39959 12.3925,-21.38999 25.99625,0 13.27125,22.37625 -13.27125,22.7025 -24.56875,0.11 -13.82,-23.79876 z m 39.8125,-23.88999 -28.86125,0 -0.7225,1.24625 -12.3925,21.39 -0.72625,1.255 0.7275,1.25374 13.82,23.79876 0.7275,1.25125 1.44625,-0.006 24.56875,-0.11 1.4275,-0.006 0.72,-1.2325 13.27125,-22.7025 0.7425,-1.27 -0.75125,-1.26625 -13.27125,-22.37625 -0.72625,-1.225"
|
||||
inkscape:connector-curvature="0"
|
||||
inkscape:export-filename="C:\Users\Adam\Desktop\bg_logo1.png"
|
||||
inkscape:export-xdpi="63.625523"
|
||||
inkscape:export-ydpi="63.625523" />
|
||||
<g
|
||||
id="g3383-5-5-2-2-3-0"
|
||||
transform="matrix(0.125,0,0,-0.125,112.08304,959.82207)"
|
||||
style="fill:url(#linearGradient10687-2-5);fill-opacity:1"
|
||||
inkscape:export-filename="C:\Users\Adam\Desktop\bg_logo1.png"
|
||||
inkscape:export-xdpi="63.625523"
|
||||
inkscape:export-ydpi="63.625523">
|
||||
<g
|
||||
clip-path="url(#clipPath3387-3-6-4-2-8-4)"
|
||||
id="g3385-0-6-4-8-0-1"
|
||||
style="fill:url(#linearGradient10685-2-2);fill-opacity:1">
|
||||
<path
|
||||
id="path3397-9-6-1-6-9-7"
|
||||
style="fill:url(#linearGradient4492-8-8);fill-opacity:1;fill-rule:nonzero;stroke:none"
|
||||
d="m 862.109,3289.75 -109.086,-190.45 69.122,-124.42 164.511,-0.47 c 0,0 111.044,188.28 116.564,197.63 7.66,0 43.03,0 43.03,0 l -67.03,117.71 -217.111,0"
|
||||
inkscape:connector-curvature="0" />
|
||||
</g>
|
||||
</g>
|
||||
<path
|
||||
id="path3399-6-7-3-2-0-1"
|
||||
style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"
|
||||
d="m 207.64603,572.41959 12.92424,-22.56624 25.68775,0 6.95625,12.21375 -3.94375,0 -14.56837,24.7025 -19.11525,-0.055 -7.94087,-14.295 z m 40.06574,-25.06624 -28.59012,0 -0.71975,1.2575 -12.92537,22.56625 -0.70112,1.22375 0.68512,1.23249 7.94137,14.295 0.71087,1.2825 1.46638,0.004 19.11525,0.055 1.43212,0.004 0.729,-1.23375 13.84375,-23.47249 6.81625,0 -2.12875,-3.7375 -6.95625,-12.21375 -0.71875,-1.2625"
|
||||
inkscape:connector-curvature="0"
|
||||
inkscape:export-filename="C:\Users\Adam\Desktop\bg_logo1.png"
|
||||
inkscape:export-xdpi="63.625523"
|
||||
inkscape:export-ydpi="63.625523" />
|
||||
<g
|
||||
transform="matrix(1.25,0,0,-1.25,105.02062,972.84257)"
|
||||
id="g3465-0-8-9"
|
||||
inkscape:export-filename="C:\Users\Adam\Desktop\bg_logo1.png"
|
||||
inkscape:export-xdpi="63.625523"
|
||||
inkscape:export-ydpi="63.625523">
|
||||
<text
|
||||
id="text3467-9-0-8"
|
||||
transform="matrix(1,0,-0.17627963,-1,0,0)"
|
||||
x="116.98372"
|
||||
y="-267.77499"
|
||||
style="font-size:11.81779194px">
|
||||
<tspan
|
||||
sodipodi:role="line"
|
||||
style="font-size:46.39999771px;font-variant:normal;font-weight:normal;writing-mode:lr-tb;fill:#49608a;fill-opacity:1;fill-rule:nonzero;stroke:none;font-family:Denmark;-inkscape-font-specification:Denmark"
|
||||
x="116.98372"
|
||||
y="-267.77499"
|
||||
id="tspan13239">UTILITY</tspan>
|
||||
<tspan
|
||||
sodipodi:role="line"
|
||||
style="font-size:46.39999771px;font-variant:normal;font-weight:normal;writing-mode:lr-tb;fill:#49608a;fill-opacity:1;fill-rule:nonzero;stroke:none;font-family:Denmark;-inkscape-font-specification:Denmark"
|
||||
x="116.98372"
|
||||
y="-209.77499"
|
||||
id="tspan11278-3" />
|
||||
</text>
|
||||
<text
|
||||
id="text3471-0-51-2"
|
||||
transform="matrix(0.99235617,0,-0.17763746,-1.0077027,0,0)"
|
||||
style="font-size:38.40000153px"
|
||||
x="112.74373"
|
||||
y="-306.75479">
|
||||
<tspan
|
||||
id="tspan3473-6-0-9"
|
||||
sodipodi:role="line"
|
||||
style="font-size:38.40000153px;font-variant:normal;font-weight:normal;writing-mode:lr-tb;fill:#49608a;fill-opacity:1;fill-rule:nonzero;stroke:none;font-family:Denmark;-inkscape-font-specification:Denmark"
|
||||
x="112.74373"
|
||||
y="-306.75479">boost</tspan>
|
||||
</text>
|
||||
</g>
|
||||
<path
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:none"
|
||||
d="m 201.43967,613.81579 4.64114,4.2175 3.3738,-3.71306 -0.92817,-0.84354 1.68708,-1.85636 20.53445,20.81026 4.2175,-4.64111 -22.22144,-18.95384 c 0,0 1.69594,-1.83698 2.53062,-2.78454 2.53905,-2.76559 5.98925,-4.72587 5.98925,-4.72587 0,0 -6.03647,0.58224 -8.76507,2.21476 -0.84428,0.92751 -6.75676,7.40649 -6.75676,7.40649 l -0.92819,-0.84355 -3.37382,3.71308"
|
||||
id="path13283"
|
||||
inkscape:connector-curvature="0"
|
||||
sodipodi:nodetypes="cccccccccccccc" />
|
||||
<g
|
||||
id="g3086"
|
||||
transform="matrix(0.99872217,-0.05053738,0.05053738,0.99872217,-31.539183,11.181538)">
|
||||
<path
|
||||
sodipodi:nodetypes="ccccccccc"
|
||||
inkscape:connector-curvature="0"
|
||||
id="path13243"
|
||||
d="m 227.74101,611.16418 -15.09943,12.783 2.55659,3.01989 15.09944,-12.78302 c 3.56324,2.16769 7.58975,-1.2411 7.0464,-5.96538 l -4.02652,3.40879 -2.55659,-3.01989 4.02652,-3.40879 c -3.56324,-2.16769 -8.59639,2.0933 -7.04641,5.9654 z"
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:none" />
|
||||
<path
|
||||
sodipodi:nodetypes="ccccccccc"
|
||||
inkscape:connector-curvature="0"
|
||||
id="path13243-1"
|
||||
d="m 215.25729,626.9851 15.08951,-12.7947 -2.55893,-3.01791 -15.08952,12.79471 c -3.56492,-2.16491 -7.58878,1.24699 -7.04177,5.97085 l 4.02388,-3.41192 2.55892,3.01791 -4.02387,3.41192 c 3.56491,2.16492 8.59476,-2.09997 7.04178,-5.97086 z"
|
||||
style="fill:#ffffff;fill-opacity:1;stroke:none" />
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 20 KiB |
233
doc/main.qbk
Normal file
233
doc/main.qbk
Normal file
@ -0,0 +1,233 @@
|
||||
[/
|
||||
Copyright (c) 2021, Alan Freitas
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
Official repository: https://github.com/boostorg/utility
|
||||
]
|
||||
|
||||
[/#############################################
|
||||
DOCUMENT INFO
|
||||
###############################################]
|
||||
|
||||
[library Boost.Utility
|
||||
[id utility]
|
||||
[quickbook 1.6]
|
||||
[copyright 2001 Beman Dawes]
|
||||
[purpose Utility Library]
|
||||
[license
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
[@http://www.boost.org/LICENSE_1_0.txt])
|
||||
]
|
||||
[authors [Dawes, Beman]]
|
||||
[category template]
|
||||
[category generic]
|
||||
]
|
||||
|
||||
[template mdash[]'''—''']
|
||||
[template ndash[]'''–''']
|
||||
[template sect[]'''§''']
|
||||
[template hellip[]'''…''']
|
||||
|
||||
[template indexterm1[term1]'''<indexterm><primary>'''[term1]'''</primary></indexterm>''']
|
||||
[template indexterm2[term1 term2]'''<indexterm><primary>'''[term1]'''</primary><secondary>'''[term2]'''</secondary></indexterm>''']
|
||||
|
||||
[template include_file[path][^<'''<ulink url="https://github.com/boostorg/utility/blob/master/include/'''[path]'''">'''[path]'''</ulink>'''>]]
|
||||
[template issue[n]'''<ulink url="https://github.com/boostorg/utility/issues/'''[n]'''">#'''[n]'''</ulink>''']
|
||||
|
||||
[/ Named Requirements ]
|
||||
|
||||
[def __Handler__ ['Handler]]
|
||||
[def __Allocator__ [@https://en.cppreference.com/w/cpp/named_req/Allocator ['Allocator]]]
|
||||
[def __CopyAssignable__ [@https://en.cppreference.com/w/cpp/named_req/CopyAssignable ['CopyAssignable]]]
|
||||
[def __CopyConstructible__ [@https://en.cppreference.com/w/cpp/named_req/CopyConstructible ['CopyConstructible]]]
|
||||
[def __Copyable__ [@https://en.cppreference.com/w/cpp/concepts/copyable ['Copyable]]]
|
||||
[def __DefaultConstructible__ [@https://en.cppreference.com/w/cpp/named_req/DefaultConstructible ['DefaultConstructible]]]
|
||||
[def __Hash__ [@https://en.cppreference.com/w/cpp/named_req/Hash ['Hash]]]
|
||||
[def __InputIterator__ [@https://en.cppreference.com/w/cpp/named_req/InputIterator ['InputIterator]]]
|
||||
[def __MoveAssignable__ [@https://en.cppreference.com/w/cpp/named_req/MoveAssignable ['MoveAssignable]]]
|
||||
[def __MoveConstructible__ [@https://en.cppreference.com/w/cpp/named_req/MoveConstructible ['MoveConstructible]]]
|
||||
[def __RandomAccessIterator__ [@https://en.cppreference.com/w/cpp/named_req/RandomAccessIterator ['RandomAccessIterator]]]
|
||||
[def __Regular__ [@https://en.cppreference.com/w/cpp/concepts/regular ['Regular]]]
|
||||
[def __Swappable__ [@https://en.cppreference.com/w/cpp/named_req/Swappable ['Swappable]]]
|
||||
|
||||
[/ Boost types ]
|
||||
[/ (Macros are defined here because these macros are often referenced in other components) ]
|
||||
[/ (operators macros link to the a table of operators because there's no doxygen reference for the operators) ]
|
||||
|
||||
[def __BOOST_BINARY__ [link utility.utilities.BOOST_BINARY `BOOST_BINARY`]]
|
||||
[def __in_place_factory__ [link utility.utilities.in_place_factory `in_place_factory`]]
|
||||
|
||||
[def __boost_base_from_member__ [classref boost::base_from_member `boost::base_from_member`]]
|
||||
[def __boost_call_traits__ [classref boost::call_traits `boost::call_traits`]]
|
||||
[def __boost_result_of__ [classref boost::result_of `boost::result_of`]]
|
||||
[def __boost_tr1_result_of__ [classref boost::tr1_result_of `boost::tr1_result_of`]]
|
||||
[def __boost_string_view__ [classref boost::basic_string_view `boost::string_view`]]
|
||||
[def __boost_basic_string_view__ [classref boost::basic_string_view `boost::basic_string_view`]]
|
||||
|
||||
[def __additive1__ [link utility.utilities.operators.arithmetic `additive1`]]
|
||||
[def __additive2__ [link utility.utilities.operators.arithmetic `additive2`]]
|
||||
[def __arithmetic1__ [link utility.utilities.operators.arithmetic `arithmetic1`]]
|
||||
[def __arithmetic2__ [link utility.utilities.operators.arithmetic `arithmetic2`]]
|
||||
[def __base_from_member__ [classref boost::base_from_member `base_from_member`]]
|
||||
[def __basic_string_ref__ [classref boost::basic_string_ref `basic_string_ref`]]
|
||||
[def __basic_string_view__ [classref boost::basic_string_view `basic_string_view`]]
|
||||
[def __bidirectional_iteratable__ [link utility.utilities.operators.arithmetic `bidirectional_iteratable`]]
|
||||
[def __bidirectional_iterator_helper__ [link utility.utilities.operators.arithmetic `bidirectional_iterator_helper`]]
|
||||
[def __bitwise1__ [link utility.utilities.operators.arithmetic `bitwise1`]]
|
||||
[def __bitwise2__ [link utility.utilities.operators.arithmetic `bitwise2`]]
|
||||
[def __call_traits__ [classref boost::call_traits `call_traits`]]
|
||||
[def __call_traits_T__ [classref boost::call_traits `call_traits<T>`]]
|
||||
[def __call_traits_lt__T___ [classref boost::call_traits `call_traits<T&>`]]
|
||||
[def __call_traits_lt__T_lb_N_rb__gt___ [classref boost::call_traits `call_traits< T[N]>`]]
|
||||
[def __call_traits_lt__const_T_lb_N_rb__gt___ [classref boost::call_traits `call_traits< const T[N]>`]]
|
||||
[def __compressed_pair__ [classref boost::compressed_pair `compressed_pair`]]
|
||||
[def __decrementable__ [link utility.utilities.operators.arithmetic `decrementable`]]
|
||||
[def __dereferenceable__ [link utility.utilities.operators.arithmetic `dereferenceable`]]
|
||||
[def __equal_pointees__ [link utility.utilities.operators.arithmetic `equal_pointees`]]
|
||||
[def __equal_pointees_t__ [link utility.utilities.operators.arithmetic `equal_pointees_t`]]
|
||||
[def __equality_comparable1__ [link utility.utilities.operators.arithmetic `equality_comparable1`]]
|
||||
[def __equality_comparable2__ [link utility.utilities.operators.arithmetic `equality_comparable2`]]
|
||||
[def __equivalent1__ [link utility.utilities.operators.arithmetic `equivalent1`]]
|
||||
[def __equivalent2__ [link utility.utilities.operators.arithmetic `equivalent2`]]
|
||||
[def __euclidean_ring_operators1__ [link utility.utilities.operators.arithmetic `euclidean_ring_operators1`]]
|
||||
[def __euclidean_ring_operators2__ [link utility.utilities.operators.arithmetic `euclidean_ring_operators2`]]
|
||||
[def __field_operators1__ [link utility.utilities.operators.arithmetic `field_operators1`]]
|
||||
[def __field_operators2__ [link utility.utilities.operators.arithmetic `field_operators2`]]
|
||||
[def __forward_iteratable__ [link utility.utilities.operators.arithmetic `forward_iteratable`]]
|
||||
[def __forward_iterator_helper__ [link utility.utilities.operators.arithmetic `forward_iterator_helper`]]
|
||||
[def __get__ [funcref boost::get `get`]]
|
||||
[def __hash_range__ [funcref boost::hash_range `hash_range`]]
|
||||
[def __hash_value__ [funcref boost::hash_value `hash_value`]]
|
||||
[def __in_place_factory_base__ [classref boost::in_place_factory_base `in_place_factory_base`]]
|
||||
[def __incrementable__ [link utility.utilities.operators.arithmetic `incrementable`]]
|
||||
[def __indexable__ [link utility.utilities.operators.arithmetic `indexable`]]
|
||||
[def __initialized__ [classref boost::initialized `initialized`]]
|
||||
[def __initialized_value__ [globalref boost::initialized_value `initialized_value`]]
|
||||
[def __initialized_value_t__ [classref boost::initialized_value_t `initialized_value_t`]]
|
||||
[def __input_iteratable__ [link utility.utilities.operators.arithmetic `input_iteratable`]]
|
||||
[def __input_iterator_helper__ [link utility.utilities.operators.arithmetic `input_iterator_helper`]]
|
||||
[def __integer_arithmetic1__ [link utility.utilities.operators.arithmetic `integer_arithmetic1`]]
|
||||
[def __integer_arithmetic2__ [link utility.utilities.operators.arithmetic `integer_arithmetic2`]]
|
||||
[def __integer_multiplicative1__ [link utility.utilities.operators.arithmetic `integer_multiplicative1`]]
|
||||
[def __integer_multiplicative2__ [link utility.utilities.operators.arithmetic `integer_multiplicative2`]]
|
||||
[def __is_chained_base__ [link utility.utilities.operators.arithmetic `is_chained_base`]]
|
||||
[def __less_pointees__ [funcref boost::less_pointees `less_pointees`]]
|
||||
[def __less_pointees_t__ [class boost::less_pointees_t `less_pointees_t`]]
|
||||
[def __less_than_comparable1__ [link utility.utilities.operators.arithmetic `less_than_comparable1`]]
|
||||
[def __less_than_comparable2__ [link utility.utilities.operators.arithmetic `less_than_comparable2`]]
|
||||
[def __multiplicative1__ [link utility.utilities.operators.arithmetic `multiplicative1`]]
|
||||
[def __multiplicative2__ [link utility.utilities.operators.arithmetic `multiplicative2`]]
|
||||
[def __operator_eq__eq__ [link utility.utilities.operators.arithmetic `operator==`]]
|
||||
[def __operator_gt__ [link utility.utilities.operators.arithmetic `operator_gt_`]]
|
||||
[def __operator_gt__eq__ [link utility.utilities.operators.arithmetic `operator>`]]
|
||||
[def __operator_lt__ [link utility.utilities.operators.arithmetic `operator<`]]
|
||||
[def __operator_lt__eq__ [link utility.utilities.operators.arithmetic `operator<=`]]
|
||||
[def __operator_lt__lt__ [link utility.utilities.operators.arithmetic `operator<<`]]
|
||||
[def __operator_not__eq__ [link utility.utilities.operators.arithmetic `operator!=`]]
|
||||
[def __operators2__ [link utility.utilities.operators.arithmetic `operators2`]]
|
||||
[def __operators__ [link utility.utilities.operators.arithmetic `operators`]]
|
||||
[def __operators_lt_T__ [link utility.utilities.operators.arithmetic `operators<T,T>`]]
|
||||
[def __ordered_euclidean_ring_operators1__ [link utility.utilities.operators.arithmetic `ordered_euclidean_ring_operators1`]]
|
||||
[def __ordered_euclidean_ring_operators2__ [link utility.utilities.operators.arithmetic `ordered_euclidean_ring_operators2`]]
|
||||
[def __ordered_euclidian_ring_operators1__ [link utility.utilities.operators.arithmetic `ordered_euclidian_ring_operators1`]]
|
||||
[def __ordered_euclidian_ring_operators2__ [link utility.utilities.operators.arithmetic `ordered_euclidian_ring_operators2`]]
|
||||
[def __ordered_field_operators1__ [link utility.utilities.operators.arithmetic `ordered_field_operators1`]]
|
||||
[def __ordered_field_operators2__ [link utility.utilities.operators.arithmetic `ordered_field_operators2`]]
|
||||
[def __ordered_ring_operators1__ [link utility.utilities.operators.arithmetic `ordered_ring_operators1`]]
|
||||
[def __ordered_ring_operators2__ [link utility.utilities.operators.arithmetic `ordered_ring_operators2`]]
|
||||
[def __output_iteratable__ [link utility.utilities.operators.arithmetic `output_iteratable`]]
|
||||
[def __output_iterator_helper__ [link utility.utilities.operators.arithmetic `output_iterator_helper`]]
|
||||
[def __partially_ordered1__ [link utility.utilities.operators.arithmetic `partially_ordered1`]]
|
||||
[def __partially_ordered2__ [link utility.utilities.operators.arithmetic `partially_ordered2`]]
|
||||
[def __random_access_iteratable__ [link utility.utilities.operators.arithmetic `random_access_iteratable`]]
|
||||
[def __random_access_iterator_helper__ [link utility.utilities.operators.arithmetic `random_access_iterator_helper`]]
|
||||
[def __result_of__ [classref boost::result_of `result_of`]]
|
||||
[def __ring_operators1__ [link utility.utilities.operators.arithmetic `ring_operators1`]]
|
||||
[def __ring_operators2__ [link utility.utilities.operators.arithmetic `ring_operators2`]]
|
||||
[def __shiftable1__ [link utility.utilities.operators.arithmetic `shiftable1`]]
|
||||
[def __shiftable2__ [link utility.utilities.operators.arithmetic `shiftable2`]]
|
||||
[def __string_ref__ [classref boost::basic_string_ref `string_ref`]]
|
||||
[def __string_view__ [classref boost::basic_string_view `string_view`]]
|
||||
[def __swap__ [link utility.utilities.operators.arithmetic `swap`]]
|
||||
[def __totally_ordered1__ [link utility.utilities.operators.arithmetic `totally_ordered1`]]
|
||||
[def __totally_ordered2__ [link utility.utilities.operators.arithmetic `totally_ordered2`]]
|
||||
[def __tr1_result_of__ [classref boost::tr1_result_of `tr1_result_of`]]
|
||||
[def __typed_in_place_factory_base__ [classref boost::typed_in_place_factory_base `typed_in_place_factory_base`]]
|
||||
[def __u16string_ref__ [classref boost::basic_string_ref `u16string_ref`]]
|
||||
[def __u16string_view__ [classref boost::basic_string_view `u16string_view`]]
|
||||
[def __u32string_ref__ [classref boost::basic_string_ref `u32string_ref`]]
|
||||
[def __u32string_view__ [classref boost::basic_string_view `u32string_view`]]
|
||||
[def __unit_steppable__ [link utility.utilities.operators.arithmetic `unit_steppable`]]
|
||||
[def __value_initialized__ [classref boost::value_initialized `value_initialized`]]
|
||||
[def __wstring_ref__ [classref boost::basic_string_ref `wstring_ref`]]
|
||||
[def __wstring_view__ [classref boost::basic_string_view `wstring_view`]]
|
||||
|
||||
[/ std:: types ]
|
||||
|
||||
[def __assert__ [@https://en.cppreference.com/w/cpp/error/assert `assert`]]
|
||||
[def __decltype__ [@https://en.cppreference.com/w/cpp/language/decltype `decltype`]]
|
||||
[def __initializer_list__ [@https://en.cppreference.com/w/cpp/utility/initializer_list `std::initializer_list`]]
|
||||
[def __nullptr__ [@https://en.cppreference.com/w/cpp/language/nullptr `nullptr`]]
|
||||
[def __std_addressof__ [@https://en.cppreference.com/w/cpp/memory/addressof `std::addressof`]]
|
||||
[def __std_array__ [@https://en.cppreference.com/w/cpp/container/array `std::array`]]
|
||||
[def __std_basic_string__ [@https://en.cppreference.com/w/cpp/string/basic_string `std::basic_string`]]
|
||||
[def __std_basic_string_view__ [@https://en.cppreference.com/w/cpp/string/basic_string_view `std::basic_string_view`]]
|
||||
[def __std_binder1st__ [@https://en.cppreference.com/w/cpp/utility/functional/binder12 `std::binder1st`]]
|
||||
[def __std_complex__ [@https://en.cppreference.com/w/cpp/numeric/complex `std::complex`]]
|
||||
[def __std_declval__ [@https://en.cppreference.com/w/cpp/utility/declval `std::declval`]]
|
||||
[def __std_enable_if__ [@https://en.cppreference.com/w/cpp/types/enable_if `std::enable_if`]]
|
||||
[def __std_enable_if_t__ [@https://en.cppreference.com/w/cpp/types/enable_if `std::enable_if_t`]]
|
||||
[def __std_fill__ [@https://en.cppreference.com/w/cpp/algorithm/fill `std::fill`]]
|
||||
[def __std_hash__ [@https://en.cppreference.com/w/cpp/utility/hash `std::hash`]]
|
||||
[def __std_initializer_list__ [@https://en.cppreference.com/w/cpp/utility/initializer_list `std::initializer_list`]]
|
||||
[def __std_is_nothrow_constructible__ [@https://en.cppreference.com/w/cpp/types/is_constructible `std::is_nothrow_constructible`]]
|
||||
[def __std_make_pair__ [@https://en.cppreference.com/w/cpp/utility/pair/make_pair `std::make_pair`]]
|
||||
[def __std_memory_resource__ [@https://en.cppreference.com/w/cpp/memory/memory_resource `std::pmr::memory_resource`]]
|
||||
[def __std_memset__ [@https://en.cppreference.com/w/cpp/string/byte/memset `std::memset`]]
|
||||
[def __std_next__ [@https://en.cppreference.com/w/cpp/iterator/next `std::next`]]
|
||||
[def __std_nullptr_t__ [@https://en.cppreference.com/w/cpp/types/nullptr_t `std::nullptr_t`]]
|
||||
[def __std_ostream__ [@https://en.cppreference.com/w/cpp/io/basic_ostream `std::ostream`]]
|
||||
[def __std_ostream__ [@https://en.cppreference.com/w/cpp/io/basic_ostream `__std_ostream__`]]
|
||||
[def __std_pair__ [@https://en.cppreference.com/w/cpp/utility/pair `std::pair`]]
|
||||
[def __std_polymorphic_allocator__ [@https://en.cppreference.com/w/cpp/memory/polymorphic_allocator `std::pmr::polymorphic_allocator`]]
|
||||
[def __std_prev__ [@https://en.cppreference.com/w/cpp/iterator/prev `std::prev`]]
|
||||
[def __std_ptrdiff_t__ [@https://en.cppreference.com/w/cpp/types/ptrdiff_t `std::ptrdiff_t`]]
|
||||
[def __std_remove__ [@https://en.cppreference.com/w/cpp/algorithm/remove `std::remove`]]
|
||||
[def __std_result_of__ [@https://en.cppreference.com/w/cpp/types/result_of `std::result_of`]]
|
||||
[def __std_sort__ [@https://en.cppreference.com/w/cpp/algorithm/sort `std::sort`]]
|
||||
[def __std_streambuf__ [@https://en.cppreference.com/w/cpp/header/streambuf `std::streambuf`]]
|
||||
[def __std_string__ [@https://en.cppreference.com/w/cpp/string/basic_string `std::string`]]
|
||||
[def __std_string_view__ [@https://en.cppreference.com/w/cpp/string/basic_string_view `std::string_view`]]
|
||||
[def __std_unary_function__ [@https://en.cppreference.com/w/cpp/utility/functional/unary_function `std::unary_function`]]
|
||||
[def __std_unordered_map__ [@https://en.cppreference.com/w/cpp/container/unordered_map `std::unordered_map`]]
|
||||
[def __std_uses_allocator__ [@https://en.cppreference.com/w/cpp/memory/uses_allocator `std::uses_allocator`]]
|
||||
[def __std_vector__ [@https://en.cppreference.com/w/cpp/container/vector `std::vector`]]
|
||||
|
||||
[/ Dingbats ]
|
||||
|
||||
[def __good__ [role green \u2714]]
|
||||
[def __bad__ [role red \u2718]]
|
||||
|
||||
[/-----------------------------------------------------------------------------]
|
||||
|
||||
[include overview.qbk]
|
||||
|
||||
[include utilities.qbk]
|
||||
|
||||
[include other.qbk]
|
||||
|
||||
[section:reference Quick Reference]
|
||||
|
||||
[/ Reference table ]
|
||||
[xinclude quickref.xml]
|
||||
|
||||
[/ Generated reference files ]
|
||||
[/ [include reference.qbk] ]
|
||||
|
||||
[/ Generated index ]
|
||||
[/ [xinclude index.xml] ]
|
||||
|
||||
[endsect]
|
2004
doc/operators.qbk
Normal file
2004
doc/operators.qbk
Normal file
File diff suppressed because it is too large
Load Diff
29
doc/other.qbk
Normal file
29
doc/other.qbk
Normal file
@ -0,0 +1,29 @@
|
||||
[/
|
||||
Copyright (c) 2021 Alan de Freitas (alandefreitas@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
Official repository: https://github.com/boostorg/utility
|
||||
]
|
||||
|
||||
[section:more_utilities More Utilities]
|
||||
|
||||
Some utilities have been moved from Boost.Utilities to more appropriate Boost libraries:
|
||||
|
||||
# Moved to [@boost:/libs/core/index.html Boost.Core]
|
||||
# [@boost:/libs/core/doc/html/core/addressof.html addressof]
|
||||
# [@boost:/libs/core/doc/html/core/checked_delete.html checked_delete]
|
||||
# [@boost:/libs/core/doc/html/core/enable_if.html enable_if]
|
||||
# [@boost:/libs/core/doc/html/core/noncopyable.html noncopyable]
|
||||
# Moved to [@boost:/libs/type_traits/index.html Boost.TypeTraits]
|
||||
# [@boost:/libs/type_traits/doc/html/boost_typetraits/reference/declval.html declval]
|
||||
# Moved to [@boost:/libs/iterator/index.html Boost.Iterator]
|
||||
# [@boost:/libs/iterator/doc/generator_iterator.htm generator iterator adaptors]
|
||||
# [@boost:/libs/iterator/doc/html/iterator/algorithms/next_prior.html next/prior]
|
||||
# Moved to [@boost:/libs/io/index.html Boost.IO]
|
||||
# [@boost:/libs/io/doc/html/io.html ostream_string]
|
||||
# Moved to [@boost:/libs/throw_exception/index.html Boost.ThrowException]
|
||||
# [@boost:/libs/throw_exception/doc/html/throw_exception.html#using_boost_throw_exception throw_exception]
|
||||
|
||||
[endsect]
|
46
doc/overview.qbk
Normal file
46
doc/overview.qbk
Normal file
@ -0,0 +1,46 @@
|
||||
[/
|
||||
Copyright (c) 2021 Alan de Freitas (alandefreitas@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
Official repository: https://github.com/boostorg/utility
|
||||
]
|
||||
|
||||
[section Overview]
|
||||
[block'''<?dbhtml stop-chunking?>''']
|
||||
|
||||
Boost.Utility is a collection of small, useful, and general-purpose components for language support.
|
||||
|
||||
Over time,
|
||||
|
||||
* several components have been moved to more appropriate Boost libraries and
|
||||
* many of these components had variants accepted into the C++ standard
|
||||
|
||||
When the component has moved to another Boost library, Boost.Utility headers still lead to the appropriate headers
|
||||
in other libraries.
|
||||
|
||||
[table Components
|
||||
[[Boost.Utility] [Moved to Boost] [C++ Standard variant]]
|
||||
[[[@boost:/libs/core/doc/html/core/addressof.html `addressof`]] [[@boost:/libs/core/index.html Boost.Core]] [C++11 __std_addressof__]]
|
||||
[[[link utility.utilities.base_from_member `base_from_member`]] [] []]
|
||||
[[__BOOST_BINARY__] [] [C++14 [@https://en.cppreference.com/w/cpp/language/integer_literal Binary integer literal]]]
|
||||
[[[link utility.utilities.call_traits `call_traits`]] [] []]
|
||||
[[[@boost:/libs/core/doc/html/core/checked_delete.html `checked_delete`]] [[@boost:/libs/core/index.html Boost.Core]] []]
|
||||
[[[link utility.utilities.compressed_pair `compressed_pair`]] [] []]
|
||||
[[[@boost:/libs/type_traits/doc/html/boost_typetraits/reference/declval.html `declval`]] [[@boost:/libs/type_traits/index.html Boost.TypeTraits]] [C++11 __std_declval__]]
|
||||
[[[@boost:/libs/core/doc/html/core/enable_if.html `enable_if`]] [[@boost:/libs/core/index.html Boost.Core]] [C++11 __std_enable_if__]]
|
||||
[[[@boost:/libs/iterator/doc/generator_iterator.htm generator iterator adaptors]] [[@boost:/libs/iterator/index.html Boost.Iterator]] []]
|
||||
[[__in_place_factory__] [] []]
|
||||
[[[@boost:/libs/iterator/index.html `iterator_adaptors`]] [[@boost:/libs/iterator/index.html Boost.Iterator]] []]
|
||||
[[[@boost:/libs/iterator/doc/html/iterator/algorithms/next_prior.html `next` / `prior`]] [[@boost:/libs/iterator/index.html Boost.Iterator]] [C++11 __std_next__ / __std_prev__]]
|
||||
[[[@boost:/libs/core/doc/html/core/noncopyable.html `noncopyable`]] [[@boost:/libs/core/index.html Boost.Core]] []]
|
||||
[[[link utility.utilities.operators `operators`]] [] []]
|
||||
[[[@boost:/libs/io/doc/html/io.html `ostream_string`]] [[@boost:/libs/io/index.html Boost.IO]] []]
|
||||
[[[link utility.utilities.result_of `result_of`]] [] [C++11 __std_result_of__]]
|
||||
[[[link utility.utilities.string_view `string_view`]] [] [C++17 __std_string_view__]]
|
||||
[[[@boost:/libs/throw_exception/doc/html/throw_exception.html#using_boost_throw_exception `throw_exception`]] [[@boost:/libs/throw_exception/index.html Boost.ThrowException]] []]
|
||||
[[[link utility.utilities.value_init `value_init`]] [] [C++11 [@https://en.cppreference.com/w/cpp/language/list_initialization List initialization]]]
|
||||
]
|
||||
|
||||
[endsect]
|
474
doc/quickref.xml
Normal file
474
doc/quickref.xml
Normal file
@ -0,0 +1,474 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN" "../../../tools/boostbook/dtd/boostbook.dtd">
|
||||
|
||||
<!--
|
||||
Copyright (c) 2021, Alan Freitas
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
|
||||
See accompanying file LICENSE_1_0.txt
|
||||
or copy at http://boost.org/LICENSE_1_0.txt
|
||||
-->
|
||||
|
||||
<!-- See also https://tdg.docbook.org/tdg/5.1/ -->
|
||||
|
||||
<!-- Doxygen reference -->
|
||||
<informaltable frame="all">
|
||||
<tgroup cols="4">
|
||||
<colspec colname="a"/>
|
||||
<colspec colname="b"/>
|
||||
<colspec colname="c"/>
|
||||
<colspec colname="d"/>
|
||||
|
||||
<thead>
|
||||
<row>
|
||||
<entry valign="center" namest="a" nameend="a">
|
||||
<bridgehead renderas="sect2">Base from Member</bridgehead>
|
||||
</entry>
|
||||
<entry valign="center" namest="b" nameend="b">
|
||||
<bridgehead renderas="sect2">Call Traits</bridgehead>
|
||||
</entry>
|
||||
<entry valign="center" namest="c" nameend="c">
|
||||
<bridgehead renderas="sect2">Compressed Pair</bridgehead>
|
||||
</entry>
|
||||
<entry valign="center" namest="d" nameend="d">
|
||||
<bridgehead renderas="sect2">In-place Factory</bridgehead>
|
||||
</entry>
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<!-- base_from_member -->
|
||||
<entry valign="top">
|
||||
<bridgehead renderas="sect3">Classes</bridgehead>
|
||||
<simplelist type="vert" columns="1">
|
||||
<member>
|
||||
<classname alt="boost::base_from_member">base_from_member</classname>
|
||||
</member>
|
||||
</simplelist>
|
||||
</entry>
|
||||
|
||||
<!-- call_traits -->
|
||||
<entry valign="top">
|
||||
<bridgehead renderas="sect3">Type Traits</bridgehead>
|
||||
<simplelist type="vert" columns="1">
|
||||
<member>
|
||||
<classname alt="boost::call_traits">call_traits</classname>
|
||||
</member>
|
||||
<member>
|
||||
<classname alt="boost::call_traits">call_traits<T&></classname>
|
||||
</member>
|
||||
<member>
|
||||
<classname alt="boost::call_traits">call_traits<T[N]></classname>
|
||||
</member>
|
||||
<member>
|
||||
<classname alt="boost::call_traits">call_traits<const T[N]></classname>
|
||||
</member>
|
||||
</simplelist>
|
||||
</entry>
|
||||
|
||||
<!-- compressed_pair -->
|
||||
<entry valign="top">
|
||||
<bridgehead renderas="sect3">Classes</bridgehead>
|
||||
<simplelist type="vert" columns="1">
|
||||
<member>
|
||||
<classname alt="boost::compressed_pair">compressed_pair</classname>
|
||||
</member>
|
||||
</simplelist>
|
||||
|
||||
<bridgehead renderas="sect3">Functions</bridgehead>
|
||||
<simplelist type="vert" columns="1">
|
||||
<member>
|
||||
<headername alt="boost/detail/compressed_pair.hpp">swap</headername>
|
||||
</member>
|
||||
</simplelist>
|
||||
</entry>
|
||||
|
||||
<!-- in_place_factory -->
|
||||
<entry valign="top">
|
||||
<bridgehead renderas="sect3">Classes</bridgehead>
|
||||
<simplelist type="vert" columns="1">
|
||||
<member>
|
||||
<classname alt="boost::in_place_factory_base">in_place_factory_base</classname>
|
||||
</member>
|
||||
<member>
|
||||
<classname alt="boost::typed_in_place_factory_base">typed_in_place_factory_base</classname>
|
||||
</member>
|
||||
</simplelist>
|
||||
</entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
|
||||
<tgroup cols="5">
|
||||
<colspec colname="a"/>
|
||||
<colspec colname="b"/>
|
||||
<colspec colname="c"/>
|
||||
<colspec colname="d"/>
|
||||
<colspec colname="e"/>
|
||||
|
||||
<thead>
|
||||
<row>
|
||||
<entry valign="center" namest="a" nameend="e">
|
||||
<bridgehead renderas="sect2">Operators</bridgehead>
|
||||
</entry>
|
||||
</row>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<row>
|
||||
<entry valign="top">
|
||||
<!-- 13 classes per cell -->
|
||||
<bridgehead renderas="sect3">Classes (1 of 5)</bridgehead>
|
||||
<simplelist type="vert" columns="1">
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.grpd_oprs.additive1">additive1</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.grpd_oprs.additive2">additive2</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.grpd_oprs.arithmetic1">arithmetic1</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.grpd_oprs.arithmetic2">arithmetic2</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.deref.grpd_iter_oprs.bidirectional_iteratable">bidirectional_iteratable</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.deref.iterator.bidirectional_iterator_helper">
|
||||
bidirectional_iterator_helper
|
||||
</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.grpd_oprs.bitwise1">bitwise1</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.grpd_oprs.bitwise2">bitwise2</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.smpl_oprs.decrementable">decrementable</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.deref.dereference.dereferenceable">dereferenceable</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.smpl_oprs.equality_comparable1">equality_comparable1</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.smpl_oprs.equality_comparable2">equality_comparable2</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.smpl_oprs.equivalent1">equivalent1</link>
|
||||
</member>
|
||||
</simplelist>
|
||||
</entry>
|
||||
|
||||
<entry valign="top">
|
||||
<bridgehead renderas="sect3">Classes (2 of 5)</bridgehead>
|
||||
<simplelist type="vert" columns="1">
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.smpl_oprs.equivalent2">equivalent2</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.grpd_oprs.euclidean_ring_operators1">euclidean_ring_operators1
|
||||
</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.grpd_oprs.euclidean_ring_operators2">euclidean_ring_operators2
|
||||
</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.grpd_oprs.field_operators1">field_operators1</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.grpd_oprs.field_operators2">field_operators2</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.deref.grpd_iter_oprs.forward_iteratable">forward_iteratable</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.deref.iterator.forward_iterator_helper">forward_iterator_helper</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.smpl_oprs.incrementable">incrementable</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.deref.dereference.indexable">indexable</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.deref.grpd_iter_oprs.input_iteratable">input_iteratable</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.deref.iterator.input_iterator_helper">input_iterator_helper</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.grpd_oprs.integer_arithmetic1">integer_arithmetic1</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.grpd_oprs.integer_arithmetic2">integer_arithmetic2</link>
|
||||
</member>
|
||||
</simplelist>
|
||||
</entry>
|
||||
|
||||
<entry valign="top">
|
||||
<bridgehead renderas="sect3">Classes (3 of 5)</bridgehead>
|
||||
<simplelist type="vert" columns="1">
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.grpd_oprs.integer_multiplicative1">integer_multiplicative1</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.grpd_oprs.integer_multiplicative2">integer_multiplicative2</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.smpl_oprs.less_than_comparable1">less_than_comparable1</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.smpl_oprs.less_than_comparable2">less_than_comparable2</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.grpd_oprs.multiplicative1">multiplicative1</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.grpd_oprs.multiplicative2">multiplicative2</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.ex_oprs.operators1">operators1</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.ex_oprs.operators2">operators2</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.ex_oprs.operators2">operators<T,T></link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.grpd_oprs.ordered_euclidean_ring_operators1">
|
||||
ordered_euclidean_ring_operators1
|
||||
</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.grpd_oprs.ordered_euclidean_ring_operators2">
|
||||
ordered_euclidean_ring_operators2
|
||||
</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.grpd_oprs.ordered_field_operators1">ordered_field_operators1</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.grpd_oprs.ordered_field_operators2">ordered_field_operators2</link>
|
||||
</member>
|
||||
</simplelist>
|
||||
</entry>
|
||||
|
||||
<entry valign="top">
|
||||
<bridgehead renderas="sect3">Classes (4 of 5)</bridgehead>
|
||||
<simplelist type="vert" columns="1">
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.grpd_oprs.ordered_ring_operators1">ordered_ring_operators1</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.grpd_oprs.ordered_ring_operators2">ordered_ring_operators2</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.deref.grpd_iter_oprs.output_iteratable">output_iteratable</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.deref.iterator.output_iterator_helper">output_iterator_helper</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.smpl_oprs.partially_ordered1">partially_ordered1</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.smpl_oprs.partially_ordered2">partially_ordered2</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.deref.grpd_iter_oprs.random_access_iteratable">random_access_iteratable</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.deref.iterator.random_access_iterator_helper">
|
||||
random_access_iterator_helper
|
||||
</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.grpd_oprs.ring_operators1">ring_operators1</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.grpd_oprs.ring_operators2">ring_operators2</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.grpd_oprs.shiftable1">shiftable1</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.grpd_oprs.shiftable2">shiftable2</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.grpd_oprs.totally_ordered1">totally_ordered1</link>
|
||||
</member>
|
||||
</simplelist>
|
||||
</entry>
|
||||
|
||||
<entry valign="top">
|
||||
<bridgehead renderas="sect3">Classes (5 of 5)</bridgehead>
|
||||
<simplelist type="vert" columns="1">
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.grpd_oprs.totally_ordered2">totally_ordered2</link>
|
||||
</member>
|
||||
<member>
|
||||
<link linkend="utility.utilities.operators.arithmetic.grpd_oprs.unit_steppable">unit_steppable</link>
|
||||
</member>
|
||||
</simplelist>
|
||||
</entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
|
||||
<tgroup cols="5">
|
||||
<colspec colname="a"/>
|
||||
<colspec colname="b"/>
|
||||
<colspec colname="c"/>
|
||||
<colspec colname="d"/>
|
||||
<colspec colname="e"/>
|
||||
|
||||
<thead>
|
||||
<row>
|
||||
<entry valign="center" namest="a" nameend="a">
|
||||
<bridgehead renderas="sect2">Result of</bridgehead>
|
||||
</entry>
|
||||
<entry valign="center" namest="b" nameend="d">
|
||||
<bridgehead renderas="sect2">String View</bridgehead>
|
||||
</entry>
|
||||
<entry valign="center" namest="e" nameend="e">
|
||||
<bridgehead renderas="sect2">Value Init</bridgehead>
|
||||
</entry>
|
||||
</row>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<row>
|
||||
<!-- result_of -->
|
||||
<entry valign="top">
|
||||
<bridgehead renderas="sect3">Type Traits</bridgehead>
|
||||
<simplelist type="vert" columns="1">
|
||||
<member>
|
||||
<classname alt="boost::result_of">result_of</classname>
|
||||
</member>
|
||||
<member>
|
||||
<classname alt="boost::tr1_result_of">tr1_result_of</classname>
|
||||
</member>
|
||||
</simplelist>
|
||||
</entry>
|
||||
|
||||
<!-- string_view -->
|
||||
<entry valign="top">
|
||||
<bridgehead renderas="sect3">Aliases</bridgehead>
|
||||
<simplelist type="vert" columns="1">
|
||||
<member>
|
||||
<classname alt="boost::basic_string_view">string_view</classname>
|
||||
</member>
|
||||
<member>
|
||||
<classname alt="boost::basic_string_ref">u16string_ref</classname>
|
||||
</member>
|
||||
<member>
|
||||
<classname alt="boost::basic_string_view">u16string_view</classname>
|
||||
</member>
|
||||
<member>
|
||||
<classname alt="boost::basic_string_ref">u32string_ref</classname>
|
||||
</member>
|
||||
<member>
|
||||
<classname alt="boost::basic_string_view">u32string_view</classname>
|
||||
</member>
|
||||
<member>
|
||||
<classname alt="boost::basic_string_ref">wstring_ref</classname>
|
||||
</member>
|
||||
<member>
|
||||
<classname alt="boost::basic_string_view">wstring_view</classname>
|
||||
</member>
|
||||
<member>
|
||||
<classname alt="boost::basic_string_ref">string_ref</classname>
|
||||
</member>
|
||||
</simplelist>
|
||||
</entry>
|
||||
|
||||
<entry valign="top">
|
||||
<bridgehead renderas="sect3">Classes</bridgehead>
|
||||
<simplelist type="vert" columns="1">
|
||||
<member>
|
||||
<classname alt="boost::basic_string_ref">basic_string_ref</classname>
|
||||
</member>
|
||||
<member>
|
||||
<classname alt="boost::basic_string_view">basic_string_view</classname>
|
||||
</member>
|
||||
</simplelist>
|
||||
<bridgehead renderas="sect3">Functions</bridgehead>
|
||||
<simplelist type="vert" columns="1">
|
||||
<member>
|
||||
<functionname alt="boost::hash_range">hash_range</functionname>
|
||||
</member>
|
||||
<member>
|
||||
<functionname alt="boost::hash_value">hash_value</functionname>
|
||||
</member>
|
||||
</simplelist>
|
||||
</entry>
|
||||
|
||||
<entry valign="top">
|
||||
<bridgehead renderas="sect3">Operators</bridgehead>
|
||||
<simplelist type="vert" columns="1">
|
||||
<member>
|
||||
<headername alt="boost/utility/string_view.hpp">operator==</headername>
|
||||
</member>
|
||||
<member>
|
||||
<headername alt="boost/utility/string_view.hpp">operator!=</headername>
|
||||
</member>
|
||||
<member>
|
||||
<headername alt="boost/utility/string_view.hpp">operator<</headername>
|
||||
</member>
|
||||
<member>
|
||||
<headername alt="boost/utility/string_view.hpp">operator<=</headername>
|
||||
</member>
|
||||
<member>
|
||||
<headername alt="boost/utility/string_view.hpp">operator></headername>
|
||||
</member>
|
||||
<member>
|
||||
<headername alt="boost/utility/string_view.hpp">operator>=</headername>
|
||||
</member>
|
||||
<member>
|
||||
<headername alt="boost/utility/string_view.hpp">operator<<</headername>
|
||||
</member>
|
||||
</simplelist>
|
||||
</entry>
|
||||
|
||||
<!-- value_init -->
|
||||
<entry valign="top">
|
||||
<bridgehead renderas="sect3">Classes</bridgehead>
|
||||
<simplelist type="vert" columns="1">
|
||||
<member>
|
||||
<classname alt="boost::initialized">initialized</classname>
|
||||
</member>
|
||||
<member>
|
||||
<classname alt="boost::initialized_value_t">initialized_value_t</classname>
|
||||
</member>
|
||||
<member>
|
||||
<classname alt="boost::value_initialized">value_initialized</classname>
|
||||
</member>
|
||||
</simplelist>
|
||||
<bridgehead renderas="sect3">Functions</bridgehead>
|
||||
<simplelist type="vert" columns="1">
|
||||
<member>
|
||||
<headername alt="boost/utility/value_init.hpp">get</headername>
|
||||
</member>
|
||||
<member>
|
||||
<headername alt="boost/utility/value_init.hpp">swap</headername>
|
||||
</member>
|
||||
</simplelist>
|
||||
<bridgehead renderas="sect3">Constants</bridgehead>
|
||||
<simplelist type="vert" columns="1">
|
||||
<member>
|
||||
<globalname alt="boost::initialized_value">initialized_value</globalname>
|
||||
</member>
|
||||
</simplelist>
|
||||
</entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</informaltable>
|
417
doc/result_of.qbk
Normal file
417
doc/result_of.qbk
Normal file
@ -0,0 +1,417 @@
|
||||
[/
|
||||
/ Copyright (c) 2012 Marshall Clow
|
||||
/ Copyright (c) 2021, Alan Freitas
|
||||
/
|
||||
/ Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
/ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
/]
|
||||
|
||||
[/===============]
|
||||
[section:result_of Result of]
|
||||
[/===============]
|
||||
|
||||
[section Introduction]
|
||||
|
||||
The class template __result_of__ helps determine the type of a
|
||||
call expression. For example, given an lvalue `f` of type `F`
|
||||
and lvalues `t1`,`t2`, ..., `tN` of types `T1`, `T2`, ..., `TN`,
|
||||
respectively, the type __result_of__`<F(T1, T2, ..., TN)>::type` defines
|
||||
the result type of the expression `f(t1, t2, ...,tN)`.
|
||||
|
||||
This implementation permits the type `F` to be a function pointer,
|
||||
function reference, member function pointer, or class type. By default,
|
||||
N may be any value between 0 and 16. To change the upper limit, define
|
||||
the macro `BOOST_RESULT_OF_NUM_ARGS` to the maximum value for N. Class
|
||||
template __result_of__ resides in the header
|
||||
[@../../../../boost/utility/result_of.hpp `<boost/utility/result_of.hpp>`].
|
||||
|
||||
If your compiler's support for __decltype__ is adequate, __result_of__
|
||||
automatically uses it to deduce the type of the call expression, in
|
||||
which case __result_of__`<F(T1, T2, ..., TN)>::type` names the type
|
||||
__decltype__`(boost::declval<F>()(boost::declval<T1>(),
|
||||
boost::declval<T2>(), ..., boost::declval<TN>()))`, as in the
|
||||
following example.
|
||||
|
||||
```
|
||||
struct functor {
|
||||
template<class T>
|
||||
T operator()(T x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
};
|
||||
|
||||
typedef __boost_result_of__<functor(int)>::type type; // type is int
|
||||
```
|
||||
|
||||
You can test whether __result_of__ is using __decltype__ by checking if
|
||||
the macro `BOOST_RESULT_OF_USE_DECLTYPE` is defined after
|
||||
including `result_of.hpp`. You can also force __result_of__ to use
|
||||
__decltype__ by defining `BOOST_RESULT_OF_USE_DECLTYPE` prior
|
||||
to including `result_of.hpp`.
|
||||
|
||||
If __decltype__ is not used, then automatic result type deduction of function
|
||||
objects is not possible. Instead, __result_of__ uses the following protocol
|
||||
to allow the programmer to specify a type. When `F` is a class type with a
|
||||
member type `result_type`, `result_of<F(T1, T2, ..., TN)>::type` is
|
||||
`F::result_type`. When `F` does not contain `result_type`,
|
||||
`result_of<F(T1, T2, ..., TN)>::type` is
|
||||
`F::result<F(T1, T2, ..., TN)>::type` when
|
||||
`N > 0` or `void` when `N = 0`.
|
||||
|
||||
Note that it is the responsibility of the programmer to ensure that
|
||||
function objects accurately advertise their result
|
||||
type via this protocol, as in the following example.
|
||||
|
||||
```
|
||||
struct functor {
|
||||
template <class> struct result;
|
||||
|
||||
template<class F, class T>
|
||||
struct result<F(T)> {
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
T operator()(T x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
};
|
||||
|
||||
typedef __boost_result_of__<functor(int)>::type type; // type is int
|
||||
```
|
||||
|
||||
Since __decltype__ is a language feature standardized in C++11, if you are
|
||||
writing a function object to be used with __result_of__, for maximum
|
||||
portability, you might consider following the above protocol
|
||||
even if your compiler has proper __decltype__ support.
|
||||
|
||||
If you wish to continue to use the protocol on compilers that
|
||||
support __decltype__, there are two options:
|
||||
|
||||
* You can use __boost_tr1_result_of__, which is also defined in
|
||||
[@../../../boost/utility/result_of.hpp `<boost/utility/result_of.hpp>`].
|
||||
|
||||
* Alternatively, you can define the macro `BOOST_RESULT_OF_USE_TR1`,
|
||||
which causes __result_of__ to use the protocol described above instead
|
||||
of __decltype__. If you choose to follow the protocol, take care to
|
||||
ensure that the `result_type` and `result<>` members accurately
|
||||
represent the return type of `operator()` given a call expression.
|
||||
|
||||
Additionally, __boost_result_of__ provides a third mode of operation,
|
||||
which some users may find convenient. When
|
||||
`BOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK` is defined,
|
||||
__boost_result_of__ behaves as follows. If the function object has a member
|
||||
type `result_type` or member template `result<>`, then __boost_result_of__
|
||||
will use the TR1 protocol.
|
||||
|
||||
Otherwise, __boost_result_of__ will use __decltype__. Using TR1 with
|
||||
a __decltype__ fallback may workaround certain problems at the cost of portability.
|
||||
For example:
|
||||
|
||||
* Deficient compiler: If your code requires __boost_result_of__ to work
|
||||
with incomplete return types but your compiler's __decltype__ implementation
|
||||
does not support incomplete return types, then you can use the TR1 protocol
|
||||
as a workaround. Support for incomplete return types was added late in the
|
||||
C++11 standardization process
|
||||
(see [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3276.pdf N3276])
|
||||
and is not implemented by some compilers.
|
||||
|
||||
* Deficient legacy code: If your existing TR1 function object advertises a different type than
|
||||
the actual result type deduced by __decltype__, then using TR1 with a __decltype__ fallback
|
||||
will allow you to work with both your existing TR1 function objects and new C++11
|
||||
function object. This situation could occur if your legacy function objects
|
||||
misused the TR1 protocol. See the documentation on known [link utility.utilities.result_of.result_of_tr1_diff differences]
|
||||
between __boost_result_of__ and TR1.
|
||||
|
||||
* [#BOOST_NO_RESULT_OF] This implementation of __result_of__ requires class template
|
||||
partial specialization, the ability to parse function types properly, and support
|
||||
for SFINAE. If __result_of__ is not supported by your compiler, including the header
|
||||
[@../../../boost/utility/result_of.hpp `<boost/utility/result_of.hpp>`] will define
|
||||
the macro `BOOST_NO_RESULT_OF`.
|
||||
|
||||
For additional information about __result_of__, see the C++ Library
|
||||
Technical Report, [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf N1836],
|
||||
or, for motivation and design rationale, the __result_of__
|
||||
[@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1454.html proposal].
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:result_of_guidelines Usage guidelines for __boost_result_of__]
|
||||
|
||||
The following are general suggestions about when and how to use __boost_result_of__.
|
||||
|
||||
# If you are targeting C++11 and are not concerned about portability to
|
||||
non-compliant compilers or previous versions of the standard, then use
|
||||
`__std_result_of__`. If `__std_result_of__` meets your needs, then
|
||||
there's no reason to stop using it.
|
||||
|
||||
# If you are targeting C++11 but may port your code to legacy compilers
|
||||
at some time in the future, then use __boost_result_of__ with __decltype__.
|
||||
When __decltype__ is used __boost_result_of__ and `__std_result_of__` are usually
|
||||
interchangeable. See the documentation on known [link utility.utilities.result_of.result_of_cxx11_diff differences]
|
||||
between __boost_result_of__ and C++11 __std_result_of__.
|
||||
|
||||
# If compiler portability is required, use __boost_result_of__ with the TR1 protocol
|
||||
|
||||
Regardless of how you configure __boost_result_of__, it is
|
||||
important to bear in mind that the return type of a
|
||||
function may change depending on its arguments, and
|
||||
additionally, the return type of a member function may
|
||||
change depending on the cv-qualification of the
|
||||
object. __boost_result_of__ must be passed
|
||||
the appropriately cv-qualified types in order to
|
||||
deduce the corresponding return type.
|
||||
|
||||
For example:
|
||||
|
||||
```
|
||||
struct functor {
|
||||
int& operator()(int);
|
||||
int const& operator()(int) const;
|
||||
|
||||
float& operator()(float&);
|
||||
float const& operator()(float const&);
|
||||
};
|
||||
|
||||
typedef __boost_result_of__<
|
||||
functor(int)
|
||||
>::type type1; // type1 is int &
|
||||
|
||||
typedef __boost_result_of__<
|
||||
const functor(int)
|
||||
>::type type2; // type2 is int const &
|
||||
|
||||
typedef __boost_result_of__<
|
||||
functor(float&)
|
||||
>::type type3; // type3 is float &
|
||||
|
||||
typedef __boost_result_of__<
|
||||
functor(float const&)
|
||||
>::type type4; // type4 is float const &
|
||||
```
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:result_of_tr1_protocol_guidelines Usage guidelines for the TR1 result_of protocol]
|
||||
|
||||
On compliant C++11 compilers, __boost_result_of__ can
|
||||
use __decltype__ to deduce the type of any
|
||||
call expression, including calls to function
|
||||
objects. However, on pre-C++11 compilers or on
|
||||
compilers without adequate decltype support,
|
||||
additional scaffolding is needed from function
|
||||
objects as described above. The following are
|
||||
suggestions about how to use the TR1 protocol.
|
||||
|
||||
* When the return type does not depend on the
|
||||
argument types or the cv-qualification of the
|
||||
function object, simply
|
||||
define `result_type`. There is no need
|
||||
to use the `result` template unless the
|
||||
return type varies.
|
||||
|
||||
* Use the protocol specified type when defining
|
||||
function prototypes. This can help ensure the
|
||||
actual return type does not get out of sync with
|
||||
the protocol specification. For example:
|
||||
|
||||
```
|
||||
struct functor {
|
||||
typedef int result_type;
|
||||
result_type operator()(int);
|
||||
};
|
||||
```
|
||||
|
||||
* Always specify the `result` specialization near the corresponding
|
||||
`operator()` overload. This can make it easier to keep the specializations
|
||||
in sync with the overloads. For example:
|
||||
|
||||
```
|
||||
struct functor {
|
||||
template<class> struct result;
|
||||
|
||||
template<class F>
|
||||
struct result<F(int)> {
|
||||
typedef int& type;
|
||||
};
|
||||
result<functor(int)>::type operator()(int);
|
||||
|
||||
template<class F>
|
||||
struct result<const F(int)> {
|
||||
typedef int const& type;
|
||||
};
|
||||
result<const functor(int)>::type operator()(int) const;
|
||||
};
|
||||
```
|
||||
|
||||
* Use type transformations to simplify
|
||||
the `result` template specialization. For
|
||||
example, the following uses [@../type_traits/doc/html/index.html Boost.TypeTraits]
|
||||
to specialize the `result` template for
|
||||
a single `operator()` that can be called on
|
||||
both a const and non-const function object with
|
||||
either an lvalue or rvalue argument.
|
||||
|
||||
```
|
||||
struct functor {
|
||||
template<class> struct result;
|
||||
|
||||
template<class F, class T>
|
||||
struct result<F(T)>
|
||||
: boost::remove_cv<
|
||||
typename boost::remove_reference<T>::type
|
||||
>
|
||||
{};
|
||||
|
||||
template<class T>
|
||||
T operator()(T const& x) const;
|
||||
};
|
||||
```
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:result_of_tr1_diff Known differences between __boost_result_of__ and __boost_tr1_result_of__]
|
||||
|
||||
When using __decltype__, __boost_result_of__ ignores the TR1 protocol and instead deduces the
|
||||
return type of function objects directly via __decltype__. In most situations, users
|
||||
will not notice a difference, so long as they use the protocol correctly. The following are situations in
|
||||
which the type deduced by __boost_result_of__ is known to differ depending on whether
|
||||
__decltype__ or the TR1 protocol is used.
|
||||
|
||||
TR1 protocol misusage: When using the TR1 protocol, __boost_result_of__ cannot
|
||||
detect whether the actual type of a call to a function object is the same as the
|
||||
type specified by the protocol, which allows for the possibility of inadvertent
|
||||
mismatches between the specified type and the actual type. When using __decltype__,
|
||||
these subtle bugs may result in compilation errors. For example:
|
||||
|
||||
```
|
||||
struct functor {
|
||||
typedef short result_type;
|
||||
int operator()(short);
|
||||
};
|
||||
|
||||
#ifdef BOOST_RESULT_OF_USE_DECLTYPE
|
||||
|
||||
BOOST_STATIC_ASSERT((
|
||||
boost::is_same<__boost_result_of__<functor(short)>::type, int>::value
|
||||
));
|
||||
|
||||
#else
|
||||
|
||||
BOOST_STATIC_ASSERT((
|
||||
boost::is_same<__boost_result_of__<functor(short)>::type, short>::value
|
||||
));
|
||||
|
||||
#endif
|
||||
```
|
||||
|
||||
Note that the user can force __boost_result_of__ to use the TR1
|
||||
protocol even on platforms that support __decltype__ by
|
||||
defining `BOOST_RESULT_OF_USE_TR1`.
|
||||
|
||||
Nullary function objects: When using the TR1 protocol, __boost_result_of__
|
||||
cannot always deduce the type of calls to nullary function objects, in which case the
|
||||
type defaults to void. When using __decltype__, __boost_result_of__ always gives the
|
||||
actual type of the call expression. For example:
|
||||
|
||||
```
|
||||
struct functor {
|
||||
template<class> struct result {
|
||||
typedef int type;
|
||||
};
|
||||
int operator()();
|
||||
};
|
||||
|
||||
#ifdef BOOST_RESULT_OF_USE_DECLTYPE
|
||||
|
||||
BOOST_STATIC_ASSERT((
|
||||
boost::is_same<__boost_result_of__<functor()>::type, int>::value
|
||||
));
|
||||
|
||||
#else
|
||||
|
||||
BOOST_STATIC_ASSERT((
|
||||
boost::is_same<__boost_result_of__<functor()>::type, void>::value
|
||||
));
|
||||
|
||||
#endif
|
||||
```
|
||||
|
||||
Note that there are some workarounds for the nullary function problem.
|
||||
So long as the return type does not vary, `result_type` can always be used to
|
||||
specify the return type regardless of arity. If the return type does vary,
|
||||
then the user can specialize __boost_result_of__ itself for nullary calls.
|
||||
|
||||
Non-class prvalues and cv-qualification: When using the TR1 protocol, __boost_result_of__ will
|
||||
report the cv-qualified type specified by `result_type` or the `result` template regardless of
|
||||
the actual cv-qualification of the call expression. When using __decltype__, __boost_result_of__
|
||||
will report the actual type of the call expression, which is not cv-qualified when the expression
|
||||
is a non-class prvalue. For example:
|
||||
|
||||
```
|
||||
struct functor {
|
||||
template<class> struct result;
|
||||
template<class F, class T> struct result<F(const T)> {
|
||||
typedef const T type;
|
||||
};
|
||||
|
||||
const short operator()(const short);
|
||||
int const & operator()(int const &);
|
||||
};
|
||||
|
||||
// Non-prvalue call expressions work the same with or without decltype.
|
||||
|
||||
BOOST_STATIC_ASSERT((
|
||||
boost::is_same<
|
||||
__boost_result_of__<functor(int const &)>::type,
|
||||
int const &
|
||||
::value
|
||||
));
|
||||
|
||||
// Non-class prvalue call expressions are not actually cv-qualified,
|
||||
// but only the decltype-based result_of reports this accurately.
|
||||
|
||||
#ifdef BOOST_RESULT_OF_USE_DECLTYPE
|
||||
|
||||
BOOST_STATIC_ASSERT((
|
||||
boost::is_same<
|
||||
__boost_result_of__<functor(const short)>::type,
|
||||
short
|
||||
::value
|
||||
));
|
||||
|
||||
#else
|
||||
|
||||
BOOST_STATIC_ASSERT((
|
||||
boost::is_same<
|
||||
__boost_result_of__<functor(const short)>::type,
|
||||
const short
|
||||
::value
|
||||
));
|
||||
|
||||
#endif
|
||||
```
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:result_of_cxx11_diff Known differences between __boost_result_of__ and C++11 result_of]
|
||||
|
||||
When using __decltype__, __boost_result_of__ implements most of the C++11 __std_result_of__
|
||||
specification. One known exception is that __boost_result_of__ does not implement the
|
||||
requirements regarding pointers to member data.
|
||||
|
||||
[endsect]
|
||||
|
||||
[/===============]
|
||||
[xinclude tmp/result_of_reference.xml]
|
||||
[/===============]
|
||||
|
||||
[section Acknowledgments]
|
||||
|
||||
Created by Doug Gregor. Contributions from Daniel Walker, Eric Niebler, Michel Morin and others.
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
@ -1,167 +0,0 @@
|
||||
[/
|
||||
/ Copyright (c) 2012 Marshall Clow
|
||||
/
|
||||
/ Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
/ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
/]
|
||||
|
||||
[article String_Ref
|
||||
[quickbook 1.5]
|
||||
[authors [Clow, Marshall]]
|
||||
[copyright 2012 Marshall Clow]
|
||||
[license
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
[@http://www.boost.org/LICENSE_1_0.txt])
|
||||
]
|
||||
]
|
||||
|
||||
[/===============]
|
||||
[section Overview]
|
||||
[/===============]
|
||||
|
||||
Boost.StringRef is an implementation of Jeffrey Yaskin's [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3442.html N3442:
|
||||
string_ref: a non-owning reference to a string].
|
||||
|
||||
When you are parsing/processing strings from some external source, frequently you want to pass a piece of text to a procedure for specialized processing. The canonical way to do this is as a `std::string`, but that has certain drawbacks:
|
||||
|
||||
1) If you are processing a buffer of text (say a HTTP response or the contents of a file), then you have to create the string from the text you want to pass, which involves memory allocation and copying of data.
|
||||
|
||||
2) if a routine receives a constant `std::string` and wants to pass a portion of that string to another routine, then it must create a new string of that substring.
|
||||
|
||||
3) A routine receives a constant `std::string` and wants to return a portion of the string, then it must create a new string to return.
|
||||
|
||||
`string_ref` is designed to solve these efficiency problems. A `string_ref` is a read-only reference to a contiguous sequence of characters, and provides much of the functionality of `std::string`. A `string_ref` is cheap to create, copy and pass by value, because it does not actually own the storage that it points to.
|
||||
|
||||
A `string_ref` is implemented as a small struct that contains a pointer to the start of the character data and a count. A `string_ref` is cheap to create and cheap to copy.
|
||||
|
||||
`string_ref` acts as a container; it includes all the methods that you would expect in a container, including iteration support, `operator []`, `at` and `size`. It can be used with any of the iterator-based algorithms in the STL - as long as you don't need to change the underlying data (`sort` and `remove`, for example, will not work)
|
||||
|
||||
Besides generic container functionality, `string_ref` provides a subset of the interface of `std::string`. This makes it easy to replace parameters of type `const std::string &` with `boost::string_ref`. Like `std::string`, `string_ref` has a static member variable named `npos` to denote the result of failed searches, and to mean "the end".
|
||||
|
||||
Because a `string_ref` does not own the data that it "points to", it introduces lifetime issues into code that uses it. The programmer must ensure that the data that a `string_ref` refers to exists as long as the `string_ref` does.
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[/===============]
|
||||
[section Examples]
|
||||
[/===============]
|
||||
|
||||
Integrating `string_ref` into your code is fairly simple. Wherever you pass a `const std::string &` or `std::string` as a parameter, that's a candidate for passing a `boost::string_ref`.
|
||||
|
||||
std::string extract_part ( const std::string &bar ) {
|
||||
return bar.substr ( 2, 3 );
|
||||
}
|
||||
|
||||
if ( extract_part ( "ABCDEFG" ).front() == 'C' ) { /* do something */ }
|
||||
|
||||
Let's figure out what happens in this (contrived) example.
|
||||
|
||||
First, a temporary string is created from the string literal `"ABCDEFG"`, and it is passed (by reference) to the routine `extract_part`. Then a second string is created in the call `std::string::substr` and returned to `extract_part` (this copy may be elided by RVO). Then `extract_part` returns that string back to the caller (again this copy may be elided). The first temporary string is deallocated, and `front` is called on the second string, and then it is deallocated as well.
|
||||
|
||||
Two `std::string`s are created, and two copy operations. That's (potentially) four memory allocations and deallocations, and the associated copying of data.
|
||||
|
||||
Now let's look at the same code with `string_ref`:
|
||||
|
||||
boost::string_ref extract_part ( boost::string_ref bar ) {
|
||||
return bar.substr ( 2, 3 );
|
||||
}
|
||||
|
||||
if ( extract_part ( "ABCDEFG" ).front() == "C" ) { /* do something */ }
|
||||
|
||||
No memory allocations. No copying of character data. No changes to the code other than the types. There are two `string_ref`s created, and two `string_ref`s copied, but those are cheap operations.
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
[/=================]
|
||||
[section:reference Reference ]
|
||||
[/=================]
|
||||
|
||||
The header file "string_ref.hpp" defines a template `boost::basic_string_ref`, and four specializations - for `char` / `wchar_t` / `char16_t` / `char32_t` .
|
||||
|
||||
`#include <boost/utility/string_ref.hpp>`
|
||||
|
||||
Construction and copying:
|
||||
|
||||
BOOST_CONSTEXPR basic_string_ref (); // Constructs an empty string_ref
|
||||
BOOST_CONSTEXPR basic_string_ref(const charT* str); // Constructs from a NULL-terminated string
|
||||
BOOST_CONSTEXPR basic_string_ref(const charT* str, size_type len); // Constructs from a pointer, length pair
|
||||
template<typename Allocator>
|
||||
basic_string_ref(const std::basic_string<charT, traits, Allocator>& str); // Constructs from a std::string
|
||||
basic_string_ref (const basic_string_ref &rhs);
|
||||
basic_string_ref& operator=(const basic_string_ref &rhs);
|
||||
|
||||
`string_ref` does not define a move constructor nor a move-assignment operator because copying a `string_ref` is just a cheap as moving one.
|
||||
|
||||
Basic container-like functions:
|
||||
|
||||
BOOST_CONSTEXPR size_type size() const ;
|
||||
BOOST_CONSTEXPR size_type length() const ;
|
||||
BOOST_CONSTEXPR size_type max_size() const ;
|
||||
BOOST_CONSTEXPR bool empty() const ;
|
||||
|
||||
// All iterators are const_iterators
|
||||
BOOST_CONSTEXPR const_iterator begin() const ;
|
||||
BOOST_CONSTEXPR const_iterator cbegin() const ;
|
||||
BOOST_CONSTEXPR const_iterator end() const ;
|
||||
BOOST_CONSTEXPR const_iterator cend() const ;
|
||||
const_reverse_iterator rbegin() const ;
|
||||
const_reverse_iterator crbegin() const ;
|
||||
const_reverse_iterator rend() const ;
|
||||
const_reverse_iterator crend() const ;
|
||||
|
||||
Access to the individual elements (all of which are const):
|
||||
|
||||
BOOST_CONSTEXPR const charT& operator[](size_type pos) const ;
|
||||
const charT& at(size_t pos) const ;
|
||||
BOOST_CONSTEXPR const charT& front() const ;
|
||||
BOOST_CONSTEXPR const charT& back() const ;
|
||||
BOOST_CONSTEXPR const charT* data() const ;
|
||||
|
||||
Modifying the `string_ref` (but not the underlying data):
|
||||
|
||||
void clear();
|
||||
void remove_prefix(size_type n);
|
||||
void remove_suffix(size_type n);
|
||||
|
||||
Searching:
|
||||
|
||||
size_type find(basic_string_ref s) const ;
|
||||
size_type find(charT c) const ;
|
||||
size_type rfind(basic_string_ref s) const ;
|
||||
size_type rfind(charT c) const ;
|
||||
size_type find_first_of(charT c) const ;
|
||||
size_type find_last_of (charT c) const ;
|
||||
|
||||
size_type find_first_of(basic_string_ref s) const ;
|
||||
size_type find_last_of(basic_string_ref s) const ;
|
||||
size_type find_first_not_of(basic_string_ref s) const ;
|
||||
size_type find_first_not_of(charT c) const ;
|
||||
size_type find_last_not_of(basic_string_ref s) const ;
|
||||
size_type find_last_not_of(charT c) const ;
|
||||
|
||||
String-like operations:
|
||||
|
||||
BOOST_CONSTEXPR basic_string_ref substr(size_type pos, size_type n=npos) const ; // Creates a new string_ref
|
||||
bool starts_with(charT c) const ;
|
||||
bool starts_with(basic_string_ref x) const ;
|
||||
bool ends_with(charT c) const ;
|
||||
bool ends_with(basic_string_ref x) const ;
|
||||
|
||||
[endsect]
|
||||
|
||||
[/===============]
|
||||
[section History]
|
||||
[/===============]
|
||||
|
||||
[heading boost 1.53]
|
||||
* Introduced
|
||||
|
||||
|
||||
[endsect]
|
||||
|
||||
|
||||
|
||||
|
209
doc/string_view.qbk
Normal file
209
doc/string_view.qbk
Normal file
@ -0,0 +1,209 @@
|
||||
[/
|
||||
/ Copyright (c) 2012 Marshall Clow
|
||||
/ Copyright (c) 2021, Alan Freitas
|
||||
/
|
||||
/ Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
/ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
/]
|
||||
|
||||
[/===============]
|
||||
[section:string_view String View]
|
||||
[/===============]
|
||||
|
||||
[section Introduction]
|
||||
|
||||
The class __boost_string_view__ and other classes derived from __basic_string_view__ represent references to strings or substrings. When you are parsing/processing strings from some external source, frequently you want to pass a piece of text to a procedure for specialized processing. Before __std_string_view__, the canonical way to do this used to be a __std_string__, but that has certain drawbacks:
|
||||
|
||||
1) If you are processing a buffer of text (say a HTTP response or the contents of a file), then you have to create the string from the text you want to pass, which involves memory allocation and copying of data.
|
||||
|
||||
2) If a routine receives a constant __std_string__ and wants to pass a portion of that string to another routine, then it must create a new string of that substring.
|
||||
|
||||
3) If a routine receives a constant __std_string__ and wants to return a portion of the string, then it must create a new string to return.
|
||||
|
||||
__boost_string_view__ is designed to solve these efficiency problems. A __boost_string_view__ is a read-only reference to a contiguous sequence of characters, and provides much of the functionality of __std_string__. A __boost_string_view__ is cheap to create, copy and pass by value, because it does not actually own the storage that it points to.
|
||||
|
||||
A __boost_string_view__ is implemented as a small struct that contains a pointer to the start of the character `data` and a `count`. A __boost_string_view__ is cheap to create and cheap to copy.
|
||||
|
||||
__boost_string_view__ acts as a container; it includes all the methods that you would expect in a container, including iteration support, `operator[]`, `at` and `size`. It can be used with any of the iterator-based algorithms in the STL - as long as you do not need to change the underlying data. For example, __std_sort__ and __std_remove__ will not work.
|
||||
|
||||
Besides generic container functionality, __boost_string_view__ provides a subset of the interface of __std_string__. This makes it easy to replace parameters of type `const __std_string__ &` with __boost_string_view__. Like __std_string__, __boost_string_view__ has a static member variable named `npos` to denote the result of failed searches, and to mean "the end".
|
||||
|
||||
[caution Because a __boost_string_view__ does not own the data that it refers to, it introduces lifetime issues into code that uses it. The programmer must ensure that the data that a __string_view__ refers to exists as long as the __string_view__ does.]
|
||||
|
||||
[note
|
||||
|
||||
Boost.Utility also includes the class __string_ref__:
|
||||
|
||||
- __string_ref__ is the initial implementation of Jeffrey Yaskin's [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3442.html N3442:
|
||||
string_ref: a non-owning reference to a string].
|
||||
|
||||
- __string_view__ is an updated implementation to reflect the Library Fundamentals TS [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4480.html N4480: \[string.view\]].
|
||||
|
||||
Please prefer __string_view__ / __basic_string_view__ over __string_ref__ / __basic_string_ref__:
|
||||
|
||||
- The __basic_string_view__ class better matches __std_basic_string_view__.
|
||||
|
||||
- __basic_string_view__ has WAY more constexpr support.
|
||||
|
||||
- Code that uses __basic_string_ref__ should continue to work.
|
||||
|
||||
- Not much code depends on __basic_string_ref__ anymore.
|
||||
|
||||
|
||||
]
|
||||
[endsect]
|
||||
|
||||
[/===============]
|
||||
[section Examples]
|
||||
[/===============]
|
||||
|
||||
Integrating __string_view__ into your code is fairly simple. Wherever you pass a `const __std_string__ &` or __std_string__ as a parameter, that's a candidate for passing a __boost_string_view__.
|
||||
|
||||
```
|
||||
__std_string__ extract_part ( const __std_string__ &bar ) {
|
||||
return bar.substr ( 2, 3 );
|
||||
}
|
||||
|
||||
if ( extract_part ( "ABCDEFG" ).front() == 'C' ) { /* do something */ }
|
||||
```
|
||||
|
||||
Let's figure out what happens in this contrived example.
|
||||
|
||||
* First, a temporary string is created from the string literal `"ABCDEFG"`, and it is passed (by reference) to the routine `extract_part`.
|
||||
* Then a second string is created in the call `__std_string__::substr` and returned to `extract_part` (this copy may be elided by RVO).
|
||||
* Then `extract_part` returns that string back to the caller (again this copy may be elided).
|
||||
* The first temporary string is deallocated, and `front` is called on the second string, and then it is deallocated as well.
|
||||
|
||||
Two __std_string__ s are created, and two copy operations. That is potentially four memory allocations and deallocations, and the associated copying of data.
|
||||
|
||||
Now let's look at the same code with __string_view__:
|
||||
|
||||
```
|
||||
__boost_string_view__ extract_part ( __boost_string_view__ bar ) {
|
||||
return bar.substr ( 2, 3 );
|
||||
}
|
||||
|
||||
if ( extract_part ( "ABCDEFG" ).front() == "C" ) { /* do something */ }
|
||||
```
|
||||
|
||||
No memory allocations. No copying of character data. No changes to the code other than the types. There are two __string_view__ s created, and two __string_view__ s copied, but those are cheap operations.
|
||||
[endsect]
|
||||
|
||||
[/=================]
|
||||
[section:reference Synopsis]
|
||||
[/=================]
|
||||
|
||||
The header file [@../../../../boost/utility/string_view.hpp `<boost/utility/string_view.hpp>`] defines a template __boost_basic_string_view__, and four specializations __string_view__, __wstring_view__, __u16string_view__, __u32string_view__ - for `char` / `wchar_t` / `char16_t` / `char32_t`.
|
||||
|
||||
`#include <boost/utility/string_view.hpp>`
|
||||
|
||||
Construction and copying:
|
||||
|
||||
```
|
||||
constexpr basic_string_view (); // Constructs an empty string_view
|
||||
constexpr basic_string_view(const charT* str); // Constructs from a NULL-terminated string
|
||||
constexpr basic_string_view(const charT* str, size_type len); // Constructs from a pointer, length pair
|
||||
template<typename Allocator>
|
||||
basic_string_view(const __std_basic_string__<charT, traits, Allocator>& str); // Constructs from a std::string
|
||||
basic_string_view (const basic_string_view &rhs);
|
||||
basic_string_view& operator=(const basic_string_view &rhs);
|
||||
```
|
||||
|
||||
__string_view__ does not define a move constructor nor a move-assignment operator because copying a __string_view__ is just a cheap as moving one.
|
||||
|
||||
Basic container-like functions:
|
||||
|
||||
```
|
||||
constexpr size_type size() const ;
|
||||
constexpr size_type length() const ;
|
||||
constexpr size_type max_size() const ;
|
||||
constexpr bool empty() const ;
|
||||
|
||||
// All iterators are const_iterators
|
||||
constexpr const_iterator begin() const ;
|
||||
constexpr const_iterator cbegin() const ;
|
||||
constexpr const_iterator end() const ;
|
||||
constexpr const_iterator cend() const ;
|
||||
const_reverse_iterator rbegin() const ;
|
||||
const_reverse_iterator crbegin() const ;
|
||||
const_reverse_iterator rend() const ;
|
||||
const_reverse_iterator crend() const ;
|
||||
```
|
||||
|
||||
Access to the individual elements (all of which are const):
|
||||
|
||||
```
|
||||
constexpr const charT& operator[](size_type pos) const ;
|
||||
const charT& at(size_t pos) const ;
|
||||
constexpr const charT& front() const ;
|
||||
constexpr const charT& back() const ;
|
||||
constexpr const charT* data() const ;
|
||||
```
|
||||
|
||||
Modifying the __string_view__ (but not the underlying data):
|
||||
|
||||
```
|
||||
void clear();
|
||||
void remove_prefix(size_type n);
|
||||
void remove_suffix(size_type n);
|
||||
```
|
||||
|
||||
Searching:
|
||||
|
||||
```
|
||||
size_type find(basic_string_view s) const ;
|
||||
size_type find(charT c) const ;
|
||||
size_type rfind(basic_string_view s) const ;
|
||||
size_type rfind(charT c) const ;
|
||||
size_type find_first_of(charT c) const ;
|
||||
size_type find_last_of (charT c) const ;
|
||||
|
||||
size_type find_first_of(basic_string_view s) const ;
|
||||
size_type find_last_of(basic_string_view s) const ;
|
||||
size_type find_first_not_of(basic_string_view s) const ;
|
||||
size_type find_first_not_of(charT c) const ;
|
||||
size_type find_last_not_of(basic_string_view s) const ;
|
||||
size_type find_last_not_of(charT c) const ;
|
||||
```
|
||||
|
||||
String-like operations:
|
||||
|
||||
```
|
||||
constexpr basic_string_view substr(size_type pos, size_type n=npos) const ; // Creates a new string_view
|
||||
bool starts_with(charT c) const ;
|
||||
bool starts_with(basic_string_view x) const ;
|
||||
bool ends_with(charT c) const ;
|
||||
bool ends_with(basic_string_view x) const ;
|
||||
```
|
||||
[endsect]
|
||||
|
||||
|
||||
[/===============]
|
||||
[section History]
|
||||
[/===============]
|
||||
|
||||
[h5 boost 1.71]
|
||||
* Glen Fernandes updated the implementation of the stream insertion operator to
|
||||
write directly to the `basic_streambuf` and refactored that functionality into
|
||||
a common utility.
|
||||
|
||||
[h5 boost 1.53]
|
||||
* Introduced
|
||||
|
||||
[endsect]
|
||||
|
||||
[/===============]
|
||||
[xinclude tmp/string_view_reference.xml]
|
||||
[/===============]
|
||||
|
||||
[/===============]
|
||||
[section Acknowledgments]
|
||||
[/===============]
|
||||
|
||||
Author: Clow, Marshall
|
||||
|
||||
Copyright 2012 Marshall Clow
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
2
doc/tmp/.gitignore
vendored
Normal file
2
doc/tmp/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
*.qbk
|
||||
*.xml
|
32
doc/utilities.qbk
Normal file
32
doc/utilities.qbk
Normal file
@ -0,0 +1,32 @@
|
||||
[/
|
||||
Copyright (c) 2021 Alan de Freitas (alandefreitas@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
Official repository: https://github.com/boostorg/utility
|
||||
]
|
||||
|
||||
[section:utilities Utilities]
|
||||
|
||||
The entire contents of Boost.Utility are in `namespace boost`.
|
||||
|
||||
[warning
|
||||
|
||||
Direct use of the header [@../../../../boost/utility.hpp `<boost/utility.hpp>`] is discouraged and it will be deprecated.
|
||||
|
||||
Please include the headers relative to individual components instead.
|
||||
|
||||
]
|
||||
|
||||
[include base_from_member.qbk]
|
||||
[include BOOST_BINARY.qbk]
|
||||
[include call_traits.qbk]
|
||||
[include compressed_pair.qbk]
|
||||
[include in_place_factory.qbk]
|
||||
[include operators.qbk]
|
||||
[include result_of.qbk]
|
||||
[include string_view.qbk]
|
||||
[include value_init.qbk]
|
||||
|
||||
[endsect]
|
578
doc/value_init.qbk
Normal file
578
doc/value_init.qbk
Normal file
@ -0,0 +1,578 @@
|
||||
[/
|
||||
/ Copyright (c) 2012 Marshall Clow
|
||||
/ Copyright (c) 2021, Alan Freitas
|
||||
/
|
||||
/ Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
/ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
/]
|
||||
|
||||
[/===============]
|
||||
[section:value_init Value Init]
|
||||
[/===============]
|
||||
|
||||
[section Introduction]
|
||||
|
||||
Constructing and initializing objects in a generic way is difficult in
|
||||
C++. The problem is that there are several different rules that apply
|
||||
for initialization. Depending on the type, the value of a newly constructed
|
||||
object can be zero-initialized (logically 0), default-constructed (using
|
||||
the default constructor), or indeterminate. When writing generic code,
|
||||
this problem must be addressed. The template __value_initialized__ provides
|
||||
a solution with consistent syntax for value initialization of scalar,
|
||||
union and class types. Moreover, __value_initialized__ offers a workaround to various
|
||||
compiler issues regarding value-initialization.
|
||||
|
||||
Furthermore, a `const` object __initialized_value__ is provided,
|
||||
to avoid repeating the type name when retrieving the value from a
|
||||
`__value_initialized__<T>` object.
|
||||
|
||||
There are various ways to initialize a variable, in C++. The following
|
||||
declarations all ['may] have a local variable initialized to its default
|
||||
value:
|
||||
|
||||
```
|
||||
T1 var1;
|
||||
T2 var2 = 0;
|
||||
T3 var3 = {};
|
||||
T4 var4 = T4();
|
||||
```
|
||||
|
||||
Unfortunately, whether or not any of those declarations correctly
|
||||
initialize the variable very much depends on its type. The first
|
||||
declaration is valid for any __DefaultConstructible__ type by definition.
|
||||
|
||||
However, it does not always do an initialization. It correctly initializes
|
||||
the variable when it's an instance of a class, and the author of the class
|
||||
has provided a proper default constructor. On the other hand, the value of
|
||||
`var1` is ['indeterminate] when its type is an arithmetic type, like `int`,
|
||||
`float`, or `char`.
|
||||
|
||||
An arithmetic variable is of course initialized properly by the second declaration,
|
||||
`T2 var2 = 0`. But this initialization form will not usually work for a
|
||||
class type, unless the class was especially written to support being
|
||||
initialized that way.
|
||||
|
||||
The third form, `T3 var3 = {}`, initializes an aggregate, typically a "C-style"
|
||||
`struct` or a "C-style" array. However, at the time this library was developed,
|
||||
the syntax did not allow for a class that has an explicitly declared constructor.
|
||||
|
||||
The fourth form is the most generic form of them, as it can be used to initialize
|
||||
arithmetic types, class types, aggregates, pointers, and other types.
|
||||
The declaration, `T4 var4 = T4()`, should be read as follows: First a temporary
|
||||
object is created, by `T4()`. This object is [link utility.utilities.value_init.details.value_initialization value-initialized].
|
||||
Next the temporary object is copied to the named variable, `var4`. Afterwards,
|
||||
the temporary is destroyed. While the copying and the destruction are likely to
|
||||
be optimized away, C++ still requires the type `T4` to be __CopyConstructible__.
|
||||
So `T4` needs to be ['both] __DefaultConstructible__ ['and] __CopyConstructible__.
|
||||
|
||||
A class may not be CopyConstructible, for example because it may have a
|
||||
private and undefined copy constructor, or because it may be derived from
|
||||
`boost::noncopyable`. Scott Meyers \[[link utility.utilities.value_init.references 2]\] explains why a
|
||||
class would be defined like that.
|
||||
|
||||
There is another, less obvious disadvantage to the fourth form, `T4 var4 = T4()`:
|
||||
It suffers from various [link utility.utilities.value_init.details.compiler_issues compiler issues], causing
|
||||
a variable to be left uninitialized in some compiler specific cases.
|
||||
|
||||
The template __value_initialized__ offers a generic way to initialize
|
||||
an object, like `T4 var4 = T4()`, but without requiring its type
|
||||
to be __CopyConstructible__. And it offers a workaround to those compiler issues
|
||||
regarding value-initialization as well. It allows getting an initialized
|
||||
variable of any type; it ['only] requires the type to be __DefaultConstructible__.
|
||||
A properly ['value-initialized] object of type `T` is constructed by the following
|
||||
declaration:
|
||||
|
||||
```
|
||||
value_initialized<T> var;
|
||||
```
|
||||
|
||||
The template __initialized__ offers both value-initialization and direct-initialization.
|
||||
It is especially useful as a data member type, allowing the very same object
|
||||
to be either direct-initialized or value-initialized.
|
||||
|
||||
The `const` object __initialized_value__ allows value-initializing a variable as follows:
|
||||
|
||||
```
|
||||
T var = initialized_value;
|
||||
```
|
||||
|
||||
This form of initialization is semantically equivalent to `T4 var4 = T4()`,
|
||||
but robust against the aforementioned compiler issues.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:details Details]
|
||||
|
||||
The C++ standard \[[link utility.utilities.value_init.references 3]\] contains the definitions
|
||||
of `zero-initialization` and `default-initialization`. Informally, zero-initialization
|
||||
means that the object is given the initial value `0` converted to the type and
|
||||
default-initialization means that [@https://en.cppreference.com/w/cpp/named_req/PODType POD] \[[link utility.utilities.value_init.references 4]\] types are zero-initialized,
|
||||
while non-POD class types are initialized with their corresponding default constructors.
|
||||
|
||||
A ['declaration] can contain an ['initializer], which specifies the
|
||||
object's initial value. The initializer can be just '()', which states that
|
||||
the object shall be value-initialized (but see below). However, if a ['declaration]
|
||||
has no ['initializer] and it is of a non-`const`, non-`static` POD type, the
|
||||
initial value is indeterminate: (see [sect]8.5, \[dcl.init\], for the
|
||||
accurate definitions).
|
||||
|
||||
```
|
||||
int x; // no initializer. x value is indeterminate.
|
||||
__std_string__ s; // no initializer, s is default-constructed.
|
||||
|
||||
int y = int();
|
||||
// y is initialized using copy-initialization
|
||||
// but the temporary uses an empty set of parentheses as the initializer,
|
||||
// so it is default-constructed.
|
||||
// A default constructed POD type is zero-initialized,
|
||||
// therefore, y == 0.
|
||||
|
||||
void foo ( __std_string__ ) ;
|
||||
foo ( __std_string__() ) ;
|
||||
// the temporary string is default constructed
|
||||
// as indicated by the initializer ()
|
||||
```
|
||||
|
||||
[section:value_initialization value-initialization]
|
||||
|
||||
The first [@http://www.open-std.org/JTC1/SC22/WG21/docs/cwg_defects.html Technical
|
||||
Corrigendum for the C++ Standard] (TC1), whose draft was released to the public in
|
||||
November 2001, introduced [@http://www.open-std.org/JTC1/SC22/WG21/docs/cwg_defects.html#178 Core
|
||||
Issue 178], among many other issues.
|
||||
|
||||
That issue introduced the new concept of `value-initialization`, and also fixed the
|
||||
wording for zero-initialization. Informally, value-initialization is similar to
|
||||
default-initialization with the exception that in some cases non-static data members
|
||||
and base class sub-objects are also value-initialized.
|
||||
|
||||
The difference is that an object that is value-initialized will not have, or at least
|
||||
is less likely to have, indeterminate values for data members and base class sub-objects;
|
||||
unlike the case of an object default constructed (see Core Issue 178 for a
|
||||
normative description).
|
||||
|
||||
In order to specify value-initialization of an object we need to use the
|
||||
empty-set initializer: `()`.
|
||||
|
||||
As before, a declaration with no initializer specifies default-initialization,
|
||||
and a declaration with a non-empty initializer specifies copy (`=xxx`) or
|
||||
direct (`xxx`) initialization.
|
||||
|
||||
```
|
||||
template<class T> void eat(T);
|
||||
|
||||
int x ; // indeterminate initial value.
|
||||
|
||||
__std_string__ s; // default-initialized.
|
||||
|
||||
eat ( int() ) ; // value-initialized
|
||||
|
||||
eat ( __std_string__() ) ; // value-initialized
|
||||
```
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:syntax value-initialization syntax]
|
||||
|
||||
Value initialization is specified using `()`. However, the empty set of
|
||||
parentheses is not permitted by the syntax of initializers because it is
|
||||
parsed as the declaration of a function taking no arguments:
|
||||
|
||||
```
|
||||
int x() ; // declares function int(*)()
|
||||
```
|
||||
|
||||
Thus, the empty `()` must be put in some other initialization context.
|
||||
|
||||
One alternative is to use copy-initialization syntax:
|
||||
|
||||
```
|
||||
int x = int();
|
||||
```
|
||||
|
||||
This works perfectly fine for POD types. But for non-POD class types,
|
||||
copy-initialization searches for a suitable constructor, which could be,
|
||||
for instance, the copy-constructor. It also searches for a suitable conversion
|
||||
sequence but this does not apply in this context.
|
||||
|
||||
For an arbitrary unknown type, using this syntax may not have the
|
||||
value-initialization effect intended because we don't know if a copy
|
||||
from a default constructed object is exactly the same as a default
|
||||
constructed object, and the compiler is allowed, in
|
||||
some cases, but never required to, optimize the copy away.
|
||||
|
||||
One possible generic solution is to use value-initialization of a non static
|
||||
data member:
|
||||
|
||||
```
|
||||
template<class T>
|
||||
struct W
|
||||
{
|
||||
// value-initialization of 'data' here.
|
||||
W() : data() {}
|
||||
|
||||
T data;
|
||||
};
|
||||
|
||||
W<int> w;
|
||||
// w.data is value-initialized for any type.
|
||||
```
|
||||
|
||||
This is the solution as it was supplied by earlier versions of the
|
||||
`__value_initialized__<T>` template class. Unfortunately this approach
|
||||
suffered from various compiler issues.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:compiler_issues Compiler issues]
|
||||
|
||||
Various compilers have not yet fully implemented value-initialization.
|
||||
So when an object should be ['value-initialized] according to the C++ Standard,
|
||||
it ['may] in practice still be left uninitialized, because of those
|
||||
compiler issues. It is hard to make a general statement on what those issues
|
||||
are like, because they depend on the compiler you are using, its version number,
|
||||
and the type of object you would like to have value-initialized.
|
||||
|
||||
All compilers we have tested so far support value-initialization for arithmetic types properly.
|
||||
However, various compilers may leave some types of ['aggregates] uninitialized, when they
|
||||
should be value-initialized. Value-initialization of objects of a pointer-to-member type may also
|
||||
go wrong on various compilers.
|
||||
|
||||
At the moment of writing, May 2010, the following reported issues regarding
|
||||
value-initialization are still there in current compiler releases:
|
||||
|
||||
* [@https://connect.microsoft.com/VisualStudio/feedback/details/100744 Microsoft Visual Studio Feedback ID 100744, Value-initialization in new-expression]: Reported by Pavel Kuznetsov (MetaCommunications Engineering), 2005.
|
||||
* [@http://connect.microsoft.com/VisualStudio/feedback/details/484295 Microsoft Visual Studio Feedback ID 484295, VC++ does not value-initialize members of derived classes without user-declared constructor] Reported by Sylvester Hesp, 2009.
|
||||
* [@https://connect.microsoft.com/VisualStudio/feedback/details/499606 Microsoft Visual Studio Feedback ID 499606, Presence of copy constructor breaks member class initialization] Reported by Alex Vakulenko, 2009
|
||||
* [@http://qc.embarcadero.com/wc/qcmain.aspx?d=83751 Embarcadero/C++Builder Report 83751, Value-initialization: arrays should have each element value-initialized] Reported by Niels Dekker (LKEB), 2010.
|
||||
* [@http://qc.embarcadero.com/wc/qcmain.aspx?d=83851 Embarcadero/C++Builder Report 83851, Value-initialized temporary triggers internal backend error C1798] Reported by Niels Dekker, 2010.
|
||||
* [@http://qc.embarcadero.com/wc/qcmain.aspx?d=84279 Embarcadero/C++Builder Report 84279, Internal compiler error (F1004), value-initializing member function pointer by "new T()"] Reported by Niels Dekker, 2010
|
||||
* Sun CR 6947016, Sun 5.10 may fail to value-initialize an object of a non-POD aggregate. Reported to Steve Clamage by Niels Dekker, 2010.
|
||||
* IBM's XL V10.1 and V11.1 may fail to value-initialize a temporary of a non-POD aggregate. Reported to Michael Wong by Niels Dekker, 2010.
|
||||
* Intel support issue 589832, Attempt to value-initialize pointer-to-member triggers internal error on Intel 11.1. Reported by John Maddock, 2010.
|
||||
|
||||
Note that all known GCC issues regarding value-initialization are fixed with GCC version 4.4, including
|
||||
[@http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30111 GCC Bug 30111]. Clang also has completely implemented
|
||||
value-initialization, as far as we know, now that [@http://llvm.org/bugs/show_bug.cgi?id=7139 Clang Bug 7139]
|
||||
is fixed.
|
||||
|
||||
New versions of __value_initialized__ (Boost release version 1.35 or higher) offer a workaround to these
|
||||
issues: __value_initialized__ may now clear its internal data, prior to constructing the object that it
|
||||
contains. It will do so for those compilers that need to have such a workaround, based on the
|
||||
[@boost:/libs/config/doc/html/boost_config/boost_macro_reference.html#boost_config.boost_macro_reference.macros_that_describe_defects
|
||||
compiler defect macro] `BOOST_NO_COMPLETE_VALUE_INITIALIZATION`.
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:types Types and objects]
|
||||
|
||||
[section:val_init `template class value_initialized<T>`]
|
||||
|
||||
```
|
||||
namespace boost {
|
||||
|
||||
template<class T>
|
||||
class __value_initialized__
|
||||
{
|
||||
|
||||
public :
|
||||
|
||||
__value_initialized__() : x() {}
|
||||
|
||||
operator T const &() const { return x ; }
|
||||
|
||||
operator T&() { return x ; }
|
||||
|
||||
T const &data() const { return x ; }
|
||||
|
||||
T& data() { return x ; }
|
||||
|
||||
void swap( __value_initialized__& );
|
||||
|
||||
private :
|
||||
|
||||
[unspecified] x ;
|
||||
|
||||
} ;
|
||||
|
||||
template<class T>
|
||||
|
||||
T const& get ( __value_initialized__<T> const& x )
|
||||
{
|
||||
return x.data();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T& get ( __value_initialized__<T>& x )
|
||||
{
|
||||
return x.data();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void swap ( __value_initialized__<T>& lhs, __value_initialized__<T>& rhs )
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
```
|
||||
|
||||
An object of this template class is a `T`-wrapper convertible to `'T&'` whose
|
||||
wrapped object (data member of type `T`) is [link utility.utilities.value_init.details.value_initialization value-initialized] upon default-initialization
|
||||
of this wrapper class:
|
||||
|
||||
```
|
||||
int zero = 0;
|
||||
__value_initialized__<int> x;
|
||||
assert( x == zero ) ;
|
||||
|
||||
__std_string__ def;
|
||||
__value_initialized__< __std_string__ > y;
|
||||
assert( y == def ) ;
|
||||
```
|
||||
|
||||
The purpose of this wrapper is to provide a consistent syntax for value initialization
|
||||
of scalar, union and class types (POD and non-POD) since the correct syntax for value
|
||||
initialization varies (see [link utility.utilities.value_init.details.syntax value-initialization syntax]).
|
||||
|
||||
The wrapped object can be accessed either through the conversion operator
|
||||
`T&`, the member function `data()`, or the non-member function `get()`:
|
||||
|
||||
```
|
||||
void watch(int);
|
||||
|
||||
__value_initialized__<int> x;
|
||||
|
||||
watch(x) ; // operator T& used.
|
||||
watch(x.data());
|
||||
watch( get(x) ) // function get() used
|
||||
```
|
||||
|
||||
Both `const` and non-`const` objects can be wrapped. Mutable objects can be
|
||||
modified directly from within the wrapper but constant objects cannot:
|
||||
|
||||
When `T` is a __Swappable__ type, `__value_initialized__<T>`
|
||||
is swappable as well, by calling its `swap` member function
|
||||
as well as by calling `boost::swap`.
|
||||
|
||||
```
|
||||
__value_initialized__<int> x;
|
||||
static_cast<int&>(x) = 1 ; // OK
|
||||
get(x) = 1 ; // OK
|
||||
|
||||
__value_initialized__<int const> y ;
|
||||
static_cast<int&>(y) = 1 ; // ERROR: cannot cast to int&
|
||||
static_cast<int const&>(y) = 1 ; // ERROR: cannot modify a const value
|
||||
get(y) = 1 ; // ERROR: cannot modify a const value
|
||||
```
|
||||
|
||||
[warning
|
||||
|
||||
The __value_initialized__ implementation of Boost version 1.40.0 and older
|
||||
allowed ['non-const] access to the wrapped object, from a constant wrapper,
|
||||
both by its conversion operator and its `data()` member function.
|
||||
|
||||
For example:
|
||||
|
||||
```
|
||||
__value_initialized__<int> const x_c;
|
||||
int& xr = x_c ; // OK, conversion to int& available even though x_c is itself const.
|
||||
xr = 2 ;
|
||||
```
|
||||
|
||||
The reason for this obscure behavior was that some compilers did not accept the following valid code:
|
||||
|
||||
```
|
||||
struct X
|
||||
{
|
||||
operator int&() ;
|
||||
operator int const&() const ;
|
||||
};
|
||||
X x ;
|
||||
(x == 1) ; // ERROR HERE!
|
||||
```
|
||||
|
||||
The current version of __value_initialized__ no longer has this obscure behavior.
|
||||
As compilers nowadays widely support overloading the conversion operator by having a `const`
|
||||
and a `non-const` version, we have decided to fix the issue accordingly. So the current version
|
||||
supports the idea of logical constness.
|
||||
|
||||
]
|
||||
|
||||
[section Recommended practice: The non-member get() idiom]
|
||||
|
||||
The obscure behavior of being able to modify a non-`const`
|
||||
wrapped object from within a constant wrapper (as was supported by previous
|
||||
versions of __value_initialized__) can be avoided if access to the wrapped object
|
||||
is always performed with the `get()` idiom:
|
||||
|
||||
```
|
||||
value_initialized<int> x;
|
||||
get(x) = 1; // OK
|
||||
value_initialized<int const> cx;
|
||||
get(x) = 1; // ERROR: Cannot modify a const object
|
||||
|
||||
value_initialized<int> const x_c;
|
||||
get(x_c) = 1; // ERROR: Cannot modify a const object
|
||||
|
||||
value_initialized<int const> const cx_c;
|
||||
get(cx_c) = 1; // ERROR: Cannot modify a const object
|
||||
```
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:initialized `template class initialized<T>`]
|
||||
|
||||
|
||||
```
|
||||
namespace boost {
|
||||
|
||||
template<class T>
|
||||
class __initialized__
|
||||
{
|
||||
|
||||
public :
|
||||
|
||||
__initialized__() : x() {}
|
||||
|
||||
explicit __initialized__(T const & arg) : x(arg) {}
|
||||
|
||||
operator T const &() const;
|
||||
|
||||
operator T&();
|
||||
|
||||
T const &data() const;
|
||||
|
||||
T& data();
|
||||
|
||||
void swap( __initialized__& );
|
||||
|
||||
private :
|
||||
|
||||
[unspecified] x ;
|
||||
|
||||
};
|
||||
|
||||
template<class T>
|
||||
T const& get ( __initialized__<T> const& x );
|
||||
|
||||
template<class T>
|
||||
T& get ( __initialized__<T>& x );
|
||||
|
||||
template<class T>
|
||||
void swap ( __initialized__<T>& lhs, __initialized__<T>& rhs );
|
||||
|
||||
} // namespace boost
|
||||
```
|
||||
|
||||
The template class `boost::__initialized__<T>` supports both value-initialization
|
||||
and direct-initialization, so its interface is a superset of the interface
|
||||
of `__value_initialized__<T>`: Its default-constructor value-initializes the
|
||||
wrapped object just like the default-constructor of `__value_initialized__<T>`,
|
||||
but `boost::__initialized__<T>` also offers an extra `explicit`
|
||||
constructor, which direct-initializes the wrapped object by the specified value.
|
||||
|
||||
`__initialized__<T>` is especially useful when the wrapped
|
||||
object must be either value-initialized or direct-initialized, depending on
|
||||
runtime conditions. For example, `__initialized__<T>` could
|
||||
hold the value of a data member that may be value-initialized by some
|
||||
constructors, and direct-initialized by others.
|
||||
|
||||
On the other hand, if it is known beforehand that the
|
||||
object must ['always] be value-initialized, `__value_initialized__<T>`
|
||||
may be preferable. And if the object must always be
|
||||
direct-initialized, none of the two wrappers really needs to be used.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:initialized_value `initialized_value`]
|
||||
|
||||
```
|
||||
namespace boost {
|
||||
class __initialized_value_t__
|
||||
{
|
||||
public :
|
||||
template <class T> operator T() const ;
|
||||
};
|
||||
|
||||
__initialized_value_t__ const initialized_value = {} ;
|
||||
|
||||
} // namespace boost
|
||||
```
|
||||
|
||||
__initialized_value__ provides a convenient way to get
|
||||
an initialized value: its conversion operator provides an appropriate
|
||||
['value-initialized] object for any __CopyConstructible__ type.
|
||||
|
||||
Suppose you need to have an initialized variable of type `T`.
|
||||
You could do it as follows:
|
||||
|
||||
```
|
||||
T var = T();
|
||||
```
|
||||
|
||||
But as mentioned before, this form suffers from various compiler issues.
|
||||
The template __value_initialized__ offers a workaround:
|
||||
|
||||
```
|
||||
T var = get( __value_initialized__<T>() );
|
||||
```
|
||||
|
||||
Unfortunately both forms repeat the type name, which
|
||||
is rather short now (`T`), but could of course be
|
||||
more like `Namespace::Template<Arg>::Type`.
|
||||
|
||||
Instead, one could use __initialized_value__ as follows:
|
||||
|
||||
```
|
||||
T var = __initialized_value__;
|
||||
```
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
||||
[section:references References]
|
||||
|
||||
# Bjarne Stroustrup, Gabriel Dos Reis, and J. Stephen Adamczyk wrote various papers,
|
||||
proposing to extend the support for brace-enclosed ['initializer lists]
|
||||
in C++. This [@https://en.cppreference.com/w/cpp/language/list_initialization feature] has
|
||||
now been available since C++11. This would allow a variable `var` of any __DefaultConstructible__ type
|
||||
`T` to be ['value-initialized] by doing `T var = {}`. The papers are listed at Bjarne's web page,
|
||||
[@http://www.research.att.com/~bs/WG21.html My C++ Standards committee papers].
|
||||
|
||||
# Scott Meyers, Effective C++, Third Edition, item 6, ['Explicitly disallow the use of
|
||||
compiler-generated functions you do not want], [@http://www.aristeia.com/books.html Scott Meyers: Books and CDs]
|
||||
|
||||
# The C++ Standard, Second edition (2003), ISO/IEC 14882:2003
|
||||
|
||||
# POD stands for [@https://en.cppreference.com/w/cpp/named_req/PODType "Plain Old Data"]
|
||||
|
||||
[endsect]
|
||||
|
||||
[/===============]
|
||||
[xinclude tmp/value_init_reference.xml]
|
||||
[/===============]
|
||||
|
||||
[section:acknowledgements Acknowledgements]
|
||||
|
||||
__value_initialized__ was developed by Fernando Cacciola, with help and suggestions
|
||||
from David Abrahams and Darin Adler.
|
||||
|
||||
Special thanks to Bjorn Karlsson who carefully edited and completed this documentation.
|
||||
|
||||
__value_initialized__ was reimplemented by Fernando Cacciola and Niels Dekker
|
||||
for Boost release version 1.35 (2008), offering a workaround to various compiler issues.
|
||||
|
||||
`boost::__initialized__` was very much inspired by feedback from Edward Diener and Jeffrey Hellrung.
|
||||
|
||||
__initialized_value__ was written by Niels Dekker, and added to Boost release version 1.36 (2008).
|
||||
|
||||
Developed by [@mailto:fernando_cacciola@hotmail.com Fernando Cacciola]. The latest version of
|
||||
this file can be found at [@http://www.boost.org www.boost.org].
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
@ -1,15 +1,19 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv=refresh content="0; URL=../core/doc/html/core/enable_if.html">
|
||||
<title>Automatic redirection</title>
|
||||
<title>Boost.EnableIf</title>
|
||||
<meta http-equiv="refresh" content="0; URL=../core/doc/html/core/enable_if.html">
|
||||
</head>
|
||||
<body>
|
||||
Automatic redirection failed, please go to
|
||||
<a href="../core/doc/html/core/enable_if.html">enable_if.html</a>. <hr>
|
||||
<p><EFBFBD> Copyright Beman Dawes, 2001</p>
|
||||
<p>Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy
|
||||
at <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</p>
|
||||
<a href="../core/doc/html/core/enable_if.html">../core/doc/html/core/enable_if.html</a>
|
||||
<hr>
|
||||
<tt>
|
||||
Boost.EnableIf<br>
|
||||
<br>
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
<a href=http://www.boost.org/LICENSE_1_0.txt>http://www.boost.org/LICENSE_1_0.txt</a>) <br>
|
||||
<br>
|
||||
</tt>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -1,163 +0,0 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Language" content="en-us">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
|
||||
|
||||
<title>Generator Iterator Adaptor Documentation</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="#FFFFFF" text="#000000">
|
||||
<img src="../../boost.png" alt="boost.png (6897 bytes)" align="middle"
|
||||
width="277" height="86">
|
||||
|
||||
<h1>Generator Iterator Adaptor</h1>
|
||||
|
||||
<p>Defined in header <a href=
|
||||
"../../boost/generator_iterator.hpp">boost/generator_iterator.hpp</a></p>
|
||||
|
||||
<p>The generator iterator adaptor makes it easier to create custom input
|
||||
iterators from 0-ary functions and function objects. The adaptor takes a
|
||||
<a href="http://www.sgi.com/tech/stl/Generator.html">Generator</a> and
|
||||
creates a model of <a href=
|
||||
"http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>. Each
|
||||
increment retrieves an item from the generator and makes it available to be
|
||||
retrieved by dereferencing. The motivation for this iterator is that some
|
||||
concepts can be more naturally expressed as a generator, while most STL
|
||||
algorithms expect an iterator. An example is the <a href=
|
||||
"../random/index.html">Random Number</a> library.</p>
|
||||
|
||||
<h2>Synopsis</h2>
|
||||
|
||||
<blockquote>
|
||||
<pre>
|
||||
namespace boost {
|
||||
template <class Generator>
|
||||
class generator_iterator_policies;
|
||||
|
||||
template <class Generator>
|
||||
class generator_iterator_generator;
|
||||
|
||||
template <class Generator>
|
||||
typename generator_iterator_generator<Generator>::type
|
||||
make_generator_iterator(Generator & gen);
|
||||
}
|
||||
</pre>
|
||||
</blockquote>
|
||||
<hr>
|
||||
|
||||
<h2>The Generator Iterator Generator Class</h2>
|
||||
|
||||
<p>The class generator_iterator_generator is a helper class whose purpose
|
||||
is to construct a generator iterator type. The template parameter for this
|
||||
class is the Generator function object type that is being wrapped. The
|
||||
generator iterator adaptor only holds a reference (or pointer) to the
|
||||
function object, therefore the function object must outlive the generator
|
||||
iterator adaptor constructed from it.</p>
|
||||
<pre>
|
||||
template <class Generator>
|
||||
class generator_iterator_generator
|
||||
{
|
||||
public:
|
||||
typedef <i>unspecified</i> type; // the resulting generator iterator type
|
||||
}
|
||||
</pre>
|
||||
|
||||
<h3>Template Parameters</h3>
|
||||
|
||||
<table border summary="">
|
||||
<tr>
|
||||
<th>Parameter</th>
|
||||
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td><tt><a href=
|
||||
"http://www.sgi.com/tech/stl/Generator.html">Generator</a></tt></td>
|
||||
|
||||
<td>The generator (0-ary function object) type being wrapped. The
|
||||
return type of the function must be defined as
|
||||
<tt>Generator::result_type</tt>. The function object must be a model of
|
||||
<a href=
|
||||
"http://www.sgi.com/tech/stl/Generator.html">Generator</a>.</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h3>Concept Model</h3>
|
||||
|
||||
<p>The generator iterator class is a model of <a href=
|
||||
"http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>.</p>
|
||||
|
||||
<h3>Members</h3>
|
||||
|
||||
<p>The generator iterator implements the member functions and operators
|
||||
required of the <a href=
|
||||
"http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>
|
||||
concept.<br></p>
|
||||
<hr>
|
||||
|
||||
<h2><a name="make_generator_iterator" id="make_generator_iterator">The
|
||||
Generator Iterator Object Generator</a></h2>
|
||||
|
||||
<p>The <tt>make_generator_iterator()</tt> function provides a convenient
|
||||
way to create generator iterator objects. The function saves the user the
|
||||
trouble of explicitly writing out the iterator types.</p>
|
||||
|
||||
<blockquote>
|
||||
<pre>
|
||||
template <class Generator>
|
||||
typename generator_iterator_generator<Generator>::type
|
||||
make_generator_iterator(Generator & gen);
|
||||
</pre>
|
||||
</blockquote>
|
||||
<hr>
|
||||
|
||||
<h3>Example</h3>
|
||||
|
||||
<p>The following program shows how <code>generator_iterator</code>
|
||||
transforms a generator into an input iterator.</p>
|
||||
|
||||
<blockquote>
|
||||
<pre>
|
||||
#include <iostream>
|
||||
#include <boost/generator_iterator.hpp>
|
||||
|
||||
class my_generator
|
||||
{
|
||||
public:
|
||||
typedef int result_type;
|
||||
my_generator() : state(0) { }
|
||||
int operator()() { return ++state; }
|
||||
private:
|
||||
int state;
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
my_generator gen;
|
||||
boost::generator_iterator_generator<my_generator>::type it = boost::make_generator_iterator(gen);
|
||||
for(int i = 0; i < 10; ++i, ++it)
|
||||
std::cout << *it << std::endl;
|
||||
}
|
||||
</pre>
|
||||
</blockquote>
|
||||
<hr>
|
||||
|
||||
<p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src=
|
||||
"../../doc/images/valid-html401.png" alt="Valid HTML 4.01 Transitional"
|
||||
height="31" width="88"></a></p>
|
||||
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->05 December, 2006<!--webbot bot="Timestamp" endspan i-checksum="38516" --></p>
|
||||
|
||||
<p><i>Copyright © 2001 <a href=
|
||||
"http://www.boost.org/people/jens_maurer.htm">Jens Maurer</a></i></p>
|
||||
|
||||
<p><i>Distributed under the Boost Software License, Version 1.0. (See
|
||||
accompanying file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or
|
||||
copy at <a href=
|
||||
"http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)</i></p>
|
||||
</body>
|
||||
</html>
|
@ -1,63 +0,0 @@
|
||||
//
|
||||
// Copyright 2014 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
|
||||
#include <boost/generator_iterator.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
class X
|
||||
{
|
||||
private:
|
||||
|
||||
int v;
|
||||
|
||||
public:
|
||||
|
||||
typedef int result_type;
|
||||
|
||||
X(): v( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
int operator()()
|
||||
{
|
||||
return ++v;
|
||||
}
|
||||
};
|
||||
|
||||
template<class InputIterator, class Size, class OutputIterator> OutputIterator copy_n( InputIterator first, Size n, OutputIterator result )
|
||||
{
|
||||
while( n-- > 0 )
|
||||
{
|
||||
*result++ = *first++;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void copy_test()
|
||||
{
|
||||
X x;
|
||||
boost::generator_iterator<X> in( &x );
|
||||
|
||||
int const N = 4;
|
||||
int v[ N ] = { 0 };
|
||||
|
||||
::copy_n( in, 4, v );
|
||||
|
||||
BOOST_TEST_EQ( v[0], 1 );
|
||||
BOOST_TEST_EQ( v[1], 2 );
|
||||
BOOST_TEST_EQ( v[2], 3 );
|
||||
BOOST_TEST_EQ( v[3], 4 );
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
copy_test();
|
||||
return boost::report_errors();
|
||||
}
|
@ -8,7 +8,7 @@
|
||||
import quickbook ;
|
||||
using boostbook ;
|
||||
|
||||
doxygen reference : ../../../../boost/utility/identity_type.hpp
|
||||
doxygen reference : ../../include/boost/utility/identity_type.hpp
|
||||
: <reftitle>"Reference"
|
||||
<doxygen:param>PREDEFINED="DOXYGEN"
|
||||
<doxygen:param>QUIET=YES
|
||||
|
@ -6,7 +6,7 @@
|
||||
<body>
|
||||
Automatic redirection failed, click this
|
||||
<a href="doc/html/index.html">link</a> <hr>
|
||||
<p><EFBFBD> Copyright Lorenzo Caminiti, 2009-2012</p>
|
||||
<p>Copyright © Lorenzo Caminiti, 2009-2012</p>
|
||||
<p>Distributed under the Boost Software License, Version 1.0 (see
|
||||
accompanying file <a href="../../../LICENSE_1_0.txt">
|
||||
LICENSE_1_0.txt</a> or a copy at
|
||||
|
@ -1,296 +1,19 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//SoftQuad Software//DTD HoTMetaL PRO 5.0::19981217::extensions to HTML 4.0//EN" "hmpro5.dtd">
|
||||
|
||||
<HTML>
|
||||
|
||||
<HEAD>
|
||||
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
|
||||
<TITLE>In_place_factory Documentation</TITLE>
|
||||
</HEAD>
|
||||
|
||||
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080">
|
||||
<H2 align="left"><IMG SRC="../../boost.png" WIDTH="276" HEIGHT="86"></H2>
|
||||
|
||||
<blockquote>
|
||||
<blockquote>
|
||||
<blockquote>
|
||||
<blockquote>
|
||||
<blockquote>
|
||||
<blockquote>
|
||||
<H2 align="left">Header <<A
|
||||
HREF="../../boost/utility/in_place_factory.hpp">boost/utility/in_place_factory.hpp</A>> </H2>
|
||||
|
||||
<H2 align="left">Header <<A
|
||||
HREF="../../boost/utility/typed_in_place_factory.hpp">boost/utility/typed_in_place_factory.hpp</A>> </H2>
|
||||
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
</blockquote>
|
||||
<p> </p>
|
||||
|
||||
<H2>Contents</H2>
|
||||
<DL CLASS="page-index">
|
||||
<DT><A HREF="#mot">Motivation</A></DT>
|
||||
<DT><A HREF="#framework">Framework</A></DT>
|
||||
<DT><A HREF="#specification">Specification</A></DT>
|
||||
<DT><A HREF="#container-usage">Container-side Usage</A></DT>
|
||||
<DT><A HREF="#user-usage">User-side Usage</A></DT>
|
||||
</DL>
|
||||
|
||||
<HR>
|
||||
|
||||
<H2><A NAME="mot"></A>Motivation</H2>
|
||||
|
||||
<p>Suppose we have a class</p>
|
||||
<pre>struct X
|
||||
{
|
||||
X ( int, std::string ) ;
|
||||
} ;</pre>
|
||||
<p>And a container for it which supports an empty state (that is, which can contain zero objects):</p>
|
||||
<pre>struct C
|
||||
{
|
||||
C() : contained_(0) {}
|
||||
~C() { delete contained_ ; }
|
||||
X* contained_ ;
|
||||
} ;</pre>
|
||||
<p>A container designed to support an empty state typically doesn't require the contained type to be DefaultConstructible,
|
||||
but it typically requires it to be CopyConstructible as a mechanism to
|
||||
initialize the object to store:</p>
|
||||
<pre>struct C
|
||||
{
|
||||
C() : contained_(0) {}
|
||||
C ( X const& v ) : contained_ ( new X(v) ) {}
|
||||
~C() { delete contained_ ; }
|
||||
X* contained_ ;
|
||||
} ;</pre>
|
||||
<p>There is a subtle problem with this: since the mechanism used to initialize the stored object is copy construction,
|
||||
there must exist a previously constructed source object to copy from. This
|
||||
object is likely to be temporary and serve no purpose besides being the source</p>
|
||||
<pre>void foo()
|
||||
{
|
||||
// Temporary object created.
|
||||
C c( X(123,"hello") ) ;
|
||||
}
|
||||
</pre>
|
||||
<p>A solution to this problem is to support direct construction of the contained
|
||||
object right in the container's storage.<br>
|
||||
In this scheme, the user supplies the arguments for the X constructor
|
||||
directly to the container:</p>
|
||||
<pre>struct C
|
||||
{
|
||||
C() : contained_(0) {}
|
||||
C ( X const& v ) : contained_ ( new X(v) ) {}
|
||||
C ( int a0, std::string a1 ) : contained_ ( new X(a0,a1) ) {}
|
||||
~C() { delete contained_ ; }
|
||||
X* contained_ ;
|
||||
} ;</pre>
|
||||
<pre>void foo()
|
||||
{
|
||||
// Wrapped object constructed in-place
|
||||
// No temporary created.
|
||||
C c(123,"hello") ;
|
||||
}
|
||||
</pre>
|
||||
<p>Clearly, this solution doesn't scale well since the container must duplicate all the constructor overloads from the contained type
|
||||
(at least all those which are to be supported directly in the container).</p>
|
||||
|
||||
<H2><A NAME="framework"></A>Framework</H2>
|
||||
<p>
|
||||
This library proposes a framework to allow some containers to directly contruct contained objects in-place without requiring
|
||||
the entire set of constructor overloads from the contained type. It also allows the container to remove the CopyConstuctible
|
||||
requirement from the contained type since objects can be directly constructed in-place without need of a copy.<br>
|
||||
The only requirement on the container is that it must provide proper storage (that is, correctly aligned and sized).
|
||||
Naturally, the container will typically support uninitialized storage to avoid the in-place construction to override
|
||||
a fully-constructed object (as this would defeat the purpose of in-place construction)
|
||||
</p>
|
||||
<p>For this purpose, the framework provides two families of classes collectively called: InPlaceFactories and TypedInPlaceFactories.<br>
|
||||
Essentially, these classes hold a sequence of actual parameters and a method to contruct an object in place using these parameters.
|
||||
Each member of the family differs only in the number (and type) of the parameter list. The first family
|
||||
takes the type of the object to construct directly in method provided for that
|
||||
purpose, whereas the second family incorporates that type in the factory class
|
||||
itself..</p>
|
||||
<p>From the container POV, using the framework amounts to calling the factory's method to contruct the object in place.
|
||||
From the user POV, it amounts to creating the right factory object to hold the parameters and pass it to the container.<br>
|
||||
The following simplified example shows the basic idea. A complete example follows the formal specification of the framework:</p>
|
||||
<pre>struct C
|
||||
{
|
||||
template<class InPlaceFactory>
|
||||
C ( InPlaceFactory const& aFactory )
|
||||
:
|
||||
contained_ ( uninitialized_storage() )
|
||||
{
|
||||
aFactory.template apply<X>(contained_);
|
||||
}
|
||||
|
||||
~C()
|
||||
{
|
||||
contained_ -> X::~X();
|
||||
delete[] contained_ ;
|
||||
}
|
||||
|
||||
char* uninitialized_storage() { return new char[sizeof(X)] ; }
|
||||
|
||||
char* contained_ ;
|
||||
} ;
|
||||
|
||||
void foo()
|
||||
{
|
||||
C c( in_place(123,"hello") ) ;
|
||||
}
|
||||
</pre>
|
||||
|
||||
<HR>
|
||||
|
||||
<H2><A NAME="specification">Specification</A></H2>
|
||||
|
||||
<p>The following is the first member of the family of 'in_place_factory' classes, along with its corresponding helper template function.
|
||||
The rest of the family varies only in the number and type of template (and constructor) parameters.</p>
|
||||
<PRE>namespace boost {
|
||||
|
||||
struct in_place_factory_base {} ;
|
||||
|
||||
template<class A0>
|
||||
class in_place_factory : public in_place_factory_base
|
||||
{
|
||||
public:</PRE>
|
||||
|
||||
<PRE> in_place_factory ( A0 const& a0 ) : m_a0(a0) {}
|
||||
|
||||
template< class T >
|
||||
void apply ( void* address ) const
|
||||
{
|
||||
new (address) T(m_a0);
|
||||
}
|
||||
|
||||
private:</PRE>
|
||||
|
||||
<PRE> A0 const& m_a0 ;
|
||||
} ;
|
||||
|
||||
template<class A0>
|
||||
in_place_factory<A0> in_place ( A0 const& a0 )
|
||||
{
|
||||
return in_place_factory<A0>(a0);
|
||||
}
|
||||
</PRE>
|
||||
|
||||
<p>Similarly, the following is the first member of the family of 'typed_in_place_factory' classes, along with its corresponding
|
||||
helper template function. The rest of the family varies only in the number and type of template (and constructor) parameters.</p>
|
||||
<PRE>namespace boost {
|
||||
|
||||
struct typed_in_place_factory_base {} ;
|
||||
|
||||
template<class T, class A0>
|
||||
class typed_in_place_factory : public typed_in_place_factory_base
|
||||
{
|
||||
public:</PRE>
|
||||
|
||||
<PRE> typed_in_place_factory ( A0 const& a0 ) : m_a0(a0) {}
|
||||
|
||||
void apply ( void* address ) const
|
||||
{
|
||||
new (address) T(m_a0);
|
||||
}
|
||||
|
||||
private:</PRE>
|
||||
|
||||
<PRE> A0 const& m_a0 ;
|
||||
} ;
|
||||
|
||||
template<class T, class A0>
|
||||
typed_in_place_factory<A0> in_place ( A0 const& a0 )
|
||||
{
|
||||
return typed_in_place_factory<T,A0>(a0);
|
||||
}</PRE>
|
||||
|
||||
<PRE>}
|
||||
</PRE>
|
||||
|
||||
<p>As you can see, the 'in_place_factory' and 'typed_in_place_factory' template classes varies only in the way they specify
|
||||
the target type: in the first family, the type is given as a template argument to the apply member function while in the
|
||||
second it is given directly as part of the factory class.<br>
|
||||
When the container holds a unique non-polymorphic type (such as the case of Boost.Optional), it knows the exact dynamic-type
|
||||
of the contained object and can pass it to the apply() method of a (non-typed) factory.
|
||||
In this case, end users can use an 'in_place_factory' instance which can be constructed without the type of the object to construct.<br>
|
||||
However, if the container holds heterogeneous or polymorphic objects (such as the case of Boost.Variant), the dynamic-type
|
||||
of the object to be constructed must be known by the factory itslef. In this case, end users must use a 'typed_in_place_factory'
|
||||
instead.</p>
|
||||
|
||||
<HR>
|
||||
|
||||
<h2><A NAME="container-usage">Container-side Usage</a></h2>
|
||||
|
||||
<p>As shown in the introductory simplified example, the container class must
|
||||
contain methods that accept an instance of
|
||||
these factories and pass the object's storage to the factory's apply method.<br>
|
||||
However, the type of the factory class cannot be completly specified in the container class because that would
|
||||
defeat the whole purpose of the factories which is to allow the container to accept a variadic argument list
|
||||
for the constructor of its contained object.<br>
|
||||
The correct function overload must be based on the only distinctive and common
|
||||
characteristic of all the classes in each family, the base class.<br>
|
||||
Depending on the container class, you can use 'enable_if' to generate the right overload, or use the following
|
||||
dispatch technique (used in the Boost.Optional class):
|
||||
</p>
|
||||
<pre>struct C
|
||||
{
|
||||
C() : contained_(0) {}
|
||||
C ( X const& v ) : contained_ ( new X(v) ) {}
|
||||
|
||||
template<class Expr>
|
||||
C ( Expr const& expr )
|
||||
:
|
||||
contained_ ( uninitialized_storage() )
|
||||
{
|
||||
construct(expr,&expr)
|
||||
}
|
||||
|
||||
~C() { delete contained_ ; }
|
||||
|
||||
template<class InPlaceFactory>
|
||||
void construct ( InPlaceFactory const& aFactory, boost::in_place_factory_base* )
|
||||
{
|
||||
aFactory.template apply<X>(contained_);
|
||||
}
|
||||
|
||||
template<class TypedInPlaceFactory>
|
||||
void construct ( TypedInPlaceFactory const& aFactory, boost::typed_in_place_factory_base* )
|
||||
{
|
||||
aFactory.apply(contained_);
|
||||
}
|
||||
|
||||
X* uninitialized_storage() { return static_cast<X*>(new char[sizeof(X)]) ; }
|
||||
|
||||
X* contained_ ;
|
||||
} ;
|
||||
</pre>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>Boost.InPlaceFactory</title>
|
||||
<meta http-equiv="refresh" content="0; URL=./doc/html/utility/utilities/in_place_factory.html">
|
||||
</head>
|
||||
<body>
|
||||
Automatic redirection failed, please go to
|
||||
<a href="./doc/html/utility/utilities/in_place_factory.html">./doc/html/utility/utilities/in_place_factory.html</a>
|
||||
<hr>
|
||||
|
||||
<h2><A NAME="user-usage">User-side Usage</a></h2>
|
||||
|
||||
<p>End users pass to the container an instance of a factory object holding the actual parameters needed to construct the
|
||||
contained object directly within the container. For this, the helper template function 'in_place' is used.<br>
|
||||
The call 'in_place(a0,a1,a2,...,an)' constructs a (non-typed) 'in_place_factory' instance with the given argument list.<br>
|
||||
The call 'in_place<T>(a0,a1,a2,...,an)' constructs a 'typed_in_place_factory' instance with the given argument list for the
|
||||
type 'T'.</p>
|
||||
<pre>void foo()
|
||||
{
|
||||
C a( in_place(123,"hello") ) ; // in_place_factory passed
|
||||
C b( in_place<X>(456,"world") ) ; // typed_in_place_factory passed
|
||||
}
|
||||
</pre>
|
||||
|
||||
<P>Revised September 17, 2004</P>
|
||||
<p><EFBFBD> Copyright Fernando Luis Cacciola Carballal, 2004</p>
|
||||
<p> Use, modification, and distribution are subject to the Boost Software
|
||||
License, Version 1.0. (See accompanying file <a href="../../LICENSE_1_0.txt">
|
||||
LICENSE_1_0.txt</a> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">
|
||||
www.boost.org/LICENSE_1_0.txt</a>)</p>
|
||||
<P>Developed by <A HREF="mailto:fernando_cacciola@hotmail.com">Fernando Cacciola</A>,
|
||||
the latest version of this file can be found at <A
|
||||
HREF="http://www.boost.org">www.boost.org</A>, and the boost
|
||||
<A HREF="http://www.boost.org/more/mailing_lists.htm#main">discussion lists</A></P>
|
||||
</BODY>
|
||||
</HTML>
|
||||
<tt>
|
||||
Boost.InPlaceFactory<br>
|
||||
<br>
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
<a href=http://www.boost.org/LICENSE_1_0.txt>http://www.boost.org/LICENSE_1_0.txt</a>) <br>
|
||||
<br>
|
||||
</tt>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -100,7 +100,7 @@ struct call_traits<T&>
|
||||
typedef T& param_type; // hh removed const
|
||||
};
|
||||
|
||||
#if BOOST_WORKAROUND( __BORLANDC__, < 0x5A0 )
|
||||
#if BOOST_WORKAROUND( BOOST_BORLANDC, < 0x5A0 )
|
||||
// these are illegal specialisations; cv-qualifies applied to
|
||||
// references have no effect according to [8.3.2p1],
|
||||
// C++ Builder requires them though as it treats cv-qualified
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
#include <boost/type_traits/remove_cv.hpp>
|
||||
#include <boost/type_traits/is_empty.hpp>
|
||||
#include <boost/type_traits/is_final.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/call_traits.hpp>
|
||||
|
||||
@ -42,6 +43,14 @@ class compressed_pair;
|
||||
|
||||
namespace details
|
||||
{
|
||||
template<class T, bool E = boost::is_final<T>::value>
|
||||
struct compressed_pair_empty
|
||||
: ::boost::false_type { };
|
||||
|
||||
template<class T>
|
||||
struct compressed_pair_empty<T, false>
|
||||
: ::boost::is_empty<T> { };
|
||||
|
||||
// JM altered 26 Jan 2000:
|
||||
template <class T1, class T2, bool IsSame, bool FirstEmpty, bool SecondEmpty>
|
||||
struct compressed_pair_switch;
|
||||
@ -338,13 +347,15 @@ namespace details
|
||||
|
||||
template <class T1, class T2>
|
||||
class compressed_pair
|
||||
: private ::boost::details::compressed_pair_imp<T1, T2,
|
||||
#ifndef BOOST_UTILITY_DOCS
|
||||
: private ::boost::details::compressed_pair_imp<T1, T2,
|
||||
::boost::details::compressed_pair_switch<
|
||||
T1,
|
||||
T2,
|
||||
::boost::is_same<typename remove_cv<T1>::type, typename remove_cv<T2>::type>::value,
|
||||
::boost::is_empty<T1>::value,
|
||||
::boost::is_empty<T2>::value>::value>
|
||||
::boost::details::compressed_pair_empty<T1>::value,
|
||||
::boost::details::compressed_pair_empty<T2>::value>::value>
|
||||
#endif // BOOST_UTILITY_DOCS
|
||||
{
|
||||
private:
|
||||
typedef details::compressed_pair_imp<T1, T2,
|
||||
@ -352,8 +363,8 @@ private:
|
||||
T1,
|
||||
T2,
|
||||
::boost::is_same<typename remove_cv<T1>::type, typename remove_cv<T2>::type>::value,
|
||||
::boost::is_empty<T1>::value,
|
||||
::boost::is_empty<T2>::value>::value> base;
|
||||
::boost::details::compressed_pair_empty<T1>::value,
|
||||
::boost::details::compressed_pair_empty<T2>::value>::value> base;
|
||||
public:
|
||||
typedef T1 first_type;
|
||||
typedef T2 second_type;
|
||||
@ -383,13 +394,15 @@ public:
|
||||
//
|
||||
template <class T>
|
||||
class compressed_pair<T, T>
|
||||
#ifndef BOOST_UTILITY_DOCS
|
||||
: private details::compressed_pair_imp<T, T,
|
||||
::boost::details::compressed_pair_switch<
|
||||
T,
|
||||
T,
|
||||
::boost::is_same<typename remove_cv<T>::type, typename remove_cv<T>::type>::value,
|
||||
::boost::is_empty<T>::value,
|
||||
::boost::is_empty<T>::value>::value>
|
||||
::boost::details::compressed_pair_empty<T>::value,
|
||||
::boost::details::compressed_pair_empty<T>::value>::value>
|
||||
#endif // BOOST_UTILITY_DOCS
|
||||
{
|
||||
private:
|
||||
typedef details::compressed_pair_imp<T, T,
|
||||
@ -397,8 +410,8 @@ private:
|
||||
T,
|
||||
T,
|
||||
::boost::is_same<typename remove_cv<T>::type, typename remove_cv<T>::type>::value,
|
||||
::boost::is_empty<T>::value,
|
||||
::boost::is_empty<T>::value>::value> base;
|
||||
::boost::details::compressed_pair_empty<T>::value,
|
||||
::boost::details::compressed_pair_empty<T>::value>::value> base;
|
||||
public:
|
||||
typedef T first_type;
|
||||
typedef T second_type;
|
||||
|
@ -20,10 +20,11 @@
|
||||
- John Maddock Jan 2000.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef BOOST_UTILITY_DOCS
|
||||
#ifndef BOOST_OB_COMPRESSED_PAIR_HPP
|
||||
#define BOOST_OB_COMPRESSED_PAIR_HPP
|
||||
|
||||
|
||||
#include <algorithm>
|
||||
#ifndef BOOST_OBJECT_TYPE_TRAITS_HPP
|
||||
#include <boost/type_traits/object_traits.hpp>
|
||||
@ -494,6 +495,4 @@ inline void swap(compressed_pair<T1, T2>& x, compressed_pair<T1, T2>& y)
|
||||
} // boost
|
||||
|
||||
#endif // BOOST_OB_COMPRESSED_PAIR_HPP
|
||||
|
||||
|
||||
|
||||
#endif // BOOST_UTILITY_DOCS
|
||||
|
@ -1,165 +0,0 @@
|
||||
// Boost next_prior.hpp header file ---------------------------------------//
|
||||
|
||||
// (C) Copyright Dave Abrahams and Daniel Walker 1999-2003. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org/libs/utility for documentation.
|
||||
|
||||
// Revision History
|
||||
// 13 Dec 2003 Added next(x, n) and prior(x, n) (Daniel Walker)
|
||||
|
||||
#ifndef BOOST_NEXT_PRIOR_HPP_INCLUDED
|
||||
#define BOOST_NEXT_PRIOR_HPP_INCLUDED
|
||||
|
||||
#include <iterator>
|
||||
#if defined(_MSC_VER) && _MSC_VER <= 1310
|
||||
#include <boost/mpl/and.hpp>
|
||||
#include <boost/type_traits/is_integral.hpp>
|
||||
#endif
|
||||
#include <boost/type_traits/is_unsigned.hpp>
|
||||
#include <boost/type_traits/integral_promotion.hpp>
|
||||
#include <boost/type_traits/make_signed.hpp>
|
||||
#include <boost/type_traits/has_plus.hpp>
|
||||
#include <boost/type_traits/has_plus_assign.hpp>
|
||||
#include <boost/type_traits/has_minus.hpp>
|
||||
#include <boost/type_traits/has_minus_assign.hpp>
|
||||
|
||||
namespace boost {
|
||||
|
||||
// Helper functions for classes like bidirectional iterators not supporting
|
||||
// operator+ and operator-
|
||||
//
|
||||
// Usage:
|
||||
// const std::list<T>::iterator p = get_some_iterator();
|
||||
// const std::list<T>::iterator prev = boost::prior(p);
|
||||
// const std::list<T>::iterator next = boost::next(prev, 2);
|
||||
|
||||
// Contributed by Dave Abrahams
|
||||
|
||||
namespace next_prior_detail {
|
||||
|
||||
template< typename T, typename Distance, bool HasPlus = has_plus< T, Distance >::value >
|
||||
struct next_impl2
|
||||
{
|
||||
static T call(T x, Distance n)
|
||||
{
|
||||
std::advance(x, n);
|
||||
return x;
|
||||
}
|
||||
};
|
||||
|
||||
template< typename T, typename Distance >
|
||||
struct next_impl2< T, Distance, true >
|
||||
{
|
||||
static T call(T x, Distance n)
|
||||
{
|
||||
return x + n;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template< typename T, typename Distance, bool HasPlusAssign = has_plus_assign< T, Distance >::value >
|
||||
struct next_impl1 :
|
||||
public next_impl2< T, Distance >
|
||||
{
|
||||
};
|
||||
|
||||
template< typename T, typename Distance >
|
||||
struct next_impl1< T, Distance, true >
|
||||
{
|
||||
static T call(T x, Distance n)
|
||||
{
|
||||
x += n;
|
||||
return x;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<
|
||||
typename T,
|
||||
typename Distance,
|
||||
typename PromotedDistance = typename integral_promotion< Distance >::type,
|
||||
#if !defined(_MSC_VER) || _MSC_VER > 1310
|
||||
bool IsUInt = is_unsigned< PromotedDistance >::value
|
||||
#else
|
||||
// MSVC 7.1 has problems with applying is_unsigned to non-integral types
|
||||
bool IsUInt = mpl::and_< is_integral< PromotedDistance >, is_unsigned< PromotedDistance > >::value
|
||||
#endif
|
||||
>
|
||||
struct prior_impl3
|
||||
{
|
||||
static T call(T x, Distance n)
|
||||
{
|
||||
std::advance(x, -n);
|
||||
return x;
|
||||
}
|
||||
};
|
||||
|
||||
template< typename T, typename Distance, typename PromotedDistance >
|
||||
struct prior_impl3< T, Distance, PromotedDistance, true >
|
||||
{
|
||||
static T call(T x, Distance n)
|
||||
{
|
||||
typedef typename make_signed< PromotedDistance >::type signed_distance;
|
||||
std::advance(x, -static_cast< signed_distance >(static_cast< PromotedDistance >(n)));
|
||||
return x;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template< typename T, typename Distance, bool HasMinus = has_minus< T, Distance >::value >
|
||||
struct prior_impl2 :
|
||||
public prior_impl3< T, Distance >
|
||||
{
|
||||
};
|
||||
|
||||
template< typename T, typename Distance >
|
||||
struct prior_impl2< T, Distance, true >
|
||||
{
|
||||
static T call(T x, Distance n)
|
||||
{
|
||||
return x - n;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template< typename T, typename Distance, bool HasMinusAssign = has_minus_assign< T, Distance >::value >
|
||||
struct prior_impl1 :
|
||||
public prior_impl2< T, Distance >
|
||||
{
|
||||
};
|
||||
|
||||
template< typename T, typename Distance >
|
||||
struct prior_impl1< T, Distance, true >
|
||||
{
|
||||
static T call(T x, Distance n)
|
||||
{
|
||||
x -= n;
|
||||
return x;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace next_prior_detail
|
||||
|
||||
template <class T>
|
||||
inline T next(T x) { return ++x; }
|
||||
|
||||
template <class T, class Distance>
|
||||
inline T next(T x, Distance n)
|
||||
{
|
||||
return next_prior_detail::next_impl1< T, Distance >::call(x, n);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T prior(T x) { return --x; }
|
||||
|
||||
template <class T, class Distance>
|
||||
inline T prior(T x, Distance n)
|
||||
{
|
||||
return next_prior_detail::prior_impl1< T, Distance >::call(x, n);
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_NEXT_PRIOR_HPP_INCLUDED
|
@ -1,7 +1,7 @@
|
||||
// Boost operators.hpp header file ----------------------------------------//
|
||||
|
||||
// (C) Copyright David Abrahams, Jeremy Siek, Daryle Walker 1999-2001.
|
||||
// (C) Copyright Daniel Frey 2002-2016.
|
||||
// (C) Copyright Daniel Frey 2002-2017.
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
@ -9,6 +9,9 @@
|
||||
// See http://www.boost.org/libs/utility/operators.htm for documentation.
|
||||
|
||||
// Revision History
|
||||
// 23 Nov 17 Protect dereferenceable<> from overloaded operator&.
|
||||
// 15 Oct 17 Adapted to C++17, replace std::iterator<> with manual
|
||||
// implementation.
|
||||
// 22 Feb 16 Added ADL protection, preserve old work-arounds in
|
||||
// operators_v1.hpp and clean up this file. (Daniel Frey)
|
||||
// 16 Dec 10 Limit warning suppression for 4284 to older versions of VC++
|
||||
@ -96,6 +99,7 @@
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/detail/workaround.hpp>
|
||||
#include <boost/core/addressof.hpp>
|
||||
|
||||
#if defined(__sgi) && !defined(__GNUC__)
|
||||
# pragma set woff 1234
|
||||
@ -105,6 +109,15 @@
|
||||
# pragma warning( disable : 4284 ) // complaint about return type of
|
||||
#endif // operator-> not begin a UDT
|
||||
|
||||
// Define BOOST_OPERATORS_CONSTEXPR to be like BOOST_CONSTEXPR but empty under MSVC < v19.22
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, < 1922)
|
||||
#define BOOST_OPERATORS_CONSTEXPR
|
||||
#elif defined __sun
|
||||
#define BOOST_OPERATORS_CONSTEXPR
|
||||
#else
|
||||
#define BOOST_OPERATORS_CONSTEXPR BOOST_CONSTEXPR
|
||||
#endif
|
||||
|
||||
// In this section we supply the xxxx1 and xxxx2 forms of the operator
|
||||
// templates, which are explicitly targeted at the 1-type-argument and
|
||||
// 2-type-argument operator forms, respectively.
|
||||
@ -128,34 +141,34 @@ template <typename T> class empty_base {};
|
||||
template <class T, class U, class B = operators_detail::empty_base<T> >
|
||||
struct less_than_comparable2 : B
|
||||
{
|
||||
friend bool operator<=(const T& x, const U& y) { return !static_cast<bool>(x > y); }
|
||||
friend bool operator>=(const T& x, const U& y) { return !static_cast<bool>(x < y); }
|
||||
friend bool operator>(const U& x, const T& y) { return y < x; }
|
||||
friend bool operator<(const U& x, const T& y) { return y > x; }
|
||||
friend bool operator<=(const U& x, const T& y) { return !static_cast<bool>(y < x); }
|
||||
friend bool operator>=(const U& x, const T& y) { return !static_cast<bool>(y > x); }
|
||||
friend BOOST_OPERATORS_CONSTEXPR bool operator<=(const T& x, const U& y) { return !static_cast<bool>(x > y); }
|
||||
friend BOOST_OPERATORS_CONSTEXPR bool operator>=(const T& x, const U& y) { return !static_cast<bool>(x < y); }
|
||||
friend BOOST_OPERATORS_CONSTEXPR bool operator>(const U& x, const T& y) { return y < x; }
|
||||
friend BOOST_OPERATORS_CONSTEXPR bool operator<(const U& x, const T& y) { return y > x; }
|
||||
friend BOOST_OPERATORS_CONSTEXPR bool operator<=(const U& x, const T& y) { return !static_cast<bool>(y < x); }
|
||||
friend BOOST_OPERATORS_CONSTEXPR bool operator>=(const U& x, const T& y) { return !static_cast<bool>(y > x); }
|
||||
};
|
||||
|
||||
template <class T, class B = operators_detail::empty_base<T> >
|
||||
struct less_than_comparable1 : B
|
||||
{
|
||||
friend bool operator>(const T& x, const T& y) { return y < x; }
|
||||
friend bool operator<=(const T& x, const T& y) { return !static_cast<bool>(y < x); }
|
||||
friend bool operator>=(const T& x, const T& y) { return !static_cast<bool>(x < y); }
|
||||
friend BOOST_OPERATORS_CONSTEXPR bool operator>(const T& x, const T& y) { return y < x; }
|
||||
friend BOOST_OPERATORS_CONSTEXPR bool operator<=(const T& x, const T& y) { return !static_cast<bool>(y < x); }
|
||||
friend BOOST_OPERATORS_CONSTEXPR bool operator>=(const T& x, const T& y) { return !static_cast<bool>(x < y); }
|
||||
};
|
||||
|
||||
template <class T, class U, class B = operators_detail::empty_base<T> >
|
||||
struct equality_comparable2 : B
|
||||
{
|
||||
friend bool operator==(const U& y, const T& x) { return x == y; }
|
||||
friend bool operator!=(const U& y, const T& x) { return !static_cast<bool>(x == y); }
|
||||
friend bool operator!=(const T& y, const U& x) { return !static_cast<bool>(y == x); }
|
||||
friend BOOST_OPERATORS_CONSTEXPR bool operator==(const U& y, const T& x) { return x == y; }
|
||||
friend BOOST_OPERATORS_CONSTEXPR bool operator!=(const U& y, const T& x) { return !static_cast<bool>(x == y); }
|
||||
friend BOOST_OPERATORS_CONSTEXPR bool operator!=(const T& y, const U& x) { return !static_cast<bool>(y == x); }
|
||||
};
|
||||
|
||||
template <class T, class B = operators_detail::empty_base<T> >
|
||||
struct equality_comparable1 : B
|
||||
{
|
||||
friend bool operator!=(const T& x, const T& y) { return !static_cast<bool>(x == y); }
|
||||
friend BOOST_OPERATORS_CONSTEXPR bool operator!=(const T& x, const T& y) { return !static_cast<bool>(x == y); }
|
||||
};
|
||||
|
||||
// A macro which produces "name_2left" from "name".
|
||||
@ -300,7 +313,7 @@ struct dereferenceable : B
|
||||
{
|
||||
P operator->() const
|
||||
{
|
||||
return &*static_cast<const T&>(*this);
|
||||
return ::boost::addressof(*static_cast<const T&>(*this));
|
||||
}
|
||||
};
|
||||
|
||||
@ -358,7 +371,7 @@ BOOST_BINARY_OPERATOR( right_shiftable, >> )
|
||||
template <class T, class U, class B = operators_detail::empty_base<T> >
|
||||
struct equivalent2 : B
|
||||
{
|
||||
friend bool operator==(const T& x, const U& y)
|
||||
friend BOOST_OPERATORS_CONSTEXPR bool operator==(const T& x, const U& y)
|
||||
{
|
||||
return !static_cast<bool>(x < y) && !static_cast<bool>(x > y);
|
||||
}
|
||||
@ -367,7 +380,7 @@ struct equivalent2 : B
|
||||
template <class T, class B = operators_detail::empty_base<T> >
|
||||
struct equivalent1 : B
|
||||
{
|
||||
friend bool operator==(const T&x, const T&y)
|
||||
friend BOOST_OPERATORS_CONSTEXPR bool operator==(const T&x, const T&y)
|
||||
{
|
||||
return !static_cast<bool>(x < y) && !static_cast<bool>(y < x);
|
||||
}
|
||||
@ -376,28 +389,28 @@ struct equivalent1 : B
|
||||
template <class T, class U, class B = operators_detail::empty_base<T> >
|
||||
struct partially_ordered2 : B
|
||||
{
|
||||
friend bool operator<=(const T& x, const U& y)
|
||||
friend BOOST_OPERATORS_CONSTEXPR bool operator<=(const T& x, const U& y)
|
||||
{ return static_cast<bool>(x < y) || static_cast<bool>(x == y); }
|
||||
friend bool operator>=(const T& x, const U& y)
|
||||
friend BOOST_OPERATORS_CONSTEXPR bool operator>=(const T& x, const U& y)
|
||||
{ return static_cast<bool>(x > y) || static_cast<bool>(x == y); }
|
||||
friend bool operator>(const U& x, const T& y)
|
||||
friend BOOST_OPERATORS_CONSTEXPR bool operator>(const U& x, const T& y)
|
||||
{ return y < x; }
|
||||
friend bool operator<(const U& x, const T& y)
|
||||
friend BOOST_OPERATORS_CONSTEXPR bool operator<(const U& x, const T& y)
|
||||
{ return y > x; }
|
||||
friend bool operator<=(const U& x, const T& y)
|
||||
friend BOOST_OPERATORS_CONSTEXPR bool operator<=(const U& x, const T& y)
|
||||
{ return static_cast<bool>(y > x) || static_cast<bool>(y == x); }
|
||||
friend bool operator>=(const U& x, const T& y)
|
||||
friend BOOST_OPERATORS_CONSTEXPR bool operator>=(const U& x, const T& y)
|
||||
{ return static_cast<bool>(y < x) || static_cast<bool>(y == x); }
|
||||
};
|
||||
|
||||
template <class T, class B = operators_detail::empty_base<T> >
|
||||
struct partially_ordered1 : B
|
||||
{
|
||||
friend bool operator>(const T& x, const T& y)
|
||||
friend BOOST_OPERATORS_CONSTEXPR bool operator>(const T& x, const T& y)
|
||||
{ return y < x; }
|
||||
friend bool operator<=(const T& x, const T& y)
|
||||
friend BOOST_OPERATORS_CONSTEXPR bool operator<=(const T& x, const T& y)
|
||||
{ return static_cast<bool>(x < y) || static_cast<bool>(x == y); }
|
||||
friend bool operator>=(const T& x, const T& y)
|
||||
friend BOOST_OPERATORS_CONSTEXPR bool operator>=(const T& x, const T& y)
|
||||
{ return static_cast<bool>(y < x) || static_cast<bool>(x == y); }
|
||||
};
|
||||
|
||||
@ -824,6 +837,21 @@ template <class T> struct operators<T, T>
|
||||
// Iterator helper classes (contributed by Jeremy Siek) -------------------//
|
||||
// (Input and output iterator helpers contributed by Daryle Walker) -------//
|
||||
// (Changed to use combined operator classes by Daryle Walker) ------------//
|
||||
// (Adapted to C++17 by Daniel Frey) --------------------------------------//
|
||||
template <class Category,
|
||||
class T,
|
||||
class Distance = std::ptrdiff_t,
|
||||
class Pointer = T*,
|
||||
class Reference = T&>
|
||||
struct iterator_helper
|
||||
{
|
||||
typedef Category iterator_category;
|
||||
typedef T value_type;
|
||||
typedef Distance difference_type;
|
||||
typedef Pointer pointer;
|
||||
typedef Reference reference;
|
||||
};
|
||||
|
||||
template <class T,
|
||||
class V,
|
||||
class D = std::ptrdiff_t,
|
||||
@ -831,13 +859,13 @@ template <class T,
|
||||
class R = V const &>
|
||||
struct input_iterator_helper
|
||||
: input_iteratable<T, P
|
||||
, std::iterator<std::input_iterator_tag, V, D, P, R
|
||||
, iterator_helper<std::input_iterator_tag, V, D, P, R
|
||||
> > {};
|
||||
|
||||
template<class T>
|
||||
struct output_iterator_helper
|
||||
: output_iteratable<T
|
||||
, std::iterator<std::output_iterator_tag, void, void, void, void
|
||||
, iterator_helper<std::output_iterator_tag, void, void, void, void
|
||||
> >
|
||||
{
|
||||
T& operator*() { return static_cast<T&>(*this); }
|
||||
@ -851,7 +879,7 @@ template <class T,
|
||||
class R = V&>
|
||||
struct forward_iterator_helper
|
||||
: forward_iteratable<T, P
|
||||
, std::iterator<std::forward_iterator_tag, V, D, P, R
|
||||
, iterator_helper<std::forward_iterator_tag, V, D, P, R
|
||||
> > {};
|
||||
|
||||
template <class T,
|
||||
@ -861,7 +889,7 @@ template <class T,
|
||||
class R = V&>
|
||||
struct bidirectional_iterator_helper
|
||||
: bidirectional_iteratable<T, P
|
||||
, std::iterator<std::bidirectional_iterator_tag, V, D, P, R
|
||||
, iterator_helper<std::bidirectional_iterator_tag, V, D, P, R
|
||||
> > {};
|
||||
|
||||
template <class T,
|
||||
@ -871,7 +899,7 @@ template <class T,
|
||||
class R = V&>
|
||||
struct random_access_iterator_helper
|
||||
: random_access_iteratable<T, P, D, R
|
||||
, std::iterator<std::random_access_iterator_tag, V, D, P, R
|
||||
, iterator_helper<std::random_access_iterator_tag, V, D, P, R
|
||||
> >
|
||||
{
|
||||
friend D requires_difference_operator(const T& x, const T& y) {
|
||||
|
@ -9,13 +9,16 @@
|
||||
#ifndef BOOST_UTILITY_HPP
|
||||
#define BOOST_UTILITY_HPP
|
||||
|
||||
#include <boost/utility/addressof.hpp>
|
||||
// Use of this header is discouraged and it will be deprecated.
|
||||
// Please include one or more of the headers below instead.
|
||||
|
||||
#include <boost/utility/base_from_member.hpp>
|
||||
#include <boost/utility/binary.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/utility/identity_type.hpp>
|
||||
#include <boost/checked_delete.hpp>
|
||||
#include <boost/next_prior.hpp>
|
||||
#include <boost/noncopyable.hpp>
|
||||
|
||||
#include <boost/core/addressof.hpp>
|
||||
#include <boost/core/enable_if.hpp>
|
||||
#include <boost/core/checked_delete.hpp>
|
||||
#include <boost/core/noncopyable.hpp>
|
||||
|
||||
#endif // BOOST_UTILITY_HPP
|
||||
|
@ -47,13 +47,14 @@
|
||||
// {}
|
||||
// This macro should only persist within this file.
|
||||
|
||||
#ifndef BOOST_UTILITY_DOCS
|
||||
#define BOOST_PRIVATE_CTR_DEF( z, n, data ) \
|
||||
template < BOOST_PP_ENUM_PARAMS(n, typename T) > \
|
||||
base_from_member( BOOST_PP_ENUM_BINARY_PARAMS(n, T, x) ) \
|
||||
: member( BOOST_PP_ENUM_PARAMS(n, x) ) \
|
||||
{} \
|
||||
/**/
|
||||
|
||||
#endif // BOOST_UTILITY_DOCS
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
@ -68,6 +68,7 @@
|
||||
( (0) BOOST_DETAIL_CREATE_BINARY_LITERAL_OCTAL_SEQUENCE( d, bit_groupings ) \
|
||||
)
|
||||
|
||||
#ifndef BOOST_UTILITY_DOCS
|
||||
#define BOOST_DETAIL_CREATE_BINARY_LITERAL_OCTAL_SEQUENCE( d, bit_groupings ) \
|
||||
BOOST_PP_SEQ_TRANSFORM \
|
||||
( BOOST_DETAIL_TRIPLE_TO_OCTAL_OPERATION \
|
||||
@ -703,6 +704,6 @@
|
||||
#define BOOST_DETAIL_BINARY_LITERAL_ELEMENT_11111100 (1)(1)(1)(1)(1)(1)(0)(0),
|
||||
#define BOOST_DETAIL_BINARY_LITERAL_ELEMENT_11111101 (1)(1)(1)(1)(1)(1)(0)(1),
|
||||
#define BOOST_DETAIL_BINARY_LITERAL_ELEMENT_11111110 (1)(1)(1)(1)(1)(1)(1)(0),
|
||||
#define BOOST_DETAIL_BINARY_LITERAL_ELEMENT_11111111 (1)(1)(1)(1)(1)(1)(1)(1),
|
||||
|
||||
#define BOOST_DETAIL_BINARY_LITERAL_ELEMENT_11111111 (1)(1)(1)(1)(1)(1)(1)(1),
|
||||
#endif // BOOST_UTILITY_DOCS
|
||||
#endif
|
||||
|
@ -33,8 +33,12 @@ bool equal_pointees ( OptionalPointee const& x, OptionalPointee const& y )
|
||||
}
|
||||
|
||||
template<class OptionalPointee>
|
||||
struct equal_pointees_t : std::binary_function<OptionalPointee,OptionalPointee,bool>
|
||||
struct equal_pointees_t
|
||||
{
|
||||
typedef bool result_type;
|
||||
typedef OptionalPointee first_argument_type;
|
||||
typedef OptionalPointee second_argument_type;
|
||||
|
||||
bool operator() ( OptionalPointee const& x, OptionalPointee const& y ) const
|
||||
{ return equal_pointees(x,y) ; }
|
||||
} ;
|
||||
@ -56,8 +60,12 @@ bool less_pointees ( OptionalPointee const& x, OptionalPointee const& y )
|
||||
}
|
||||
|
||||
template<class OptionalPointee>
|
||||
struct less_pointees_t : std::binary_function<OptionalPointee,OptionalPointee,bool>
|
||||
struct less_pointees_t
|
||||
{
|
||||
typedef bool result_type;
|
||||
typedef OptionalPointee first_argument_type;
|
||||
typedef OptionalPointee second_argument_type;
|
||||
|
||||
bool operator() ( OptionalPointee const& x, OptionalPointee const& y ) const
|
||||
{ return less_pointees(x,y) ; }
|
||||
} ;
|
||||
|
16
include/boost/utility/detail/minstd_rand.hpp
Normal file
16
include/boost/utility/detail/minstd_rand.hpp
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef BOOST_UTILITY_DETAIL_MINSTD_RAND_HPP_INCLUDED
|
||||
#define BOOST_UTILITY_DETAIL_MINSTD_RAND_HPP_INCLUDED
|
||||
|
||||
// Copyright 2017 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
//
|
||||
// See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
//
|
||||
// An implementation of minstd_rand that does not require
|
||||
// the Random library
|
||||
|
||||
#include <boost/core/detail/minstd_rand.hpp>
|
||||
|
||||
#endif // #ifndef BOOST_UTILITY_DETAIL_MINSTD_RAND_HPP_INCLUDED
|
@ -22,19 +22,19 @@
|
||||
# define BOOST_RESULT_OF_ARGS BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)
|
||||
#endif
|
||||
|
||||
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
|
||||
#if !BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x551))
|
||||
template<typename F BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(),typename T)>
|
||||
struct tr1_result_of<F(BOOST_RESULT_OF_ARGS)>
|
||||
: mpl::if_<
|
||||
mpl::or_< is_pointer<F>, is_member_function_pointer<F> >
|
||||
: conditional<
|
||||
is_pointer<F>::value || is_member_function_pointer<F>::value
|
||||
, boost::detail::tr1_result_of_impl<
|
||||
typename remove_cv<F>::type,
|
||||
typename remove_cv<F>::type(BOOST_RESULT_OF_ARGS),
|
||||
(boost::detail::has_result_type<F>::value)>
|
||||
(boost::detail::result_of_has_result_type<F>::value)>
|
||||
, boost::detail::tr1_result_of_impl<
|
||||
F,
|
||||
F(BOOST_RESULT_OF_ARGS),
|
||||
(boost::detail::has_result_type<F>::value)> >::type { };
|
||||
(boost::detail::result_of_has_result_type<F>::value)> >::type { };
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_RESULT_OF_USE_DECLTYPE
|
||||
@ -46,7 +46,7 @@ struct result_of<F(BOOST_RESULT_OF_ARGS)>
|
||||
#ifdef BOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK
|
||||
template<typename F BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(),typename T)>
|
||||
struct result_of<F(BOOST_RESULT_OF_ARGS)>
|
||||
: mpl::if_<mpl::or_<detail::has_result_type<F>, detail::has_result<F> >,
|
||||
: conditional<detail::result_of_has_result_type<F>::value || detail::result_of_has_result<F>::value,
|
||||
tr1_result_of<F(BOOST_RESULT_OF_ARGS)>,
|
||||
detail::cpp0x_result_of<F(BOOST_RESULT_OF_ARGS)> >::type { };
|
||||
#endif // BOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK
|
||||
@ -57,8 +57,8 @@ namespace detail {
|
||||
|
||||
template<typename F BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(),typename T)>
|
||||
struct cpp0x_result_of<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T))>
|
||||
: mpl::if_<
|
||||
is_member_function_pointer<F>
|
||||
: conditional<
|
||||
is_member_function_pointer<F>::value
|
||||
, detail::tr1_result_of_impl<
|
||||
typename remove_cv<F>::type,
|
||||
typename remove_cv<F>::type(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), false
|
||||
@ -82,25 +82,22 @@ struct BOOST_PP_CAT(result_of_callable_fun_2_, BOOST_PP_ITERATION())<R(BOOST_PP_
|
||||
};
|
||||
|
||||
template<typename F>
|
||||
struct BOOST_PP_CAT(result_of_callable_fun_, BOOST_PP_ITERATION());
|
||||
struct BOOST_PP_CAT(result_of_callable_fun_, BOOST_PP_ITERATION())
|
||||
: BOOST_PP_CAT(result_of_callable_fun_2_, BOOST_PP_ITERATION())<F>
|
||||
{};
|
||||
|
||||
template<typename F>
|
||||
struct BOOST_PP_CAT(result_of_callable_fun_, BOOST_PP_ITERATION())<F *>
|
||||
: BOOST_PP_CAT(result_of_callable_fun_2_, BOOST_PP_ITERATION())<F>
|
||||
{};
|
||||
|
||||
template<typename F>
|
||||
struct BOOST_PP_CAT(result_of_callable_fun_, BOOST_PP_ITERATION())<F &>
|
||||
: BOOST_PP_CAT(result_of_callable_fun_2_, BOOST_PP_ITERATION())<F>
|
||||
{};
|
||||
|
||||
template<typename F>
|
||||
struct BOOST_PP_CAT(result_of_select_call_wrapper_type_, BOOST_PP_ITERATION())
|
||||
: mpl::eval_if<
|
||||
is_class<typename remove_reference<F>::type>,
|
||||
: conditional<
|
||||
is_class<typename remove_reference<F>::type>::value,
|
||||
result_of_wrap_callable_class<F>,
|
||||
mpl::identity<BOOST_PP_CAT(result_of_callable_fun_, BOOST_PP_ITERATION())<typename remove_cv<F>::type> >
|
||||
>
|
||||
type_identity<BOOST_PP_CAT(result_of_callable_fun_, BOOST_PP_ITERATION())<typename remove_cv<typename remove_reference<F>::type>::type> >
|
||||
>::type
|
||||
{};
|
||||
|
||||
template<typename F BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(), typename T)>
|
||||
@ -111,7 +108,7 @@ struct BOOST_PP_CAT(result_of_is_callable_, BOOST_PP_ITERATION()) {
|
||||
(boost::declval<wrapper_t>()(BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_ITERATION(), boost::declval<T, >() BOOST_PP_INTERCEPT)), result_of_weird_type())
|
||||
))
|
||||
);
|
||||
typedef mpl::bool_<value> type;
|
||||
typedef integral_constant<bool, value> type;
|
||||
};
|
||||
|
||||
template<typename F BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(),typename T)>
|
||||
@ -154,7 +151,7 @@ struct cpp0x_result_of_impl<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)),
|
||||
|
||||
#else // defined(BOOST_RESULT_OF_USE_DECLTYPE) || defined(BOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK)
|
||||
|
||||
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
|
||||
#if !BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x551))
|
||||
template<typename F BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(),typename T)>
|
||||
struct result_of<F(BOOST_RESULT_OF_ARGS)>
|
||||
: tr1_result_of<F(BOOST_RESULT_OF_ARGS)> { };
|
||||
@ -180,7 +177,7 @@ struct tr1_result_of_impl<R (&)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), F
|
||||
typedef R type;
|
||||
};
|
||||
|
||||
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
|
||||
#if !BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x551))
|
||||
template<typename R, typename FArgs BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_ITERATION(),typename T)>
|
||||
struct tr1_result_of_impl<R (T0::*)
|
||||
(BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_ITERATION(),T)),
|
||||
|
190
include/boost/utility/detail/result_of_variadic.hpp
Normal file
190
include/boost/utility/detail/result_of_variadic.hpp
Normal file
@ -0,0 +1,190 @@
|
||||
// Boost result_of library
|
||||
|
||||
// Copyright Douglas Gregor 2004. Use, modification and
|
||||
// distribution is subject to the Boost Software License, Version
|
||||
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// Copyright Daniel Walker, Eric Niebler, Michel Morin 2008-2012.
|
||||
// Use, modification and distribution is subject to the Boost Software
|
||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or
|
||||
// copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// For more information, see http://www.boost.org/libs/utility
|
||||
|
||||
#ifndef BOOST_RESULT_OF_HPP
|
||||
# error Boost result_of - do not include this file!
|
||||
#endif
|
||||
|
||||
template<typename F, typename... Args>
|
||||
struct tr1_result_of<F(Args...)>
|
||||
: conditional<
|
||||
is_pointer<F>::value || is_member_function_pointer<F>::value
|
||||
, boost::detail::tr1_result_of_impl<
|
||||
typename remove_cv<F>::type,
|
||||
typename remove_cv<F>::type(Args...),
|
||||
(boost::detail::result_of_has_result_type<F>::value)>
|
||||
, boost::detail::tr1_result_of_impl<
|
||||
F,
|
||||
F(Args...),
|
||||
(boost::detail::result_of_has_result_type<F>::value)> >::type { };
|
||||
|
||||
#ifdef BOOST_RESULT_OF_USE_DECLTYPE
|
||||
template<typename F, typename... Args>
|
||||
struct result_of<F(Args...)>
|
||||
: detail::cpp0x_result_of<F(Args...)> { };
|
||||
#endif // BOOST_RESULT_OF_USE_DECLTYPE
|
||||
|
||||
#ifdef BOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK
|
||||
template<typename F, typename... Args>
|
||||
struct result_of<F(Args...)>
|
||||
: conditional<detail::result_of_has_result_type<F>::value || detail::result_of_has_result<F>::value,
|
||||
tr1_result_of<F(Args...)>,
|
||||
detail::cpp0x_result_of<F(Args...)> >::type { };
|
||||
#endif // BOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK
|
||||
|
||||
#if defined(BOOST_RESULT_OF_USE_DECLTYPE) || defined(BOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK)
|
||||
|
||||
namespace detail {
|
||||
|
||||
template<typename F, typename... Args>
|
||||
struct cpp0x_result_of<F(Args...)>
|
||||
: conditional<
|
||||
is_member_function_pointer<F>::value
|
||||
, detail::tr1_result_of_impl<
|
||||
typename remove_cv<F>::type,
|
||||
typename remove_cv<F>::type(Args...), false
|
||||
>
|
||||
, detail::cpp0x_result_of_impl<
|
||||
F(Args...)
|
||||
>
|
||||
>::type
|
||||
{};
|
||||
|
||||
#ifdef BOOST_NO_SFINAE_EXPR
|
||||
|
||||
template<typename F>
|
||||
struct result_of_callable_fun_2;
|
||||
|
||||
template<typename R, typename... Args>
|
||||
struct result_of_callable_fun_2<R(Args...)> {
|
||||
R operator()(Args...) const;
|
||||
typedef result_of_private_type const &(*pfn_t)(...);
|
||||
operator pfn_t() const volatile;
|
||||
};
|
||||
|
||||
template<typename F>
|
||||
struct result_of_callable_fun
|
||||
: result_of_callable_fun_2<F>
|
||||
{};
|
||||
|
||||
template<typename F>
|
||||
struct result_of_callable_fun<F *>
|
||||
: result_of_callable_fun_2<F>
|
||||
{};
|
||||
|
||||
template<typename F>
|
||||
struct result_of_select_call_wrapper_type
|
||||
: conditional<
|
||||
is_class<typename remove_reference<F>::type>::value,
|
||||
result_of_wrap_callable_class<F>,
|
||||
type_identity<result_of_callable_fun<typename remove_cv<typename remove_reference<F>::type>::type> >
|
||||
>::type
|
||||
{};
|
||||
|
||||
template<typename F, typename... Args>
|
||||
struct result_of_is_callable {
|
||||
typedef typename result_of_select_call_wrapper_type<F>::type wrapper_t;
|
||||
static const bool value = (
|
||||
sizeof(result_of_no_type) == sizeof(detail::result_of_is_private_type(
|
||||
(boost::declval<wrapper_t>()(boost::declval<Args>()...), result_of_weird_type())
|
||||
))
|
||||
);
|
||||
typedef integral_constant<bool, value> type;
|
||||
};
|
||||
|
||||
template<typename F, typename... Args>
|
||||
struct cpp0x_result_of_impl<F(Args...), true>
|
||||
: lazy_enable_if<
|
||||
result_of_is_callable<F, Args...>
|
||||
, cpp0x_result_of_impl<F(Args...), false>
|
||||
>
|
||||
{};
|
||||
|
||||
template<typename F, typename... Args>
|
||||
struct cpp0x_result_of_impl<F(Args...), false>
|
||||
{
|
||||
typedef decltype(
|
||||
boost::declval<F>()(
|
||||
boost::declval<Args>()...
|
||||
)
|
||||
) type;
|
||||
};
|
||||
|
||||
#else // BOOST_NO_SFINAE_EXPR
|
||||
|
||||
template<typename F, typename... Args>
|
||||
struct cpp0x_result_of_impl<F(Args...),
|
||||
typename result_of_always_void<decltype(
|
||||
boost::declval<F>()(
|
||||
boost::declval<Args>()...
|
||||
)
|
||||
)>::type> {
|
||||
typedef decltype(
|
||||
boost::declval<F>()(
|
||||
boost::declval<Args>()...
|
||||
)
|
||||
) type;
|
||||
};
|
||||
|
||||
#endif // BOOST_NO_SFINAE_EXPR
|
||||
|
||||
} // namespace detail
|
||||
|
||||
#else // defined(BOOST_RESULT_OF_USE_DECLTYPE) || defined(BOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK)
|
||||
|
||||
template<typename F, typename... Args>
|
||||
struct result_of<F(Args...)>
|
||||
: tr1_result_of<F(Args...)> { };
|
||||
|
||||
#endif // defined(BOOST_RESULT_OF_USE_DECLTYPE)
|
||||
|
||||
namespace detail {
|
||||
|
||||
template<typename R, typename FArgs, typename... Args>
|
||||
struct tr1_result_of_impl<R (*)(Args...), FArgs, false>
|
||||
{
|
||||
typedef R type;
|
||||
};
|
||||
|
||||
template<typename R, typename FArgs, typename... Args>
|
||||
struct tr1_result_of_impl<R (&)(Args...), FArgs, false>
|
||||
{
|
||||
typedef R type;
|
||||
};
|
||||
|
||||
template<typename R, typename FArgs, typename C, typename... Args>
|
||||
struct tr1_result_of_impl<R (C::*)(Args...), FArgs, false>
|
||||
{
|
||||
typedef R type;
|
||||
};
|
||||
|
||||
template<typename R, typename FArgs, typename C, typename... Args>
|
||||
struct tr1_result_of_impl<R (C::*)(Args...) const, FArgs, false>
|
||||
{
|
||||
typedef R type;
|
||||
};
|
||||
|
||||
template<typename R, typename FArgs, typename C, typename... Args>
|
||||
struct tr1_result_of_impl<R (C::*)(Args...) volatile, FArgs, false>
|
||||
{
|
||||
typedef R type;
|
||||
};
|
||||
|
||||
template<typename R, typename FArgs, typename C, typename... Args>
|
||||
struct tr1_result_of_impl<R (C::*)(Args...) const volatile, FArgs, false>
|
||||
{
|
||||
typedef R type;
|
||||
};
|
||||
|
||||
}
|
@ -19,15 +19,21 @@ namespace boost {
|
||||
|
||||
class in_place_factory_base {} ;
|
||||
|
||||
#ifndef BOOST_UTILITY_DOCS
|
||||
#define BOOST_PP_ITERATION_LIMITS (0, BOOST_MAX_INPLACE_FACTORY_ARITY)
|
||||
#define BOOST_PP_FILENAME_1 <boost/utility/in_place_factory.hpp>
|
||||
#endif // BOOST_UTILITY_DOCS
|
||||
|
||||
#include BOOST_PP_ITERATE()
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/utility/detail/in_place_factory_suffix.hpp>
|
||||
|
||||
#ifndef BOOST_UTILITY_DOCS
|
||||
#define BOOST_UTILITY_INPLACE_FACTORY_04APR2007_HPP
|
||||
#endif
|
||||
|
||||
#else
|
||||
#define N BOOST_PP_ITERATION()
|
||||
|
||||
|
@ -10,31 +10,37 @@
|
||||
#define BOOST_RESULT_OF_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/preprocessor/cat.hpp>
|
||||
#include <boost/preprocessor/iteration/iterate.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_params.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_trailing_params.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_shifted_params.hpp>
|
||||
#include <boost/preprocessor/facilities/intercept.hpp>
|
||||
#include <boost/detail/workaround.hpp>
|
||||
#include <boost/mpl/has_xxx.hpp>
|
||||
#include <boost/mpl/if.hpp>
|
||||
#include <boost/mpl/eval_if.hpp>
|
||||
#include <boost/mpl/bool.hpp>
|
||||
#include <boost/mpl/identity.hpp>
|
||||
#include <boost/mpl/or.hpp>
|
||||
#include <boost/type_traits/is_class.hpp>
|
||||
#include <boost/type_traits/is_pointer.hpp>
|
||||
#include <boost/type_traits/is_member_function_pointer.hpp>
|
||||
#include <boost/type_traits/remove_cv.hpp>
|
||||
#include <boost/type_traits/remove_reference.hpp>
|
||||
#include <boost/utility/declval.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/type_traits/declval.hpp>
|
||||
#include <boost/type_traits/conditional.hpp>
|
||||
#include <boost/type_traits/type_identity.hpp>
|
||||
#include <boost/type_traits/integral_constant.hpp>
|
||||
#include <boost/core/enable_if.hpp>
|
||||
|
||||
#ifdef BOOST_NO_CXX11_VARIADIC_TEMPLATES
|
||||
# undef BOOST_RESULT_OF_NO_VARIADIC_TEMPLATES
|
||||
# define BOOST_RESULT_OF_NO_VARIADIC_TEMPLATES
|
||||
#endif
|
||||
#ifdef BOOST_RESULT_OF_NO_VARIADIC_TEMPLATES
|
||||
# include <boost/preprocessor/cat.hpp>
|
||||
# include <boost/preprocessor/iteration/iterate.hpp>
|
||||
# include <boost/preprocessor/repetition/enum_params.hpp>
|
||||
# include <boost/preprocessor/repetition/enum_trailing_params.hpp>
|
||||
# include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
||||
# include <boost/preprocessor/repetition/enum_shifted_params.hpp>
|
||||
# include <boost/preprocessor/facilities/intercept.hpp>
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_UTILITY_DOCS
|
||||
#ifndef BOOST_RESULT_OF_NUM_ARGS
|
||||
# define BOOST_RESULT_OF_NUM_ARGS 16
|
||||
#endif
|
||||
#endif // BOOST_UTILITY_DOCS
|
||||
|
||||
// Use the decltype-based version of result_of by default if the compiler
|
||||
// supports N3276 <http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2011/n3276.pdf>.
|
||||
@ -47,10 +53,7 @@
|
||||
BOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK cannot be defined at the same time.
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK) && defined(BOOST_MPL_CFG_NO_HAS_XXX_TEMPLATE)
|
||||
# error Cannot fallback to decltype if BOOST_MPL_CFG_NO_HAS_XXX_TEMPLATE is not defined.
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_UTILITY_DOCS
|
||||
#ifndef BOOST_RESULT_OF_USE_TR1
|
||||
# ifndef BOOST_RESULT_OF_USE_DECLTYPE
|
||||
# ifndef BOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK
|
||||
@ -62,6 +65,7 @@
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
#endif // BOOST_UTILITY_DOCS
|
||||
|
||||
namespace boost {
|
||||
|
||||
@ -71,11 +75,40 @@ template<typename F> struct tr1_result_of; // a TR1-style implementation of resu
|
||||
#if !defined(BOOST_NO_SFINAE)
|
||||
namespace detail {
|
||||
|
||||
BOOST_MPL_HAS_XXX_TRAIT_DEF(result_type)
|
||||
typedef char result_of_yes_type; // sizeof(result_of_yes_type) == 1
|
||||
typedef char (&result_of_no_type)[2]; // sizeof(result_of_no_type) == 2
|
||||
|
||||
template<class T> struct result_of_has_type {};
|
||||
|
||||
template<class T> struct result_of_has_result_type_impl
|
||||
{
|
||||
template<class U> static result_of_yes_type f( result_of_has_type<typename U::result_type>* );
|
||||
template<class U> static result_of_no_type f( ... );
|
||||
|
||||
typedef boost::integral_constant<bool, sizeof(f<T>(0)) == sizeof(result_of_yes_type)> type;
|
||||
};
|
||||
|
||||
template<class T> struct result_of_has_result_type: result_of_has_result_type_impl<T>::type
|
||||
{
|
||||
};
|
||||
|
||||
// Work around a nvcc bug by only defining has_result when it's needed.
|
||||
#ifdef BOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK
|
||||
BOOST_MPL_HAS_XXX_TEMPLATE_DEF(result)
|
||||
|
||||
template<template<class> class C> struct result_of_has_template {};
|
||||
|
||||
template<class T> struct result_of_has_result_impl
|
||||
{
|
||||
template<class U> static result_of_yes_type f( result_of_has_template<U::template result>* );
|
||||
template<class U> static result_of_no_type f( ... );
|
||||
|
||||
typedef boost::integral_constant<bool, sizeof(f<T>(0)) == sizeof(result_of_yes_type)> type;
|
||||
};
|
||||
|
||||
template<class T> struct result_of_has_result: result_of_has_result_impl<T>::type
|
||||
{
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
template<typename F, typename FArgs, bool HasResultType> struct tr1_result_of_impl;
|
||||
@ -86,8 +119,8 @@ template<typename F> struct cpp0x_result_of;
|
||||
|
||||
// There doesn't seem to be any other way to turn this off such that the presence of
|
||||
// the user-defined operator,() below doesn't cause spurious warning all over the place,
|
||||
// so unconditionally turn it off.
|
||||
#if BOOST_MSVC
|
||||
// so unconditionally and globally turn it off. (https://svn.boost.org/trac10/ticket/7663)
|
||||
#ifdef BOOST_MSVC
|
||||
# pragma warning(disable: 4913) // user defined binary operator ',' exists but no overload could convert all operands, default built-in binary operator ',' used
|
||||
#endif
|
||||
|
||||
@ -97,19 +130,23 @@ struct result_of_weird_type {
|
||||
friend result_of_private_type operator,(result_of_private_type, result_of_weird_type);
|
||||
};
|
||||
|
||||
typedef char result_of_yes_type; // sizeof(result_of_yes_type) == 1
|
||||
typedef char (&result_of_no_type)[2]; // sizeof(result_of_no_type) == 2
|
||||
|
||||
template<typename T>
|
||||
result_of_no_type result_of_is_private_type(T const &);
|
||||
result_of_yes_type result_of_is_private_type(result_of_private_type);
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable: 4512) // assignment operator could not be generated.
|
||||
#endif
|
||||
template<typename C>
|
||||
struct result_of_callable_class : C {
|
||||
result_of_callable_class();
|
||||
typedef result_of_private_type const &(*pfn_t)(...);
|
||||
operator pfn_t() const volatile;
|
||||
};
|
||||
#ifdef BOOST_MSVC
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
template<typename C>
|
||||
struct result_of_wrap_callable_class {
|
||||
@ -180,10 +217,10 @@ struct tr1_result_of_impl<F, FArgs, true>
|
||||
};
|
||||
|
||||
template<typename FArgs>
|
||||
struct is_function_with_no_args : mpl::false_ {};
|
||||
struct is_function_with_no_args : false_type {};
|
||||
|
||||
template<typename F>
|
||||
struct is_function_with_no_args<F(void)> : mpl::true_ {};
|
||||
struct is_function_with_no_args<F(void)> : true_type {};
|
||||
|
||||
template<typename F, typename FArgs>
|
||||
struct result_of_nested_result : F::template result<FArgs>
|
||||
@ -191,15 +228,24 @@ struct result_of_nested_result : F::template result<FArgs>
|
||||
|
||||
template<typename F, typename FArgs>
|
||||
struct tr1_result_of_impl<F, FArgs, false>
|
||||
: mpl::if_<is_function_with_no_args<FArgs>,
|
||||
: conditional<is_function_with_no_args<FArgs>::value,
|
||||
result_of_void_impl<F>,
|
||||
result_of_nested_result<F, FArgs> >::type
|
||||
{};
|
||||
|
||||
} // end namespace detail
|
||||
|
||||
#define BOOST_PP_ITERATION_PARAMS_1 (3,(0,BOOST_RESULT_OF_NUM_ARGS,<boost/utility/detail/result_of_iterate.hpp>))
|
||||
#include BOOST_PP_ITERATE()
|
||||
#ifndef BOOST_RESULT_OF_NO_VARIADIC_TEMPLATES
|
||||
# include <boost/utility/detail/result_of_variadic.hpp>
|
||||
#else
|
||||
# define BOOST_PP_ITERATION_PARAMS_1 (3,(0,BOOST_RESULT_OF_NUM_ARGS,<boost/utility/detail/result_of_iterate.hpp>))
|
||||
# include BOOST_PP_ITERATE()
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
// inform dependency trackers, as they can't see through macro includes
|
||||
#include <boost/utility/detail/result_of_iterate.hpp>
|
||||
#endif
|
||||
|
||||
#else
|
||||
# define BOOST_NO_RESULT_OF 1
|
||||
|
@ -1,5 +1,6 @@
|
||||
/*
|
||||
Copyright (c) Marshall Clow 2012-2015.
|
||||
Copyright (c) Glen Joseph Fernandes 2019 (glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@ -17,6 +18,7 @@
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/detail/workaround.hpp>
|
||||
#include <boost/io/ostream_put.hpp>
|
||||
#include <boost/utility/string_ref_fwd.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
|
||||
@ -92,6 +94,13 @@ namespace boost {
|
||||
basic_string_ref(const std::basic_string<charT, traits, Allocator>& str)
|
||||
: ptr_(str.data()), len_(str.length()) {}
|
||||
|
||||
// #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
|
||||
// // Constructing a string_ref from a temporary string is a bad idea
|
||||
// template<typename Allocator>
|
||||
// basic_string_ref( std::basic_string<charT, traits, Allocator>&&)
|
||||
// = delete;
|
||||
// #endif
|
||||
|
||||
BOOST_CONSTEXPR basic_string_ref(const charT* str, size_type len) BOOST_NOEXCEPT
|
||||
: ptr_(str), len_(len) {}
|
||||
|
||||
@ -119,13 +128,13 @@ namespace boost {
|
||||
// capacity
|
||||
BOOST_CONSTEXPR size_type size() const { return len_; }
|
||||
BOOST_CONSTEXPR size_type length() const { return len_; }
|
||||
BOOST_CONSTEXPR size_type max_size() const { return len_; }
|
||||
BOOST_CONSTEXPR size_type max_size() const { return ~static_cast<size_type>(0) / (sizeof(value_type) * 2u); }
|
||||
BOOST_CONSTEXPR bool empty() const { return len_ == 0; }
|
||||
|
||||
// element access
|
||||
BOOST_CONSTEXPR const charT& operator[](size_type pos) const { return ptr_[pos]; }
|
||||
|
||||
const charT& at(size_t pos) const {
|
||||
const charT& at(size_type pos) const {
|
||||
if ( pos >= len_ )
|
||||
BOOST_THROW_EXCEPTION( std::out_of_range ( "boost::string_ref::at" ) );
|
||||
return ptr_[pos];
|
||||
@ -152,12 +161,14 @@ namespace boost {
|
||||
|
||||
|
||||
// basic_string_ref string operations
|
||||
basic_string_ref substr() const {
|
||||
return basic_string_ref(data(), size());
|
||||
}
|
||||
|
||||
basic_string_ref substr(size_type pos, size_type n=npos) const {
|
||||
if ( pos > size())
|
||||
BOOST_THROW_EXCEPTION( std::out_of_range ( "string_ref::substr" ) );
|
||||
if ( n == npos || pos + n > size())
|
||||
n = size () - pos;
|
||||
return basic_string_ref ( data() + pos, n );
|
||||
return basic_string_ref(data() + pos, (std::min)(size() - pos, n));
|
||||
}
|
||||
|
||||
int compare(basic_string_ref x) const {
|
||||
@ -176,6 +187,7 @@ namespace boost {
|
||||
}
|
||||
|
||||
size_type find(basic_string_ref s) const {
|
||||
if (s.empty()) return 0;
|
||||
const_iterator iter = std::search ( this->cbegin (), this->cend (),
|
||||
s.cbegin (), s.cend (), traits::eq );
|
||||
return iter == this->cend () ? npos : std::distance ( this->cbegin (), iter );
|
||||
@ -188,6 +200,7 @@ namespace boost {
|
||||
}
|
||||
|
||||
size_type rfind(basic_string_ref s) const {
|
||||
if (s.empty()) return 0;
|
||||
const_reverse_iterator iter = std::search ( this->crbegin (), this->crend (),
|
||||
s.crbegin (), s.crend (), traits::eq );
|
||||
return iter == this->crend () ? npos : (std::distance(iter, this->crend()) - s.size());
|
||||
@ -414,52 +427,11 @@ namespace boost {
|
||||
return basic_string_ref<charT, traits>(x) >= y;
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
|
||||
template<class charT, class traits>
|
||||
inline void sr_insert_fill_chars(std::basic_ostream<charT, traits>& os, std::size_t n) {
|
||||
enum { chunk_size = 8 };
|
||||
charT fill_chars[chunk_size];
|
||||
std::fill_n(fill_chars, static_cast< std::size_t >(chunk_size), os.fill());
|
||||
for (; n >= chunk_size && os.good(); n -= chunk_size)
|
||||
os.write(fill_chars, static_cast< std::size_t >(chunk_size));
|
||||
if (n > 0 && os.good())
|
||||
os.write(fill_chars, n);
|
||||
}
|
||||
|
||||
template<class charT, class traits>
|
||||
void sr_insert_aligned(std::basic_ostream<charT, traits>& os, const basic_string_ref<charT,traits>& str) {
|
||||
const std::size_t size = str.size();
|
||||
const std::size_t alignment_size = static_cast< std::size_t >(os.width()) - size;
|
||||
const bool align_left = (os.flags() & std::basic_ostream<charT, traits>::adjustfield) == std::basic_ostream<charT, traits>::left;
|
||||
if (!align_left) {
|
||||
detail::sr_insert_fill_chars(os, alignment_size);
|
||||
if (os.good())
|
||||
os.write(str.data(), size);
|
||||
}
|
||||
else {
|
||||
os.write(str.data(), size);
|
||||
if (os.good())
|
||||
detail::sr_insert_fill_chars(os, alignment_size);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
// Inserter
|
||||
template<class charT, class traits>
|
||||
inline std::basic_ostream<charT, traits>&
|
||||
operator<<(std::basic_ostream<charT, traits>& os, const basic_string_ref<charT,traits>& str) {
|
||||
if (os.good()) {
|
||||
const std::size_t size = str.size();
|
||||
const std::size_t w = static_cast< std::size_t >(os.width());
|
||||
if (w <= size)
|
||||
os.write(str.data(), size);
|
||||
else
|
||||
detail::sr_insert_aligned(os, str);
|
||||
os.width(0);
|
||||
}
|
||||
return os;
|
||||
return boost::io::ostream_put(os, str.data(), str.size());
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
@ -1,6 +1,7 @@
|
||||
/*
|
||||
<20> Copyright (c) Marshall Clow 2012-2015.
|
||||
<20> Copyright Beman Dawes 2015
|
||||
Copyright (c) Marshall Clow 2012-2015.
|
||||
Copyright (c) Beman Dawes 2015
|
||||
Copyright (c) Glen Joseph Fernandes 2019 (glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
@ -19,8 +20,10 @@
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/detail/workaround.hpp>
|
||||
#include <boost/io/ostream_put.hpp>
|
||||
#include <boost/utility/string_view_fwd.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
#include <stdexcept>
|
||||
@ -91,9 +94,15 @@ namespace boost {
|
||||
#endif
|
||||
|
||||
template<typename Allocator>
|
||||
basic_string_view(const std::basic_string<charT, traits,
|
||||
Allocator>& str) BOOST_NOEXCEPT
|
||||
: ptr_(str.data()), len_(str.length()) {}
|
||||
basic_string_view(const std::basic_string<charT, traits, Allocator>& str) BOOST_NOEXCEPT
|
||||
: ptr_(str.data()), len_(str.length()) {}
|
||||
|
||||
// #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
|
||||
// // Constructing a string_view from a temporary string is a bad idea
|
||||
// template<typename Allocator>
|
||||
// basic_string_view( std::basic_string<charT, traits, Allocator>&&)
|
||||
// = delete;
|
||||
// #endif
|
||||
|
||||
BOOST_CONSTEXPR basic_string_view(const charT* str)
|
||||
: ptr_(str), len_(traits::length(str)) {}
|
||||
@ -114,17 +123,14 @@ namespace boost {
|
||||
// capacity
|
||||
BOOST_CONSTEXPR size_type size() const BOOST_NOEXCEPT { return len_; }
|
||||
BOOST_CONSTEXPR size_type length() const BOOST_NOEXCEPT { return len_; }
|
||||
BOOST_CONSTEXPR size_type max_size() const BOOST_NOEXCEPT { return len_; }
|
||||
BOOST_CONSTEXPR size_type max_size() const BOOST_NOEXCEPT { return ~static_cast<size_type>(0) / (sizeof(value_type) * 2u); }
|
||||
BOOST_CONSTEXPR bool empty() const BOOST_NOEXCEPT { return len_ == 0; }
|
||||
|
||||
// element access
|
||||
BOOST_CONSTEXPR const_reference operator[](size_type pos) const BOOST_NOEXCEPT { return ptr_[pos]; }
|
||||
|
||||
BOOST_CONSTEXPR const_reference at(size_t pos) const {
|
||||
return pos >= len_ ? BOOST_THROW_EXCEPTION(std::out_of_range("boost::string_view::at")) : ptr_[pos];
|
||||
// if ( pos >= len_ )
|
||||
// BOOST_THROW_EXCEPTION( std::out_of_range ( "boost::string_view::at" ) );
|
||||
// return ptr_[pos];
|
||||
BOOST_CONSTEXPR const_reference at(size_type pos) const {
|
||||
return pos >= len_ ? BOOST_THROW_EXCEPTION(std::out_of_range("boost::string_view::at")), ptr_[0] : ptr_[pos];
|
||||
}
|
||||
|
||||
BOOST_CONSTEXPR const_reference front() const { return ptr_[0]; }
|
||||
@ -135,6 +141,8 @@ namespace boost {
|
||||
void clear() BOOST_NOEXCEPT { len_ = 0; } // Boost extension
|
||||
|
||||
BOOST_CXX14_CONSTEXPR void remove_prefix(size_type n) {
|
||||
BOOST_ASSERT(n <= size());
|
||||
// This check is deprecated and is left for backward compatibility. It will be removed in the future.
|
||||
if ( n > len_ )
|
||||
n = len_;
|
||||
ptr_ += n;
|
||||
@ -142,6 +150,8 @@ namespace boost {
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR void remove_suffix(size_type n) {
|
||||
BOOST_ASSERT(n <= size());
|
||||
// This check is deprecated and is left for backward compatibility. It will be removed in the future.
|
||||
if ( n > len_ )
|
||||
n = len_;
|
||||
len_ -= n;
|
||||
@ -180,18 +190,18 @@ namespace boost {
|
||||
if (pos > size())
|
||||
BOOST_THROW_EXCEPTION(std::out_of_range("string_view::copy" ));
|
||||
size_type rlen = (std::min)(n, len_ - pos);
|
||||
// use std::copy(begin() + pos, begin() + pos + rlen, s) rather than
|
||||
// std::copy_n(begin() + pos, rlen, s) to support pre-C++11 standard libraries
|
||||
std::copy(begin() + pos, begin() + pos + rlen, s);
|
||||
traits_type::copy(s, data() + pos, rlen);
|
||||
return rlen;
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR basic_string_view substr() const {
|
||||
return basic_string_view(data(), size());
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR basic_string_view substr(size_type pos, size_type n=npos) const {
|
||||
if ( pos > size())
|
||||
BOOST_THROW_EXCEPTION( std::out_of_range ( "string_view::substr" ) );
|
||||
if (n == npos || pos + n > size())
|
||||
n = size () - pos;
|
||||
return basic_string_view(data() + pos, n);
|
||||
return basic_string_view(data() + pos, (std::min)(size() - pos, n));
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR int compare(basic_string_view x) const BOOST_NOEXCEPT {
|
||||
@ -200,7 +210,7 @@ namespace boost {
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR int compare(size_type pos1, size_type n1, basic_string_view x)
|
||||
const BOOST_NOEXCEPT {
|
||||
const {
|
||||
return substr(pos1, n1).compare(x);
|
||||
}
|
||||
|
||||
@ -240,18 +250,45 @@ namespace boost {
|
||||
traits::compare(ptr_ + len_ - x.len_, x.ptr_, x.len_) == 0;
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR bool contains(basic_string_view s) const BOOST_NOEXCEPT {
|
||||
return find(s) != npos;
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR bool contains(charT c) const BOOST_NOEXCEPT {
|
||||
return find(c) != npos;
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR bool contains(const charT* s) const BOOST_NOEXCEPT {
|
||||
return find(s) != npos;
|
||||
}
|
||||
|
||||
// find
|
||||
BOOST_CXX14_CONSTEXPR size_type find(basic_string_view s, size_type pos = 0) const BOOST_NOEXCEPT {
|
||||
if (pos > size())
|
||||
return npos;
|
||||
if (s.empty())
|
||||
return pos;
|
||||
const_iterator iter = std::search(this->cbegin() + pos, this->cend(),
|
||||
s.cbegin (), s.cend (), traits::eq);
|
||||
return iter == this->cend () ? npos : std::distance(this->cbegin (), iter);
|
||||
if (s.size() > size() - pos)
|
||||
return npos;
|
||||
const charT* cur = ptr_ + pos;
|
||||
const charT* last = cend() - s.size() + 1;
|
||||
for (; cur != last ; ++cur) {
|
||||
cur = traits::find(cur, last - cur, s[0]);
|
||||
if (!cur)
|
||||
return npos;
|
||||
if (traits::compare(cur, s.cbegin(), s.size()) == 0)
|
||||
return cur - ptr_;
|
||||
}
|
||||
return npos;
|
||||
}
|
||||
BOOST_CXX14_CONSTEXPR size_type find(charT c, size_type pos = 0) const BOOST_NOEXCEPT {
|
||||
if (pos > size())
|
||||
return npos;
|
||||
const charT* ret_ptr = traits::find(ptr_ + pos, len_ - pos, c);
|
||||
if (ret_ptr)
|
||||
return ret_ptr - ptr_;
|
||||
return npos;
|
||||
}
|
||||
BOOST_CXX14_CONSTEXPR size_type find(charT c, size_type pos = 0) const BOOST_NOEXCEPT
|
||||
{ return find(basic_string_view(&c, 1), pos); }
|
||||
BOOST_CXX14_CONSTEXPR size_type find(const charT* s, size_type pos, size_type n) const BOOST_NOEXCEPT
|
||||
{ return find(basic_string_view(s, n), pos); }
|
||||
BOOST_CXX14_CONSTEXPR size_type find(const charT* s, size_type pos = 0) const BOOST_NOEXCEPT
|
||||
@ -288,7 +325,7 @@ namespace boost {
|
||||
return iter == this->cend () ? npos : std::distance ( this->cbegin (), iter );
|
||||
}
|
||||
BOOST_CXX14_CONSTEXPR size_type find_first_of(charT c, size_type pos = 0) const BOOST_NOEXCEPT
|
||||
{ return find_first_of(basic_string_view(&c, 1), pos); }
|
||||
{ return find(c, pos); }
|
||||
BOOST_CXX14_CONSTEXPR size_type find_first_of(const charT* s, size_type pos, size_type n) const BOOST_NOEXCEPT
|
||||
{ return find_first_of(basic_string_view(s, n), pos); }
|
||||
BOOST_CXX14_CONSTEXPR size_type find_first_of(const charT* s, size_type pos = 0) const BOOST_NOEXCEPT
|
||||
@ -369,7 +406,7 @@ namespace boost {
|
||||
// Comparison operators
|
||||
// Equality
|
||||
template<typename charT, typename traits>
|
||||
inline bool operator==(basic_string_view<charT, traits> x,
|
||||
inline BOOST_CXX14_CONSTEXPR bool operator==(basic_string_view<charT, traits> x,
|
||||
basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
|
||||
if (x.size () != y.size ()) return false;
|
||||
return x.compare(y) == 0;
|
||||
@ -377,7 +414,7 @@ namespace boost {
|
||||
|
||||
// Inequality
|
||||
template<typename charT, typename traits>
|
||||
inline bool operator!=(basic_string_view<charT, traits> x,
|
||||
inline BOOST_CXX14_CONSTEXPR bool operator!=(basic_string_view<charT, traits> x,
|
||||
basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
|
||||
if ( x.size () != y.size ()) return true;
|
||||
return x.compare(y) != 0;
|
||||
@ -385,224 +422,183 @@ namespace boost {
|
||||
|
||||
// Less than
|
||||
template<typename charT, typename traits>
|
||||
inline bool operator<(basic_string_view<charT, traits> x,
|
||||
inline BOOST_CXX14_CONSTEXPR bool operator<(basic_string_view<charT, traits> x,
|
||||
basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
|
||||
return x.compare(y) < 0;
|
||||
}
|
||||
|
||||
// Greater than
|
||||
template<typename charT, typename traits>
|
||||
inline bool operator>(basic_string_view<charT, traits> x,
|
||||
inline BOOST_CXX14_CONSTEXPR bool operator>(basic_string_view<charT, traits> x,
|
||||
basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
|
||||
return x.compare(y) > 0;
|
||||
}
|
||||
|
||||
// Less than or equal to
|
||||
template<typename charT, typename traits>
|
||||
inline bool operator<=(basic_string_view<charT, traits> x,
|
||||
inline BOOST_CXX14_CONSTEXPR bool operator<=(basic_string_view<charT, traits> x,
|
||||
basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
|
||||
return x.compare(y) <= 0;
|
||||
}
|
||||
|
||||
// Greater than or equal to
|
||||
template<typename charT, typename traits>
|
||||
inline bool operator>=(basic_string_view<charT, traits> x,
|
||||
inline BOOST_CXX14_CONSTEXPR bool operator>=(basic_string_view<charT, traits> x,
|
||||
basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
|
||||
return x.compare(y) >= 0;
|
||||
}
|
||||
|
||||
// "sufficient additional overloads of comparison functions"
|
||||
template<typename charT, typename traits, typename Allocator>
|
||||
inline bool operator==(basic_string_view<charT, traits> x,
|
||||
inline BOOST_CXX14_CONSTEXPR bool operator==(basic_string_view<charT, traits> x,
|
||||
const std::basic_string<charT, traits, Allocator> & y) BOOST_NOEXCEPT {
|
||||
return x == basic_string_view<charT, traits>(y);
|
||||
}
|
||||
|
||||
template<typename charT, typename traits, typename Allocator>
|
||||
inline bool operator==(const std::basic_string<charT, traits, Allocator> & x,
|
||||
inline BOOST_CXX14_CONSTEXPR bool operator==(const std::basic_string<charT, traits, Allocator> & x,
|
||||
basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
|
||||
return basic_string_view<charT, traits>(x) == y;
|
||||
}
|
||||
|
||||
template<typename charT, typename traits>
|
||||
inline bool operator==(basic_string_view<charT, traits> x,
|
||||
inline BOOST_CXX14_CONSTEXPR bool operator==(basic_string_view<charT, traits> x,
|
||||
const charT * y) BOOST_NOEXCEPT {
|
||||
return x == basic_string_view<charT, traits>(y);
|
||||
}
|
||||
|
||||
template<typename charT, typename traits>
|
||||
inline bool operator==(const charT * x,
|
||||
inline BOOST_CXX14_CONSTEXPR bool operator==(const charT * x,
|
||||
basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
|
||||
return basic_string_view<charT, traits>(x) == y;
|
||||
}
|
||||
|
||||
template<typename charT, typename traits, typename Allocator>
|
||||
inline bool operator!=(basic_string_view<charT, traits> x,
|
||||
inline BOOST_CXX14_CONSTEXPR bool operator!=(basic_string_view<charT, traits> x,
|
||||
const std::basic_string<charT, traits, Allocator> & y) BOOST_NOEXCEPT {
|
||||
return x != basic_string_view<charT, traits>(y);
|
||||
}
|
||||
|
||||
template<typename charT, typename traits, typename Allocator>
|
||||
inline bool operator!=(const std::basic_string<charT, traits, Allocator> & x,
|
||||
inline BOOST_CXX14_CONSTEXPR bool operator!=(const std::basic_string<charT, traits, Allocator> & x,
|
||||
basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
|
||||
return basic_string_view<charT, traits>(x) != y;
|
||||
}
|
||||
|
||||
template<typename charT, typename traits>
|
||||
inline bool operator!=(basic_string_view<charT, traits> x,
|
||||
inline BOOST_CXX14_CONSTEXPR bool operator!=(basic_string_view<charT, traits> x,
|
||||
const charT * y) BOOST_NOEXCEPT {
|
||||
return x != basic_string_view<charT, traits>(y);
|
||||
}
|
||||
|
||||
template<typename charT, typename traits>
|
||||
inline bool operator!=(const charT * x,
|
||||
inline BOOST_CXX14_CONSTEXPR bool operator!=(const charT * x,
|
||||
basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
|
||||
return basic_string_view<charT, traits>(x) != y;
|
||||
}
|
||||
|
||||
template<typename charT, typename traits, typename Allocator>
|
||||
inline bool operator<(basic_string_view<charT, traits> x,
|
||||
inline BOOST_CXX14_CONSTEXPR bool operator<(basic_string_view<charT, traits> x,
|
||||
const std::basic_string<charT, traits, Allocator> & y) BOOST_NOEXCEPT {
|
||||
return x < basic_string_view<charT, traits>(y);
|
||||
}
|
||||
|
||||
template<typename charT, typename traits, typename Allocator>
|
||||
inline bool operator<(const std::basic_string<charT, traits, Allocator> & x,
|
||||
inline BOOST_CXX14_CONSTEXPR bool operator<(const std::basic_string<charT, traits, Allocator> & x,
|
||||
basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
|
||||
return basic_string_view<charT, traits>(x) < y;
|
||||
}
|
||||
|
||||
template<typename charT, typename traits>
|
||||
inline bool operator<(basic_string_view<charT, traits> x,
|
||||
inline BOOST_CXX14_CONSTEXPR bool operator<(basic_string_view<charT, traits> x,
|
||||
const charT * y) BOOST_NOEXCEPT {
|
||||
return x < basic_string_view<charT, traits>(y);
|
||||
}
|
||||
|
||||
template<typename charT, typename traits>
|
||||
inline bool operator<(const charT * x,
|
||||
inline BOOST_CXX14_CONSTEXPR bool operator<(const charT * x,
|
||||
basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
|
||||
return basic_string_view<charT, traits>(x) < y;
|
||||
}
|
||||
|
||||
template<typename charT, typename traits, typename Allocator>
|
||||
inline bool operator>(basic_string_view<charT, traits> x,
|
||||
inline BOOST_CXX14_CONSTEXPR bool operator>(basic_string_view<charT, traits> x,
|
||||
const std::basic_string<charT, traits, Allocator> & y) BOOST_NOEXCEPT {
|
||||
return x > basic_string_view<charT, traits>(y);
|
||||
}
|
||||
|
||||
template<typename charT, typename traits, typename Allocator>
|
||||
inline bool operator>(const std::basic_string<charT, traits, Allocator> & x,
|
||||
inline BOOST_CXX14_CONSTEXPR bool operator>(const std::basic_string<charT, traits, Allocator> & x,
|
||||
basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
|
||||
return basic_string_view<charT, traits>(x) > y;
|
||||
}
|
||||
|
||||
template<typename charT, typename traits>
|
||||
inline bool operator>(basic_string_view<charT, traits> x,
|
||||
inline BOOST_CXX14_CONSTEXPR bool operator>(basic_string_view<charT, traits> x,
|
||||
const charT * y) BOOST_NOEXCEPT {
|
||||
return x > basic_string_view<charT, traits>(y);
|
||||
}
|
||||
|
||||
template<typename charT, typename traits>
|
||||
inline bool operator>(const charT * x,
|
||||
inline BOOST_CXX14_CONSTEXPR bool operator>(const charT * x,
|
||||
basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
|
||||
return basic_string_view<charT, traits>(x) > y;
|
||||
}
|
||||
|
||||
template<typename charT, typename traits, typename Allocator>
|
||||
inline bool operator<=(basic_string_view<charT, traits> x,
|
||||
inline BOOST_CXX14_CONSTEXPR bool operator<=(basic_string_view<charT, traits> x,
|
||||
const std::basic_string<charT, traits, Allocator> & y) BOOST_NOEXCEPT {
|
||||
return x <= basic_string_view<charT, traits>(y);
|
||||
}
|
||||
|
||||
template<typename charT, typename traits, typename Allocator>
|
||||
inline bool operator<=(const std::basic_string<charT, traits, Allocator> & x,
|
||||
inline BOOST_CXX14_CONSTEXPR bool operator<=(const std::basic_string<charT, traits, Allocator> & x,
|
||||
basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
|
||||
return basic_string_view<charT, traits>(x) <= y;
|
||||
}
|
||||
|
||||
template<typename charT, typename traits>
|
||||
inline bool operator<=(basic_string_view<charT, traits> x,
|
||||
inline BOOST_CXX14_CONSTEXPR bool operator<=(basic_string_view<charT, traits> x,
|
||||
const charT * y) BOOST_NOEXCEPT {
|
||||
return x <= basic_string_view<charT, traits>(y);
|
||||
}
|
||||
|
||||
template<typename charT, typename traits>
|
||||
inline bool operator<=(const charT * x,
|
||||
inline BOOST_CXX14_CONSTEXPR bool operator<=(const charT * x,
|
||||
basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
|
||||
return basic_string_view<charT, traits>(x) <= y;
|
||||
}
|
||||
|
||||
template<typename charT, typename traits, typename Allocator>
|
||||
inline bool operator>=(basic_string_view<charT, traits> x,
|
||||
inline BOOST_CXX14_CONSTEXPR bool operator>=(basic_string_view<charT, traits> x,
|
||||
const std::basic_string<charT, traits, Allocator> & y) BOOST_NOEXCEPT {
|
||||
return x >= basic_string_view<charT, traits>(y);
|
||||
}
|
||||
|
||||
template<typename charT, typename traits, typename Allocator>
|
||||
inline bool operator>=(const std::basic_string<charT, traits, Allocator> & x,
|
||||
inline BOOST_CXX14_CONSTEXPR bool operator>=(const std::basic_string<charT, traits, Allocator> & x,
|
||||
basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
|
||||
return basic_string_view<charT, traits>(x) >= y;
|
||||
}
|
||||
|
||||
template<typename charT, typename traits>
|
||||
inline bool operator>=(basic_string_view<charT, traits> x,
|
||||
inline BOOST_CXX14_CONSTEXPR bool operator>=(basic_string_view<charT, traits> x,
|
||||
const charT * y) BOOST_NOEXCEPT {
|
||||
return x >= basic_string_view<charT, traits>(y);
|
||||
}
|
||||
|
||||
template<typename charT, typename traits>
|
||||
inline bool operator>=(const charT * x,
|
||||
inline BOOST_CXX14_CONSTEXPR bool operator>=(const charT * x,
|
||||
basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
|
||||
return basic_string_view<charT, traits>(x) >= y;
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
|
||||
template<class charT, class traits>
|
||||
inline void sv_insert_fill_chars(std::basic_ostream<charT, traits>& os, std::size_t n) {
|
||||
enum { chunk_size = 8 };
|
||||
charT fill_chars[chunk_size];
|
||||
std::fill_n(fill_chars, static_cast< std::size_t >(chunk_size), os.fill());
|
||||
for (; n >= chunk_size && os.good(); n -= chunk_size)
|
||||
os.write(fill_chars, static_cast< std::size_t >(chunk_size));
|
||||
if (n > 0 && os.good())
|
||||
os.write(fill_chars, n);
|
||||
}
|
||||
|
||||
template<class charT, class traits>
|
||||
void sv_insert_aligned(std::basic_ostream<charT, traits>& os, const basic_string_view<charT,traits>& str) {
|
||||
const std::size_t size = str.size();
|
||||
const std::size_t alignment_size = static_cast< std::size_t >(os.width()) - size;
|
||||
const bool align_left = (os.flags() & std::basic_ostream<charT, traits>::adjustfield) == std::basic_ostream<charT, traits>::left;
|
||||
if (!align_left) {
|
||||
detail::sv_insert_fill_chars(os, alignment_size);
|
||||
if (os.good())
|
||||
os.write(str.data(), size);
|
||||
}
|
||||
else {
|
||||
os.write(str.data(), size);
|
||||
if (os.good())
|
||||
detail::sv_insert_fill_chars(os, alignment_size);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
// Inserter
|
||||
template<class charT, class traits>
|
||||
inline std::basic_ostream<charT, traits>&
|
||||
operator<<(std::basic_ostream<charT, traits>& os,
|
||||
const basic_string_view<charT,traits>& str) {
|
||||
if (os.good()) {
|
||||
const std::size_t size = str.size();
|
||||
const std::size_t w = static_cast< std::size_t >(os.width());
|
||||
if (w <= size)
|
||||
os.write(str.data(), size);
|
||||
else
|
||||
detail::sv_insert_aligned(os, str);
|
||||
os.width(0);
|
||||
}
|
||||
return os;
|
||||
return boost::io::ostream_put(os, str.data(), str.size());
|
||||
}
|
||||
|
||||
#if 0
|
||||
@ -676,6 +672,13 @@ namespace boost {
|
||||
}
|
||||
#endif
|
||||
|
||||
// Forward declaration of Boost.ContainerHash function
|
||||
template <class It> std::size_t hash_range(It, It);
|
||||
|
||||
template <class charT, class traits>
|
||||
std::size_t hash_value(basic_string_view<charT, traits> s) {
|
||||
return boost::hash_range(s.begin(), s.end());
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
@ -19,15 +19,20 @@ namespace boost {
|
||||
|
||||
class typed_in_place_factory_base {} ;
|
||||
|
||||
#ifndef BOOST_UTILITY_DOCS
|
||||
#define BOOST_PP_ITERATION_LIMITS (0, BOOST_MAX_INPLACE_FACTORY_ARITY)
|
||||
#define BOOST_PP_FILENAME_1 <boost/utility/typed_in_place_factory.hpp>
|
||||
#include BOOST_PP_ITERATE()
|
||||
#endif // BOOST_UTILITY_DOCS
|
||||
|
||||
#include BOOST_PP_ITERATE()
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/utility/detail/in_place_factory_suffix.hpp>
|
||||
|
||||
#ifndef BOOST_UTILITY_DOCS
|
||||
#define BOOST_UTILITY_TYPED_INPLACE_FACTORY_04APR2007_HPP
|
||||
#endif // BOOST_UTILITY_DOCS
|
||||
|
||||
#else
|
||||
#define N BOOST_PP_ITERATION()
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
// (C) Copyright 2002-2008, Fernando Luis Cacciola Carballal.
|
||||
// Copyright 2020 Peter Dimov
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -21,29 +22,26 @@
|
||||
// issues, by clearing the bytes of T, before constructing the T object it
|
||||
// contains. More details on these issues are at libs/utility/value_init.htm
|
||||
|
||||
#include <boost/aligned_storage.hpp>
|
||||
#include <boost/config.hpp> // For BOOST_NO_COMPLETE_VALUE_INITIALIZATION.
|
||||
#include <boost/detail/workaround.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/type_traits/cv_traits.hpp>
|
||||
#include <boost/type_traits/alignment_of.hpp>
|
||||
#include <boost/swap.hpp>
|
||||
#include <boost/core/invoke_swap.hpp>
|
||||
#include <cstring>
|
||||
#include <new>
|
||||
#include <cstddef>
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(push)
|
||||
// It is safe to ignore the following warning from MSVC 7.1 or higher:
|
||||
// "warning C4351: new behavior: elements of array will be default initialized"
|
||||
#pragma warning(disable: 4351)
|
||||
// It is safe to ignore the following MSVC warning, which may pop up when T is
|
||||
// It is safe to ignore the following MSVC warning, which may pop up when T is
|
||||
// a const type: "warning C4512: assignment operator could not be generated".
|
||||
#pragma warning(disable: 4512)
|
||||
#endif
|
||||
|
||||
#ifndef BOOST_UTILITY_DOCS
|
||||
|
||||
#ifdef BOOST_NO_COMPLETE_VALUE_INITIALIZATION
|
||||
// Implementation detail: The macro BOOST_DETAIL_VALUE_INIT_WORKAROUND_SUGGESTED
|
||||
// suggests that a workaround should be applied, because of compiler issues
|
||||
// Implementation detail: The macro BOOST_DETAIL_VALUE_INIT_WORKAROUND_SUGGESTED
|
||||
// suggests that a workaround should be applied, because of compiler issues
|
||||
// regarding value-initialization.
|
||||
#define BOOST_DETAIL_VALUE_INIT_WORKAROUND_SUGGESTED
|
||||
#endif
|
||||
@ -58,112 +56,80 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // BOOST_UTILITY_DOCS
|
||||
|
||||
namespace boost {
|
||||
|
||||
namespace detail {
|
||||
|
||||
struct zero_init
|
||||
{
|
||||
zero_init()
|
||||
{
|
||||
}
|
||||
|
||||
zero_init( void * p, std::size_t n )
|
||||
{
|
||||
std::memset( p, 0, n );
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<class T>
|
||||
class initialized
|
||||
#if BOOST_DETAIL_VALUE_INIT_WORKAROUND
|
||||
: detail::zero_init
|
||||
#endif
|
||||
{
|
||||
private :
|
||||
struct wrapper
|
||||
{
|
||||
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x592))
|
||||
typename
|
||||
#endif
|
||||
remove_const<T>::type data;
|
||||
private:
|
||||
|
||||
BOOST_GPU_ENABLED
|
||||
wrapper()
|
||||
:
|
||||
data()
|
||||
{
|
||||
}
|
||||
|
||||
BOOST_GPU_ENABLED
|
||||
wrapper(T const & arg)
|
||||
:
|
||||
data(arg)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
mutable
|
||||
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x592))
|
||||
typename
|
||||
#endif
|
||||
aligned_storage<sizeof(wrapper), alignment_of<wrapper>::value>::type x;
|
||||
|
||||
BOOST_GPU_ENABLED
|
||||
wrapper * wrapper_address() const
|
||||
{
|
||||
return static_cast<wrapper *>( static_cast<void*>(&x));
|
||||
}
|
||||
T data_;
|
||||
|
||||
public :
|
||||
|
||||
BOOST_GPU_ENABLED
|
||||
initialized()
|
||||
{
|
||||
initialized():
|
||||
#if BOOST_DETAIL_VALUE_INIT_WORKAROUND
|
||||
std::memset(&x, 0, sizeof(x));
|
||||
zero_init( &const_cast< char& >( reinterpret_cast<char const volatile&>( data_ ) ), sizeof( data_ ) ),
|
||||
#endif
|
||||
new (wrapper_address()) wrapper();
|
||||
data_()
|
||||
{
|
||||
}
|
||||
|
||||
BOOST_GPU_ENABLED
|
||||
initialized(initialized const & arg)
|
||||
explicit initialized(T const & arg): data_( arg )
|
||||
{
|
||||
new (wrapper_address()) wrapper( static_cast<wrapper const &>(*(arg.wrapper_address())));
|
||||
}
|
||||
|
||||
BOOST_GPU_ENABLED
|
||||
explicit initialized(T const & arg)
|
||||
{
|
||||
new (wrapper_address()) wrapper(arg);
|
||||
}
|
||||
|
||||
BOOST_GPU_ENABLED
|
||||
initialized & operator=(initialized const & arg)
|
||||
{
|
||||
// Assignment is only allowed when T is non-const.
|
||||
BOOST_STATIC_ASSERT( ! is_const<T>::value );
|
||||
*wrapper_address() = static_cast<wrapper const &>(*(arg.wrapper_address()));
|
||||
return *this;
|
||||
}
|
||||
|
||||
BOOST_GPU_ENABLED
|
||||
~initialized()
|
||||
{
|
||||
wrapper_address()->wrapper::~wrapper();
|
||||
}
|
||||
|
||||
BOOST_GPU_ENABLED
|
||||
T const & data() const
|
||||
{
|
||||
return wrapper_address()->data;
|
||||
return data_;
|
||||
}
|
||||
|
||||
BOOST_GPU_ENABLED
|
||||
T& data()
|
||||
{
|
||||
return wrapper_address()->data;
|
||||
return data_;
|
||||
}
|
||||
|
||||
BOOST_GPU_ENABLED
|
||||
void swap(initialized & arg)
|
||||
{
|
||||
::boost::swap( this->data(), arg.data() );
|
||||
::boost::core::invoke_swap( this->data(), arg.data() );
|
||||
}
|
||||
|
||||
BOOST_GPU_ENABLED
|
||||
operator T const &() const
|
||||
{
|
||||
return wrapper_address()->data;
|
||||
return data_;
|
||||
}
|
||||
|
||||
BOOST_GPU_ENABLED
|
||||
operator T&()
|
||||
{
|
||||
return wrapper_address()->data;
|
||||
return data_;
|
||||
}
|
||||
|
||||
} ;
|
||||
@ -198,13 +164,13 @@ class value_initialized
|
||||
initialized<T> m_data;
|
||||
|
||||
public :
|
||||
|
||||
|
||||
BOOST_GPU_ENABLED
|
||||
value_initialized()
|
||||
:
|
||||
m_data()
|
||||
{ }
|
||||
|
||||
|
||||
BOOST_GPU_ENABLED
|
||||
T const & data() const
|
||||
{
|
||||
@ -262,7 +228,7 @@ void swap ( value_initialized<T> & lhs, value_initialized<T> & rhs )
|
||||
class initialized_value_t
|
||||
{
|
||||
public :
|
||||
|
||||
|
||||
template <class T> BOOST_GPU_ENABLED operator T() const
|
||||
{
|
||||
return initialized<T>().data();
|
||||
|
63
index.html
63
index.html
@ -1,48 +1,19 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Language" content="en-us">
|
||||
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
|
||||
<meta name="ProgId" content="FrontPage.Editor.Document">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
|
||||
<title>Boost Utility Library</title>
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF">
|
||||
<h1><IMG SRC="../../boost.png" WIDTH="276" HEIGHT="86" align="center">Boost
|
||||
Utility Library</h1>
|
||||
<p>The Boost Utility Library isn't really a single library at all. It is just a
|
||||
collection for components too small to be called libraries in their own right.</p>
|
||||
<p>But that doesn't mean there isn't useful stuff here. Take a look:</p>
|
||||
<blockquote>
|
||||
<p>
|
||||
<a href="../core/doc/html/core/addressof.html">addressof</a> (moved to the Boost.Core library)<br>
|
||||
<a href="doc/html/base_from_member.html">base_from_member</a><br>
|
||||
<a href="utility.htm#BOOST_BINARY">BOOST_BINARY</a><br>
|
||||
<a href="call_traits.htm">call_traits</a><br>
|
||||
<a href="../core/doc/html/core/checked_delete.html">checked_delete</a> (moved to the Boost.Core library)<br>
|
||||
<a href="doc/html/compressed_pair.html">compressed_pair</a><br>
|
||||
<a href="doc/html/declval.html">declval</a><br>
|
||||
<a href="../core/doc/html/core/enable_if.html">enable_if</a> (moved to the Boost.Core library)<br>
|
||||
<a href="in_place_factories.html">in_place_factory</a><br>
|
||||
<a href="iterator_adaptors.htm">iterator_adaptors</a><br>
|
||||
<a href="generator_iterator.htm">generator iterator adaptors</a><br>
|
||||
<a href="utility.htm#functions_next_prior">next/prior</a><br>
|
||||
<a href="../core/doc/html/core/noncopyable.html">noncopyable</a> (moved to the Boost.Core library)<br>
|
||||
<a href="operators.htm">operators</a><br>
|
||||
<a href="utility.htm#result_of">result_of</a><br>
|
||||
<a href="throw_exception.html">throw_exception</a><br>
|
||||
<a href="utility.htm">utility</a><br>
|
||||
<a href="doc/html/string_ref.html">string_ref</a><br>
|
||||
<a href="value_init.htm">value_init</a><br>
|
||||
</p>
|
||||
</blockquote>
|
||||
<hr>
|
||||
<p>© Copyright Beman Dawes, 2001</p>
|
||||
<p>Distributed under the Boost Software License, Version 1.0. (See
|
||||
accompanying file <a href="../../LICENSE_1_0.txt">
|
||||
LICENSE_1_0.txt</a> or copy at
|
||||
<a href="http://www.boost.org/LICENSE_1_0.txt">
|
||||
www.boost.org/LICENSE_1_0.txt</a>)</p>
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->07 November, 2006<!--webbot bot="Timestamp" endspan i-checksum="39368" --></p>
|
||||
</body>
|
||||
<head>
|
||||
<title>Boost.Utility</title>
|
||||
<meta http-equiv="refresh" content="0; URL=./doc/html/index.html">
|
||||
</head>
|
||||
<body>
|
||||
Automatic redirection failed, please go to
|
||||
<a href="./doc/html/index.html">./doc/html/index.html</a>
|
||||
<hr>
|
||||
<tt>
|
||||
Boost.Utility<br>
|
||||
<br>
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
<a href=http://www.boost.org/LICENSE_1_0.txt>http://www.boost.org/LICENSE_1_0.txt</a>) <br>
|
||||
<br>
|
||||
</tt>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -1,11 +1,19 @@
|
||||
<!-- Copyright David Abrahams 2004. Distributed under the Boost -->
|
||||
<!-- Software License, Version 1.0. (See accompanying -->
|
||||
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0; URL=../iterator/doc/index.html">
|
||||
<title>Boost.Iterator</title>
|
||||
<meta http-equiv="refresh" content="0; URL=../iterator/doc/index.html">
|
||||
</head>
|
||||
<body>
|
||||
This documentation moved to <a href="../iterator/doc/index.html">../iterator/doc/index.html</a>.
|
||||
Automatic redirection failed, please go to
|
||||
<a href="../iterator/doc/index.html">../iterator/doc/index.html</a>
|
||||
<hr>
|
||||
<tt>
|
||||
Boost.Iterator<br>
|
||||
<br>
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
<a href=http://www.boost.org/LICENSE_1_0.txt>http://www.boost.org/LICENSE_1_0.txt</a>) <br>
|
||||
<br>
|
||||
</tt>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -5,15 +5,13 @@
|
||||
"authors": [
|
||||
"Dave Abrahams and others"
|
||||
],
|
||||
"description": "Class noncopyable plus checked_delete(), checked_array_delete(), next(), prior() function templates, plus base-from-member idiom.",
|
||||
"description": "Various utilities, such as base-from-member idiom and binary literals in C++03.",
|
||||
"documentation": "utility.htm",
|
||||
"category": [
|
||||
"Algorithms",
|
||||
"Function-objects",
|
||||
"Memory",
|
||||
"Miscellaneous",
|
||||
"Patterns"
|
||||
]
|
||||
],
|
||||
"cxxstd": "03"
|
||||
},
|
||||
{
|
||||
"key": "utility/call_traits",
|
||||
@ -25,7 +23,8 @@
|
||||
"documentation": "call_traits.htm",
|
||||
"category": [
|
||||
"Generic"
|
||||
]
|
||||
],
|
||||
"cxxstd": "03"
|
||||
},
|
||||
{
|
||||
"key": "utility/compressed_pair",
|
||||
@ -33,12 +32,13 @@
|
||||
"authors": [
|
||||
"John Maddock, Howard Hinnant, et al"
|
||||
],
|
||||
"description": "Empty member optimization.",
|
||||
"description": "A pair class with empty member optimization.",
|
||||
"documentation": "compressed_pair.htm",
|
||||
"category": [
|
||||
"Data",
|
||||
"Patterns"
|
||||
]
|
||||
],
|
||||
"cxxstd": "03"
|
||||
},
|
||||
{
|
||||
"key": "utility/identity_type",
|
||||
@ -53,7 +53,8 @@
|
||||
],
|
||||
"maintainers": [
|
||||
"Lorenzo Caminiti <lorcaminiti -at- gmail.com>"
|
||||
]
|
||||
],
|
||||
"cxxstd": "03"
|
||||
},
|
||||
{
|
||||
"key": "utility/in_place_factories",
|
||||
@ -65,7 +66,8 @@
|
||||
"documentation": "in_place_factories.html",
|
||||
"category": [
|
||||
"Generic"
|
||||
]
|
||||
],
|
||||
"cxxstd": "03"
|
||||
},
|
||||
{
|
||||
"key": "utility/operators",
|
||||
@ -74,7 +76,7 @@
|
||||
"Dave Abrahams",
|
||||
"Jeremy Siek"
|
||||
],
|
||||
"description": "Templates ease arithmetic classes and iterators.",
|
||||
"description": "Templates to simplify operator definition in arithmetic classes and iterators.",
|
||||
"documentation": "operators.htm",
|
||||
"category": [
|
||||
"Generic",
|
||||
@ -83,20 +85,37 @@
|
||||
],
|
||||
"maintainers": [
|
||||
"Daniel Frey <d.frey -at- gmx.de>"
|
||||
]
|
||||
],
|
||||
"cxxstd": "03"
|
||||
},
|
||||
{
|
||||
"key": "utility/result_of",
|
||||
"name": "Result Of",
|
||||
"description": "Determines the type of a function call expression.",
|
||||
"documentation": "utility.htm#result_of",
|
||||
"documentation": "doc/html/utility/utilities/result_of.html",
|
||||
"category": [
|
||||
"Function-objects"
|
||||
],
|
||||
"authors": "",
|
||||
"maintainers": [
|
||||
"Daniel Walker <daniel.j.walker -at- gmail.com>"
|
||||
]
|
||||
],
|
||||
"cxxstd": "03"
|
||||
},
|
||||
{
|
||||
"key": "utility/string_view",
|
||||
"name": "String View",
|
||||
"description": "String view templates.",
|
||||
"documentation": "doc/html/utility/utilities/string_view.html",
|
||||
"category": [
|
||||
"Containers",
|
||||
"String"
|
||||
],
|
||||
"authors": "Marshall Clow",
|
||||
"maintainers": [
|
||||
"Marshall Clow <marshall -at- idio.com>"
|
||||
],
|
||||
"cxxstd": "03"
|
||||
},
|
||||
{
|
||||
"key": "utility/value_initialized",
|
||||
@ -108,6 +127,7 @@
|
||||
"documentation": "value_init.htm",
|
||||
"category": [
|
||||
"Miscellaneous"
|
||||
]
|
||||
],
|
||||
"cxxstd": "03"
|
||||
}
|
||||
]
|
||||
|
@ -1,406 +0,0 @@
|
||||
// (C) Copyright David Abrahams 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
// Revision History
|
||||
// 1 Apr 2001 Fixes for ICL; use BOOST_STATIC_CONSTANT
|
||||
// 11 Feb 2001 Fixes for Borland (David Abrahams)
|
||||
// 23 Jan 2001 Added test for wchar_t (David Abrahams)
|
||||
// 23 Jan 2001 Now statically selecting a test for signed numbers to avoid
|
||||
// warnings with fancy compilers. Added commentary and
|
||||
// additional dumping of traits data for tested types (David
|
||||
// Abrahams).
|
||||
// 21 Jan 2001 Initial version (David Abrahams)
|
||||
|
||||
#include <boost/detail/numeric_traits.hpp>
|
||||
#include <cassert>
|
||||
#include <boost/type_traits.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <boost/utility.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <climits>
|
||||
#include <typeinfo>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#ifndef BOOST_NO_LIMITS
|
||||
# include <limits>
|
||||
#endif
|
||||
|
||||
// =================================================================================
|
||||
// template class complement_traits<Number> --
|
||||
//
|
||||
// statically computes the max and min for 1s and 2s-complement binary
|
||||
// numbers. This helps on platforms without <limits> support. It also shows
|
||||
// an example of a recursive template that works with MSVC!
|
||||
//
|
||||
|
||||
template <unsigned size> struct complement; // forward
|
||||
|
||||
// The template complement, below, does all the real work, using "poor man's
|
||||
// partial specialization". We need complement_traits_aux<> so that MSVC doesn't
|
||||
// complain about undefined min/max as we're trying to recursively define them.
|
||||
template <class Number, unsigned size>
|
||||
struct complement_traits_aux
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(Number, max = complement<size>::template traits<Number>::max);
|
||||
BOOST_STATIC_CONSTANT(Number, min = complement<size>::template traits<Number>::min);
|
||||
};
|
||||
|
||||
template <unsigned size>
|
||||
struct complement
|
||||
{
|
||||
template <class Number>
|
||||
struct traits
|
||||
{
|
||||
private:
|
||||
// indirection through complement_traits_aux necessary to keep MSVC happy
|
||||
typedef complement_traits_aux<Number, size - 1> prev;
|
||||
public:
|
||||
#if defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ == 0 && __GNUC_PATCHLEVEL__ == 2
|
||||
// GCC 4.0.2 ICEs on these C-style casts
|
||||
BOOST_STATIC_CONSTANT(Number, max =
|
||||
Number((prev::max) << CHAR_BIT)
|
||||
+ Number(UCHAR_MAX));
|
||||
BOOST_STATIC_CONSTANT(Number, min = Number((prev::min) << CHAR_BIT));
|
||||
#else
|
||||
// Avoid left shifting negative integers, use multiplication instead
|
||||
BOOST_STATIC_CONSTANT(Number, shift = 1u << CHAR_BIT);
|
||||
BOOST_STATIC_CONSTANT(Number, max =
|
||||
Number(Number(prev::max) * shift)
|
||||
+ Number(UCHAR_MAX));
|
||||
BOOST_STATIC_CONSTANT(Number, min = Number(Number(prev::min) * shift));
|
||||
#endif
|
||||
};
|
||||
};
|
||||
|
||||
// Template class complement_base<> -- defines values for min and max for
|
||||
// complement<1>, at the deepest level of recursion. Uses "poor man's partial
|
||||
// specialization" again.
|
||||
template <bool is_signed> struct complement_base;
|
||||
|
||||
template <> struct complement_base<false>
|
||||
{
|
||||
template <class Number>
|
||||
struct values
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(Number, min = 0);
|
||||
BOOST_STATIC_CONSTANT(Number, max = UCHAR_MAX);
|
||||
};
|
||||
};
|
||||
|
||||
template <> struct complement_base<true>
|
||||
{
|
||||
template <class Number>
|
||||
struct values
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(Number, min = SCHAR_MIN);
|
||||
BOOST_STATIC_CONSTANT(Number, max = SCHAR_MAX);
|
||||
};
|
||||
};
|
||||
|
||||
// Base specialization of complement, puts an end to the recursion.
|
||||
template <>
|
||||
struct complement<1>
|
||||
{
|
||||
template <class Number>
|
||||
struct traits
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, is_signed = boost::detail::is_signed<Number>::value);
|
||||
BOOST_STATIC_CONSTANT(Number, min =
|
||||
complement_base<is_signed>::template values<Number>::min);
|
||||
BOOST_STATIC_CONSTANT(Number, max =
|
||||
complement_base<is_signed>::template values<Number>::max);
|
||||
};
|
||||
};
|
||||
|
||||
// Now here's the "pretty" template you're intended to actually use.
|
||||
// complement_traits<Number>::min, complement_traits<Number>::max are the
|
||||
// minimum and maximum values of Number if Number is a built-in integer type.
|
||||
template <class Number>
|
||||
struct complement_traits
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(Number, max = (complement_traits_aux<Number, sizeof(Number)>::max));
|
||||
BOOST_STATIC_CONSTANT(Number, min = (complement_traits_aux<Number, sizeof(Number)>::min));
|
||||
};
|
||||
|
||||
// =================================================================================
|
||||
|
||||
// Support for streaming various numeric types in exactly the format I want. I
|
||||
// needed this in addition to all the assertions so that I could see exactly
|
||||
// what was going on.
|
||||
//
|
||||
// Numbers go through a 2-stage conversion process (by default, though, no real
|
||||
// conversion).
|
||||
//
|
||||
template <class T> struct stream_as {
|
||||
typedef T t1;
|
||||
typedef T t2;
|
||||
};
|
||||
|
||||
// char types first get converted to unsigned char, then to unsigned.
|
||||
template <> struct stream_as<char> {
|
||||
typedef unsigned char t1;
|
||||
typedef unsigned t2;
|
||||
};
|
||||
template <> struct stream_as<unsigned char> {
|
||||
typedef unsigned char t1; typedef unsigned t2;
|
||||
};
|
||||
template <> struct stream_as<signed char> {
|
||||
typedef unsigned char t1; typedef unsigned t2;
|
||||
};
|
||||
|
||||
#if defined(BOOST_MSVC_STD_ITERATOR) // No intmax streaming built-in
|
||||
|
||||
// With this library implementation, __int64 and __uint64 get streamed as strings
|
||||
template <> struct stream_as<boost::uintmax_t> {
|
||||
typedef std::string t1;
|
||||
typedef std::string t2;
|
||||
};
|
||||
|
||||
template <> struct stream_as<boost::intmax_t> {
|
||||
typedef std::string t1;
|
||||
typedef std::string t2;
|
||||
};
|
||||
#endif
|
||||
|
||||
// Standard promotion process for streaming
|
||||
template <class T> struct promote
|
||||
{
|
||||
static typename stream_as<T>::t1 from(T x) {
|
||||
typedef typename stream_as<T>::t1 t1;
|
||||
return t1(x);
|
||||
}
|
||||
};
|
||||
|
||||
#if defined(BOOST_MSVC_STD_ITERATOR) // No intmax streaming built-in
|
||||
|
||||
// On this platform, stream them as long/unsigned long if they fit.
|
||||
// Otherwise, write a string.
|
||||
template <> struct promote<boost::uintmax_t> {
|
||||
std::string static from(const boost::uintmax_t x) {
|
||||
if (x > ULONG_MAX)
|
||||
return std::string("large unsigned value");
|
||||
else
|
||||
return boost::lexical_cast<std::string>((unsigned long)x);
|
||||
}
|
||||
};
|
||||
template <> struct promote<boost::intmax_t> {
|
||||
std::string static from(const boost::intmax_t x) {
|
||||
if (x > boost::intmax_t(ULONG_MAX))
|
||||
return std::string("large positive signed value");
|
||||
else if (x >= 0)
|
||||
return boost::lexical_cast<std::string>((unsigned long)x);
|
||||
|
||||
if (x < boost::intmax_t(LONG_MIN))
|
||||
return std::string("large negative signed value");
|
||||
else
|
||||
return boost::lexical_cast<std::string>((long)x);
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
// This is the function which converts types to the form I want to stream them in.
|
||||
template <class T>
|
||||
typename stream_as<T>::t2 stream_number(T x)
|
||||
{
|
||||
return promote<T>::from(x);
|
||||
}
|
||||
// =================================================================================
|
||||
|
||||
//
|
||||
// Tests for built-in signed and unsigned types
|
||||
//
|
||||
|
||||
// Tag types for selecting tests
|
||||
struct unsigned_tag {};
|
||||
struct signed_tag {};
|
||||
|
||||
// Tests for unsigned numbers. The extra default Number parameter works around
|
||||
// an MSVC bug.
|
||||
template <class Number>
|
||||
void test_aux(unsigned_tag, Number*)
|
||||
{
|
||||
typedef typename boost::detail::numeric_traits<Number>::difference_type difference_type;
|
||||
BOOST_STATIC_ASSERT(!boost::detail::is_signed<Number>::value);
|
||||
BOOST_STATIC_ASSERT(
|
||||
(sizeof(Number) < sizeof(boost::intmax_t))
|
||||
| (boost::is_same<difference_type, boost::intmax_t>::value));
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ == 0 && __GNUC_PATCHLEVEL__ == 2
|
||||
// GCC 4.0.2 ICEs on this C-style cases
|
||||
BOOST_STATIC_ASSERT((complement_traits<Number>::max) > Number(0));
|
||||
BOOST_STATIC_ASSERT((complement_traits<Number>::min) == Number(0));
|
||||
#else
|
||||
// Force casting to Number here to work around the fact that it's an enum on MSVC
|
||||
BOOST_STATIC_ASSERT(Number(complement_traits<Number>::max) > Number(0));
|
||||
BOOST_STATIC_ASSERT(Number(complement_traits<Number>::min) == Number(0));
|
||||
#endif
|
||||
|
||||
const Number max = complement_traits<Number>::max;
|
||||
const Number min = complement_traits<Number>::min;
|
||||
|
||||
const Number test_max = (sizeof(Number) < sizeof(boost::intmax_t))
|
||||
? max
|
||||
: max / 2 - 1;
|
||||
|
||||
std::cout << std::hex << "(unsigned) min = " << stream_number(min) << ", max = "
|
||||
<< stream_number(max) << "..." << std::flush;
|
||||
std::cout << "difference_type = " << typeid(difference_type).name() << "..."
|
||||
<< std::flush;
|
||||
|
||||
difference_type d1 = boost::detail::numeric_distance(Number(0), test_max);
|
||||
difference_type d2 = boost::detail::numeric_distance(test_max, Number(0));
|
||||
|
||||
std::cout << "0->" << stream_number(test_max) << "==" << std::dec << stream_number(d1) << "; "
|
||||
<< std::hex << stream_number(test_max) << "->0==" << std::dec << stream_number(d2) << "..." << std::flush;
|
||||
|
||||
assert(d1 == difference_type(test_max));
|
||||
assert(d2 == -difference_type(test_max));
|
||||
}
|
||||
|
||||
// Tests for signed numbers. The extra default Number parameter works around an
|
||||
// MSVC bug.
|
||||
struct out_of_range_tag {};
|
||||
struct in_range_tag {};
|
||||
|
||||
// This test morsel gets executed for numbers whose difference will always be
|
||||
// representable in intmax_t
|
||||
template <class Number>
|
||||
void signed_test(in_range_tag, Number*)
|
||||
{
|
||||
BOOST_STATIC_ASSERT(boost::detail::is_signed<Number>::value);
|
||||
typedef typename boost::detail::numeric_traits<Number>::difference_type difference_type;
|
||||
const Number max = complement_traits<Number>::max;
|
||||
const Number min = complement_traits<Number>::min;
|
||||
|
||||
difference_type d1 = boost::detail::numeric_distance(min, max);
|
||||
difference_type d2 = boost::detail::numeric_distance(max, min);
|
||||
|
||||
std::cout << stream_number(min) << "->" << stream_number(max) << "==";
|
||||
std::cout << std::dec << stream_number(d1) << "; ";
|
||||
std::cout << std::hex << stream_number(max) << "->" << stream_number(min)
|
||||
<< "==" << std::dec << stream_number(d2) << "..." << std::flush;
|
||||
assert(d1 == difference_type(max) - difference_type(min));
|
||||
assert(d2 == difference_type(min) - difference_type(max));
|
||||
}
|
||||
|
||||
// This test morsel gets executed for numbers whose difference may exceed the
|
||||
// capacity of intmax_t.
|
||||
template <class Number>
|
||||
void signed_test(out_of_range_tag, Number*)
|
||||
{
|
||||
BOOST_STATIC_ASSERT(boost::detail::is_signed<Number>::value);
|
||||
typedef typename boost::detail::numeric_traits<Number>::difference_type difference_type;
|
||||
const Number max = complement_traits<Number>::max;
|
||||
const Number min = complement_traits<Number>::min;
|
||||
|
||||
difference_type min_distance = complement_traits<difference_type>::min;
|
||||
difference_type max_distance = complement_traits<difference_type>::max;
|
||||
|
||||
const Number n1 = Number(min + max_distance);
|
||||
const Number n2 = Number(max + min_distance);
|
||||
difference_type d1 = boost::detail::numeric_distance(min, n1);
|
||||
difference_type d2 = boost::detail::numeric_distance(max, n2);
|
||||
|
||||
std::cout << stream_number(min) << "->" << stream_number(n1) << "==";
|
||||
std::cout << std::dec << stream_number(d1) << "; ";
|
||||
std::cout << std::hex << stream_number(max) << "->" << stream_number(n2)
|
||||
<< "==" << std::dec << stream_number(d2) << "..." << std::flush;
|
||||
assert(d1 == max_distance);
|
||||
assert(d2 == min_distance);
|
||||
}
|
||||
|
||||
template <class Number>
|
||||
void test_aux(signed_tag, Number*)
|
||||
{
|
||||
typedef typename boost::detail::numeric_traits<Number>::difference_type difference_type;
|
||||
BOOST_STATIC_ASSERT(boost::detail::is_signed<Number>::value);
|
||||
BOOST_STATIC_ASSERT(
|
||||
(sizeof(Number) < sizeof(boost::intmax_t))
|
||||
| (boost::is_same<difference_type, Number>::value));
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ == 0 && __GNUC_PATCHLEVEL__ == 2
|
||||
// GCC 4.0.2 ICEs on this cast
|
||||
BOOST_STATIC_ASSERT((complement_traits<Number>::max) > Number(0));
|
||||
BOOST_STATIC_ASSERT((complement_traits<Number>::min) < Number(0));
|
||||
#else
|
||||
// Force casting to Number here to work around the fact that it's an enum on MSVC
|
||||
BOOST_STATIC_ASSERT(Number(complement_traits<Number>::max) > Number(0));
|
||||
BOOST_STATIC_ASSERT(Number(complement_traits<Number>::min) < Number(0));
|
||||
#endif
|
||||
const Number max = complement_traits<Number>::max;
|
||||
const Number min = complement_traits<Number>::min;
|
||||
|
||||
std::cout << std::hex << "min = " << stream_number(min) << ", max = "
|
||||
<< stream_number(max) << "..." << std::flush;
|
||||
std::cout << "difference_type = " << typeid(difference_type).name() << "..."
|
||||
<< std::flush;
|
||||
|
||||
typedef typename boost::detail::if_true<
|
||||
(sizeof(Number) < sizeof(boost::intmax_t))>
|
||||
::template then<
|
||||
in_range_tag,
|
||||
out_of_range_tag
|
||||
>::type
|
||||
range_tag;
|
||||
signed_test<Number>(range_tag(), 0);
|
||||
}
|
||||
|
||||
|
||||
// Test for all numbers. The extra default Number parameter works around an MSVC
|
||||
// bug.
|
||||
template <class Number>
|
||||
void test(Number* = 0)
|
||||
{
|
||||
std::cout << "testing " << typeid(Number).name() << ":\n"
|
||||
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
|
||||
<< "is_signed: " << (std::numeric_limits<Number>::is_signed ? "true\n" : "false\n")
|
||||
<< "is_bounded: " << (std::numeric_limits<Number>::is_bounded ? "true\n" : "false\n")
|
||||
<< "digits: " << std::numeric_limits<Number>::digits << "\n"
|
||||
#endif
|
||||
<< "..." << std::flush;
|
||||
|
||||
// factoring out difference_type for the assert below confused Borland :(
|
||||
typedef boost::detail::is_signed<
|
||||
#if !defined(BOOST_MSVC) || BOOST_MSVC > 1300
|
||||
typename
|
||||
#endif
|
||||
boost::detail::numeric_traits<Number>::difference_type
|
||||
> is_signed;
|
||||
BOOST_STATIC_ASSERT(is_signed::value);
|
||||
|
||||
typedef typename boost::detail::if_true<
|
||||
boost::detail::is_signed<Number>::value
|
||||
>::template then<signed_tag, unsigned_tag>::type signedness;
|
||||
|
||||
test_aux<Number>(signedness(), 0);
|
||||
std::cout << "passed" << std::endl;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test<char>();
|
||||
test<unsigned char>();
|
||||
test<signed char>();
|
||||
test<wchar_t>();
|
||||
test<short>();
|
||||
test<unsigned short>();
|
||||
test<int>();
|
||||
test<unsigned int>();
|
||||
test<long>();
|
||||
test<unsigned long>();
|
||||
#if defined(BOOST_HAS_LONG_LONG) && !defined(BOOST_NO_INTEGRAL_INT64_T)
|
||||
test< ::boost::long_long_type>();
|
||||
test< ::boost::ulong_long_type>();
|
||||
#elif defined(BOOST_MSVC)
|
||||
// The problem of not having compile-time static class constants other than
|
||||
// enums prevents this from working, since values get truncated.
|
||||
// test<boost::uintmax_t>();
|
||||
// test<boost::intmax_t>();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
2159
operators.htm
2159
operators.htm
File diff suppressed because it is too large
Load Diff
@ -1,322 +0,0 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
|
||||
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
|
||||
<meta name="ProgId" content="FrontPage.Editor.Document">
|
||||
<title>Shared Container Iterator Documentation</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="#FFFFFF" text="#000000">
|
||||
|
||||
<img src="../../boost.png" alt="boost.png (6897 bytes)"
|
||||
align="center" width="277" height="86">
|
||||
|
||||
<h1>Shared Container Iterator</h1>
|
||||
|
||||
Defined in header
|
||||
<a href="../../boost/shared_container_iterator.hpp">boost/shared_container_iterator.hpp</a>
|
||||
|
||||
<p>
|
||||
The purpose of the shared container iterator is to attach the lifetime
|
||||
of a container to the lifetime of its iterators. In other words, the
|
||||
container will not be deleted until after all its iterators are
|
||||
destroyed. The shared container iterator is typically used to
|
||||
implement functions that return iterators over a range of objects that
|
||||
only need to exist for the lifetime of the iterators. By returning a
|
||||
pair of shared iterators from a function, the callee can return a
|
||||
heap-allocated range of objects whose lifetime is automatically managed.
|
||||
<p>
|
||||
The shared container iterator augments an iterator over a shared
|
||||
container. It maintains a reference count on the shared
|
||||
container. If only shared container iterators hold references to
|
||||
the container, the container's lifetime will end when the last shared
|
||||
container iterator over it is destroyed. In any case, the shared
|
||||
container is guaranteed to persist beyond the lifetime of all
|
||||
the iterators. In all other ways, the
|
||||
shared container iterator behaves the same as its base iterator.
|
||||
|
||||
|
||||
<h2>Synopsis</h2>
|
||||
|
||||
<pre>
|
||||
namespace boost {
|
||||
template <typename <a href="http://www.sgi.com/tech/stl/Container.html">Container</a>>
|
||||
class shared_container_iterator;
|
||||
|
||||
template <typename <a href="http://www.sgi.com/tech/stl/Container.html">Container</a>>
|
||||
shared_container_iterator<Container>
|
||||
make_shared_container_iterator(typename Container::iterator base,
|
||||
boost::shared_ptr<Container> const& container);
|
||||
|
||||
std::pair<
|
||||
typename shared_container_iterator<Container>,
|
||||
typename shared_container_iterator<Container>
|
||||
>
|
||||
make_shared_container_range(boost::shared_ptr<Container> const& container);
|
||||
}
|
||||
</pre>
|
||||
|
||||
<hr>
|
||||
|
||||
<h2><a name="generator">The Shared Container Iterator Type</a></h2>
|
||||
|
||||
<pre>
|
||||
template <typename Container> class shared_container_iterator;
|
||||
</pre>
|
||||
|
||||
The class template <tt>shared_container_iterator</tt>
|
||||
is the shared container iterator type. The <tt>Container</tt> template
|
||||
type argument must model the
|
||||
<a href="http://www.sgi.com/tech/stl/Container.html">Container</a>
|
||||
concept.
|
||||
|
||||
<h3>Example</h3>
|
||||
|
||||
<p>
|
||||
The following example illustrates how to create an iterator that
|
||||
regulates the lifetime of a reference counted <tt>std::vector</tt>.
|
||||
Though the original shared pointer <tt>ints</tt> ceases to exist
|
||||
after <tt>set_range()</tt> returns, the
|
||||
<tt>shared_counter_iterator</tt> objects maintain references to the
|
||||
underlying vector and thereby extend the container's lifetime.
|
||||
<p>
|
||||
<a href="./shared_iterator_example1.cpp">shared_iterator_example1.cpp</a>:
|
||||
<PRE>
|
||||
<font color="#008040">#include "shared_container_iterator.hpp"</font>
|
||||
<font color="#008040">#include "boost/shared_ptr.hpp"</font>
|
||||
<font color="#008040">#include <algorithm></font>
|
||||
<font color="#008040">#include <iostream></font>
|
||||
<font color="#008040">#include <vector></font>
|
||||
|
||||
<B>typedef</B> boost::shared_container_iterator< std::vector<<B>int</B>> > iterator;
|
||||
|
||||
|
||||
<B>void</B> set_range(iterator& i, iterator& end) {
|
||||
|
||||
boost::shared_ptr< std::vector<<B>int</B>> > ints(<B>new</B> std::vector<<B>int</B>>());
|
||||
|
||||
ints->push_back(<font color="#0000A0">0</font>);
|
||||
ints->push_back(<font color="#0000A0">1</font>);
|
||||
ints->push_back(<font color="#0000A0">2</font>);
|
||||
ints->push_back(<font color="#0000A0">3</font>);
|
||||
ints->push_back(<font color="#0000A0">4</font>);
|
||||
ints->push_back(<font color="#0000A0">5</font>);
|
||||
|
||||
i = iterator(ints->begin(),ints);
|
||||
end = iterator(ints->end(),ints);
|
||||
}
|
||||
|
||||
|
||||
<B>int</B> main() {
|
||||
|
||||
iterator i,end;
|
||||
|
||||
set_range(i,end);
|
||||
|
||||
std::copy(i,end,std::ostream_iterator<<B>int</B>>(std::cout,<font color="#0000FF">","</font>));
|
||||
std::cout.put(<font color="#0000FF">'\n'</font>);
|
||||
|
||||
<B>return</B> <font color="#0000A0">0</font>;
|
||||
}
|
||||
</PRE>
|
||||
|
||||
The output from this part is:
|
||||
<pre>
|
||||
0,1,2,3,4,5,
|
||||
</pre>
|
||||
|
||||
<h3>Template Parameters</h3>
|
||||
|
||||
<Table border>
|
||||
<TR>
|
||||
<TH>Parameter</TH><TH>Description</TH>
|
||||
</TR>
|
||||
|
||||
<TR>
|
||||
<TD><a
|
||||
href="http://www.sgi.com/tech/stl/Container.html"><tt>Container</tt></a></TD>
|
||||
<TD>The type of the container that we wish to iterate over. It must be
|
||||
a model of the
|
||||
<a href="http://www.sgi.com/tech/stl/Container.html"><tt>Container</tt></a>
|
||||
concept.
|
||||
</TD>
|
||||
</TR>
|
||||
</Table>
|
||||
|
||||
<h3>Model of</h3>
|
||||
|
||||
The <tt>shared_container_iterator<Container></tt> type models the
|
||||
same iterator concept as the base iterator
|
||||
(<tt>Container::iterator</tt>).
|
||||
|
||||
<h3>Members</h3>
|
||||
|
||||
The shared container iterator type implements the member functions and
|
||||
operators required of the <a
|
||||
href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">Random Access Iterator</a>
|
||||
concept, though only operations defined for the base iterator will be valid.
|
||||
In addition it has the following constructor:
|
||||
|
||||
<pre>
|
||||
shared_container_iterator(Container::iterator const& it,
|
||||
boost::shared_ptr<Container> const& container)
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
<hr>
|
||||
<p>
|
||||
|
||||
|
||||
<h2><a name="make_iterator">The Shared Container Iterator Object Generator</a></h2>
|
||||
|
||||
<pre>
|
||||
template <typename Container>
|
||||
shared_container_iterator<Container>
|
||||
make_shared_container_iterator(Container::iterator base,
|
||||
boost::shared_ptr<Container> const& container)
|
||||
</pre>
|
||||
|
||||
This function provides an alternative to directly constructing a
|
||||
shared container iterator. Using the object generator, a shared
|
||||
container iterator can be created and passed to a function without
|
||||
explicitly specifying its type.
|
||||
|
||||
<h3>Example</h3>
|
||||
|
||||
This example, similar to the previous, uses
|
||||
<tt>make_shared_container_iterator()</tt> to create the iterators.
|
||||
|
||||
<p>
|
||||
<a href="./shared_iterator_example2.cpp">shared_iterator_example2.cpp</a>:
|
||||
|
||||
<PRE>
|
||||
<font color="#008040">#include "shared_container_iterator.hpp"</font>
|
||||
<font color="#008040">#include "boost/shared_ptr.hpp"</font>
|
||||
<font color="#008040">#include <algorithm></font>
|
||||
<font color="#008040">#include <iterator></font>
|
||||
<font color="#008040">#include <iostream></font>
|
||||
<font color="#008040">#include <vector></font>
|
||||
|
||||
|
||||
<B>template</B> <<B>typename</B> Iterator>
|
||||
<B>void</B> print_range_nl (Iterator begin, Iterator end) {
|
||||
<B>typedef</B> <B>typename</B> std::iterator_traits<Iterator>::value_type val;
|
||||
std::copy(begin,end,std::ostream_iterator<val>(std::cout,<font color="#0000FF">","</font>));
|
||||
std::cout.put(<font color="#0000FF">'\n'</font>);
|
||||
}
|
||||
|
||||
|
||||
<B>int</B> main() {
|
||||
|
||||
<B>typedef</B> boost::shared_ptr< std::vector<<B>int</B>> > ints_t;
|
||||
{
|
||||
ints_t ints(<B>new</B> std::vector<<B>int</B>>());
|
||||
|
||||
ints->push_back(<font color="#0000A0">0</font>);
|
||||
ints->push_back(<font color="#0000A0">1</font>);
|
||||
ints->push_back(<font color="#0000A0">2</font>);
|
||||
ints->push_back(<font color="#0000A0">3</font>);
|
||||
ints->push_back(<font color="#0000A0">4</font>);
|
||||
ints->push_back(<font color="#0000A0">5</font>);
|
||||
|
||||
print_range_nl(boost::make_shared_container_iterator(ints->begin(),ints),
|
||||
boost::make_shared_container_iterator(ints->end(),ints));
|
||||
}
|
||||
|
||||
|
||||
|
||||
<B>return</B> <font color="#0000A0">0</font>;
|
||||
}
|
||||
</PRE>
|
||||
|
||||
Observe that the <tt>shared_container_iterator</tt> type is never
|
||||
explicitly named. The output from this example is the same as the previous.
|
||||
|
||||
<h2><a name="make_range">The Shared Container Iterator Range Generator</a></h2>
|
||||
|
||||
<pre>
|
||||
template <typename Container>
|
||||
std::pair<
|
||||
shared_container_iterator<Container>,
|
||||
shared_container_iterator<Container>
|
||||
>
|
||||
make_shared_container_range(boost::shared_ptr<Container> const& container);
|
||||
</pre>
|
||||
|
||||
Class <tt>shared_container_iterator</tt> is meant primarily to return,
|
||||
using iterators, a range of values that we can guarantee will be alive as
|
||||
long as the iterators are. This is a convenience
|
||||
function to do just that. It is equivalent to
|
||||
|
||||
<pre>
|
||||
std::make_pair(make_shared_container_iterator(container->begin(),container),
|
||||
make_shared_container_iterator(container->end(),container));
|
||||
</pre>
|
||||
|
||||
<h3>Example</h3>
|
||||
|
||||
In the following example, a range of values is returned as a pair of
|
||||
<tt>shared_container_iterator</tt> objects.
|
||||
|
||||
|
||||
<p>
|
||||
<a href="./shared_iterator_example3.cpp">shared_iterator_example3.cpp</a>:
|
||||
|
||||
<PRE>
|
||||
<font color="#008040">#include "shared_container_iterator.hpp"</font>
|
||||
<font color="#008040">#include "boost/shared_ptr.hpp"</font>
|
||||
<font color="#008040">#include "boost/tuple/tuple.hpp" // for boost::tie</font>
|
||||
<font color="#008040">#include <algorithm> // for std::copy</font>
|
||||
<font color="#008040">#include <iostream> </font>
|
||||
<font color="#008040">#include <vector></font>
|
||||
|
||||
|
||||
<B>typedef</B> boost::shared_container_iterator< std::vector<<B>int</B>> > iterator;
|
||||
|
||||
std::pair<iterator,iterator>
|
||||
return_range() {
|
||||
boost::shared_ptr< std::vector<<B>int</B>> > range(<B>new</B> std::vector<<B>int</B>>());
|
||||
range->push_back(<font color="#0000A0">0</font>);
|
||||
range->push_back(<font color="#0000A0">1</font>);
|
||||
range->push_back(<font color="#0000A0">2</font>);
|
||||
range->push_back(<font color="#0000A0">3</font>);
|
||||
range->push_back(<font color="#0000A0">4</font>);
|
||||
range->push_back(<font color="#0000A0">5</font>);
|
||||
<B>return</B> boost::make_shared_container_range(range);
|
||||
}
|
||||
|
||||
|
||||
<B>int</B> main() {
|
||||
|
||||
|
||||
iterator i,end;
|
||||
|
||||
boost::tie(i,end) = return_range();
|
||||
|
||||
std::copy(i,end,std::ostream_iterator<<B>int</B>>(std::cout,<font color="#0000FF">","</font>));
|
||||
std::cout.put(<font color="#0000FF">'\n'</font>);
|
||||
|
||||
<B>return</B> <font color="#0000A0">0</font>;
|
||||
}
|
||||
</PRE>
|
||||
|
||||
Though the <tt>range</tt> object only lives for the duration of the
|
||||
<tt>return_range</tt> call, the reference counted
|
||||
<tt>std::vector</tt> will live until <tt>i</tt> and <tt>end</tt>
|
||||
are both destroyed. The output from this example is the same as
|
||||
the previous two.
|
||||
|
||||
|
||||
<hr>
|
||||
<!-- hhmts start -->
|
||||
Last modified: Mon Aug 11 11:27:03 EST 2003
|
||||
<!-- hhmts end -->
|
||||
<p><EFBFBD> Copyright 2003 The Trustees of Indiana University.
|
||||
Use, modification and distribution is subject to the Boost Software
|
||||
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
http://www.boost.org/LICENSE_1_0.txt)</p>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
@ -1,42 +0,0 @@
|
||||
// Copyright 2003 The Trustees of Indiana University.
|
||||
|
||||
// Use, modification and distribution is subject to the Boost Software
|
||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include "boost/shared_container_iterator.hpp"
|
||||
#include "boost/shared_ptr.hpp"
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
typedef boost::shared_container_iterator< std::vector<int> > iterator;
|
||||
|
||||
|
||||
void set_range(iterator& i, iterator& end) {
|
||||
|
||||
boost::shared_ptr< std::vector<int> > ints(new std::vector<int>());
|
||||
|
||||
ints->push_back(0);
|
||||
ints->push_back(1);
|
||||
ints->push_back(2);
|
||||
ints->push_back(3);
|
||||
ints->push_back(4);
|
||||
ints->push_back(5);
|
||||
|
||||
i = iterator(ints->begin(),ints);
|
||||
end = iterator(ints->end(),ints);
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
iterator i,end;
|
||||
|
||||
set_range(i,end);
|
||||
|
||||
std::copy(i,end,std::ostream_iterator<int>(std::cout,","));
|
||||
std::cout.put('\n');
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
// Copyright 2003 The Trustees of Indiana University.
|
||||
|
||||
// Use, modification and distribution is subject to the Boost Software
|
||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include "boost/shared_container_iterator.hpp"
|
||||
#include "boost/shared_ptr.hpp"
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
|
||||
template <typename Iterator>
|
||||
void print_range_nl (Iterator begin, Iterator end) {
|
||||
typedef typename std::iterator_traits<Iterator>::value_type val;
|
||||
std::copy(begin,end,std::ostream_iterator<val>(std::cout,","));
|
||||
std::cout.put('\n');
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
typedef boost::shared_ptr< std::vector<int> > ints_t;
|
||||
{
|
||||
ints_t ints(new std::vector<int>());
|
||||
|
||||
ints->push_back(0);
|
||||
ints->push_back(1);
|
||||
ints->push_back(2);
|
||||
ints->push_back(3);
|
||||
ints->push_back(4);
|
||||
ints->push_back(5);
|
||||
|
||||
print_range_nl(boost::make_shared_container_iterator(ints->begin(),ints),
|
||||
boost::make_shared_container_iterator(ints->end(),ints));
|
||||
}
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
// Copyright 2003 The Trustees of Indiana University.
|
||||
|
||||
// Use, modification and distribution is subject to the Boost Software
|
||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include "boost/shared_container_iterator.hpp"
|
||||
#include "boost/shared_ptr.hpp"
|
||||
#include "boost/tuple/tuple.hpp" // for boost::tie
|
||||
#include <algorithm> // for std::copy
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
|
||||
typedef boost::shared_container_iterator< std::vector<int> > iterator;
|
||||
|
||||
std::pair<iterator,iterator>
|
||||
return_range() {
|
||||
boost::shared_ptr< std::vector<int> > range(new std::vector<int>());
|
||||
range->push_back(0);
|
||||
range->push_back(1);
|
||||
range->push_back(2);
|
||||
range->push_back(3);
|
||||
range->push_back(4);
|
||||
range->push_back(5);
|
||||
return boost::make_shared_container_range(range);
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
|
||||
iterator i,end;
|
||||
|
||||
boost::tie(i,end) = return_range();
|
||||
|
||||
std::copy(i,end,std::ostream_iterator<int>(std::cout,","));
|
||||
std::cout.put('\n');
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
// Copyright 2003 The Trustees of Indiana University.
|
||||
|
||||
// Use, modification and distribution is subject to the Boost Software
|
||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// Shared container iterator adaptor
|
||||
// Author: Ronald Garcia
|
||||
// See http://boost.org/libs/utility/shared_container_iterator.html
|
||||
// for documentation.
|
||||
|
||||
//
|
||||
// shared_iterator_test.cpp - Regression tests for shared_container_iterator.
|
||||
//
|
||||
|
||||
|
||||
#include "boost/shared_container_iterator.hpp"
|
||||
#include "boost/shared_ptr.hpp"
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
|
||||
struct resource {
|
||||
static int count;
|
||||
resource() { ++count; }
|
||||
resource(resource const&) { ++count; }
|
||||
~resource() { --count; }
|
||||
};
|
||||
int resource::count = 0;
|
||||
|
||||
typedef std::vector<resource> resources_t;
|
||||
|
||||
typedef boost::shared_container_iterator< resources_t > iterator;
|
||||
|
||||
|
||||
void set_range(iterator& i, iterator& end) {
|
||||
|
||||
boost::shared_ptr< resources_t > objs(new resources_t());
|
||||
|
||||
for (int j = 0; j != 6; ++j)
|
||||
objs->push_back(resource());
|
||||
|
||||
i = iterator(objs->begin(),objs);
|
||||
end = iterator(objs->end(),objs);
|
||||
assert(resource::count == 6);
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
assert(resource::count == 0);
|
||||
|
||||
{
|
||||
iterator i;
|
||||
{
|
||||
iterator end;
|
||||
set_range(i,end);
|
||||
assert(resource::count == 6);
|
||||
}
|
||||
assert(resource::count == 6);
|
||||
}
|
||||
assert(resource::count == 0);
|
||||
|
||||
return 0;
|
||||
}
|
@ -8,40 +8,42 @@
|
||||
# bring in rules for testing
|
||||
import testing ;
|
||||
|
||||
alias unit_test_framework
|
||||
: # sources
|
||||
/boost//unit_test_framework
|
||||
;
|
||||
project : requirements <library>/boost/utility//boost_utility ;
|
||||
|
||||
# Please keep the tests ordered by filename
|
||||
test-suite utility
|
||||
:
|
||||
[ run ../base_from_member_test.cpp ]
|
||||
[ run ../base_from_member_ref_test.cpp ]
|
||||
[ run ../binary_test.cpp ]
|
||||
[ run ../call_traits_test.cpp : -u ]
|
||||
[ run ../compressed_pair_test.cpp ../../test/build//boost_test_exec_monitor/<link>static ]
|
||||
[ run ../iterators_test.cpp ../../test/build//boost_test_exec_monitor/<link>static ]
|
||||
[ run next_prior_test.cpp ../../test/build//boost_test_exec_monitor/<link>static ]
|
||||
[ run ../numeric_traits_test.cpp ]
|
||||
[ run ../operators_test.cpp ../../test/build//boost_test_exec_monitor/<link>static ]
|
||||
[ compile result_of_test.cpp ]
|
||||
[ run ../shared_iterator_test.cpp ]
|
||||
[ run string_ref_test1.cpp unit_test_framework ]
|
||||
[ run string_ref_test2.cpp unit_test_framework ]
|
||||
[ run string_ref_test_io.cpp unit_test_framework ]
|
||||
[ run string_view_test1.cpp unit_test_framework ]
|
||||
[ run string_view_test2.cpp unit_test_framework ]
|
||||
[ run string_view_test_io.cpp unit_test_framework ]
|
||||
[ run ../value_init_test.cpp ]
|
||||
[ run ../value_init_workaround_test.cpp ]
|
||||
[ run ../initialized_test.cpp ]
|
||||
[ compile-fail ../value_init_test_fail1.cpp ]
|
||||
[ compile-fail ../value_init_test_fail2.cpp ]
|
||||
[ compile-fail ../value_init_test_fail3.cpp ]
|
||||
[ compile-fail ../initialized_test_fail1.cpp ]
|
||||
[ compile-fail ../initialized_test_fail2.cpp ]
|
||||
run base_from_member_test.cpp ;
|
||||
run base_from_member_ref_test.cpp ;
|
||||
|
||||
[ run ../generator_iterator_test.cpp ]
|
||||
;
|
||||
run binary_test.cpp ;
|
||||
|
||||
run call_traits_test.cpp : -u : : <library>/boost/type_traits//testing ;
|
||||
|
||||
run compressed_pair_test.cpp ;
|
||||
run compressed_pair_final_test.cpp ;
|
||||
|
||||
run iterators_test.cpp ;
|
||||
|
||||
run operators_test.cpp ;
|
||||
compile operators_constexpr_test.cpp ;
|
||||
|
||||
compile result_of_test.cpp ;
|
||||
|
||||
# compile-fail string_ref_from_rvalue.cpp ;
|
||||
run string_ref_test1.cpp ;
|
||||
run string_ref_test2.cpp ;
|
||||
run string_ref_test_io.cpp ;
|
||||
# compile-fail string_view_from_rvalue.cpp ;
|
||||
compile string_view_constexpr_test1.cpp ;
|
||||
run string_view_test1.cpp : : : <library>/boost/container_hash//boost_container_hash ;
|
||||
run string_view_test2.cpp ;
|
||||
run string_view_test_io.cpp ;
|
||||
|
||||
run value_init_test.cpp ;
|
||||
run value_init_test2.cpp ;
|
||||
run value_init_test3.cpp ;
|
||||
run value_init_workaround_test.cpp ;
|
||||
run initialized_test.cpp ;
|
||||
compile-fail value_init_test_fail1.cpp ;
|
||||
compile-fail value_init_test_fail2.cpp ;
|
||||
compile-fail value_init_test_fail3.cpp ;
|
||||
compile-fail initialized_test_fail1.cpp ;
|
||||
compile-fail initialized_test_fail2.cpp ;
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
#include <boost/utility/base_from_member.hpp>
|
||||
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
struct foo : boost::base_from_member<int&>
|
||||
{
|
@ -10,15 +10,14 @@
|
||||
// 14 Jun 2003 Adjusted code for Boost.Test changes (Daryle Walker)
|
||||
// 29 Aug 2001 Initial Version (Daryle Walker)
|
||||
|
||||
#include <boost/test/minimal.hpp> // for BOOST_CHECK, main
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
#include <boost/config.hpp> // for BOOST_NO_MEMBER_TEMPLATES
|
||||
#include <boost/cstdlib.hpp> // for boost::exit_success
|
||||
#include <boost/noncopyable.hpp> // for boost::noncopyable
|
||||
|
||||
#include <boost/utility/base_from_member.hpp> // for boost::base_from_member
|
||||
|
||||
#include <functional> // for std::binary_function, std::less
|
||||
#include <functional> // for std::less
|
||||
#include <iostream> // for std::cout (std::ostream, std::endl indirectly)
|
||||
#include <set> // for std::set
|
||||
#include <typeinfo> // for std::type_info
|
||||
@ -46,7 +45,6 @@ template < typename T >
|
||||
|
||||
// A custom comparison type is needed
|
||||
struct object_id_compare
|
||||
: std::binary_function<object_id, object_id, bool>
|
||||
{
|
||||
bool operator ()( object_id const &a, object_id const &b ) const;
|
||||
|
||||
@ -173,13 +171,13 @@ object_registrar obj_reg;
|
||||
|
||||
// Main functionality
|
||||
int
|
||||
test_main( int , char * [] )
|
||||
main()
|
||||
{
|
||||
BOOST_CHECK( obj_reg.db_.empty() );
|
||||
BOOST_CHECK( obj_reg.defrauders_in_.empty() );
|
||||
BOOST_CHECK( obj_reg.defrauders_out_.empty() );
|
||||
BOOST_CHECK( obj_reg.overeager_.empty() );
|
||||
BOOST_CHECK( obj_reg.overkilled_.empty() );
|
||||
BOOST_TEST( obj_reg.db_.empty() );
|
||||
BOOST_TEST( obj_reg.defrauders_in_.empty() );
|
||||
BOOST_TEST( obj_reg.defrauders_out_.empty() );
|
||||
BOOST_TEST( obj_reg.overeager_.empty() );
|
||||
BOOST_TEST( obj_reg.overkilled_.empty() );
|
||||
|
||||
// Make a separate block to examine pre- and post-effects
|
||||
{
|
||||
@ -187,20 +185,20 @@ test_main( int , char * [] )
|
||||
using std::endl;
|
||||
|
||||
bad_class bc;
|
||||
BOOST_CHECK( obj_reg.db_.size() == 3 );
|
||||
BOOST_CHECK( obj_reg.defrauders_in_.size() == 1 );
|
||||
BOOST_TEST( obj_reg.db_.size() == 3 );
|
||||
BOOST_TEST( obj_reg.defrauders_in_.size() == 1 );
|
||||
|
||||
good_class_1 gc1;
|
||||
BOOST_CHECK( obj_reg.db_.size() == 6 );
|
||||
BOOST_CHECK( obj_reg.defrauders_in_.size() == 1 );
|
||||
BOOST_TEST( obj_reg.db_.size() == 6 );
|
||||
BOOST_TEST( obj_reg.defrauders_in_.size() == 1 );
|
||||
|
||||
good_class_2 gc2;
|
||||
BOOST_CHECK( obj_reg.db_.size() == 11 );
|
||||
BOOST_CHECK( obj_reg.defrauders_in_.size() == 1 );
|
||||
BOOST_TEST( obj_reg.db_.size() == 11 );
|
||||
BOOST_TEST( obj_reg.defrauders_in_.size() == 1 );
|
||||
|
||||
BOOST_CHECK( obj_reg.defrauders_out_.empty() );
|
||||
BOOST_CHECK( obj_reg.overeager_.empty() );
|
||||
BOOST_CHECK( obj_reg.overkilled_.empty() );
|
||||
BOOST_TEST( obj_reg.defrauders_out_.empty() );
|
||||
BOOST_TEST( obj_reg.overeager_.empty() );
|
||||
BOOST_TEST( obj_reg.overkilled_.empty() );
|
||||
|
||||
// Getting the addresses of the objects ensure
|
||||
// that they're used, and not optimized away.
|
||||
@ -209,13 +207,13 @@ test_main( int , char * [] )
|
||||
cout << "Object 'gc2' is at " << &gc2 << '.' << endl;
|
||||
}
|
||||
|
||||
BOOST_CHECK( obj_reg.db_.empty() );
|
||||
BOOST_CHECK( obj_reg.defrauders_in_.size() == 1 );
|
||||
BOOST_CHECK( obj_reg.defrauders_out_.size() == 1 );
|
||||
BOOST_CHECK( obj_reg.overeager_.empty() );
|
||||
BOOST_CHECK( obj_reg.overkilled_.empty() );
|
||||
BOOST_TEST( obj_reg.db_.empty() );
|
||||
BOOST_TEST( obj_reg.defrauders_in_.size() == 1 );
|
||||
BOOST_TEST( obj_reg.defrauders_out_.size() == 1 );
|
||||
BOOST_TEST( obj_reg.overeager_.empty() );
|
||||
BOOST_TEST( obj_reg.overkilled_.empty() );
|
||||
|
||||
return boost::exit_success;
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
http://www.boost.org/LICENSE_1_0.txt)
|
||||
==============================================================================*/
|
||||
|
||||
#include <boost/test/minimal.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/utility/binary.hpp>
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
@ -614,34 +614,34 @@ typedef char (&unsigned_long_int_id_type)[unsigned_long_int_id];
|
||||
unsigned_int_id_type binary_type_checker( unsigned int );
|
||||
unsigned_long_int_id_type binary_type_checker( unsigned long int );
|
||||
|
||||
int test_main( int, char *[] )
|
||||
int main()
|
||||
{
|
||||
BOOST_CHECK( is_ascending_from_0_array( unsigned_ints_1_bit ) );
|
||||
BOOST_CHECK( is_ascending_from_0_array( unsigned_ints_2_bits ) );
|
||||
BOOST_CHECK( is_ascending_from_0_array( unsigned_ints_3_bits ) );
|
||||
BOOST_CHECK( is_ascending_from_0_array( unsigned_ints_4_bits ) );
|
||||
BOOST_CHECK( is_ascending_from_0_array( unsigned_ints_5_bits ) );
|
||||
BOOST_CHECK( is_ascending_from_0_array( unsigned_ints_6_bits ) );
|
||||
BOOST_CHECK( is_ascending_from_0_array( unsigned_ints_7_bits ) );
|
||||
BOOST_CHECK( is_ascending_from_0_array( unsigned_ints_8_bits ) );
|
||||
BOOST_TEST( is_ascending_from_0_array( unsigned_ints_1_bit ) );
|
||||
BOOST_TEST( is_ascending_from_0_array( unsigned_ints_2_bits ) );
|
||||
BOOST_TEST( is_ascending_from_0_array( unsigned_ints_3_bits ) );
|
||||
BOOST_TEST( is_ascending_from_0_array( unsigned_ints_4_bits ) );
|
||||
BOOST_TEST( is_ascending_from_0_array( unsigned_ints_5_bits ) );
|
||||
BOOST_TEST( is_ascending_from_0_array( unsigned_ints_6_bits ) );
|
||||
BOOST_TEST( is_ascending_from_0_array( unsigned_ints_7_bits ) );
|
||||
BOOST_TEST( is_ascending_from_0_array( unsigned_ints_8_bits ) );
|
||||
|
||||
BOOST_CHECK( std::equal( &random_unsigned_ints_hex[0]
|
||||
BOOST_TEST( std::equal( &random_unsigned_ints_hex[0]
|
||||
, random_unsigned_ints_hex + num_random_test_values
|
||||
, &random_unsigned_ints_binary[0]
|
||||
)
|
||||
);
|
||||
|
||||
BOOST_CHECK( sizeof( binary_type_checker( BOOST_BINARY_U( 110100 1010 ) ) )
|
||||
BOOST_TEST( sizeof( binary_type_checker( BOOST_BINARY_U( 110100 1010 ) ) )
|
||||
== unsigned_int_id
|
||||
);
|
||||
|
||||
BOOST_CHECK( sizeof( binary_type_checker( BOOST_BINARY_UL( 11110 ) ) )
|
||||
BOOST_TEST( sizeof( binary_type_checker( BOOST_BINARY_UL( 11110 ) ) )
|
||||
== unsigned_long_int_id
|
||||
);
|
||||
|
||||
BOOST_CHECK( sizeof( binary_type_checker( BOOST_BINARY_LU( 10 0001 ) ) )
|
||||
BOOST_TEST( sizeof( binary_type_checker( BOOST_BINARY_LU( 10 0001 ) ) )
|
||||
== unsigned_long_int_id
|
||||
);
|
||||
|
||||
return 0;
|
||||
return boost::report_errors();
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
// boost::compressed_pair test program
|
||||
|
||||
// (C) Copyright John Maddock 2000.
|
||||
// boost::compressed_pair test program
|
||||
|
||||
// (C) Copyright John Maddock 2000.
|
||||
// Use, modification and distribution are subject to the Boost Software License,
|
||||
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt).
|
||||
@ -18,8 +18,8 @@
|
||||
#include <typeinfo>
|
||||
#include <boost/call_traits.hpp>
|
||||
|
||||
#include <libs/type_traits/test/test.hpp>
|
||||
#include <libs/type_traits/test/check_type.hpp>
|
||||
// type_traits/test utilities
|
||||
#include "check_type.hpp"
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(disable:4181) // : warning C4181: qualifier applied to reference type; ignored
|
||||
@ -45,7 +45,7 @@ struct contained
|
||||
|
||||
// stored value:
|
||||
value_type v_;
|
||||
|
||||
|
||||
// constructors:
|
||||
contained() {}
|
||||
contained(param_type p) : v_(p){}
|
||||
@ -197,11 +197,11 @@ struct comparible_UDT
|
||||
comparible_UDT() : i_(2){}
|
||||
comparible_UDT(const comparible_UDT& other) : i_(other.i_){}
|
||||
comparible_UDT& operator=(const comparible_UDT& other)
|
||||
{
|
||||
{
|
||||
i_ = other.i_;
|
||||
return *this;
|
||||
}
|
||||
bool operator == (const comparible_UDT& v){ return v.i_ == i_; }
|
||||
bool operator == (const comparible_UDT& v) const { return v.i_ == i_; }
|
||||
};
|
||||
|
||||
int main()
|
||||
@ -339,7 +339,7 @@ void call_traits_test<T, isarray>::assert_construct(typename call_traits_test<T,
|
||||
param_type p2(v);
|
||||
param_type p3(r);
|
||||
param_type p4(p);
|
||||
|
||||
|
||||
unused_variable(v2);
|
||||
unused_variable(v3);
|
||||
unused_variable(v4);
|
||||
@ -376,7 +376,7 @@ void call_traits_test<T, true>::assert_construct(typename boost::call_traits<T>:
|
||||
reference r = t;
|
||||
const_reference cr = t;
|
||||
reference r2 = r;
|
||||
#ifndef __BORLANDC__
|
||||
#ifndef BOOST_BORLANDC
|
||||
// C++ Builder buglet:
|
||||
const_reference cr2 = r;
|
||||
#endif
|
||||
@ -388,12 +388,12 @@ void call_traits_test<T, true>::assert_construct(typename boost::call_traits<T>:
|
||||
param_type p2(v);
|
||||
param_type p3(r);
|
||||
param_type p4(p);
|
||||
|
||||
|
||||
unused_variable(v2);
|
||||
unused_variable(v3);
|
||||
unused_variable(v4);
|
||||
unused_variable(v5);
|
||||
#ifndef __BORLANDC__
|
||||
#ifndef BOOST_BORLANDC
|
||||
unused_variable(r2);
|
||||
unused_variable(cr2);
|
||||
#endif
|
55
test/compressed_pair_final_test.cpp
Normal file
55
test/compressed_pair_final_test.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
Copyright 2018 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/config.hpp>
|
||||
#if !defined(BOOST_NO_CXX11_FINAL)
|
||||
#include <boost/compressed_pair.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
struct type1 {
|
||||
operator bool() const {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
struct type2 final {
|
||||
operator bool() const {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
#if !defined(BOOST_IS_FINAL)
|
||||
namespace boost {
|
||||
|
||||
template<>
|
||||
struct is_final<type2>
|
||||
: true_type { };
|
||||
|
||||
} /* boost*/
|
||||
#endif
|
||||
|
||||
template<class T1, class T2>
|
||||
void test()
|
||||
{
|
||||
boost::compressed_pair<T1, T2> p;
|
||||
BOOST_TEST(!p.first());
|
||||
BOOST_TEST(!p.second());
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test<type1, type2>();
|
||||
test<type2, type1>();
|
||||
test<type2, type2>();
|
||||
return boost::report_errors();
|
||||
}
|
||||
#else
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
@ -14,7 +14,7 @@
|
||||
#include <cassert>
|
||||
|
||||
#include <boost/compressed_pair.hpp>
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
using namespace boost;
|
||||
|
||||
@ -79,47 +79,47 @@ void compressed_pair_tester<T1, T2>::test(first_param_type p1, second_param_type
|
||||
// first param construct:
|
||||
boost::compressed_pair<T1,T2> cp2(p1);
|
||||
cp2.second() = p2;
|
||||
BOOST_CHECK(cp2.first() == p1);
|
||||
BOOST_CHECK(cp2.second() == p2);
|
||||
BOOST_TEST(cp2.first() == p1);
|
||||
BOOST_TEST(cp2.second() == p2);
|
||||
// second param construct:
|
||||
boost::compressed_pair<T1,T2> cp3(p2);
|
||||
cp3.first() = p1;
|
||||
BOOST_CHECK(cp3.second() == p2);
|
||||
BOOST_CHECK(cp3.first() == p1);
|
||||
BOOST_TEST(cp3.second() == p2);
|
||||
BOOST_TEST(cp3.first() == p1);
|
||||
// both param construct:
|
||||
boost::compressed_pair<T1,T2> cp4(p1, p2);
|
||||
BOOST_CHECK(cp4.first() == p1);
|
||||
BOOST_CHECK(cp4.second() == p2);
|
||||
BOOST_TEST(cp4.first() == p1);
|
||||
BOOST_TEST(cp4.second() == p2);
|
||||
boost::compressed_pair<T1,T2> cp5(p3, p4);
|
||||
BOOST_CHECK(cp5.first() == p3);
|
||||
BOOST_CHECK(cp5.second() == p4);
|
||||
BOOST_TEST(cp5.first() == p3);
|
||||
BOOST_TEST(cp5.second() == p4);
|
||||
// check const members:
|
||||
const boost::compressed_pair<T1,T2>& cpr1 = cp4;
|
||||
BOOST_CHECK(cpr1.first() == p1);
|
||||
BOOST_CHECK(cpr1.second() == p2);
|
||||
BOOST_TEST(cpr1.first() == p1);
|
||||
BOOST_TEST(cpr1.second() == p2);
|
||||
|
||||
// copy construct:
|
||||
boost::compressed_pair<T1,T2> cp6(cp4);
|
||||
BOOST_CHECK(cp6.first() == p1);
|
||||
BOOST_CHECK(cp6.second() == p2);
|
||||
BOOST_TEST(cp6.first() == p1);
|
||||
BOOST_TEST(cp6.second() == p2);
|
||||
// assignment:
|
||||
cp1 = cp4;
|
||||
BOOST_CHECK(cp1.first() == p1);
|
||||
BOOST_CHECK(cp1.second() == p2);
|
||||
BOOST_TEST(cp1.first() == p1);
|
||||
BOOST_TEST(cp1.second() == p2);
|
||||
cp1 = cp5;
|
||||
BOOST_CHECK(cp1.first() == p3);
|
||||
BOOST_CHECK(cp1.second() == p4);
|
||||
BOOST_TEST(cp1.first() == p3);
|
||||
BOOST_TEST(cp1.second() == p4);
|
||||
// swap:
|
||||
cp4.swap(cp5);
|
||||
BOOST_CHECK(cp4.first() == p3);
|
||||
BOOST_CHECK(cp4.second() == p4);
|
||||
BOOST_CHECK(cp5.first() == p1);
|
||||
BOOST_CHECK(cp5.second() == p2);
|
||||
BOOST_TEST(cp4.first() == p3);
|
||||
BOOST_TEST(cp4.second() == p4);
|
||||
BOOST_TEST(cp5.first() == p1);
|
||||
BOOST_TEST(cp5.second() == p2);
|
||||
swap(cp4,cp5);
|
||||
BOOST_CHECK(cp4.first() == p1);
|
||||
BOOST_CHECK(cp4.second() == p2);
|
||||
BOOST_CHECK(cp5.first() == p3);
|
||||
BOOST_CHECK(cp5.second() == p4);
|
||||
BOOST_TEST(cp4.first() == p1);
|
||||
BOOST_TEST(cp4.second() == p2);
|
||||
BOOST_TEST(cp5.first() == p3);
|
||||
BOOST_TEST(cp5.second() == p4);
|
||||
}
|
||||
|
||||
//
|
||||
@ -148,20 +148,20 @@ void compressed_pair_reference_tester<T1, T2>::test(first_param_type p1, second_
|
||||
#endif
|
||||
// both param construct:
|
||||
boost::compressed_pair<T1,T2> cp4(p1, p2);
|
||||
BOOST_CHECK(cp4.first() == p1);
|
||||
BOOST_CHECK(cp4.second() == p2);
|
||||
BOOST_TEST(cp4.first() == p1);
|
||||
BOOST_TEST(cp4.second() == p2);
|
||||
boost::compressed_pair<T1,T2> cp5(p3, p4);
|
||||
BOOST_CHECK(cp5.first() == p3);
|
||||
BOOST_CHECK(cp5.second() == p4);
|
||||
BOOST_TEST(cp5.first() == p3);
|
||||
BOOST_TEST(cp5.second() == p4);
|
||||
// check const members:
|
||||
const boost::compressed_pair<T1,T2>& cpr1 = cp4;
|
||||
BOOST_CHECK(cpr1.first() == p1);
|
||||
BOOST_CHECK(cpr1.second() == p2);
|
||||
BOOST_TEST(cpr1.first() == p1);
|
||||
BOOST_TEST(cpr1.second() == p2);
|
||||
|
||||
// copy construct:
|
||||
boost::compressed_pair<T1,T2> cp6(cp4);
|
||||
BOOST_CHECK(cp6.first() == p1);
|
||||
BOOST_CHECK(cp6.second() == p2);
|
||||
BOOST_TEST(cp6.first() == p1);
|
||||
BOOST_TEST(cp6.second() == p2);
|
||||
// assignment:
|
||||
// VC6 bug:
|
||||
// When second() is an empty class, VC6 performs the
|
||||
@ -174,8 +174,8 @@ void compressed_pair_reference_tester<T1, T2>::test(first_param_type p1, second_
|
||||
// settings - some generate the problem others do not.
|
||||
cp4.first() = p3;
|
||||
cp4.second() = p4;
|
||||
BOOST_CHECK(cp4.first() == p3);
|
||||
BOOST_CHECK(cp4.second() == p4);
|
||||
BOOST_TEST(cp4.first() == p3);
|
||||
BOOST_TEST(cp4.second() == p4);
|
||||
}
|
||||
//
|
||||
// supplimentary tests for case where first arg only is a reference type:
|
||||
@ -199,8 +199,8 @@ void compressed_pair_reference1_tester<T1, T2>::test(first_param_type p1, second
|
||||
// first param construct:
|
||||
boost::compressed_pair<T1,T2> cp2(p1);
|
||||
cp2.second() = p2;
|
||||
BOOST_CHECK(cp2.first() == p1);
|
||||
BOOST_CHECK(cp2.second() == p2);
|
||||
BOOST_TEST(cp2.first() == p1);
|
||||
BOOST_TEST(cp2.second() == p2);
|
||||
#endif
|
||||
}
|
||||
//
|
||||
@ -225,8 +225,8 @@ void compressed_pair_reference2_tester<T1, T2>::test(first_param_type p1, second
|
||||
// second param construct:
|
||||
boost::compressed_pair<T1,T2> cp3(p2);
|
||||
cp3.first() = p1;
|
||||
BOOST_CHECK(cp3.second() == p2);
|
||||
BOOST_CHECK(cp3.first() == p1);
|
||||
BOOST_TEST(cp3.second() == p2);
|
||||
BOOST_TEST(cp3.first() == p1);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -253,14 +253,14 @@ void compressed_pair_array1_tester<T1, T2>::test(first_param_type p1, second_par
|
||||
// second param construct:
|
||||
boost::compressed_pair<T1,T2> cp3(p2);
|
||||
cp3.first()[0] = p1[0];
|
||||
BOOST_CHECK(cp3.second() == p2);
|
||||
BOOST_CHECK(cp3.first()[0] == p1[0]);
|
||||
BOOST_TEST(cp3.second() == p2);
|
||||
BOOST_TEST(cp3.first()[0] == p1[0]);
|
||||
// check const members:
|
||||
const boost::compressed_pair<T1,T2>& cpr1 = cp3;
|
||||
BOOST_CHECK(cpr1.first()[0] == p1[0]);
|
||||
BOOST_CHECK(cpr1.second() == p2);
|
||||
BOOST_TEST(cpr1.first()[0] == p1[0]);
|
||||
BOOST_TEST(cpr1.second() == p2);
|
||||
|
||||
BOOST_CHECK(sizeof(T1) == sizeof(cp1.first()));
|
||||
BOOST_TEST(sizeof(T1) == sizeof(cp1.first()));
|
||||
}
|
||||
|
||||
template <class T1, class T2>
|
||||
@ -283,14 +283,14 @@ void compressed_pair_array2_tester<T1, T2>::test(first_param_type p1, second_par
|
||||
// first param construct:
|
||||
boost::compressed_pair<T1,T2> cp2(p1);
|
||||
cp2.second()[0] = p2[0];
|
||||
BOOST_CHECK(cp2.first() == p1);
|
||||
BOOST_CHECK(cp2.second()[0] == p2[0]);
|
||||
BOOST_TEST(cp2.first() == p1);
|
||||
BOOST_TEST(cp2.second()[0] == p2[0]);
|
||||
// check const members:
|
||||
const boost::compressed_pair<T1,T2>& cpr1 = cp2;
|
||||
BOOST_CHECK(cpr1.first() == p1);
|
||||
BOOST_CHECK(cpr1.second()[0] == p2[0]);
|
||||
BOOST_TEST(cpr1.first() == p1);
|
||||
BOOST_TEST(cpr1.second()[0] == p2[0]);
|
||||
|
||||
BOOST_CHECK(sizeof(T2) == sizeof(cp1.second()));
|
||||
BOOST_TEST(sizeof(T2) == sizeof(cp1.second()));
|
||||
}
|
||||
|
||||
template <class T1, class T2>
|
||||
@ -312,18 +312,18 @@ void compressed_pair_array_tester<T1, T2>::test(first_param_type p1, second_para
|
||||
boost::compressed_pair<T1,T2> cp1;
|
||||
cp1.first()[0] = p1[0];
|
||||
cp1.second()[0] = p2[0];
|
||||
BOOST_CHECK(cp1.first()[0] == p1[0]);
|
||||
BOOST_CHECK(cp1.second()[0] == p2[0]);
|
||||
BOOST_TEST(cp1.first()[0] == p1[0]);
|
||||
BOOST_TEST(cp1.second()[0] == p2[0]);
|
||||
// check const members:
|
||||
const boost::compressed_pair<T1,T2>& cpr1 = cp1;
|
||||
BOOST_CHECK(cpr1.first()[0] == p1[0]);
|
||||
BOOST_CHECK(cpr1.second()[0] == p2[0]);
|
||||
BOOST_TEST(cpr1.first()[0] == p1[0]);
|
||||
BOOST_TEST(cpr1.second()[0] == p2[0]);
|
||||
|
||||
BOOST_CHECK(sizeof(T1) == sizeof(cp1.first()));
|
||||
BOOST_CHECK(sizeof(T2) == sizeof(cp1.second()));
|
||||
BOOST_TEST(sizeof(T1) == sizeof(cp1.first()));
|
||||
BOOST_TEST(sizeof(T2) == sizeof(cp1.second()));
|
||||
}
|
||||
|
||||
int test_main(int, char *[])
|
||||
int main()
|
||||
{
|
||||
// declare some variables to pass to the tester:
|
||||
non_empty1 ne1(2);
|
||||
@ -383,13 +383,5 @@ int test_main(int, char *[])
|
||||
compressed_pair_array2_tester<empty_POD_UDT,non_empty2[2]>::test(e1, nea3, e1, nea4);
|
||||
// T1 == T2, both non-empty
|
||||
compressed_pair_array_tester<non_empty1[2],non_empty1[2]>::test(nea1, nea1, nea2, nea2);
|
||||
return 0;
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
|
||||
unsigned int expected_failures = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
// 2 May 2010 (Created) Niels Dekker
|
||||
|
||||
#include <boost/utility/value_init.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
#include <string>
|
||||
|
@ -12,11 +12,9 @@
|
||||
// library (Daryle Walker)
|
||||
// 12 Dec 99 Initial version with iterator operators (Jeremy Siek)
|
||||
|
||||
#define BOOST_INCLUDE_MAIN
|
||||
#include <boost/test/test_tools.hpp> // for main
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
#include <boost/config.hpp> // for BOOST_STATIC_CONSTANT
|
||||
#include <boost/cstdlib.hpp> // for boost::exit_success
|
||||
#include <boost/operators.hpp> // for boost::random_access_iterator_helper
|
||||
|
||||
#include <cstddef> // for std::ptrdiff_t, std::size_t
|
||||
@ -126,7 +124,7 @@ typename test_opr<T, R, P>::iter_type const
|
||||
|
||||
// Main testing function
|
||||
int
|
||||
test_main( int , char * [] )
|
||||
main()
|
||||
{
|
||||
using std::string;
|
||||
|
||||
@ -136,7 +134,7 @@ test_main( int , char * [] )
|
||||
test1_type::master_test( "non-const string" );
|
||||
test2_type::master_test( "const string" );
|
||||
|
||||
return boost::exit_success;
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
// Tests for all of the operators added by random_access_iterator_helper
|
||||
@ -174,7 +172,7 @@ test_opr<T, R, P>::post_increment_test
|
||||
oss << *i++ << ' ';
|
||||
}
|
||||
|
||||
BOOST_CHECK( oss.str() == "apple orange pear peach grape plum ");
|
||||
BOOST_TEST( oss.str() == "apple orange pear peach grape plum ");
|
||||
}
|
||||
|
||||
// Test post-decrement
|
||||
@ -193,7 +191,7 @@ test_opr<T, R, P>::post_decrement_test
|
||||
oss << *i << ' ';
|
||||
}
|
||||
|
||||
BOOST_CHECK( oss.str() == "plum grape peach pear orange apple ");
|
||||
BOOST_TEST( oss.str() == "plum grape peach pear orange apple ");
|
||||
}
|
||||
|
||||
// Test indirect structure referral
|
||||
@ -211,7 +209,7 @@ test_opr<T, R, P>::indirect_referral_test
|
||||
oss << i->size() << ' ';
|
||||
}
|
||||
|
||||
BOOST_CHECK( oss.str() == "5 6 4 5 5 4 ");
|
||||
BOOST_TEST( oss.str() == "5 6 4 5 5 4 ");
|
||||
}
|
||||
|
||||
// Test offset addition
|
||||
@ -230,7 +228,7 @@ test_opr<T, R, P>::offset_addition_test
|
||||
oss << *i << ' ';
|
||||
}
|
||||
|
||||
BOOST_CHECK( oss.str() == "apple pear grape ");
|
||||
BOOST_TEST( oss.str() == "apple pear grape ");
|
||||
}
|
||||
|
||||
// Test offset addition, in reverse order
|
||||
@ -249,7 +247,7 @@ test_opr<T, R, P>::reverse_offset_addition_test
|
||||
oss << *i << ' ';
|
||||
}
|
||||
|
||||
BOOST_CHECK( oss.str() == "apple pear grape ");
|
||||
BOOST_TEST( oss.str() == "apple pear grape ");
|
||||
}
|
||||
|
||||
// Test offset subtraction
|
||||
@ -272,7 +270,7 @@ test_opr<T, R, P>::offset_subtraction_test
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_CHECK( oss.str() == "grape pear apple ");
|
||||
BOOST_TEST( oss.str() == "grape pear apple ");
|
||||
}
|
||||
|
||||
// Test comparisons
|
||||
@ -296,10 +294,10 @@ test_opr<T, R, P>::comparison_test
|
||||
{
|
||||
ptrdiff_t const j_offset = j - fruit_begin;
|
||||
|
||||
BOOST_CHECK( (i != j) == (i_offset != j_offset) );
|
||||
BOOST_CHECK( (i > j) == (i_offset > j_offset) );
|
||||
BOOST_CHECK( (i <= j) == (i_offset <= j_offset) );
|
||||
BOOST_CHECK( (i >= j) == (i_offset >= j_offset) );
|
||||
BOOST_TEST( (i != j) == (i_offset != j_offset) );
|
||||
BOOST_TEST( (i > j) == (i_offset > j_offset) );
|
||||
BOOST_TEST( (i <= j) == (i_offset <= j_offset) );
|
||||
BOOST_TEST( (i >= j) == (i_offset >= j_offset) );
|
||||
}
|
||||
}
|
||||
cout << std::endl;
|
||||
@ -320,5 +318,5 @@ test_opr<T, R, P>::indexing_test
|
||||
oss << fruit_begin[ k ] << ' ';
|
||||
}
|
||||
|
||||
BOOST_CHECK( oss.str() == "apple orange pear peach grape plum ");
|
||||
BOOST_TEST( oss.str() == "apple orange pear peach grape plum ");
|
||||
}
|
@ -1,97 +0,0 @@
|
||||
// Boost test program for next() and prior() utilities.
|
||||
|
||||
// Copyright 2003 Daniel Walker. Use, modification, and distribution
|
||||
// are subject to the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or a copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt.)
|
||||
|
||||
// See http://www.boost.org/libs/utility for documentation.
|
||||
|
||||
// Revision History 13 Dec 2003 Initial Version (Daniel Walker)
|
||||
|
||||
// next() and prior() are replacements for operator+ and operator- for
|
||||
// non-random-access iterators. The semantics of these operators are
|
||||
// such that after executing j = i + n, std::distance(i, j) equals
|
||||
// n. Tests are provided to ensure next() has the same
|
||||
// result. Parallel tests are provided for prior(). The tests call
|
||||
// next() and prior() several times. next() and prior() are very
|
||||
// simple functions, though, and it would be very strange if these
|
||||
// tests were to fail.
|
||||
|
||||
#define BOOST_INCLUDE_MAIN
|
||||
#include <boost/test/test_tools.hpp>
|
||||
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/next_prior.hpp>
|
||||
|
||||
template<class RandomAccessIterator, class ForwardIterator>
|
||||
bool plus_one_test(RandomAccessIterator first, RandomAccessIterator last, ForwardIterator first2)
|
||||
{
|
||||
RandomAccessIterator i = first;
|
||||
ForwardIterator j = first2;
|
||||
while(i != last)
|
||||
i = i + 1, j = boost::next(j);
|
||||
return std::distance(first, i) == std::distance(first2, j);
|
||||
}
|
||||
|
||||
template<class RandomAccessIterator, class ForwardIterator>
|
||||
bool plus_n_test(RandomAccessIterator first, RandomAccessIterator last, ForwardIterator first2)
|
||||
{
|
||||
RandomAccessIterator i = first;
|
||||
ForwardIterator j = first2;
|
||||
for(int n = 0; i != last; ++n)
|
||||
i = first + n, j = boost::next(first2, n);
|
||||
return std::distance(first, i) == std::distance(first2, j);
|
||||
}
|
||||
|
||||
template<class RandomAccessIterator, class BidirectionalIterator>
|
||||
bool minus_one_test(RandomAccessIterator first, RandomAccessIterator last, BidirectionalIterator last2)
|
||||
{
|
||||
RandomAccessIterator i = last;
|
||||
BidirectionalIterator j = last2;
|
||||
while(i != first)
|
||||
i = i - 1, j = boost::prior(j);
|
||||
return std::distance(i, last) == std::distance(j, last2);
|
||||
}
|
||||
|
||||
template<class RandomAccessIterator, class BidirectionalIterator>
|
||||
bool minus_n_test(RandomAccessIterator first, RandomAccessIterator last, BidirectionalIterator last2)
|
||||
{
|
||||
RandomAccessIterator i = last;
|
||||
BidirectionalIterator j = last2;
|
||||
for(int n = 0; i != first; ++n)
|
||||
i = last - n, j = boost::prior(last2, n);
|
||||
return std::distance(i, last) == std::distance(j, last2);
|
||||
}
|
||||
|
||||
template<class Iterator, class Distance>
|
||||
bool minus_n_unsigned_test(Iterator first, Iterator last, Distance size)
|
||||
{
|
||||
Iterator i = boost::prior(last, size);
|
||||
return i == first;
|
||||
}
|
||||
|
||||
int test_main(int, char*[])
|
||||
{
|
||||
std::vector<int> x(8);
|
||||
std::list<int> y(x.begin(), x.end());
|
||||
|
||||
// Tests with iterators
|
||||
BOOST_REQUIRE(plus_one_test(x.begin(), x.end(), y.begin()));
|
||||
BOOST_REQUIRE(plus_n_test(x.begin(), x.end(), y.begin()));
|
||||
BOOST_REQUIRE(minus_one_test(x.begin(), x.end(), y.end()));
|
||||
BOOST_REQUIRE(minus_n_test(x.begin(), x.end(), y.end()));
|
||||
BOOST_REQUIRE(minus_n_unsigned_test(x.begin(), x.end(), x.size()));
|
||||
BOOST_REQUIRE(minus_n_unsigned_test(y.begin(), y.end(), y.size()));
|
||||
|
||||
// Tests with integers
|
||||
BOOST_REQUIRE(boost::next(5) == 6);
|
||||
BOOST_REQUIRE(boost::next(5, 7) == 12);
|
||||
BOOST_REQUIRE(boost::prior(5) == 4);
|
||||
BOOST_REQUIRE(boost::prior(5, 7) == -2);
|
||||
BOOST_REQUIRE(boost::prior(5, 7u) == -2);
|
||||
|
||||
return 0;
|
||||
}
|
59
test/operators_constexpr_test.cpp
Normal file
59
test/operators_constexpr_test.cpp
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
Copyright 2020 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#if !defined(BOOST_NO_CXX11_CONSTEXPR) && \
|
||||
(!defined(BOOST_MSVC) || (BOOST_MSVC >= 1922))
|
||||
#include <boost/operators.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
|
||||
namespace {
|
||||
|
||||
class Value
|
||||
: boost::operators<Value> {
|
||||
public:
|
||||
BOOST_OPERATORS_CONSTEXPR explicit Value(int v)
|
||||
: v_(v) { }
|
||||
|
||||
BOOST_OPERATORS_CONSTEXPR bool
|
||||
operator<(const Value& x) const {
|
||||
return v_ < x.v_;
|
||||
}
|
||||
|
||||
BOOST_OPERATORS_CONSTEXPR bool
|
||||
operator==(const Value& x) const {
|
||||
return v_ == x.v_;
|
||||
}
|
||||
|
||||
private:
|
||||
int v_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
BOOST_STATIC_ASSERT(!static_cast<bool>(Value(1) == Value(2)));
|
||||
BOOST_STATIC_ASSERT(Value(1) != Value(2));
|
||||
BOOST_STATIC_ASSERT(Value(1) < Value(2));
|
||||
BOOST_STATIC_ASSERT(Value(1) <= Value(2));
|
||||
BOOST_STATIC_ASSERT(!static_cast<bool>(Value(1) > Value(2)));
|
||||
BOOST_STATIC_ASSERT(!static_cast<bool>(Value(1) >= Value(2)));
|
||||
|
||||
BOOST_STATIC_ASSERT(!static_cast<bool>(Value(2) == Value(1)));
|
||||
BOOST_STATIC_ASSERT(Value(2) != Value(1));
|
||||
BOOST_STATIC_ASSERT(!static_cast<bool>(Value(2) < Value(1)));
|
||||
BOOST_STATIC_ASSERT(!static_cast<bool>(Value(2) <= Value(1)));
|
||||
BOOST_STATIC_ASSERT(Value(2) > Value(1));
|
||||
BOOST_STATIC_ASSERT(Value(2) >= Value(1));
|
||||
|
||||
BOOST_STATIC_ASSERT(Value(1) == Value(1));
|
||||
BOOST_STATIC_ASSERT(!static_cast<bool>(Value(1) != Value(1)));
|
||||
BOOST_STATIC_ASSERT(!static_cast<bool>(Value(1) < Value(1)));
|
||||
BOOST_STATIC_ASSERT(Value(1) <= Value(1));
|
||||
BOOST_STATIC_ASSERT(!static_cast<bool>(Value(1) > Value(1)));
|
||||
BOOST_STATIC_ASSERT(Value(1) >= Value(1));
|
||||
#endif
|
@ -21,17 +21,13 @@
|
||||
// 12 Dec 99 Minor update, output confirmation message.
|
||||
// 15 Nov 99 Initial version
|
||||
|
||||
#define BOOST_INCLUDE_MAIN
|
||||
|
||||
#include <boost/config.hpp> // for BOOST_MSVC
|
||||
#include <boost/cstdlib.hpp> // for boost::exit_success
|
||||
#include <boost/operators.hpp> // for the tested items
|
||||
#include <boost/random/linear_congruential.hpp> // for boost::minstd_rand
|
||||
#include <boost/test/test_tools.hpp> // for main
|
||||
#include <boost/utility/detail/minstd_rand.hpp> // for boost::detail::minstd_rand
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
#include <iostream> // for std::cout (std::endl indirectly)
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
// avoiding a template version of true_value so as to not confuse VC++
|
||||
@ -53,9 +49,9 @@ namespace
|
||||
void operator!() const;
|
||||
|
||||
public:
|
||||
convertible_to_bool( const bool value ) : _value( value ) {}
|
||||
convertible_to_bool( const bool value ) : _value( value ) {}
|
||||
|
||||
operator unspecified_bool_type() const
|
||||
operator unspecified_bool_type() const
|
||||
{ return _value ? &convertible_to_bool::_value : 0; }
|
||||
};
|
||||
|
||||
@ -67,14 +63,14 @@ namespace
|
||||
, boost::shiftable<Wrapped1<T> >
|
||||
{
|
||||
public:
|
||||
explicit Wrapped1( T v = T() ) : _value(v) {}
|
||||
T value() const { return _value; }
|
||||
explicit Wrapped1( T v = T() ) : _value(v) {}
|
||||
T value() const { return _value; }
|
||||
|
||||
convertible_to_bool operator<(const Wrapped1& x) const
|
||||
convertible_to_bool operator<(const Wrapped1& x) const
|
||||
{ return _value < x._value; }
|
||||
convertible_to_bool operator==(const Wrapped1& x) const
|
||||
convertible_to_bool operator==(const Wrapped1& x) const
|
||||
{ return _value == x._value; }
|
||||
|
||||
|
||||
Wrapped1& operator+=(const Wrapped1& x)
|
||||
{ _value += x._value; return *this; }
|
||||
Wrapped1& operator-=(const Wrapped1& x)
|
||||
@ -95,14 +91,14 @@ namespace
|
||||
{ _value <<= x._value; return *this; }
|
||||
Wrapped1& operator>>=(const Wrapped1& x)
|
||||
{ _value >>= x._value; return *this; }
|
||||
Wrapped1& operator++() { ++_value; return *this; }
|
||||
Wrapped1& operator--() { --_value; return *this; }
|
||||
|
||||
Wrapped1& operator++() { ++_value; return *this; }
|
||||
Wrapped1& operator--() { --_value; return *this; }
|
||||
|
||||
private:
|
||||
T _value;
|
||||
};
|
||||
template <class T>
|
||||
T true_value(Wrapped1<T> x) { return x.value(); }
|
||||
T true_value(Wrapped1<T> x) { return x.value(); }
|
||||
|
||||
template <class T, class U>
|
||||
class Wrapped2
|
||||
@ -119,7 +115,7 @@ namespace
|
||||
{ return _value < x._value; }
|
||||
convertible_to_bool operator==(const Wrapped2& x) const
|
||||
{ return _value == x._value; }
|
||||
|
||||
|
||||
Wrapped2& operator+=(const Wrapped2& x)
|
||||
{ _value += x._value; return *this; }
|
||||
Wrapped2& operator-=(const Wrapped2& x)
|
||||
@ -142,7 +138,7 @@ namespace
|
||||
{ _value >>= x._value; return *this; }
|
||||
Wrapped2& operator++() { ++_value; return *this; }
|
||||
Wrapped2& operator--() { --_value; return *this; }
|
||||
|
||||
|
||||
convertible_to_bool operator<(U u) const
|
||||
{ return _value < u; }
|
||||
convertible_to_bool operator>(U u) const
|
||||
@ -166,7 +162,7 @@ namespace
|
||||
};
|
||||
template <class T, class U>
|
||||
T true_value(Wrapped2<T,U> x) { return x.value(); }
|
||||
|
||||
|
||||
template <class T>
|
||||
class Wrapped3
|
||||
: boost::equivalent<Wrapped3<T> >
|
||||
@ -179,12 +175,12 @@ namespace
|
||||
|
||||
convertible_to_bool operator<(const Wrapped3& x) const
|
||||
{ return _value < x._value; }
|
||||
|
||||
|
||||
private:
|
||||
T _value;
|
||||
};
|
||||
template <class T>
|
||||
T true_value(Wrapped3<T> x) { return x.value(); }
|
||||
T true_value(Wrapped3<T> x) { return x.value(); }
|
||||
|
||||
template <class T, class U>
|
||||
class Wrapped4
|
||||
@ -201,7 +197,7 @@ namespace
|
||||
|
||||
convertible_to_bool operator<(const Wrapped4& x) const
|
||||
{ return _value < x._value; }
|
||||
|
||||
|
||||
convertible_to_bool operator<(U u) const
|
||||
{ return _value < u; }
|
||||
convertible_to_bool operator>(U u) const
|
||||
@ -212,7 +208,7 @@ namespace
|
||||
};
|
||||
template <class T, class U>
|
||||
T true_value(Wrapped4<T,U> x) { return x.value(); }
|
||||
|
||||
|
||||
// U must be convertible to T
|
||||
template <class T, class U>
|
||||
class Wrapped5
|
||||
@ -252,7 +248,7 @@ namespace
|
||||
};
|
||||
template <class T, class U>
|
||||
T true_value(Wrapped5<T,U> x) { return x.value(); }
|
||||
|
||||
|
||||
// U must be convertible to T
|
||||
template <class T, class U>
|
||||
class Wrapped6
|
||||
@ -294,7 +290,7 @@ namespace
|
||||
};
|
||||
template <class T, class U>
|
||||
T true_value(Wrapped6<T,U> x) { return x.value(); }
|
||||
|
||||
|
||||
// MyInt uses only the single template-argument form of all_operators<>
|
||||
typedef Wrapped1<int> MyInt;
|
||||
|
||||
@ -311,19 +307,19 @@ namespace
|
||||
template <class X1, class Y1, class X2, class Y2>
|
||||
void sanity_check(X1 x1, Y1 y1, X2 x2, Y2 y2)
|
||||
{
|
||||
BOOST_CHECK( true_value(y1) == true_value(y2) );
|
||||
BOOST_CHECK( true_value(x1) == true_value(x2) );
|
||||
BOOST_TEST( true_value(y1) == true_value(y2) );
|
||||
BOOST_TEST( true_value(x1) == true_value(x2) );
|
||||
}
|
||||
|
||||
template <class X1, class Y1, class X2, class Y2>
|
||||
void test_less_than_comparable_aux(X1 x1, Y1 y1, X2 x2, Y2 y2)
|
||||
{
|
||||
BOOST_CHECK( static_cast<bool>(x1 < y1) == static_cast<bool>(x2 < y2) );
|
||||
BOOST_CHECK( static_cast<bool>(x1 <= y1) == static_cast<bool>(x2 <= y2) );
|
||||
BOOST_CHECK( static_cast<bool>(x1 >= y1) == static_cast<bool>(x2 >= y2) );
|
||||
BOOST_CHECK( static_cast<bool>(x1 > y1) == static_cast<bool>(x2 > y2) );
|
||||
BOOST_TEST( static_cast<bool>(x1 < y1) == static_cast<bool>(x2 < y2) );
|
||||
BOOST_TEST( static_cast<bool>(x1 <= y1) == static_cast<bool>(x2 <= y2) );
|
||||
BOOST_TEST( static_cast<bool>(x1 >= y1) == static_cast<bool>(x2 >= y2) );
|
||||
BOOST_TEST( static_cast<bool>(x1 > y1) == static_cast<bool>(x2 > y2) );
|
||||
}
|
||||
|
||||
|
||||
template <class X1, class Y1, class X2, class Y2>
|
||||
void test_less_than_comparable(X1 x1, Y1 y1, X2 x2, Y2 y2)
|
||||
{
|
||||
@ -335,10 +331,10 @@ namespace
|
||||
template <class X1, class Y1, class X2, class Y2>
|
||||
void test_equality_comparable_aux(X1 x1, Y1 y1, X2 x2, Y2 y2)
|
||||
{
|
||||
BOOST_CHECK( static_cast<bool>(x1 == y1) == static_cast<bool>(x2 == y2) );
|
||||
BOOST_CHECK( static_cast<bool>(x1 != y1) == static_cast<bool>(x2 != y2) );
|
||||
BOOST_TEST( static_cast<bool>(x1 == y1) == static_cast<bool>(x2 == y2) );
|
||||
BOOST_TEST( static_cast<bool>(x1 != y1) == static_cast<bool>(x2 != y2) );
|
||||
}
|
||||
|
||||
|
||||
template <class X1, class Y1, class X2, class Y2>
|
||||
void test_equality_comparable(X1 x1, Y1 y1, X2 x2, Y2 y2)
|
||||
{
|
||||
@ -350,9 +346,9 @@ namespace
|
||||
template <class X1, class Y1, class X2, class Y2>
|
||||
void test_multipliable_aux(X1 x1, Y1 y1, X2 x2, Y2 y2)
|
||||
{
|
||||
BOOST_CHECK( (x1 * y1).value() == (x2 * y2) );
|
||||
BOOST_TEST( (x1 * y1).value() == (x2 * y2) );
|
||||
}
|
||||
|
||||
|
||||
template <class X1, class Y1, class X2, class Y2>
|
||||
void test_multipliable(X1 x1, Y1 y1, X2 x2, Y2 y2)
|
||||
{
|
||||
@ -361,21 +357,21 @@ namespace
|
||||
test_multipliable_aux( y1, x1, y2, x2 );
|
||||
}
|
||||
|
||||
template <class A, class B>
|
||||
void test_value_equality(A a, B b)
|
||||
{
|
||||
BOOST_CHECK(a.value() == b);
|
||||
}
|
||||
|
||||
template <class A, class B>
|
||||
void test_value_equality(A a, B b)
|
||||
{
|
||||
BOOST_TEST(a.value() == b);
|
||||
}
|
||||
|
||||
#define TEST_OP_R(op) test_value_equality(x1 op y1, x2 op y2)
|
||||
#define TEST_OP_L(op) test_value_equality(y1 op x1, y2 op x2)
|
||||
|
||||
|
||||
template <class X1, class Y1, class X2, class Y2>
|
||||
void test_addable_aux(X1 x1, Y1 y1, X2 x2, Y2 y2)
|
||||
{
|
||||
TEST_OP_R(+);
|
||||
}
|
||||
|
||||
|
||||
template <class X1, class Y1, class X2, class Y2>
|
||||
void test_addable(X1 x1, Y1 y1, X2 x2, Y2 y2)
|
||||
{
|
||||
@ -405,7 +401,7 @@ namespace
|
||||
if ( y2 != 0 )
|
||||
TEST_OP_R(/);
|
||||
}
|
||||
|
||||
|
||||
template <class X1, class Y1, class X2, class Y2>
|
||||
void test_dividable_left(X1 x1, Y1 y1, X2 x2, Y2 y2)
|
||||
{
|
||||
@ -421,7 +417,7 @@ namespace
|
||||
if ( y2 != 0 )
|
||||
TEST_OP_R(%);
|
||||
}
|
||||
|
||||
|
||||
template <class X1, class Y1, class X2, class Y2>
|
||||
void test_modable_left(X1 x1, Y1 y1, X2 x2, Y2 y2)
|
||||
{
|
||||
@ -435,7 +431,7 @@ namespace
|
||||
{
|
||||
TEST_OP_R(^);
|
||||
}
|
||||
|
||||
|
||||
template <class X1, class Y1, class X2, class Y2>
|
||||
void test_xorable(X1 x1, Y1 y1, X2 x2, Y2 y2)
|
||||
{
|
||||
@ -443,13 +439,13 @@ namespace
|
||||
test_xorable_aux( x1, y1, x2, y2 );
|
||||
test_xorable_aux( y1, x1, y2, x2 );
|
||||
}
|
||||
|
||||
|
||||
template <class X1, class Y1, class X2, class Y2>
|
||||
void test_andable_aux(X1 x1, Y1 y1, X2 x2, Y2 y2)
|
||||
{
|
||||
TEST_OP_R(&);
|
||||
}
|
||||
|
||||
|
||||
template <class X1, class Y1, class X2, class Y2>
|
||||
void test_andable(X1 x1, Y1 y1, X2 x2, Y2 y2)
|
||||
{
|
||||
@ -457,13 +453,13 @@ namespace
|
||||
test_andable_aux( x1, y1, x2, y2 );
|
||||
test_andable_aux( y1, x1, y2, x2 );
|
||||
}
|
||||
|
||||
|
||||
template <class X1, class Y1, class X2, class Y2>
|
||||
void test_orable_aux(X1 x1, Y1 y1, X2 x2, Y2 y2)
|
||||
{
|
||||
TEST_OP_R(|);
|
||||
}
|
||||
|
||||
|
||||
template <class X1, class Y1, class X2, class Y2>
|
||||
void test_orable(X1 x1, Y1 y1, X2 x2, Y2 y2)
|
||||
{
|
||||
@ -471,37 +467,37 @@ namespace
|
||||
test_orable_aux( x1, y1, x2, y2 );
|
||||
test_orable_aux( y1, x1, y2, x2 );
|
||||
}
|
||||
|
||||
|
||||
template <class X1, class Y1, class X2, class Y2>
|
||||
void test_left_shiftable(X1 x1, Y1 y1, X2 x2, Y2 y2)
|
||||
{
|
||||
sanity_check( x1, y1, x2, y2 );
|
||||
TEST_OP_R(<<);
|
||||
}
|
||||
|
||||
|
||||
template <class X1, class Y1, class X2, class Y2>
|
||||
void test_right_shiftable(X1 x1, Y1 y1, X2 x2, Y2 y2)
|
||||
{
|
||||
sanity_check( x1, y1, x2, y2 );
|
||||
TEST_OP_R(>>);
|
||||
}
|
||||
|
||||
|
||||
template <class X1, class X2>
|
||||
void test_incrementable(X1 x1, X2 x2)
|
||||
{
|
||||
sanity_check( x1, x1, x2, x2 );
|
||||
BOOST_CHECK( (x1++).value() == x2++ );
|
||||
BOOST_CHECK( x1.value() == x2 );
|
||||
BOOST_TEST( (x1++).value() == x2++ );
|
||||
BOOST_TEST( x1.value() == x2 );
|
||||
}
|
||||
|
||||
|
||||
template <class X1, class X2>
|
||||
void test_decrementable(X1 x1, X2 x2)
|
||||
{
|
||||
sanity_check( x1, x1, x2, x2 );
|
||||
BOOST_CHECK( (x1--).value() == x2-- );
|
||||
BOOST_CHECK( x1.value() == x2 );
|
||||
BOOST_TEST( (x1--).value() == x2-- );
|
||||
BOOST_TEST( x1.value() == x2 );
|
||||
}
|
||||
|
||||
|
||||
template <class X1, class Y1, class X2, class Y2>
|
||||
void test_all(X1 x1, Y1 y1, X2 x2, Y2 y2)
|
||||
{
|
||||
@ -520,7 +516,7 @@ namespace
|
||||
test_incrementable( x1, x2 );
|
||||
test_decrementable( x1, x2 );
|
||||
}
|
||||
|
||||
|
||||
template <class X1, class Y1, class X2, class Y2>
|
||||
void test_left(X1 x1, Y1 y1, X2 x2, Y2 y2)
|
||||
{
|
||||
@ -532,12 +528,12 @@ namespace
|
||||
template <class Big, class Small>
|
||||
struct tester
|
||||
{
|
||||
void operator()(boost::minstd_rand& randomizer) const
|
||||
void operator()(boost::detail::minstd_rand& randomizer) const
|
||||
{
|
||||
Big b1 = Big( randomizer() );
|
||||
Big b2 = Big( randomizer() );
|
||||
Small s = Small( randomizer() );
|
||||
|
||||
|
||||
test_all( Wrapped1<Big>(b1), Wrapped1<Big>(b2), b1, b2 );
|
||||
test_all( Wrapped2<Big, Small>(b1), s, b1, s );
|
||||
}
|
||||
@ -546,11 +542,11 @@ namespace
|
||||
template <class Big, class Small>
|
||||
struct tester_left
|
||||
{
|
||||
void operator()(boost::minstd_rand& randomizer) const
|
||||
void operator()(boost::detail::minstd_rand& randomizer) const
|
||||
{
|
||||
Big b1 = Big( randomizer() );
|
||||
Small s = Small( randomizer() );
|
||||
|
||||
|
||||
test_left( Wrapped6<Big, Small>(b1), s, b1, s );
|
||||
}
|
||||
};
|
||||
@ -603,10 +599,10 @@ template Wrapped6<unsigned long, unsigned char>;
|
||||
template Wrapped6<unsigned int, unsigned char>;
|
||||
#endif
|
||||
|
||||
#define PRIVATE_EXPR_TEST(e, t) BOOST_CHECK( ((e), (t)) )
|
||||
#define PRIVATE_EXPR_TEST(e, t) BOOST_TEST( ((e), (t)) )
|
||||
|
||||
int
|
||||
test_main( int , char * [] )
|
||||
main()
|
||||
{
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
@ -615,18 +611,20 @@ test_main( int , char * [] )
|
||||
Point x;
|
||||
x = x + Point(3, 4);
|
||||
x = x - Point(3, 4);
|
||||
|
||||
|
||||
cout << "Created point, and operated on it." << endl;
|
||||
|
||||
|
||||
#if !defined(UBSAN)
|
||||
// Using random values produce UB in various tests, such as shifting by more than the left operand capacity or signed integer overflows
|
||||
for (int n = 0; n < 1000; ++n) // was 10,000 but took too long (Beman)
|
||||
{
|
||||
boost::minstd_rand r;
|
||||
boost::detail::minstd_rand r;
|
||||
tester<long, int>()(r);
|
||||
tester<long, signed char>()(r);
|
||||
tester<long, long>()(r);
|
||||
tester<int, int>()(r);
|
||||
tester<int, signed char>()(r);
|
||||
|
||||
|
||||
tester<unsigned long, unsigned int>()(r);
|
||||
tester<unsigned long, unsigned char>()(r);
|
||||
tester<unsigned long, unsigned long>()(r);
|
||||
@ -641,29 +639,30 @@ test_main( int , char * [] )
|
||||
tester_left<unsigned long, unsigned char>()(r);
|
||||
tester_left<unsigned int, unsigned char>()(r);
|
||||
}
|
||||
|
||||
|
||||
cout << "Did random tester loop." << endl;
|
||||
#endif // !defined(UBSAN)
|
||||
|
||||
MyInt i1(1);
|
||||
MyInt i2(2);
|
||||
MyInt i;
|
||||
|
||||
BOOST_CHECK( i1.value() == 1 );
|
||||
BOOST_CHECK( i2.value() == 2 );
|
||||
BOOST_CHECK( i.value() == 0 );
|
||||
BOOST_TEST( i1.value() == 1 );
|
||||
BOOST_TEST( i2.value() == 2 );
|
||||
BOOST_TEST( i.value() == 0 );
|
||||
|
||||
cout << "Created MyInt objects.\n";
|
||||
|
||||
PRIVATE_EXPR_TEST( (i = i2), (i.value() == 2) );
|
||||
|
||||
BOOST_CHECK( static_cast<bool>(i2 == i) );
|
||||
BOOST_CHECK( static_cast<bool>(i1 != i2) );
|
||||
BOOST_CHECK( static_cast<bool>(i1 < i2) );
|
||||
BOOST_CHECK( static_cast<bool>(i1 <= i2) );
|
||||
BOOST_CHECK( static_cast<bool>(i <= i2) );
|
||||
BOOST_CHECK( static_cast<bool>(i2 > i1) );
|
||||
BOOST_CHECK( static_cast<bool>(i2 >= i1) );
|
||||
BOOST_CHECK( static_cast<bool>(i2 >= i) );
|
||||
BOOST_TEST( static_cast<bool>(i2 == i) );
|
||||
BOOST_TEST( static_cast<bool>(i1 != i2) );
|
||||
BOOST_TEST( static_cast<bool>(i1 < i2) );
|
||||
BOOST_TEST( static_cast<bool>(i1 <= i2) );
|
||||
BOOST_TEST( static_cast<bool>(i <= i2) );
|
||||
BOOST_TEST( static_cast<bool>(i2 > i1) );
|
||||
BOOST_TEST( static_cast<bool>(i2 >= i1) );
|
||||
BOOST_TEST( static_cast<bool>(i2 >= i) );
|
||||
|
||||
PRIVATE_EXPR_TEST( (i = i1 + i2), (i.value() == 3) );
|
||||
PRIVATE_EXPR_TEST( (i = i + i2), (i.value() == 5) );
|
||||
@ -687,197 +686,197 @@ test_main( int , char * [] )
|
||||
MyLong j2(2);
|
||||
MyLong j;
|
||||
|
||||
BOOST_CHECK( j1.value() == 1 );
|
||||
BOOST_CHECK( j2.value() == 2 );
|
||||
BOOST_CHECK( j.value() == 0 );
|
||||
BOOST_TEST( j1.value() == 1 );
|
||||
BOOST_TEST( j2.value() == 2 );
|
||||
BOOST_TEST( j.value() == 0 );
|
||||
|
||||
cout << "Created MyLong objects.\n";
|
||||
|
||||
PRIVATE_EXPR_TEST( (j = j2), (j.value() == 2) );
|
||||
|
||||
BOOST_CHECK( static_cast<bool>(j2 == j) );
|
||||
BOOST_CHECK( static_cast<bool>(2 == j) );
|
||||
BOOST_CHECK( static_cast<bool>(j2 == 2) );
|
||||
BOOST_CHECK( static_cast<bool>(j == j2) );
|
||||
BOOST_CHECK( static_cast<bool>(j1 != j2) );
|
||||
BOOST_CHECK( static_cast<bool>(j1 != 2) );
|
||||
BOOST_CHECK( static_cast<bool>(1 != j2) );
|
||||
BOOST_CHECK( static_cast<bool>(j1 < j2) );
|
||||
BOOST_CHECK( static_cast<bool>(1 < j2) );
|
||||
BOOST_CHECK( static_cast<bool>(j1 < 2) );
|
||||
BOOST_CHECK( static_cast<bool>(j1 <= j2) );
|
||||
BOOST_CHECK( static_cast<bool>(1 <= j2) );
|
||||
BOOST_CHECK( static_cast<bool>(j1 <= j) );
|
||||
BOOST_CHECK( static_cast<bool>(j <= j2) );
|
||||
BOOST_CHECK( static_cast<bool>(2 <= j2) );
|
||||
BOOST_CHECK( static_cast<bool>(j <= 2) );
|
||||
BOOST_CHECK( static_cast<bool>(j2 > j1) );
|
||||
BOOST_CHECK( static_cast<bool>(2 > j1) );
|
||||
BOOST_CHECK( static_cast<bool>(j2 > 1) );
|
||||
BOOST_CHECK( static_cast<bool>(j2 >= j1) );
|
||||
BOOST_CHECK( static_cast<bool>(2 >= j1) );
|
||||
BOOST_CHECK( static_cast<bool>(j2 >= 1) );
|
||||
BOOST_CHECK( static_cast<bool>(j2 >= j) );
|
||||
BOOST_CHECK( static_cast<bool>(2 >= j) );
|
||||
BOOST_CHECK( static_cast<bool>(j2 >= 2) );
|
||||
|
||||
BOOST_CHECK( static_cast<bool>((j1 + 2) == 3) );
|
||||
BOOST_CHECK( static_cast<bool>((1 + j2) == 3) );
|
||||
BOOST_TEST( static_cast<bool>(j2 == j) );
|
||||
BOOST_TEST( static_cast<bool>(2 == j) );
|
||||
BOOST_TEST( static_cast<bool>(j2 == 2) );
|
||||
BOOST_TEST( static_cast<bool>(j == j2) );
|
||||
BOOST_TEST( static_cast<bool>(j1 != j2) );
|
||||
BOOST_TEST( static_cast<bool>(j1 != 2) );
|
||||
BOOST_TEST( static_cast<bool>(1 != j2) );
|
||||
BOOST_TEST( static_cast<bool>(j1 < j2) );
|
||||
BOOST_TEST( static_cast<bool>(1 < j2) );
|
||||
BOOST_TEST( static_cast<bool>(j1 < 2) );
|
||||
BOOST_TEST( static_cast<bool>(j1 <= j2) );
|
||||
BOOST_TEST( static_cast<bool>(1 <= j2) );
|
||||
BOOST_TEST( static_cast<bool>(j1 <= j) );
|
||||
BOOST_TEST( static_cast<bool>(j <= j2) );
|
||||
BOOST_TEST( static_cast<bool>(2 <= j2) );
|
||||
BOOST_TEST( static_cast<bool>(j <= 2) );
|
||||
BOOST_TEST( static_cast<bool>(j2 > j1) );
|
||||
BOOST_TEST( static_cast<bool>(2 > j1) );
|
||||
BOOST_TEST( static_cast<bool>(j2 > 1) );
|
||||
BOOST_TEST( static_cast<bool>(j2 >= j1) );
|
||||
BOOST_TEST( static_cast<bool>(2 >= j1) );
|
||||
BOOST_TEST( static_cast<bool>(j2 >= 1) );
|
||||
BOOST_TEST( static_cast<bool>(j2 >= j) );
|
||||
BOOST_TEST( static_cast<bool>(2 >= j) );
|
||||
BOOST_TEST( static_cast<bool>(j2 >= 2) );
|
||||
|
||||
BOOST_TEST( static_cast<bool>((j1 + 2) == 3) );
|
||||
BOOST_TEST( static_cast<bool>((1 + j2) == 3) );
|
||||
PRIVATE_EXPR_TEST( (j = j1 + j2), (j.value() == 3) );
|
||||
|
||||
BOOST_CHECK( static_cast<bool>((j + 2) == 5) );
|
||||
BOOST_CHECK( static_cast<bool>((3 + j2) == 5) );
|
||||
|
||||
BOOST_TEST( static_cast<bool>((j + 2) == 5) );
|
||||
BOOST_TEST( static_cast<bool>((3 + j2) == 5) );
|
||||
PRIVATE_EXPR_TEST( (j = j + j2), (j.value() == 5) );
|
||||
|
||||
BOOST_CHECK( static_cast<bool>((j - 1) == 4) );
|
||||
|
||||
BOOST_TEST( static_cast<bool>((j - 1) == 4) );
|
||||
PRIVATE_EXPR_TEST( (j = j - j1), (j.value() == 4) );
|
||||
|
||||
BOOST_CHECK( static_cast<bool>((j * 2) == 8) );
|
||||
BOOST_CHECK( static_cast<bool>((4 * j2) == 8) );
|
||||
|
||||
BOOST_TEST( static_cast<bool>((j * 2) == 8) );
|
||||
BOOST_TEST( static_cast<bool>((4 * j2) == 8) );
|
||||
PRIVATE_EXPR_TEST( (j = j * j2), (j.value() == 8) );
|
||||
|
||||
BOOST_CHECK( static_cast<bool>((j / 2) == 4) );
|
||||
|
||||
BOOST_TEST( static_cast<bool>((j / 2) == 4) );
|
||||
PRIVATE_EXPR_TEST( (j = j / j2), (j.value() == 4) );
|
||||
|
||||
BOOST_CHECK( static_cast<bool>((j % 3) == 1) );
|
||||
|
||||
BOOST_TEST( static_cast<bool>((j % 3) == 1) );
|
||||
PRIVATE_EXPR_TEST( (j = j % ( j - j1 )), (j.value() == 1) );
|
||||
|
||||
|
||||
PRIVATE_EXPR_TEST( (j = j2 + j2), (j.value() == 4) );
|
||||
|
||||
BOOST_CHECK( static_cast<bool>((1 | j2 | j) == 7) );
|
||||
BOOST_CHECK( static_cast<bool>((j1 | 2 | j) == 7) );
|
||||
BOOST_CHECK( static_cast<bool>((j1 | j2 | 4) == 7) );
|
||||
|
||||
BOOST_TEST( static_cast<bool>((1 | j2 | j) == 7) );
|
||||
BOOST_TEST( static_cast<bool>((j1 | 2 | j) == 7) );
|
||||
BOOST_TEST( static_cast<bool>((j1 | j2 | 4) == 7) );
|
||||
PRIVATE_EXPR_TEST( (j = j1 | j2 | j), (j.value() == 7) );
|
||||
|
||||
BOOST_CHECK( static_cast<bool>((7 & j2) == 2) );
|
||||
BOOST_CHECK( static_cast<bool>((j & 2) == 2) );
|
||||
|
||||
BOOST_TEST( static_cast<bool>((7 & j2) == 2) );
|
||||
BOOST_TEST( static_cast<bool>((j & 2) == 2) );
|
||||
PRIVATE_EXPR_TEST( (j = j & j2), (j.value() == 2) );
|
||||
|
||||
|
||||
PRIVATE_EXPR_TEST( (j = j | j1), (j.value() == 3) );
|
||||
|
||||
BOOST_CHECK( static_cast<bool>((3 ^ j1) == 2) );
|
||||
BOOST_CHECK( static_cast<bool>((j ^ 1) == 2) );
|
||||
|
||||
BOOST_TEST( static_cast<bool>((3 ^ j1) == 2) );
|
||||
BOOST_TEST( static_cast<bool>((j ^ 1) == 2) );
|
||||
PRIVATE_EXPR_TEST( (j = j ^ j1), (j.value() == 2) );
|
||||
|
||||
|
||||
PRIVATE_EXPR_TEST( (j = ( j + j1 ) * ( j2 | j1 )), (j.value() == 9) );
|
||||
|
||||
BOOST_CHECK( static_cast<bool>((j1 << 2) == 4) );
|
||||
BOOST_CHECK( static_cast<bool>((j2 << 1) == 4) );
|
||||
BOOST_TEST( static_cast<bool>((j1 << 2) == 4) );
|
||||
BOOST_TEST( static_cast<bool>((j2 << 1) == 4) );
|
||||
PRIVATE_EXPR_TEST( (j = j1 << j2), (j.value() == 4) );
|
||||
|
||||
BOOST_CHECK( static_cast<bool>((j >> 2) == 1) );
|
||||
BOOST_CHECK( static_cast<bool>((j2 >> 1) == 1) );
|
||||
BOOST_TEST( static_cast<bool>((j >> 2) == 1) );
|
||||
BOOST_TEST( static_cast<bool>((j2 >> 1) == 1) );
|
||||
PRIVATE_EXPR_TEST( (j = j2 >> j1), (j.value() == 1) );
|
||||
|
||||
|
||||
cout << "Performed tests on MyLong objects.\n";
|
||||
|
||||
MyChar k1(1);
|
||||
MyChar k2(2);
|
||||
MyChar k;
|
||||
|
||||
BOOST_CHECK( k1.value() == 1 );
|
||||
BOOST_CHECK( k2.value() == 2 );
|
||||
BOOST_CHECK( k.value() == 0 );
|
||||
BOOST_TEST( k1.value() == 1 );
|
||||
BOOST_TEST( k2.value() == 2 );
|
||||
BOOST_TEST( k.value() == 0 );
|
||||
|
||||
cout << "Created MyChar objects.\n";
|
||||
|
||||
PRIVATE_EXPR_TEST( (k = k2), (k.value() == 2) );
|
||||
|
||||
BOOST_CHECK( static_cast<bool>(k2 == k) );
|
||||
BOOST_CHECK( static_cast<bool>(k1 != k2) );
|
||||
BOOST_CHECK( static_cast<bool>(k1 < k2) );
|
||||
BOOST_CHECK( static_cast<bool>(k1 <= k2) );
|
||||
BOOST_CHECK( static_cast<bool>(k <= k2) );
|
||||
BOOST_CHECK( static_cast<bool>(k2 > k1) );
|
||||
BOOST_CHECK( static_cast<bool>(k2 >= k1) );
|
||||
BOOST_CHECK( static_cast<bool>(k2 >= k) );
|
||||
|
||||
BOOST_TEST( static_cast<bool>(k2 == k) );
|
||||
BOOST_TEST( static_cast<bool>(k1 != k2) );
|
||||
BOOST_TEST( static_cast<bool>(k1 < k2) );
|
||||
BOOST_TEST( static_cast<bool>(k1 <= k2) );
|
||||
BOOST_TEST( static_cast<bool>(k <= k2) );
|
||||
BOOST_TEST( static_cast<bool>(k2 > k1) );
|
||||
BOOST_TEST( static_cast<bool>(k2 >= k1) );
|
||||
BOOST_TEST( static_cast<bool>(k2 >= k) );
|
||||
|
||||
cout << "Performed tests on MyChar objects.\n";
|
||||
|
||||
MyShort l1(1);
|
||||
MyShort l2(2);
|
||||
MyShort l;
|
||||
|
||||
BOOST_CHECK( l1.value() == 1 );
|
||||
BOOST_CHECK( l2.value() == 2 );
|
||||
BOOST_CHECK( l.value() == 0 );
|
||||
BOOST_TEST( l1.value() == 1 );
|
||||
BOOST_TEST( l2.value() == 2 );
|
||||
BOOST_TEST( l.value() == 0 );
|
||||
|
||||
cout << "Created MyShort objects.\n";
|
||||
|
||||
PRIVATE_EXPR_TEST( (l = l2), (l.value() == 2) );
|
||||
|
||||
BOOST_CHECK( static_cast<bool>(l2 == l) );
|
||||
BOOST_CHECK( static_cast<bool>(2 == l) );
|
||||
BOOST_CHECK( static_cast<bool>(l2 == 2) );
|
||||
BOOST_CHECK( static_cast<bool>(l == l2) );
|
||||
BOOST_CHECK( static_cast<bool>(l1 != l2) );
|
||||
BOOST_CHECK( static_cast<bool>(l1 != 2) );
|
||||
BOOST_CHECK( static_cast<bool>(1 != l2) );
|
||||
BOOST_CHECK( static_cast<bool>(l1 < l2) );
|
||||
BOOST_CHECK( static_cast<bool>(1 < l2) );
|
||||
BOOST_CHECK( static_cast<bool>(l1 < 2) );
|
||||
BOOST_CHECK( static_cast<bool>(l1 <= l2) );
|
||||
BOOST_CHECK( static_cast<bool>(1 <= l2) );
|
||||
BOOST_CHECK( static_cast<bool>(l1 <= l) );
|
||||
BOOST_CHECK( static_cast<bool>(l <= l2) );
|
||||
BOOST_CHECK( static_cast<bool>(2 <= l2) );
|
||||
BOOST_CHECK( static_cast<bool>(l <= 2) );
|
||||
BOOST_CHECK( static_cast<bool>(l2 > l1) );
|
||||
BOOST_CHECK( static_cast<bool>(2 > l1) );
|
||||
BOOST_CHECK( static_cast<bool>(l2 > 1) );
|
||||
BOOST_CHECK( static_cast<bool>(l2 >= l1) );
|
||||
BOOST_CHECK( static_cast<bool>(2 >= l1) );
|
||||
BOOST_CHECK( static_cast<bool>(l2 >= 1) );
|
||||
BOOST_CHECK( static_cast<bool>(l2 >= l) );
|
||||
BOOST_CHECK( static_cast<bool>(2 >= l) );
|
||||
BOOST_CHECK( static_cast<bool>(l2 >= 2) );
|
||||
|
||||
|
||||
BOOST_TEST( static_cast<bool>(l2 == l) );
|
||||
BOOST_TEST( static_cast<bool>(2 == l) );
|
||||
BOOST_TEST( static_cast<bool>(l2 == 2) );
|
||||
BOOST_TEST( static_cast<bool>(l == l2) );
|
||||
BOOST_TEST( static_cast<bool>(l1 != l2) );
|
||||
BOOST_TEST( static_cast<bool>(l1 != 2) );
|
||||
BOOST_TEST( static_cast<bool>(1 != l2) );
|
||||
BOOST_TEST( static_cast<bool>(l1 < l2) );
|
||||
BOOST_TEST( static_cast<bool>(1 < l2) );
|
||||
BOOST_TEST( static_cast<bool>(l1 < 2) );
|
||||
BOOST_TEST( static_cast<bool>(l1 <= l2) );
|
||||
BOOST_TEST( static_cast<bool>(1 <= l2) );
|
||||
BOOST_TEST( static_cast<bool>(l1 <= l) );
|
||||
BOOST_TEST( static_cast<bool>(l <= l2) );
|
||||
BOOST_TEST( static_cast<bool>(2 <= l2) );
|
||||
BOOST_TEST( static_cast<bool>(l <= 2) );
|
||||
BOOST_TEST( static_cast<bool>(l2 > l1) );
|
||||
BOOST_TEST( static_cast<bool>(2 > l1) );
|
||||
BOOST_TEST( static_cast<bool>(l2 > 1) );
|
||||
BOOST_TEST( static_cast<bool>(l2 >= l1) );
|
||||
BOOST_TEST( static_cast<bool>(2 >= l1) );
|
||||
BOOST_TEST( static_cast<bool>(l2 >= 1) );
|
||||
BOOST_TEST( static_cast<bool>(l2 >= l) );
|
||||
BOOST_TEST( static_cast<bool>(2 >= l) );
|
||||
BOOST_TEST( static_cast<bool>(l2 >= 2) );
|
||||
|
||||
cout << "Performed tests on MyShort objects.\n";
|
||||
|
||||
|
||||
MyDoubleInt di1(1);
|
||||
MyDoubleInt di2(2.);
|
||||
MyDoubleInt half(0.5);
|
||||
MyDoubleInt di;
|
||||
MyDoubleInt tmp;
|
||||
|
||||
BOOST_CHECK( di1.value() == 1 );
|
||||
BOOST_CHECK( di2.value() == 2 );
|
||||
BOOST_CHECK( di2.value() == 2 );
|
||||
BOOST_CHECK( di.value() == 0 );
|
||||
BOOST_TEST( di1.value() == 1 );
|
||||
BOOST_TEST( di2.value() == 2 );
|
||||
BOOST_TEST( di2.value() == 2 );
|
||||
BOOST_TEST( di.value() == 0 );
|
||||
|
||||
cout << "Created MyDoubleInt objects.\n";
|
||||
|
||||
PRIVATE_EXPR_TEST( (di = di2), (di.value() == 2) );
|
||||
|
||||
BOOST_CHECK( static_cast<bool>(di2 == di) );
|
||||
BOOST_CHECK( static_cast<bool>(2 == di) );
|
||||
BOOST_CHECK( static_cast<bool>(di == 2) );
|
||||
BOOST_CHECK( static_cast<bool>(di1 < di2) );
|
||||
BOOST_CHECK( static_cast<bool>(1 < di2) );
|
||||
BOOST_CHECK( static_cast<bool>(di1 <= di2) );
|
||||
BOOST_CHECK( static_cast<bool>(1 <= di2) );
|
||||
BOOST_CHECK( static_cast<bool>(di2 > di1) );
|
||||
BOOST_CHECK( static_cast<bool>(di2 > 1) );
|
||||
BOOST_CHECK( static_cast<bool>(di2 >= di1) );
|
||||
BOOST_CHECK( static_cast<bool>(di2 >= 1) );
|
||||
BOOST_CHECK( static_cast<bool>(di1 / di2 == half) );
|
||||
BOOST_CHECK( static_cast<bool>(di1 / 2 == half) );
|
||||
BOOST_CHECK( static_cast<bool>(1 / di2 == half) );
|
||||
|
||||
BOOST_TEST( static_cast<bool>(di2 == di) );
|
||||
BOOST_TEST( static_cast<bool>(2 == di) );
|
||||
BOOST_TEST( static_cast<bool>(di == 2) );
|
||||
BOOST_TEST( static_cast<bool>(di1 < di2) );
|
||||
BOOST_TEST( static_cast<bool>(1 < di2) );
|
||||
BOOST_TEST( static_cast<bool>(di1 <= di2) );
|
||||
BOOST_TEST( static_cast<bool>(1 <= di2) );
|
||||
BOOST_TEST( static_cast<bool>(di2 > di1) );
|
||||
BOOST_TEST( static_cast<bool>(di2 > 1) );
|
||||
BOOST_TEST( static_cast<bool>(di2 >= di1) );
|
||||
BOOST_TEST( static_cast<bool>(di2 >= 1) );
|
||||
BOOST_TEST( static_cast<bool>(di1 / di2 == half) );
|
||||
BOOST_TEST( static_cast<bool>(di1 / 2 == half) );
|
||||
BOOST_TEST( static_cast<bool>(1 / di2 == half) );
|
||||
PRIVATE_EXPR_TEST( (tmp=di1), static_cast<bool>((tmp/=2) == half) );
|
||||
PRIVATE_EXPR_TEST( (tmp=di1), static_cast<bool>((tmp/=di2) == half) );
|
||||
BOOST_CHECK( static_cast<bool>(di1 * di2 == di2) );
|
||||
BOOST_CHECK( static_cast<bool>(di1 * 2 == di2) );
|
||||
BOOST_CHECK( static_cast<bool>(1 * di2 == di2) );
|
||||
BOOST_TEST( static_cast<bool>(di1 * di2 == di2) );
|
||||
BOOST_TEST( static_cast<bool>(di1 * 2 == di2) );
|
||||
BOOST_TEST( static_cast<bool>(1 * di2 == di2) );
|
||||
PRIVATE_EXPR_TEST( (tmp=di1), static_cast<bool>((tmp*=2) == di2) );
|
||||
PRIVATE_EXPR_TEST( (tmp=di1), static_cast<bool>((tmp*=di2) == di2) );
|
||||
BOOST_CHECK( static_cast<bool>(di2 - di1 == di1) );
|
||||
BOOST_CHECK( static_cast<bool>(di2 - 1 == di1) );
|
||||
BOOST_CHECK( static_cast<bool>(2 - di1 == di1) );
|
||||
BOOST_TEST( static_cast<bool>(di2 - di1 == di1) );
|
||||
BOOST_TEST( static_cast<bool>(di2 - 1 == di1) );
|
||||
BOOST_TEST( static_cast<bool>(2 - di1 == di1) );
|
||||
PRIVATE_EXPR_TEST( (tmp=di2), static_cast<bool>((tmp-=1) == di1) );
|
||||
PRIVATE_EXPR_TEST( (tmp=di2), static_cast<bool>((tmp-=di1) == di1) );
|
||||
BOOST_CHECK( static_cast<bool>(di1 + di1 == di2) );
|
||||
BOOST_CHECK( static_cast<bool>(di1 + 1 == di2) );
|
||||
BOOST_CHECK( static_cast<bool>(1 + di1 == di2) );
|
||||
BOOST_TEST( static_cast<bool>(di1 + di1 == di2) );
|
||||
BOOST_TEST( static_cast<bool>(di1 + 1 == di2) );
|
||||
BOOST_TEST( static_cast<bool>(1 + di1 == di2) );
|
||||
PRIVATE_EXPR_TEST( (tmp=di1), static_cast<bool>((tmp+=1) == di2) );
|
||||
PRIVATE_EXPR_TEST( (tmp=di1), static_cast<bool>((tmp+=di1) == di2) );
|
||||
|
||||
@ -888,52 +887,52 @@ test_main( int , char * [] )
|
||||
MyLongInt li;
|
||||
MyLongInt tmp2;
|
||||
|
||||
BOOST_CHECK( li1.value() == 1 );
|
||||
BOOST_CHECK( li2.value() == 2 );
|
||||
BOOST_CHECK( li.value() == 0 );
|
||||
BOOST_TEST( li1.value() == 1 );
|
||||
BOOST_TEST( li2.value() == 2 );
|
||||
BOOST_TEST( li.value() == 0 );
|
||||
|
||||
cout << "Created MyLongInt objects.\n";
|
||||
|
||||
PRIVATE_EXPR_TEST( (li = li2), (li.value() == 2) );
|
||||
|
||||
BOOST_CHECK( static_cast<bool>(li2 == li) );
|
||||
BOOST_CHECK( static_cast<bool>(2 == li) );
|
||||
BOOST_CHECK( static_cast<bool>(li == 2) );
|
||||
BOOST_CHECK( static_cast<bool>(li1 < li2) );
|
||||
BOOST_CHECK( static_cast<bool>(1 < li2) );
|
||||
BOOST_CHECK( static_cast<bool>(li1 <= li2) );
|
||||
BOOST_CHECK( static_cast<bool>(1 <= li2) );
|
||||
BOOST_CHECK( static_cast<bool>(li2 > li1) );
|
||||
BOOST_CHECK( static_cast<bool>(li2 > 1) );
|
||||
BOOST_CHECK( static_cast<bool>(li2 >= li1) );
|
||||
BOOST_CHECK( static_cast<bool>(li2 >= 1) );
|
||||
BOOST_CHECK( static_cast<bool>(li1 % li2 == li1) );
|
||||
BOOST_CHECK( static_cast<bool>(li1 % 2 == li1) );
|
||||
BOOST_CHECK( static_cast<bool>(1 % li2 == li1) );
|
||||
|
||||
BOOST_TEST( static_cast<bool>(li2 == li) );
|
||||
BOOST_TEST( static_cast<bool>(2 == li) );
|
||||
BOOST_TEST( static_cast<bool>(li == 2) );
|
||||
BOOST_TEST( static_cast<bool>(li1 < li2) );
|
||||
BOOST_TEST( static_cast<bool>(1 < li2) );
|
||||
BOOST_TEST( static_cast<bool>(li1 <= li2) );
|
||||
BOOST_TEST( static_cast<bool>(1 <= li2) );
|
||||
BOOST_TEST( static_cast<bool>(li2 > li1) );
|
||||
BOOST_TEST( static_cast<bool>(li2 > 1) );
|
||||
BOOST_TEST( static_cast<bool>(li2 >= li1) );
|
||||
BOOST_TEST( static_cast<bool>(li2 >= 1) );
|
||||
BOOST_TEST( static_cast<bool>(li1 % li2 == li1) );
|
||||
BOOST_TEST( static_cast<bool>(li1 % 2 == li1) );
|
||||
BOOST_TEST( static_cast<bool>(1 % li2 == li1) );
|
||||
PRIVATE_EXPR_TEST( (tmp2=li1), static_cast<bool>((tmp2%=2) == li1) );
|
||||
PRIVATE_EXPR_TEST( (tmp2=li1), static_cast<bool>((tmp2%=li2) == li1) );
|
||||
BOOST_CHECK( static_cast<bool>(li1 / li2 == 0) );
|
||||
BOOST_CHECK( static_cast<bool>(li1 / 2 == 0) );
|
||||
BOOST_CHECK( static_cast<bool>(1 / li2 == 0) );
|
||||
BOOST_TEST( static_cast<bool>(li1 / li2 == 0) );
|
||||
BOOST_TEST( static_cast<bool>(li1 / 2 == 0) );
|
||||
BOOST_TEST( static_cast<bool>(1 / li2 == 0) );
|
||||
PRIVATE_EXPR_TEST( (tmp2=li1), static_cast<bool>((tmp2/=2) == 0) );
|
||||
PRIVATE_EXPR_TEST( (tmp2=li1), static_cast<bool>((tmp2/=li2) == 0) );
|
||||
BOOST_CHECK( static_cast<bool>(li1 * li2 == li2) );
|
||||
BOOST_CHECK( static_cast<bool>(li1 * 2 == li2) );
|
||||
BOOST_CHECK( static_cast<bool>(1 * li2 == li2) );
|
||||
BOOST_TEST( static_cast<bool>(li1 * li2 == li2) );
|
||||
BOOST_TEST( static_cast<bool>(li1 * 2 == li2) );
|
||||
BOOST_TEST( static_cast<bool>(1 * li2 == li2) );
|
||||
PRIVATE_EXPR_TEST( (tmp2=li1), static_cast<bool>((tmp2*=2) == li2) );
|
||||
PRIVATE_EXPR_TEST( (tmp2=li1), static_cast<bool>((tmp2*=li2) == li2) );
|
||||
BOOST_CHECK( static_cast<bool>(li2 - li1 == li1) );
|
||||
BOOST_CHECK( static_cast<bool>(li2 - 1 == li1) );
|
||||
BOOST_CHECK( static_cast<bool>(2 - li1 == li1) );
|
||||
BOOST_TEST( static_cast<bool>(li2 - li1 == li1) );
|
||||
BOOST_TEST( static_cast<bool>(li2 - 1 == li1) );
|
||||
BOOST_TEST( static_cast<bool>(2 - li1 == li1) );
|
||||
PRIVATE_EXPR_TEST( (tmp2=li2), static_cast<bool>((tmp2-=1) == li1) );
|
||||
PRIVATE_EXPR_TEST( (tmp2=li2), static_cast<bool>((tmp2-=li1) == li1) );
|
||||
BOOST_CHECK( static_cast<bool>(li1 + li1 == li2) );
|
||||
BOOST_CHECK( static_cast<bool>(li1 + 1 == li2) );
|
||||
BOOST_CHECK( static_cast<bool>(1 + li1 == li2) );
|
||||
BOOST_TEST( static_cast<bool>(li1 + li1 == li2) );
|
||||
BOOST_TEST( static_cast<bool>(li1 + 1 == li2) );
|
||||
BOOST_TEST( static_cast<bool>(1 + li1 == li2) );
|
||||
PRIVATE_EXPR_TEST( (tmp2=li1), static_cast<bool>((tmp2+=1) == li2) );
|
||||
PRIVATE_EXPR_TEST( (tmp2=li1), static_cast<bool>((tmp2+=li1) == li2) );
|
||||
|
||||
cout << "Performed tests on MyLongInt objects.\n";
|
||||
|
||||
return boost::exit_success;
|
||||
return boost::report_errors();
|
||||
}
|
@ -297,6 +297,12 @@ int main()
|
||||
BOOST_STATIC_ASSERT((is_same<result_of<const no_result_type_or_result_template<void>(void)>::type, cv_overload_check<const int> >::value));
|
||||
BOOST_STATIC_ASSERT((is_same<result_of<volatile no_result_type_or_result_template<void>(void)>::type, cv_overload_check<volatile int> >::value));
|
||||
BOOST_STATIC_ASSERT((is_same<result_of<const volatile no_result_type_or_result_template<void>(void)>::type, cv_overload_check<const volatile int> >::value));
|
||||
|
||||
BOOST_STATIC_ASSERT((is_same<result_of<func_ptr&(char, float)>::type, int>::value));
|
||||
BOOST_STATIC_ASSERT((is_same<result_of<func_ptr const&(char, float)>::type, int>::value));
|
||||
BOOST_STATIC_ASSERT((is_same<result_of<int_result_of&(double)>::type, int>::value));
|
||||
BOOST_STATIC_ASSERT((is_same<result_of<int_result_of const&(double)>::type, int>::value));
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
BOOST_STATIC_ASSERT((is_same<result_of<no_result_type_or_result(int&&)>::type, short>::value));
|
||||
BOOST_STATIC_ASSERT((is_same<result_of<no_result_type_or_result(int&)>::type, int>::value));
|
||||
|
26
test/string_ref_from_rvalue.cpp
Normal file
26
test/string_ref_from_rvalue.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
Copyright (c) Marshall Clow 2017.
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
For more information, see http://www.boost.org
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
|
||||
#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) || defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
|
||||
#error "Unsupported test"
|
||||
#endif
|
||||
|
||||
std::string makeatemp() { return "abc"; }
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::basic_string_ref<char> sv(makeatemp());
|
||||
return 0;
|
||||
}
|
@ -7,23 +7,23 @@
|
||||
For more information, see http://www.boost.org
|
||||
*/
|
||||
|
||||
#include <cstddef>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
|
||||
#define BOOST_TEST_MAIN
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
typedef boost::string_ref string_ref;
|
||||
|
||||
// Should be equal
|
||||
void interop ( const std::string &str, string_ref ref ) {
|
||||
// BOOST_CHECK ( str == ref );
|
||||
BOOST_CHECK ( str.size () == ref.size ());
|
||||
BOOST_CHECK ( std::equal ( str.begin (), str.end (), ref.begin ()));
|
||||
BOOST_CHECK ( std::equal ( str.rbegin (), str.rend (), ref.rbegin ()));
|
||||
// BOOST_TEST ( str == ref );
|
||||
BOOST_TEST ( str.size () == ref.size ());
|
||||
BOOST_TEST ( std::equal ( str.begin (), str.end (), ref.begin ()));
|
||||
BOOST_TEST ( std::equal ( str.rbegin (), str.rend (), ref.rbegin ()));
|
||||
}
|
||||
|
||||
void null_tests ( const char *p ) {
|
||||
@ -34,38 +34,38 @@ void null_tests ( const char *p ) {
|
||||
string_ref sr4 ( p );
|
||||
sr4.clear ();
|
||||
|
||||
BOOST_CHECK ( sr1 == sr2 );
|
||||
BOOST_CHECK ( sr1 == sr3 );
|
||||
BOOST_CHECK ( sr2 == sr3 );
|
||||
BOOST_CHECK ( sr1 == sr4 );
|
||||
BOOST_TEST ( sr1 == sr2 );
|
||||
BOOST_TEST ( sr1 == sr3 );
|
||||
BOOST_TEST ( sr2 == sr3 );
|
||||
BOOST_TEST ( sr1 == sr4 );
|
||||
}
|
||||
|
||||
// make sure that substrings work just like strings
|
||||
void test_substr ( const std::string &str ) {
|
||||
const size_t sz = str.size ();
|
||||
const std::size_t sz = str.size ();
|
||||
string_ref ref ( str );
|
||||
|
||||
// Substrings at the end
|
||||
for ( size_t i = 0; i <= sz; ++ i )
|
||||
for ( std::size_t i = 0; i <= sz; ++ i )
|
||||
interop ( str.substr ( i ), ref.substr ( i ));
|
||||
|
||||
// Substrings at the beginning
|
||||
for ( size_t i = 0; i <= sz; ++ i )
|
||||
for ( std::size_t i = 0; i <= sz; ++ i )
|
||||
interop ( str.substr ( 0, i ), ref.substr ( 0, i ));
|
||||
|
||||
// All possible substrings
|
||||
for ( size_t i = 0; i < sz; ++i )
|
||||
for ( size_t j = i; j < sz; ++j )
|
||||
for ( std::size_t i = 0; i < sz; ++i )
|
||||
for ( std::size_t j = i; j < sz; ++j )
|
||||
interop ( str.substr ( i, j ), ref.substr ( i, j ));
|
||||
}
|
||||
|
||||
// make sure that removing prefixes and suffixes work just like strings
|
||||
void test_remove ( const std::string &str ) {
|
||||
const size_t sz = str.size ();
|
||||
const std::size_t sz = str.size ();
|
||||
std::string work;
|
||||
string_ref ref;
|
||||
|
||||
for ( size_t i = 1; i <= sz; ++i ) {
|
||||
for ( std::size_t i = 1; i <= sz; ++i ) {
|
||||
work = str;
|
||||
ref = str;
|
||||
while ( ref.size () >= i ) {
|
||||
@ -75,7 +75,7 @@ void test_remove ( const std::string &str ) {
|
||||
}
|
||||
}
|
||||
|
||||
for ( size_t i = 1; i < sz; ++ i ) {
|
||||
for ( std::size_t i = 1; i < sz; ++ i ) {
|
||||
work = str;
|
||||
ref = str;
|
||||
while ( ref.size () >= i ) {
|
||||
@ -94,7 +94,7 @@ const char *test_strings [] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE( test_main )
|
||||
int main()
|
||||
{
|
||||
const char **p = &test_strings[0];
|
||||
|
||||
@ -106,4 +106,6 @@ BOOST_AUTO_TEST_CASE( test_main )
|
||||
|
||||
p++;
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@ -7,68 +7,69 @@
|
||||
For more information, see http://www.boost.org
|
||||
*/
|
||||
|
||||
#include <cstddef>
|
||||
#include <iostream>
|
||||
#include <cstring> // for std::strchr
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
|
||||
#define BOOST_TEST_MAIN
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
typedef boost::string_ref string_ref;
|
||||
|
||||
void ends_with ( const char *arg ) {
|
||||
const size_t sz = std::strlen ( arg );
|
||||
const std::size_t sz = std::strlen ( arg );
|
||||
string_ref sr ( arg );
|
||||
string_ref sr2 ( arg );
|
||||
const char *p = arg;
|
||||
|
||||
while ( *p ) {
|
||||
BOOST_CHECK ( sr.ends_with ( p ));
|
||||
BOOST_TEST ( sr.ends_with ( p ));
|
||||
++p;
|
||||
}
|
||||
|
||||
while ( !sr2.empty ()) {
|
||||
BOOST_CHECK ( sr.ends_with ( sr2 ));
|
||||
BOOST_TEST ( sr.ends_with ( sr2 ));
|
||||
sr2.remove_prefix (1);
|
||||
}
|
||||
|
||||
sr2 = arg;
|
||||
while ( !sr2.empty ()) {
|
||||
BOOST_CHECK ( sr.ends_with ( sr2 ));
|
||||
BOOST_TEST ( sr.ends_with ( sr2 ));
|
||||
sr2.remove_prefix (1);
|
||||
}
|
||||
|
||||
char ch = sz == 0 ? '\0' : arg [ sz - 1 ];
|
||||
sr2 = arg;
|
||||
if ( sz > 0 )
|
||||
BOOST_CHECK ( sr2.ends_with ( ch ));
|
||||
BOOST_CHECK ( !sr2.ends_with ( ++ch ));
|
||||
BOOST_CHECK ( sr2.ends_with ( string_ref ()));
|
||||
BOOST_TEST ( sr2.ends_with ( ch ));
|
||||
BOOST_TEST ( !sr2.ends_with ( ++ch ));
|
||||
BOOST_TEST ( sr2.ends_with ( string_ref ()));
|
||||
}
|
||||
|
||||
void starts_with ( const char *arg ) {
|
||||
const size_t sz = std::strlen ( arg );
|
||||
const std::size_t sz = std::strlen ( arg );
|
||||
string_ref sr ( arg );
|
||||
string_ref sr2 ( arg );
|
||||
const char *p = arg + std::strlen ( arg ) - 1;
|
||||
while ( p >= arg ) {
|
||||
std::string foo ( arg, p + 1 );
|
||||
BOOST_CHECK ( sr.starts_with ( foo ));
|
||||
--p;
|
||||
std::string foo ( arg );
|
||||
while ( !foo.empty ()) {
|
||||
BOOST_TEST ( sr.starts_with ( foo ));
|
||||
foo.erase ( foo.end () - 1 );
|
||||
}
|
||||
|
||||
while ( !sr2.empty ()) {
|
||||
BOOST_CHECK ( sr.starts_with ( sr2 ));
|
||||
BOOST_TEST ( sr.starts_with ( sr2 ));
|
||||
sr2.remove_suffix (1);
|
||||
}
|
||||
|
||||
char ch = *arg;
|
||||
sr2 = arg;
|
||||
if ( sz > 0 )
|
||||
BOOST_CHECK ( sr2.starts_with ( ch ));
|
||||
BOOST_CHECK ( !sr2.starts_with ( ++ch ));
|
||||
BOOST_CHECK ( sr2.starts_with ( string_ref ()));
|
||||
if ( sz > 0 )
|
||||
BOOST_TEST ( sr2.starts_with ( ch ));
|
||||
BOOST_TEST ( !sr2.starts_with ( ++ch ));
|
||||
BOOST_TEST ( sr2.starts_with ( string_ref ()));
|
||||
}
|
||||
|
||||
void reverse ( const char *arg ) {
|
||||
@ -78,14 +79,14 @@ void reverse ( const char *arg ) {
|
||||
string_ref sr2 ( string1 );
|
||||
std::string string2 ( sr2.rbegin (), sr2.rend ());
|
||||
|
||||
BOOST_CHECK ( std::equal ( sr2.rbegin (), sr2.rend (), arg ));
|
||||
BOOST_CHECK ( string2 == arg );
|
||||
BOOST_CHECK ( std::equal ( sr1.begin (), sr1.end (), string2.begin ()));
|
||||
BOOST_TEST ( std::equal ( sr2.rbegin (), sr2.rend (), arg ));
|
||||
BOOST_TEST ( string2 == arg );
|
||||
BOOST_TEST ( std::equal ( sr1.begin (), sr1.end (), string2.begin ()));
|
||||
}
|
||||
|
||||
// This helper function eliminates signed vs. unsigned warnings
|
||||
// This helper function eliminates signed vs. unsigned warnings
|
||||
string_ref::size_type ptr_diff ( const char *res, const char *base ) {
|
||||
BOOST_CHECK ( res >= base );
|
||||
BOOST_TEST ( res >= base );
|
||||
return static_cast<string_ref::size_type> ( res - base );
|
||||
}
|
||||
|
||||
@ -94,12 +95,16 @@ void find ( const char *arg ) {
|
||||
string_ref sr2;
|
||||
const char *p;
|
||||
|
||||
// When we search for the empty string, we find it at position 0
|
||||
BOOST_TEST ( sr1.find (sr2) == 0 );
|
||||
BOOST_TEST ( sr1.rfind(sr2) == 0 );
|
||||
|
||||
// Look for each character in the string(searching from the start)
|
||||
p = arg;
|
||||
sr1 = arg;
|
||||
while ( *p ) {
|
||||
string_ref::size_type pos = sr1.find(*p);
|
||||
BOOST_CHECK ( pos != string_ref::npos && ( pos <= ptr_diff ( p, arg )));
|
||||
BOOST_TEST ( pos != string_ref::npos && ( pos <= ptr_diff ( p, arg )));
|
||||
++p;
|
||||
}
|
||||
|
||||
@ -108,17 +113,17 @@ void find ( const char *arg ) {
|
||||
sr1 = arg;
|
||||
while ( *p ) {
|
||||
string_ref::size_type pos = sr1.rfind(*p);
|
||||
BOOST_CHECK ( pos != string_ref::npos && pos < sr1.size () && ( pos >= ptr_diff ( p, arg )));
|
||||
BOOST_TEST ( pos != string_ref::npos && pos < sr1.size () && ( pos >= ptr_diff ( p, arg )));
|
||||
++p;
|
||||
}
|
||||
|
||||
// Look for pairs on characters (searching from the start)
|
||||
// Look for pairs on characters (searching from the start)
|
||||
sr1 = arg;
|
||||
p = arg;
|
||||
while ( *p && *(p+1)) {
|
||||
string_ref sr3 ( p, 2 );
|
||||
string_ref::size_type pos = sr1.find ( sr3 );
|
||||
BOOST_CHECK ( pos != string_ref::npos && pos <= static_cast<string_ref::size_type>( p - arg ));
|
||||
BOOST_TEST ( pos != string_ref::npos && pos <= static_cast<string_ref::size_type>( p - arg ));
|
||||
p++;
|
||||
}
|
||||
|
||||
@ -129,9 +134,9 @@ void find ( const char *arg ) {
|
||||
for ( int ch = 1; ch < 256; ++ch ) {
|
||||
string_ref::size_type pos = sr1.find(ch);
|
||||
const char *strp = std::strchr ( arg, ch );
|
||||
BOOST_CHECK (( strp == NULL ) == ( pos == string_ref::npos ));
|
||||
BOOST_TEST (( strp == NULL ) == ( pos == string_ref::npos ));
|
||||
if ( strp != NULL )
|
||||
BOOST_CHECK ( ptr_diff ( strp, arg ) == pos );
|
||||
BOOST_TEST ( ptr_diff ( strp, arg ) == pos );
|
||||
}
|
||||
|
||||
sr1 = arg;
|
||||
@ -141,9 +146,9 @@ void find ( const char *arg ) {
|
||||
for ( int ch = 1; ch < 256; ++ch ) {
|
||||
string_ref::size_type pos = sr1.rfind(ch);
|
||||
const char *strp = std::strrchr ( arg, ch );
|
||||
BOOST_CHECK (( strp == NULL ) == ( pos == string_ref::npos ));
|
||||
BOOST_TEST (( strp == NULL ) == ( pos == string_ref::npos ));
|
||||
if ( strp != NULL )
|
||||
BOOST_CHECK ( ptr_diff ( strp, arg ) == pos );
|
||||
BOOST_TEST ( ptr_diff ( strp, arg ) == pos );
|
||||
}
|
||||
|
||||
|
||||
@ -152,7 +157,7 @@ void find ( const char *arg ) {
|
||||
sr1 = arg;
|
||||
while ( !sr1.empty ()) {
|
||||
string_ref::size_type pos = sr1.find(*p);
|
||||
BOOST_CHECK ( pos == 0 );
|
||||
BOOST_TEST ( pos == 0 );
|
||||
sr1.remove_prefix (1);
|
||||
++p;
|
||||
}
|
||||
@ -162,7 +167,7 @@ void find ( const char *arg ) {
|
||||
p = arg + std::strlen ( arg ) - 1;
|
||||
while ( !sr1.empty ()) {
|
||||
string_ref::size_type pos = sr1.rfind(*p);
|
||||
BOOST_CHECK ( pos == sr1.size () - 1 );
|
||||
BOOST_TEST ( pos == sr1.size () - 1 );
|
||||
sr1.remove_suffix (1);
|
||||
--p;
|
||||
}
|
||||
@ -172,7 +177,7 @@ void find ( const char *arg ) {
|
||||
p = arg;
|
||||
while ( !sr1.empty ()) {
|
||||
string_ref::size_type pos = sr1.find_first_of(*p);
|
||||
BOOST_CHECK ( pos == 0 );
|
||||
BOOST_TEST ( pos == 0 );
|
||||
sr1.remove_prefix (1);
|
||||
++p;
|
||||
}
|
||||
@ -183,7 +188,7 @@ void find ( const char *arg ) {
|
||||
p = arg + std::strlen ( arg ) - 1;
|
||||
while ( !sr1.empty ()) {
|
||||
string_ref::size_type pos = sr1.find_last_of(*p);
|
||||
BOOST_CHECK ( pos == sr1.size () - 1 );
|
||||
BOOST_TEST ( pos == sr1.size () - 1 );
|
||||
sr1.remove_suffix (1);
|
||||
--p;
|
||||
}
|
||||
@ -192,8 +197,8 @@ void find ( const char *arg ) {
|
||||
sr1 = arg;
|
||||
sr2 = arg;
|
||||
while ( !sr1.empty() ) {
|
||||
BOOST_CHECK ( sr1.find_first_of ( sr2 ) == 0 );
|
||||
BOOST_CHECK ( sr1.find_first_not_of ( sr2 ) == string_ref::npos );
|
||||
BOOST_TEST ( sr1.find_first_of ( sr2 ) == 0 );
|
||||
BOOST_TEST ( sr1.find_first_not_of ( sr2 ) == string_ref::npos );
|
||||
sr1.remove_prefix ( 1 );
|
||||
}
|
||||
|
||||
@ -202,14 +207,14 @@ void find ( const char *arg ) {
|
||||
while ( *p ) {
|
||||
string_ref::size_type pos1 = sr1.find_first_of(*p);
|
||||
string_ref::size_type pos2 = sr1.find_first_not_of(*p);
|
||||
BOOST_CHECK ( pos1 != string_ref::npos && pos1 < sr1.size () && pos1 <= ptr_diff ( p, arg ));
|
||||
BOOST_TEST ( pos1 != string_ref::npos && pos1 < sr1.size () && pos1 <= ptr_diff ( p, arg ));
|
||||
if ( pos2 != string_ref::npos ) {
|
||||
for ( size_t i = 0 ; i < pos2; ++i )
|
||||
BOOST_CHECK ( sr1[i] == *p );
|
||||
BOOST_CHECK ( sr1 [ pos2 ] != *p );
|
||||
for ( std::size_t i = 0 ; i < pos2; ++i )
|
||||
BOOST_TEST ( sr1[i] == *p );
|
||||
BOOST_TEST ( sr1 [ pos2 ] != *p );
|
||||
}
|
||||
|
||||
BOOST_CHECK ( pos2 != pos1 );
|
||||
BOOST_TEST ( pos2 != pos1 );
|
||||
++p;
|
||||
}
|
||||
|
||||
@ -217,8 +222,8 @@ void find ( const char *arg ) {
|
||||
sr1 = arg;
|
||||
sr2 = arg;
|
||||
while ( !sr1.empty() ) {
|
||||
BOOST_CHECK ( sr1.find_last_of ( sr2 ) == ( sr1.size () - 1 ));
|
||||
BOOST_CHECK ( sr1.find_last_not_of ( sr2 ) == string_ref::npos );
|
||||
BOOST_TEST ( sr1.find_last_of ( sr2 ) == ( sr1.size () - 1 ));
|
||||
BOOST_TEST ( sr1.find_last_not_of ( sr2 ) == string_ref::npos );
|
||||
sr1.remove_suffix ( 1 );
|
||||
}
|
||||
|
||||
@ -227,15 +232,15 @@ void find ( const char *arg ) {
|
||||
while ( *p ) {
|
||||
string_ref::size_type pos1 = sr1.find_last_of(*p);
|
||||
string_ref::size_type pos2 = sr1.find_last_not_of(*p);
|
||||
BOOST_CHECK ( pos1 != string_ref::npos && pos1 < sr1.size () && pos1 >= ptr_diff ( p, arg ));
|
||||
BOOST_CHECK ( pos2 == string_ref::npos || pos1 < sr1.size ());
|
||||
BOOST_TEST ( pos1 != string_ref::npos && pos1 < sr1.size () && pos1 >= ptr_diff ( p, arg ));
|
||||
BOOST_TEST ( pos2 == string_ref::npos || pos1 < sr1.size ());
|
||||
if ( pos2 != string_ref::npos ) {
|
||||
for ( size_t i = sr1.size () -1 ; i > pos2; --i )
|
||||
BOOST_CHECK ( sr1[i] == *p );
|
||||
BOOST_CHECK ( sr1 [ pos2 ] != *p );
|
||||
for ( std::size_t i = sr1.size () -1 ; i > pos2; --i )
|
||||
BOOST_TEST ( sr1[i] == *p );
|
||||
BOOST_TEST ( sr1 [ pos2 ] != *p );
|
||||
}
|
||||
|
||||
BOOST_CHECK ( pos2 != pos1 );
|
||||
BOOST_TEST ( pos2 != pos1 );
|
||||
++p;
|
||||
}
|
||||
|
||||
@ -249,13 +254,13 @@ void to_string ( const char *arg ) {
|
||||
|
||||
str1.assign ( arg );
|
||||
sr1 = arg;
|
||||
// str2 = sr1.to_string<std::allocator<char> > ();
|
||||
// str2 = sr1.to_string<std::allocator<char> > ();
|
||||
str2 = sr1.to_string ();
|
||||
BOOST_CHECK ( str1 == str2 );
|
||||
BOOST_TEST ( str1 == str2 );
|
||||
|
||||
#ifndef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
|
||||
std::string str3 = static_cast<std::string> ( sr1 );
|
||||
BOOST_CHECK ( str1 == str3 );
|
||||
BOOST_TEST ( str1 == str3 );
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -266,28 +271,28 @@ void compare ( const char *arg ) {
|
||||
|
||||
str1.assign ( arg );
|
||||
sr1 = arg;
|
||||
BOOST_CHECK ( sr1 == sr1); // compare string_ref and string_ref
|
||||
BOOST_CHECK ( sr1 == str1); // compare string and string_ref
|
||||
BOOST_CHECK ( str1 == sr1 ); // compare string_ref and string
|
||||
BOOST_CHECK ( sr1 == arg ); // compare string_ref and pointer
|
||||
BOOST_CHECK ( arg == sr1 ); // compare pointer and string_ref
|
||||
BOOST_TEST ( sr1 == sr1); // compare string_ref and string_ref
|
||||
BOOST_TEST ( sr1 == str1); // compare string and string_ref
|
||||
BOOST_TEST ( str1 == sr1 ); // compare string_ref and string
|
||||
BOOST_TEST ( sr1 == arg ); // compare string_ref and pointer
|
||||
BOOST_TEST ( arg == sr1 ); // compare pointer and string_ref
|
||||
|
||||
if ( sr1.size () > 0 ) {
|
||||
(*str1.rbegin())++;
|
||||
BOOST_CHECK ( sr1 != str1 );
|
||||
BOOST_CHECK ( str1 != sr1 );
|
||||
BOOST_CHECK ( sr1 < str1 );
|
||||
BOOST_CHECK ( sr1 <= str1 );
|
||||
BOOST_CHECK ( str1 > sr1 );
|
||||
BOOST_CHECK ( str1 >= sr1 );
|
||||
BOOST_TEST ( sr1 != str1 );
|
||||
BOOST_TEST ( str1 != sr1 );
|
||||
BOOST_TEST ( sr1 < str1 );
|
||||
BOOST_TEST ( sr1 <= str1 );
|
||||
BOOST_TEST ( str1 > sr1 );
|
||||
BOOST_TEST ( str1 >= sr1 );
|
||||
|
||||
(*str1.rbegin()) -= 2;
|
||||
BOOST_CHECK ( sr1 != str1 );
|
||||
BOOST_CHECK ( str1 != sr1 );
|
||||
BOOST_CHECK ( sr1 > str1 );
|
||||
BOOST_CHECK ( sr1 >= str1 );
|
||||
BOOST_CHECK ( str1 < sr1 );
|
||||
BOOST_CHECK ( str1 <= sr1 );
|
||||
BOOST_TEST ( sr1 != str1 );
|
||||
BOOST_TEST ( str1 != sr1 );
|
||||
BOOST_TEST ( sr1 > str1 );
|
||||
BOOST_TEST ( sr1 >= str1 );
|
||||
BOOST_TEST ( str1 < sr1 );
|
||||
BOOST_TEST ( str1 <= sr1 );
|
||||
}
|
||||
}
|
||||
|
||||
@ -301,7 +306,7 @@ const char *test_strings [] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE( test_main )
|
||||
int main()
|
||||
{
|
||||
const char **p = &test_strings[0];
|
||||
|
||||
@ -315,4 +320,6 @@ BOOST_AUTO_TEST_CASE( test_main )
|
||||
|
||||
p++;
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@ -12,8 +12,6 @@
|
||||
* \brief This header contains tests for stream operations of \c basic_string_ref.
|
||||
*/
|
||||
|
||||
#define BOOST_TEST_MODULE string_ref_test_io
|
||||
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
|
||||
#include <iomanip>
|
||||
@ -23,23 +21,10 @@
|
||||
#include <string>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/mpl/vector.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
typedef boost::mpl::vector<
|
||||
char
|
||||
#if !defined(BOOST_NO_STD_WSTRING) && !defined(BOOST_NO_STD_WSTREAMBUF) && !defined(BOOST_NO_INTRINSIC_WCHAR_T)
|
||||
, wchar_t
|
||||
#endif
|
||||
/* Current implementations seem to be missing codecvt facets to convert chars to char16_t and char32_t even though the types are available.
|
||||
#if !defined(BOOST_NO_CXX11_CHAR16_T)
|
||||
, char16_t
|
||||
#endif
|
||||
#if !defined(BOOST_NO_CXX11_CHAR32_T)
|
||||
, char32_t
|
||||
#endif
|
||||
*/
|
||||
>::type char_types;
|
||||
|
||||
static const char* test_strings[] =
|
||||
{
|
||||
@ -72,7 +57,8 @@ struct context
|
||||
};
|
||||
|
||||
// Test regular output
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE(string_ref_output, CharT, char_types)
|
||||
template<class CharT>
|
||||
void test_string_ref_output()
|
||||
{
|
||||
typedef CharT char_type;
|
||||
typedef std::basic_ostringstream< char_type > ostream_type;
|
||||
@ -82,11 +68,12 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(string_ref_output, CharT, char_types)
|
||||
|
||||
ostream_type strm;
|
||||
strm << string_ref_type(ctx.abcd);
|
||||
BOOST_CHECK(strm.str() == ctx.abcd);
|
||||
BOOST_TEST(strm.str() == ctx.abcd);
|
||||
}
|
||||
|
||||
// Test support for padding
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE(padding, CharT, char_types)
|
||||
template<class CharT>
|
||||
void test_padding()
|
||||
{
|
||||
typedef CharT char_type;
|
||||
typedef std::basic_ostringstream< char_type > ostream_type;
|
||||
@ -102,7 +89,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(padding, CharT, char_types)
|
||||
ostream_type strm_correct;
|
||||
strm_correct << ctx.begin << std::setw(8) << ctx.abcd << ctx.end;
|
||||
|
||||
BOOST_CHECK(strm_ref.str() == strm_correct.str());
|
||||
BOOST_TEST(strm_ref.str() == strm_correct.str());
|
||||
}
|
||||
|
||||
// Test for long padding
|
||||
@ -113,7 +100,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(padding, CharT, char_types)
|
||||
ostream_type strm_correct;
|
||||
strm_correct << ctx.begin << std::setw(100) << ctx.abcd << ctx.end;
|
||||
|
||||
BOOST_CHECK(strm_ref.str() == strm_correct.str());
|
||||
BOOST_TEST(strm_ref.str() == strm_correct.str());
|
||||
}
|
||||
|
||||
// Test that short width does not truncate the string
|
||||
@ -124,12 +111,13 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(padding, CharT, char_types)
|
||||
ostream_type strm_correct;
|
||||
strm_correct << ctx.begin << std::setw(1) << ctx.abcd << ctx.end;
|
||||
|
||||
BOOST_CHECK(strm_ref.str() == strm_correct.str());
|
||||
BOOST_TEST(strm_ref.str() == strm_correct.str());
|
||||
}
|
||||
}
|
||||
|
||||
// Test support for padding fill
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE(padding_fill, CharT, char_types)
|
||||
template<class CharT>
|
||||
void test_padding_fill()
|
||||
{
|
||||
typedef CharT char_type;
|
||||
typedef std::basic_ostringstream< char_type > ostream_type;
|
||||
@ -143,11 +131,12 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(padding_fill, CharT, char_types)
|
||||
ostream_type strm_correct;
|
||||
strm_correct << ctx.begin << std::setfill(static_cast< char_type >('x')) << std::setw(8) << ctx.abcd << ctx.end;
|
||||
|
||||
BOOST_CHECK(strm_ref.str() == strm_correct.str());
|
||||
BOOST_TEST(strm_ref.str() == strm_correct.str());
|
||||
}
|
||||
|
||||
// Test support for alignment
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE(alignment, CharT, char_types)
|
||||
template<class CharT>
|
||||
void test_alignment()
|
||||
{
|
||||
typedef CharT char_type;
|
||||
typedef std::basic_ostringstream< char_type > ostream_type;
|
||||
@ -163,7 +152,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(alignment, CharT, char_types)
|
||||
ostream_type strm_correct;
|
||||
strm_correct << ctx.begin << std::left << std::setw(8) << ctx.abcd << ctx.end;
|
||||
|
||||
BOOST_CHECK(strm_ref.str() == strm_correct.str());
|
||||
BOOST_TEST(strm_ref.str() == strm_correct.str());
|
||||
}
|
||||
|
||||
// Right alignment
|
||||
@ -174,6 +163,22 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(alignment, CharT, char_types)
|
||||
ostream_type strm_correct;
|
||||
strm_correct << ctx.begin << std::right << std::setw(8) << ctx.abcd << ctx.end;
|
||||
|
||||
BOOST_CHECK(strm_ref.str() == strm_correct.str());
|
||||
BOOST_TEST(strm_ref.str() == strm_correct.str());
|
||||
}
|
||||
}
|
||||
|
||||
template<class CharT>
|
||||
void test()
|
||||
{
|
||||
test_string_ref_output<CharT>();
|
||||
test_padding<CharT>();
|
||||
test_padding_fill<CharT>();
|
||||
test_alignment<CharT>();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test<char>();
|
||||
test<wchar_t>();
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
115
test/string_view_constexpr_test1.cpp
Normal file
115
test/string_view_constexpr_test1.cpp
Normal file
@ -0,0 +1,115 @@
|
||||
/*
|
||||
Copyright (c) Marshall Clow 2017-2017.
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
For more information, see http://www.boost.org
|
||||
*/
|
||||
|
||||
#include <new> // for placement new
|
||||
#include <iostream>
|
||||
#include <cstddef> // for NULL, std::size_t, std::ptrdiff_t
|
||||
#include <cstring> // for std::strchr and std::strcmp
|
||||
#include <cstdlib> // for std::malloc and std::free
|
||||
#include <cstdio> // for EOF
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/utility/string_view.hpp>
|
||||
|
||||
#if __cplusplus >= 201402L
|
||||
struct constexpr_char_traits
|
||||
{
|
||||
typedef char char_type;
|
||||
typedef int int_type;
|
||||
typedef std::streamoff off_type;
|
||||
typedef std::streampos pos_type;
|
||||
typedef std::mbstate_t state_type;
|
||||
|
||||
static void assign(char_type& c1, const char_type& c2) noexcept { c1 = c2; }
|
||||
static constexpr bool eq(char_type c1, char_type c2) noexcept { return c1 == c2; }
|
||||
static constexpr bool lt(char_type c1, char_type c2) noexcept { return c1 < c2; }
|
||||
|
||||
static constexpr int compare(const char_type* s1, const char_type* s2, std::size_t n) noexcept;
|
||||
static constexpr std::size_t length(const char_type* s) noexcept;
|
||||
static constexpr const char_type* find(const char_type* s, std::size_t n, const char_type& a) noexcept;
|
||||
static constexpr char_type* move(char_type* s1, const char_type* s2, std::size_t n) noexcept;
|
||||
static constexpr char_type* copy(char_type* s1, const char_type* s2, std::size_t n) noexcept;
|
||||
static constexpr char_type* assign(char_type* s, std::size_t n, char_type a) noexcept;
|
||||
|
||||
static constexpr int_type not_eof(int_type c) noexcept { return eq_int_type(c, eof()) ? ~eof() : c; }
|
||||
static constexpr char_type to_char_type(int_type c) noexcept { return char_type(c); }
|
||||
static constexpr int_type to_int_type(char_type c) noexcept { return int_type(c); }
|
||||
static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept { return c1 == c2; }
|
||||
static constexpr int_type eof() noexcept { return EOF; }
|
||||
};
|
||||
|
||||
// yields:
|
||||
// 0 if for each i in [0,n), X::eq(s1[i],s2[i]) is true;
|
||||
// else, a negative value if, for some j in [0,n), X::lt(s1[j],s2[j]) is true and
|
||||
// for each i in [0,j) X::eq(s2[i],s2[i]) is true;
|
||||
// else a positive value.
|
||||
constexpr int constexpr_char_traits::compare(const char_type* s1, const char_type* s2, std::size_t n) noexcept
|
||||
{
|
||||
for (; n != 0; --n, ++s1, ++s2)
|
||||
{
|
||||
if (lt(*s1, *s2))
|
||||
return -1;
|
||||
if (lt(*s2, *s1))
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// yields: the smallest i such that X::eq(s[i],charT()) is true.
|
||||
constexpr std::size_t constexpr_char_traits::length(const char_type* s) noexcept
|
||||
{
|
||||
std::size_t len = 0;
|
||||
for (; !eq(*s, char_type(0)); ++s)
|
||||
++len;
|
||||
return len;
|
||||
}
|
||||
|
||||
typedef boost::basic_string_view<char, constexpr_char_traits> string_view;
|
||||
|
||||
int main()
|
||||
{
|
||||
constexpr string_view sv1;
|
||||
constexpr string_view sv2{"abc", 3}; // ptr, len
|
||||
constexpr string_view sv3{"def"}; // ptr
|
||||
|
||||
constexpr const char *s1 = "";
|
||||
constexpr const char *s2 = "abc";
|
||||
|
||||
static_assert( (sv1 == sv1), "" );
|
||||
|
||||
static_assert(!(sv1 == sv2), "" );
|
||||
static_assert( (sv1 != sv2), "" );
|
||||
static_assert( (sv1 < sv2), "" );
|
||||
static_assert( (sv1 <= sv2), "" );
|
||||
static_assert(!(sv1 > sv2), "" );
|
||||
static_assert(!(sv1 >= sv2), "" );
|
||||
|
||||
static_assert(!(s1 == sv2), "" );
|
||||
static_assert( (s1 != sv2), "" );
|
||||
static_assert( (s1 < sv2), "" );
|
||||
static_assert( (s1 <= sv2), "" );
|
||||
static_assert(!(s1 > sv2), "" );
|
||||
static_assert(!(s1 >= sv2), "" );
|
||||
|
||||
static_assert(!(sv1 == s2), "" );
|
||||
static_assert( (sv1 != s2), "" );
|
||||
static_assert( (sv1 < s2), "" );
|
||||
static_assert( (sv1 <= s2), "" );
|
||||
static_assert(!(sv1 > s2), "" );
|
||||
static_assert(!(sv1 >= s2), "" );
|
||||
|
||||
static_assert( sv1.compare(sv2) < 0, "" );
|
||||
static_assert( sv1.compare(sv1) == 0, "" );
|
||||
static_assert( sv3.compare(sv1) > 0, "" );
|
||||
|
||||
static_assert( sv1.compare(s2) < 0, "" );
|
||||
static_assert( sv1.compare(s1) == 0, "" );
|
||||
static_assert( sv3.compare(s1) > 0, "" );
|
||||
}
|
||||
#endif
|
26
test/string_view_from_rvalue.cpp
Normal file
26
test/string_view_from_rvalue.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
Copyright (c) Marshall Clow 2017.
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
For more information, see http://www.boost.org
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
#include <boost/utility/string_view.hpp>
|
||||
|
||||
#if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) || defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
|
||||
#error "Unsupported test"
|
||||
#endif
|
||||
|
||||
std::string makeatemp() { return "abc"; }
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::basic_string_view<char> sv(makeatemp());
|
||||
return 0;
|
||||
}
|
@ -7,23 +7,24 @@
|
||||
For more information, see http://www.boost.org
|
||||
*/
|
||||
|
||||
#include <cstddef>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
#include <boost/utility/string_view.hpp>
|
||||
#include <boost/container_hash/hash.hpp>
|
||||
|
||||
#define BOOST_TEST_MAIN
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
typedef boost::string_view string_view;
|
||||
|
||||
// Should be equal
|
||||
void interop ( const std::string &str, string_view ref ) {
|
||||
// BOOST_CHECK ( str == ref );
|
||||
BOOST_CHECK ( str.size () == ref.size ());
|
||||
BOOST_CHECK ( std::equal ( str.begin (), str.end (), ref.begin ()));
|
||||
BOOST_CHECK ( std::equal ( str.rbegin (), str.rend (), ref.rbegin ()));
|
||||
// BOOST_TEST ( str == ref );
|
||||
BOOST_TEST ( str.size () == ref.size ());
|
||||
BOOST_TEST ( std::equal ( str.begin (), str.end (), ref.begin ()));
|
||||
BOOST_TEST ( std::equal ( str.rbegin (), str.rend (), ref.rbegin ()));
|
||||
}
|
||||
|
||||
void null_tests ( const char *p ) {
|
||||
@ -34,38 +35,38 @@ void null_tests ( const char *p ) {
|
||||
string_view sr4 ( p );
|
||||
sr4.clear ();
|
||||
|
||||
BOOST_CHECK ( sr1 == sr2 );
|
||||
BOOST_CHECK ( sr1 == sr3 );
|
||||
BOOST_CHECK ( sr2 == sr3 );
|
||||
BOOST_CHECK ( sr1 == sr4 );
|
||||
BOOST_TEST ( sr1 == sr2 );
|
||||
BOOST_TEST ( sr1 == sr3 );
|
||||
BOOST_TEST ( sr2 == sr3 );
|
||||
BOOST_TEST ( sr1 == sr4 );
|
||||
}
|
||||
|
||||
// make sure that substrings work just like strings
|
||||
void test_substr ( const std::string &str ) {
|
||||
const size_t sz = str.size ();
|
||||
const std::size_t sz = str.size ();
|
||||
string_view ref ( str );
|
||||
|
||||
// Substrings at the end
|
||||
for ( size_t i = 0; i <= sz; ++ i )
|
||||
for ( std::size_t i = 0; i <= sz; ++ i )
|
||||
interop ( str.substr ( i ), ref.substr ( i ));
|
||||
|
||||
// Substrings at the beginning
|
||||
for ( size_t i = 0; i <= sz; ++ i )
|
||||
for ( std::size_t i = 0; i <= sz; ++ i )
|
||||
interop ( str.substr ( 0, i ), ref.substr ( 0, i ));
|
||||
|
||||
// All possible substrings
|
||||
for ( size_t i = 0; i < sz; ++i )
|
||||
for ( size_t j = i; j < sz; ++j )
|
||||
for ( std::size_t i = 0; i < sz; ++i )
|
||||
for ( std::size_t j = i; j < sz; ++j )
|
||||
interop ( str.substr ( i, j ), ref.substr ( i, j ));
|
||||
}
|
||||
|
||||
// make sure that removing prefixes and suffixes work just like strings
|
||||
void test_remove ( const std::string &str ) {
|
||||
const size_t sz = str.size ();
|
||||
const std::size_t sz = str.size ();
|
||||
std::string work;
|
||||
string_view ref;
|
||||
|
||||
for ( size_t i = 1; i <= sz; ++i ) {
|
||||
for ( std::size_t i = 1; i <= sz; ++i ) {
|
||||
work = str;
|
||||
ref = str;
|
||||
while ( ref.size () >= i ) {
|
||||
@ -75,7 +76,7 @@ void test_remove ( const std::string &str ) {
|
||||
}
|
||||
}
|
||||
|
||||
for ( size_t i = 1; i < sz; ++ i ) {
|
||||
for ( std::size_t i = 1; i < sz; ++ i ) {
|
||||
work = str;
|
||||
ref = str;
|
||||
while ( ref.size () >= i ) {
|
||||
@ -86,6 +87,14 @@ void test_remove ( const std::string &str ) {
|
||||
}
|
||||
}
|
||||
|
||||
void test_hash(const std::string& str) {
|
||||
string_view ref = str;
|
||||
BOOST_TEST(boost::hash_value(ref) == boost::hash_value(str));
|
||||
boost::hash<std::string> hstr;
|
||||
boost::hash<string_view> hsv;
|
||||
BOOST_TEST(hsv(ref) == hstr(str));
|
||||
}
|
||||
|
||||
const char *test_strings [] = {
|
||||
"",
|
||||
"1",
|
||||
@ -94,7 +103,7 @@ const char *test_strings [] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE( test_main )
|
||||
int main()
|
||||
{
|
||||
const char **p = &test_strings[0];
|
||||
|
||||
@ -103,7 +112,10 @@ BOOST_AUTO_TEST_CASE( test_main )
|
||||
test_substr ( *p );
|
||||
test_remove ( *p );
|
||||
null_tests ( *p );
|
||||
test_hash( *p );
|
||||
|
||||
p++;
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@ -8,71 +8,99 @@
|
||||
*/
|
||||
|
||||
#include <new> // for placement new
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <algorithm> // for std::equal
|
||||
#include <cstddef> // for NULL, std::size_t, std::ptrdiff_t
|
||||
#include <cstring> // for std::strchr and std::strcmp
|
||||
#include <cstring> // for std::strlen, std::strchr and std::strcmp
|
||||
#include <cstdlib> // for std::malloc and std::free
|
||||
|
||||
#include <boost/utility/string_view.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#define BOOST_TEST_MAIN
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
typedef boost::string_view string_view;
|
||||
|
||||
void ends_with ( const char *arg ) {
|
||||
const size_t sz = std::strlen ( arg );
|
||||
const std::size_t sz = std::strlen ( arg );
|
||||
string_view sr ( arg );
|
||||
string_view sr2 ( arg );
|
||||
const char *p = arg;
|
||||
|
||||
while ( *p ) {
|
||||
BOOST_CHECK ( sr.ends_with ( p ));
|
||||
BOOST_TEST ( sr.ends_with ( p ));
|
||||
++p;
|
||||
}
|
||||
|
||||
while ( !sr2.empty ()) {
|
||||
BOOST_CHECK ( sr.ends_with ( sr2 ));
|
||||
BOOST_TEST ( sr.ends_with ( sr2 ));
|
||||
sr2.remove_prefix (1);
|
||||
}
|
||||
|
||||
sr2 = arg;
|
||||
while ( !sr2.empty ()) {
|
||||
BOOST_CHECK ( sr.ends_with ( sr2 ));
|
||||
BOOST_TEST ( sr.ends_with ( sr2 ));
|
||||
sr2.remove_prefix (1);
|
||||
}
|
||||
|
||||
char ch = sz == 0 ? '\0' : arg [ sz - 1 ];
|
||||
sr2 = arg;
|
||||
if ( sz > 0 )
|
||||
BOOST_CHECK ( sr2.ends_with ( ch ));
|
||||
BOOST_CHECK ( !sr2.ends_with ( ++ch ));
|
||||
BOOST_CHECK ( sr2.ends_with ( string_view()));
|
||||
BOOST_TEST ( sr2.ends_with ( ch ));
|
||||
BOOST_TEST ( !sr2.ends_with ( ++ch ));
|
||||
BOOST_TEST ( sr2.ends_with ( string_view()));
|
||||
}
|
||||
|
||||
void starts_with ( const char *arg ) {
|
||||
const size_t sz = std::strlen ( arg );
|
||||
const std::size_t sz = std::strlen ( arg );
|
||||
string_view sr ( arg );
|
||||
string_view sr2 ( arg );
|
||||
const char *p = arg + std::strlen ( arg ) - 1;
|
||||
while ( p >= arg ) {
|
||||
std::string foo ( arg, p + 1 );
|
||||
BOOST_CHECK ( sr.starts_with ( foo ));
|
||||
--p;
|
||||
std::string foo ( arg );
|
||||
while ( !foo.empty ()) {
|
||||
BOOST_TEST ( sr.starts_with ( foo ));
|
||||
foo.erase ( foo.end () - 1 );
|
||||
}
|
||||
|
||||
while ( !sr2.empty ()) {
|
||||
BOOST_CHECK ( sr.starts_with ( sr2 ));
|
||||
BOOST_TEST ( sr.starts_with ( sr2 ));
|
||||
sr2.remove_suffix (1);
|
||||
}
|
||||
|
||||
char ch = *arg;
|
||||
sr2 = arg;
|
||||
if ( sz > 0 )
|
||||
BOOST_CHECK ( sr2.starts_with ( ch ));
|
||||
BOOST_CHECK ( !sr2.starts_with ( ++ch ));
|
||||
BOOST_CHECK ( sr2.starts_with ( string_view ()));
|
||||
if ( sz > 0 )
|
||||
BOOST_TEST ( sr2.starts_with ( ch ));
|
||||
BOOST_TEST ( !sr2.starts_with ( ++ch ));
|
||||
BOOST_TEST ( sr2.starts_with ( string_view ()));
|
||||
}
|
||||
|
||||
void contains ( const char *arg ) {
|
||||
const std::size_t sz = std::strlen ( arg );
|
||||
string_view sr ( arg );
|
||||
string_view sr2 ( arg );
|
||||
std::string foo ( arg );
|
||||
while ( !foo.empty ()) {
|
||||
BOOST_TEST ( sr.contains ( foo ));
|
||||
if ( ( foo.size () & 1u ) != 0u )
|
||||
foo.erase ( foo.end () - 1 );
|
||||
else
|
||||
foo.erase ( foo.begin () );
|
||||
}
|
||||
|
||||
while ( !sr2.empty ()) {
|
||||
BOOST_TEST ( sr.contains ( sr2 ));
|
||||
if ( ( sr2.size () & 1u ) != 0u )
|
||||
sr2.remove_suffix (1);
|
||||
else
|
||||
sr2.remove_prefix (1);
|
||||
}
|
||||
|
||||
sr2 = arg;
|
||||
for ( std::size_t i = 0; i < sz; ++i )
|
||||
BOOST_TEST ( sr2.contains ( arg[i] ));
|
||||
BOOST_TEST ( !sr2.contains ( '\a' ));
|
||||
BOOST_TEST ( sr2.contains ( string_view ()));
|
||||
}
|
||||
|
||||
void reverse ( const char *arg ) {
|
||||
@ -82,14 +110,14 @@ void reverse ( const char *arg ) {
|
||||
string_view sr2 ( string1 );
|
||||
std::string string2 ( sr2.rbegin (), sr2.rend ());
|
||||
|
||||
BOOST_CHECK ( std::equal ( sr2.rbegin (), sr2.rend (), arg ));
|
||||
BOOST_CHECK ( string2 == arg );
|
||||
BOOST_CHECK ( std::equal ( sr1.begin (), sr1.end (), string2.begin ()));
|
||||
BOOST_TEST ( std::equal ( sr2.rbegin (), sr2.rend (), arg ));
|
||||
BOOST_TEST ( string2 == arg );
|
||||
BOOST_TEST ( std::equal ( sr1.begin (), sr1.end (), string2.begin ()));
|
||||
}
|
||||
|
||||
// This helper function eliminates signed vs. unsigned warnings
|
||||
string_view::size_type ptr_diff ( const char *res, const char *base ) {
|
||||
BOOST_CHECK ( res >= base );
|
||||
BOOST_TEST ( res >= base );
|
||||
return static_cast<string_view::size_type> ( res - base );
|
||||
}
|
||||
|
||||
@ -98,12 +126,16 @@ void find ( const char *arg ) {
|
||||
string_view sr2;
|
||||
const char *p;
|
||||
|
||||
// When we search for the empty string, we find it at position 0
|
||||
BOOST_TEST ( sr1.find (sr2) == 0 );
|
||||
BOOST_TEST ( sr1.rfind(sr2) == 0 );
|
||||
|
||||
// Look for each character in the string(searching from the start)
|
||||
p = arg;
|
||||
sr1 = arg;
|
||||
while ( *p ) {
|
||||
string_view::size_type pos = sr1.find(*p);
|
||||
BOOST_CHECK ( pos != string_view::npos && ( pos <= ptr_diff ( p, arg )));
|
||||
BOOST_TEST ( pos != string_view::npos && ( pos <= ptr_diff ( p, arg )));
|
||||
++p;
|
||||
}
|
||||
|
||||
@ -112,7 +144,7 @@ void find ( const char *arg ) {
|
||||
sr1 = arg;
|
||||
while ( *p ) {
|
||||
string_view::size_type pos = sr1.rfind(*p);
|
||||
BOOST_CHECK ( pos != string_view::npos && pos < sr1.size () && ( pos >= ptr_diff ( p, arg )));
|
||||
BOOST_TEST ( pos != string_view::npos && pos < sr1.size () && ( pos >= ptr_diff ( p, arg )));
|
||||
++p;
|
||||
}
|
||||
|
||||
@ -122,7 +154,7 @@ void find ( const char *arg ) {
|
||||
while ( *p && *(p+1)) {
|
||||
string_view sr3 ( p, 2 );
|
||||
string_view::size_type pos = sr1.find ( sr3 );
|
||||
BOOST_CHECK ( pos != string_view::npos && pos <= static_cast<string_view::size_type>( p - arg ));
|
||||
BOOST_TEST ( pos != string_view::npos && pos <= static_cast<string_view::size_type>( p - arg ));
|
||||
p++;
|
||||
}
|
||||
|
||||
@ -133,9 +165,9 @@ void find ( const char *arg ) {
|
||||
for ( int ch = 1; ch < 256; ++ch ) {
|
||||
string_view::size_type pos = sr1.find(ch);
|
||||
const char *strp = std::strchr ( arg, ch );
|
||||
BOOST_CHECK (( strp == NULL ) == ( pos == string_view::npos ));
|
||||
BOOST_TEST (( strp == NULL ) == ( pos == string_view::npos ));
|
||||
if ( strp != NULL )
|
||||
BOOST_CHECK ( ptr_diff ( strp, arg ) == pos );
|
||||
BOOST_TEST ( ptr_diff ( strp, arg ) == pos );
|
||||
}
|
||||
|
||||
sr1 = arg;
|
||||
@ -145,9 +177,9 @@ void find ( const char *arg ) {
|
||||
for ( int ch = 1; ch < 256; ++ch ) {
|
||||
string_view::size_type pos = sr1.rfind(ch);
|
||||
const char *strp = std::strrchr ( arg, ch );
|
||||
BOOST_CHECK (( strp == NULL ) == ( pos == string_view::npos ));
|
||||
BOOST_TEST (( strp == NULL ) == ( pos == string_view::npos ));
|
||||
if ( strp != NULL )
|
||||
BOOST_CHECK ( ptr_diff ( strp, arg ) == pos );
|
||||
BOOST_TEST ( ptr_diff ( strp, arg ) == pos );
|
||||
}
|
||||
|
||||
|
||||
@ -156,7 +188,7 @@ void find ( const char *arg ) {
|
||||
sr1 = arg;
|
||||
while ( !sr1.empty ()) {
|
||||
string_view::size_type pos = sr1.find(*p);
|
||||
BOOST_CHECK ( pos == 0 );
|
||||
BOOST_TEST ( pos == 0 );
|
||||
sr1.remove_prefix (1);
|
||||
++p;
|
||||
}
|
||||
@ -166,7 +198,7 @@ void find ( const char *arg ) {
|
||||
p = arg + std::strlen ( arg ) - 1;
|
||||
while ( !sr1.empty ()) {
|
||||
string_view::size_type pos = sr1.rfind(*p);
|
||||
BOOST_CHECK ( pos == sr1.size () - 1 );
|
||||
BOOST_TEST ( pos == sr1.size () - 1 );
|
||||
sr1.remove_suffix (1);
|
||||
--p;
|
||||
}
|
||||
@ -176,7 +208,7 @@ void find ( const char *arg ) {
|
||||
p = arg;
|
||||
while ( !sr1.empty ()) {
|
||||
string_view::size_type pos = sr1.find_first_of(*p);
|
||||
BOOST_CHECK ( pos == 0 );
|
||||
BOOST_TEST ( pos == 0 );
|
||||
sr1.remove_prefix (1);
|
||||
++p;
|
||||
}
|
||||
@ -187,7 +219,7 @@ void find ( const char *arg ) {
|
||||
p = arg + std::strlen ( arg ) - 1;
|
||||
while ( !sr1.empty ()) {
|
||||
string_view::size_type pos = sr1.find_last_of(*p);
|
||||
BOOST_CHECK ( pos == sr1.size () - 1 );
|
||||
BOOST_TEST ( pos == sr1.size () - 1 );
|
||||
sr1.remove_suffix (1);
|
||||
--p;
|
||||
}
|
||||
@ -196,8 +228,8 @@ void find ( const char *arg ) {
|
||||
sr1 = arg;
|
||||
sr2 = arg;
|
||||
while ( !sr1.empty() ) {
|
||||
BOOST_CHECK ( sr1.find_first_of ( sr2 ) == 0 );
|
||||
BOOST_CHECK ( sr1.find_first_not_of ( sr2 ) == string_view::npos );
|
||||
BOOST_TEST ( sr1.find_first_of ( sr2 ) == 0 );
|
||||
BOOST_TEST ( sr1.find_first_not_of ( sr2 ) == string_view::npos );
|
||||
sr1.remove_prefix ( 1 );
|
||||
}
|
||||
|
||||
@ -206,14 +238,14 @@ void find ( const char *arg ) {
|
||||
while ( *p ) {
|
||||
string_view::size_type pos1 = sr1.find_first_of(*p);
|
||||
string_view::size_type pos2 = sr1.find_first_not_of(*p);
|
||||
BOOST_CHECK ( pos1 != string_view::npos && pos1 < sr1.size () && pos1 <= ptr_diff ( p, arg ));
|
||||
BOOST_TEST ( pos1 != string_view::npos && pos1 < sr1.size () && pos1 <= ptr_diff ( p, arg ));
|
||||
if ( pos2 != string_view::npos ) {
|
||||
for ( size_t i = 0 ; i < pos2; ++i )
|
||||
BOOST_CHECK ( sr1[i] == *p );
|
||||
BOOST_CHECK ( sr1 [ pos2 ] != *p );
|
||||
for ( string_view::size_type i = 0 ; i < pos2; ++i )
|
||||
BOOST_TEST ( sr1[i] == *p );
|
||||
BOOST_TEST ( sr1 [ pos2 ] != *p );
|
||||
}
|
||||
|
||||
BOOST_CHECK ( pos2 != pos1 );
|
||||
BOOST_TEST ( pos2 != pos1 );
|
||||
++p;
|
||||
}
|
||||
|
||||
@ -221,8 +253,8 @@ void find ( const char *arg ) {
|
||||
sr1 = arg;
|
||||
sr2 = arg;
|
||||
while ( !sr1.empty() ) {
|
||||
BOOST_CHECK ( sr1.find_last_of ( sr2 ) == ( sr1.size () - 1 ));
|
||||
BOOST_CHECK ( sr1.find_last_not_of ( sr2 ) == string_view::npos );
|
||||
BOOST_TEST ( sr1.find_last_of ( sr2 ) == ( sr1.size () - 1 ));
|
||||
BOOST_TEST ( sr1.find_last_not_of ( sr2 ) == string_view::npos );
|
||||
sr1.remove_suffix ( 1 );
|
||||
}
|
||||
|
||||
@ -231,15 +263,15 @@ void find ( const char *arg ) {
|
||||
while ( *p ) {
|
||||
string_view::size_type pos1 = sr1.find_last_of(*p);
|
||||
string_view::size_type pos2 = sr1.find_last_not_of(*p);
|
||||
BOOST_CHECK ( pos1 != string_view::npos && pos1 < sr1.size () && pos1 >= ptr_diff ( p, arg ));
|
||||
BOOST_CHECK ( pos2 == string_view::npos || pos1 < sr1.size ());
|
||||
BOOST_TEST ( pos1 != string_view::npos && pos1 < sr1.size () && pos1 >= ptr_diff ( p, arg ));
|
||||
BOOST_TEST ( pos2 == string_view::npos || pos1 < sr1.size ());
|
||||
if ( pos2 != string_view::npos ) {
|
||||
for ( size_t i = sr1.size () -1 ; i > pos2; --i )
|
||||
BOOST_CHECK ( sr1[i] == *p );
|
||||
BOOST_CHECK ( sr1 [ pos2 ] != *p );
|
||||
for ( string_view::size_type i = sr1.size () -1 ; i > pos2; --i )
|
||||
BOOST_TEST ( sr1[i] == *p );
|
||||
BOOST_TEST ( sr1 [ pos2 ] != *p );
|
||||
}
|
||||
|
||||
BOOST_CHECK ( pos2 != pos1 );
|
||||
BOOST_TEST ( pos2 != pos1 );
|
||||
++p;
|
||||
}
|
||||
|
||||
@ -335,14 +367,14 @@ void to_string ( const char *arg ) {
|
||||
sr1 = arg;
|
||||
// str2 = sr1.to_string<std::allocator<char> > ();
|
||||
str2 = sr1.to_string ();
|
||||
BOOST_CHECK ( str1 == str2 );
|
||||
BOOST_TEST ( str1 == str2 );
|
||||
|
||||
std::basic_string<char, std::char_traits<char>, custom_allocator<char> > str3 = sr1.to_string(custom_allocator<char>());
|
||||
BOOST_CHECK ( std::strcmp(str1.c_str(), str3.c_str()) == 0 );
|
||||
BOOST_TEST ( std::strcmp(str1.c_str(), str3.c_str()) == 0 );
|
||||
|
||||
#ifndef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
|
||||
std::string str4 = static_cast<std::string> ( sr1 );
|
||||
BOOST_CHECK ( str1 == str4 );
|
||||
BOOST_TEST ( str1 == str4 );
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -353,28 +385,28 @@ void compare ( const char *arg ) {
|
||||
|
||||
str1.assign ( arg );
|
||||
sr1 = arg;
|
||||
BOOST_CHECK ( sr1 == sr1); // compare string_view and string_view
|
||||
BOOST_CHECK ( sr1 == str1); // compare string and string_view
|
||||
BOOST_CHECK ( str1 == sr1 ); // compare string_view and string
|
||||
BOOST_CHECK ( sr1 == arg ); // compare string_view and pointer
|
||||
BOOST_CHECK ( arg == sr1 ); // compare pointer and string_view
|
||||
BOOST_TEST ( sr1 == sr1); // compare string_view and string_view
|
||||
BOOST_TEST ( sr1 == str1); // compare string and string_view
|
||||
BOOST_TEST ( str1 == sr1 ); // compare string_view and string
|
||||
BOOST_TEST ( sr1 == arg ); // compare string_view and pointer
|
||||
BOOST_TEST ( arg == sr1 ); // compare pointer and string_view
|
||||
|
||||
if ( sr1.size () > 0 ) {
|
||||
(*str1.rbegin())++;
|
||||
BOOST_CHECK ( sr1 != str1 );
|
||||
BOOST_CHECK ( str1 != sr1 );
|
||||
BOOST_CHECK ( sr1 < str1 );
|
||||
BOOST_CHECK ( sr1 <= str1 );
|
||||
BOOST_CHECK ( str1 > sr1 );
|
||||
BOOST_CHECK ( str1 >= sr1 );
|
||||
BOOST_TEST ( sr1 != str1 );
|
||||
BOOST_TEST ( str1 != sr1 );
|
||||
BOOST_TEST ( sr1 < str1 );
|
||||
BOOST_TEST ( sr1 <= str1 );
|
||||
BOOST_TEST ( str1 > sr1 );
|
||||
BOOST_TEST ( str1 >= sr1 );
|
||||
|
||||
(*str1.rbegin()) -= 2;
|
||||
BOOST_CHECK ( sr1 != str1 );
|
||||
BOOST_CHECK ( str1 != sr1 );
|
||||
BOOST_CHECK ( sr1 > str1 );
|
||||
BOOST_CHECK ( sr1 >= str1 );
|
||||
BOOST_CHECK ( str1 < sr1 );
|
||||
BOOST_CHECK ( str1 <= sr1 );
|
||||
BOOST_TEST ( sr1 != str1 );
|
||||
BOOST_TEST ( str1 != sr1 );
|
||||
BOOST_TEST ( sr1 > str1 );
|
||||
BOOST_TEST ( sr1 >= str1 );
|
||||
BOOST_TEST ( str1 < sr1 );
|
||||
BOOST_TEST ( str1 <= sr1 );
|
||||
}
|
||||
}
|
||||
|
||||
@ -388,18 +420,21 @@ const char *test_strings [] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE( test_main )
|
||||
int main()
|
||||
{
|
||||
const char **p = &test_strings[0];
|
||||
|
||||
while ( *p != NULL ) {
|
||||
starts_with ( *p );
|
||||
ends_with ( *p );
|
||||
contains ( *p );
|
||||
reverse ( *p );
|
||||
find ( *p );
|
||||
to_string ( *p );
|
||||
compare ( *p );
|
||||
|
||||
p++;
|
||||
++p;
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@ -12,8 +12,6 @@
|
||||
* \brief This header contains tests for stream operations of \c basic_string_ref.
|
||||
*/
|
||||
|
||||
#define BOOST_TEST_MODULE string_ref_test_io
|
||||
|
||||
#include <boost/utility/string_view.hpp>
|
||||
|
||||
#include <iomanip>
|
||||
@ -23,23 +21,10 @@
|
||||
#include <string>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/mpl/vector.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
typedef boost::mpl::vector<
|
||||
char
|
||||
#if !defined(BOOST_NO_STD_WSTRING) && !defined(BOOST_NO_STD_WSTREAMBUF) && !defined(BOOST_NO_INTRINSIC_WCHAR_T)
|
||||
, wchar_t
|
||||
#endif
|
||||
/* Current implementations seem to be missing codecvt facets to convert chars to char16_t and char32_t even though the types are available.
|
||||
#if !defined(BOOST_NO_CXX11_CHAR16_T)
|
||||
, char16_t
|
||||
#endif
|
||||
#if !defined(BOOST_NO_CXX11_CHAR32_T)
|
||||
, char32_t
|
||||
#endif
|
||||
*/
|
||||
>::type char_types;
|
||||
|
||||
static const char* test_strings[] =
|
||||
{
|
||||
@ -72,7 +57,8 @@ struct context
|
||||
};
|
||||
|
||||
// Test regular output
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE(string_view_output, CharT, char_types)
|
||||
template<class CharT>
|
||||
void test_string_view_output()
|
||||
{
|
||||
typedef CharT char_type;
|
||||
typedef std::basic_ostringstream< char_type > ostream_type;
|
||||
@ -82,11 +68,12 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(string_view_output, CharT, char_types)
|
||||
|
||||
ostream_type strm;
|
||||
strm << string_view_type(ctx.abcd);
|
||||
BOOST_CHECK(strm.str() == ctx.abcd);
|
||||
BOOST_TEST(strm.str() == ctx.abcd);
|
||||
}
|
||||
|
||||
// Test support for padding
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE(padding, CharT, char_types)
|
||||
template<class CharT>
|
||||
void test_padding()
|
||||
{
|
||||
typedef CharT char_type;
|
||||
typedef std::basic_ostringstream< char_type > ostream_type;
|
||||
@ -102,7 +89,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(padding, CharT, char_types)
|
||||
ostream_type strm_correct;
|
||||
strm_correct << ctx.begin << std::setw(8) << ctx.abcd << ctx.end;
|
||||
|
||||
BOOST_CHECK(strm_ref.str() == strm_correct.str());
|
||||
BOOST_TEST(strm_ref.str() == strm_correct.str());
|
||||
}
|
||||
|
||||
// Test for long padding
|
||||
@ -113,7 +100,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(padding, CharT, char_types)
|
||||
ostream_type strm_correct;
|
||||
strm_correct << ctx.begin << std::setw(100) << ctx.abcd << ctx.end;
|
||||
|
||||
BOOST_CHECK(strm_ref.str() == strm_correct.str());
|
||||
BOOST_TEST(strm_ref.str() == strm_correct.str());
|
||||
}
|
||||
|
||||
// Test that short width does not truncate the string
|
||||
@ -124,12 +111,13 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(padding, CharT, char_types)
|
||||
ostream_type strm_correct;
|
||||
strm_correct << ctx.begin << std::setw(1) << ctx.abcd << ctx.end;
|
||||
|
||||
BOOST_CHECK(strm_ref.str() == strm_correct.str());
|
||||
BOOST_TEST(strm_ref.str() == strm_correct.str());
|
||||
}
|
||||
}
|
||||
|
||||
// Test support for padding fill
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE(padding_fill, CharT, char_types)
|
||||
template<class CharT>
|
||||
void test_padding_fill()
|
||||
{
|
||||
typedef CharT char_type;
|
||||
typedef std::basic_ostringstream< char_type > ostream_type;
|
||||
@ -143,11 +131,12 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(padding_fill, CharT, char_types)
|
||||
ostream_type strm_correct;
|
||||
strm_correct << ctx.begin << std::setfill(static_cast< char_type >('x')) << std::setw(8) << ctx.abcd << ctx.end;
|
||||
|
||||
BOOST_CHECK(strm_ref.str() == strm_correct.str());
|
||||
BOOST_TEST(strm_ref.str() == strm_correct.str());
|
||||
}
|
||||
|
||||
// Test support for alignment
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE(alignment, CharT, char_types)
|
||||
template<class CharT>
|
||||
void test_alignment()
|
||||
{
|
||||
typedef CharT char_type;
|
||||
typedef std::basic_ostringstream< char_type > ostream_type;
|
||||
@ -163,7 +152,7 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(alignment, CharT, char_types)
|
||||
ostream_type strm_correct;
|
||||
strm_correct << ctx.begin << std::left << std::setw(8) << ctx.abcd << ctx.end;
|
||||
|
||||
BOOST_CHECK(strm_ref.str() == strm_correct.str());
|
||||
BOOST_TEST(strm_ref.str() == strm_correct.str());
|
||||
}
|
||||
|
||||
// Right alignment
|
||||
@ -174,6 +163,22 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(alignment, CharT, char_types)
|
||||
ostream_type strm_correct;
|
||||
strm_correct << ctx.begin << std::right << std::setw(8) << ctx.abcd << ctx.end;
|
||||
|
||||
BOOST_CHECK(strm_ref.str() == strm_correct.str());
|
||||
BOOST_TEST(strm_ref.str() == strm_correct.str());
|
||||
}
|
||||
}
|
||||
|
||||
template<class CharT>
|
||||
void test()
|
||||
{
|
||||
test_string_view_output<CharT>();
|
||||
test_padding<CharT>();
|
||||
test_padding_fill<CharT>();
|
||||
test_alignment<CharT>();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test<char>();
|
||||
test<wchar_t>();
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@ -16,13 +16,14 @@
|
||||
#include <string>
|
||||
|
||||
#include "boost/utility/value_init.hpp"
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#ifdef BOOST_BORLANDC
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/core/invoke_swap.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/config/workaround.hpp>
|
||||
|
||||
//
|
||||
// Sample POD type
|
||||
@ -218,8 +219,8 @@ void check_initialized_value ( T const& y )
|
||||
BOOST_TEST ( y == initializedValue ) ;
|
||||
}
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#if __BORLANDC__ == 0x582
|
||||
#ifdef BOOST_BORLANDC
|
||||
#if BOOST_BORLANDC == 0x582
|
||||
void check_initialized_value( NonPOD const& )
|
||||
{
|
||||
// The initialized_value check is skipped for Borland 5.82
|
||||
@ -270,9 +271,12 @@ bool test ( T const& y, T const& z )
|
||||
boost::value_initialized<T> copy2;
|
||||
copy2 = x;
|
||||
BOOST_TEST ( boost::get(copy2) == boost::get(x) ) ;
|
||||
|
||||
boost::shared_ptr<boost::value_initialized<T> > ptr( new boost::value_initialized<T> );
|
||||
BOOST_TEST ( y == *ptr ) ;
|
||||
|
||||
{
|
||||
boost::value_initialized<T> * ptr = new boost::value_initialized<T>;
|
||||
BOOST_TEST ( y == *ptr ) ;
|
||||
delete ptr;
|
||||
}
|
||||
|
||||
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||
boost::value_initialized<T const> cx ;
|
||||
@ -287,7 +291,7 @@ bool test ( T const& y, T const& z )
|
||||
return boost::detail::test_errors() == errors_before_test ;
|
||||
}
|
||||
|
||||
int main(int, char **)
|
||||
int main()
|
||||
{
|
||||
BOOST_TEST ( test( 0,1234 ) ) ;
|
||||
BOOST_TEST ( test( 0.0,12.34 ) ) ;
|
||||
@ -357,7 +361,7 @@ int main(int, char **)
|
||||
boost::value_initialized<SwapFunctionCallTester> swapFunctionCallTester2;
|
||||
get(swapFunctionCallTester1).data = 1;
|
||||
get(swapFunctionCallTester2).data = 2;
|
||||
boost::swap(swapFunctionCallTester1, swapFunctionCallTester2);
|
||||
boost::core::invoke_swap(swapFunctionCallTester1, swapFunctionCallTester2);
|
||||
BOOST_TEST( get(swapFunctionCallTester1).data == 2 );
|
||||
BOOST_TEST( get(swapFunctionCallTester2).data == 1 );
|
||||
BOOST_TEST( get(swapFunctionCallTester1).is_custom_swap_called );
|
169
test/value_init_test2.cpp
Normal file
169
test/value_init_test2.cpp
Normal file
@ -0,0 +1,169 @@
|
||||
// Copyright 2010, Niels Dekker.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// Test program for the boost::value_initialized<T> workaround.
|
||||
//
|
||||
// 17 June 2010 (Created) Niels Dekker
|
||||
|
||||
#include <boost/utility/value_init.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/config/workaround.hpp>
|
||||
#include <iostream>
|
||||
|
||||
namespace
|
||||
{
|
||||
struct empty_struct
|
||||
{
|
||||
};
|
||||
|
||||
// A POD aggregate struct derived from an empty struct.
|
||||
// Similar to struct Foo1 from Microsoft Visual C++ bug report 484295,
|
||||
// "VC++ does not value-initialize members of derived classes without
|
||||
// user-declared constructor", reported in 2009 by Sylvester Hesp:
|
||||
// https://connect.microsoft.com/VisualStudio/feedback/details/484295
|
||||
struct derived_struct: empty_struct
|
||||
{
|
||||
int data;
|
||||
};
|
||||
|
||||
bool is_value_initialized(const derived_struct& arg)
|
||||
{
|
||||
return arg.data == 0;
|
||||
}
|
||||
|
||||
|
||||
class virtual_destructor_holder
|
||||
{
|
||||
public:
|
||||
int i;
|
||||
virtual ~virtual_destructor_holder()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
bool is_value_initialized(const virtual_destructor_holder& arg)
|
||||
{
|
||||
return arg.i == 0;
|
||||
}
|
||||
|
||||
// Equivalent to the Stats class from GCC Bug 33916,
|
||||
// "Default constructor fails to initialize array members", reported in 2007 by
|
||||
// Michael Elizabeth Chastain: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33916
|
||||
// and fixed for GCC 4.2.4.
|
||||
class private_int_array_pair
|
||||
{
|
||||
friend bool is_value_initialized(const private_int_array_pair& arg);
|
||||
private:
|
||||
int first[12];
|
||||
int second[12];
|
||||
};
|
||||
|
||||
bool is_value_initialized(const private_int_array_pair& arg)
|
||||
{
|
||||
for ( unsigned i = 0; i < 12; ++i)
|
||||
{
|
||||
if ( (arg.first[i] != 0) || (arg.second[i] != 0) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
struct int_pair_struct
|
||||
{
|
||||
int first;
|
||||
int second;
|
||||
};
|
||||
|
||||
typedef int int_pair_struct::*ptr_to_member_type;
|
||||
|
||||
struct ptr_to_member_struct
|
||||
{
|
||||
ptr_to_member_type data;
|
||||
};
|
||||
|
||||
bool is_value_initialized(const ptr_to_member_struct& arg)
|
||||
{
|
||||
return arg.data == 0;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool is_value_initialized(const T(& arg)[2])
|
||||
{
|
||||
return
|
||||
is_value_initialized(arg[0]) &&
|
||||
is_value_initialized(arg[1]);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool is_value_initialized(const boost::value_initialized<T>& arg)
|
||||
{
|
||||
return is_value_initialized(arg.data());
|
||||
}
|
||||
|
||||
// Returns zero when the specified object is value-initializated, and one otherwise.
|
||||
// Prints a message to standard output if the value-initialization has failed.
|
||||
template <class T>
|
||||
unsigned failed_to_value_initialized(const T& object, const char *const object_name)
|
||||
{
|
||||
if ( is_value_initialized(object) )
|
||||
{
|
||||
return 0u;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Note: Failed to value-initialize " << object_name << '.' << std::endl;
|
||||
return 1u;
|
||||
}
|
||||
}
|
||||
|
||||
// A macro that passed both the name and the value of the specified object to
|
||||
// the function above here.
|
||||
#define FAILED_TO_VALUE_INITIALIZE(value) failed_to_value_initialized(value, #value)
|
||||
|
||||
// Equivalent to the dirty_stack() function from GCC Bug 33916,
|
||||
// "Default constructor fails to initialize array members", reported in 2007 by
|
||||
// Michael Elizabeth Chastain: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33916
|
||||
void dirty_stack()
|
||||
{
|
||||
unsigned char array_on_stack[4096];
|
||||
for (unsigned i = 0; i < sizeof(array_on_stack); ++i)
|
||||
{
|
||||
array_on_stack[i] = 0x11;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifdef BOOST_DETAIL_VALUE_INIT_WORKAROUND_SUGGESTED
|
||||
|
||||
std::cout << "BOOST_DETAIL_VALUE_INIT_WORKAROUND_SUGGESTED is defined.\n\n";
|
||||
|
||||
#endif
|
||||
|
||||
dirty_stack();
|
||||
|
||||
BOOST_TEST( is_value_initialized( boost::value_initialized<derived_struct>() ) );
|
||||
BOOST_TEST( is_value_initialized( boost::value_initialized<virtual_destructor_holder[2]>() ) );
|
||||
BOOST_TEST( is_value_initialized( boost::value_initialized<private_int_array_pair>() ) );
|
||||
|
||||
#if !BOOST_WORKAROUND( BOOST_MSVC, BOOST_TESTED_AT(1925) )
|
||||
|
||||
// Null pointers to data members are represented as -1 in MSVC, but
|
||||
// value initialization sets them to all zero. The workaround employed
|
||||
// by value_initialized<> is to memset the storage to all zero, which
|
||||
// doesn't help.
|
||||
|
||||
BOOST_TEST( is_value_initialized( boost::value_initialized<ptr_to_member_struct>() ) );
|
||||
|
||||
#endif
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
40
test/value_init_test3.cpp
Normal file
40
test/value_init_test3.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
// Copyright 2020 Peter Dimov
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// https://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/utility/value_init.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/config/pragma_message.hpp>
|
||||
|
||||
#if __cplusplus >= 201103L || ( defined(BOOST_MSVC) && BOOST_MSVC >= 1900 )
|
||||
|
||||
struct X
|
||||
{
|
||||
int a;
|
||||
char b;
|
||||
};
|
||||
|
||||
struct Y: boost::value_initialized<X>
|
||||
{
|
||||
char c = 42;
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
Y y;
|
||||
|
||||
BOOST_TEST_EQ( y.data().a, 0 );
|
||||
BOOST_TEST_EQ( y.data().b, 0 );
|
||||
BOOST_TEST_EQ( y.c, 42 );
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
BOOST_PRAGMA_MESSAGE( "Skipping test because compiler doesn't support in-class member initializers" )
|
||||
|
||||
int main() {}
|
||||
|
||||
#endif
|
@ -13,13 +13,11 @@
|
||||
|
||||
#include "boost/utility/value_init.hpp"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#ifdef BOOST_BORLANDC
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "boost/test/minimal.hpp"
|
||||
|
||||
int test_main(int, char **)
|
||||
int main()
|
||||
{
|
||||
boost::value_initialized<int> const x_c ;
|
||||
|
||||
@ -27,11 +25,3 @@ int test_main(int, char **)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
unsigned int expected_failures = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -13,13 +13,11 @@
|
||||
|
||||
#include "boost/utility/value_init.hpp"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#ifdef BOOST_BORLANDC
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "boost/test/minimal.hpp"
|
||||
|
||||
int test_main(int, char **)
|
||||
int main()
|
||||
{
|
||||
boost::value_initialized<int const> cx ;
|
||||
|
||||
@ -27,10 +25,3 @@ int test_main(int, char **)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int expected_failures = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -13,13 +13,11 @@
|
||||
|
||||
#include "boost/utility/value_init.hpp"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#ifdef BOOST_BORLANDC
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "boost/test/minimal.hpp"
|
||||
|
||||
int test_main(int, char **)
|
||||
int main()
|
||||
{
|
||||
boost::value_initialized<int const> const cx_c ;
|
||||
|
||||
@ -27,11 +25,3 @@ int test_main(int, char **)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
unsigned int expected_failures = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -75,6 +75,24 @@ namespace
|
||||
return true;
|
||||
}
|
||||
|
||||
struct int_pair_struct
|
||||
{
|
||||
int first;
|
||||
int second;
|
||||
};
|
||||
|
||||
typedef int int_pair_struct::*ptr_to_member_type;
|
||||
|
||||
struct ptr_to_member_struct
|
||||
{
|
||||
ptr_to_member_type data;
|
||||
};
|
||||
|
||||
bool is_value_initialized(const ptr_to_member_struct& arg)
|
||||
{
|
||||
return arg.data == 0;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool is_value_initialized(const T(& arg)[2])
|
||||
{
|
||||
@ -132,7 +150,8 @@ int main()
|
||||
const unsigned num_failures =
|
||||
FAILED_TO_VALUE_INITIALIZE(boost::value_initialized<derived_struct>()) +
|
||||
FAILED_TO_VALUE_INITIALIZE(boost::value_initialized<virtual_destructor_holder[2]>()) +
|
||||
FAILED_TO_VALUE_INITIALIZE(boost::value_initialized<private_int_array_pair>());
|
||||
FAILED_TO_VALUE_INITIALIZE(boost::value_initialized<private_int_array_pair>()) +
|
||||
FAILED_TO_VALUE_INITIALIZE(boost::value_initialized<ptr_to_member_struct>());
|
||||
|
||||
#ifdef BOOST_DETAIL_VALUE_INIT_WORKAROUND_SUGGESTED
|
||||
// One or more failures are expected.
|
@ -1,15 +1,15 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv=refresh content="0; URL=../exception/doc/throw_exception.html">
|
||||
<title>Automatic redirection</title>
|
||||
<meta http-equiv=refresh content="0; URL=../throw_exception/doc/html/throw_exception.html#using_boost_throw_exception">
|
||||
<title>Automatic redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
Automatic redirection failed, please go to
|
||||
<a href="../exception/doc/throw_exception.html">throw_exception.html</a>. <hr>
|
||||
<p><EFBFBD> Copyright Beman Dawes, 2001</p>
|
||||
<p>Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy
|
||||
at <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</p>
|
||||
<a href="../throw_exception/doc/html/throw_exception.html#using_boost_throw_exception">../throw_exception/doc/html/throw_exception.html#using_boost_throw_exception</a>. <hr>
|
||||
<p>Copyright © Beman Dawes, 2001</p>
|
||||
<p>Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy
|
||||
at <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</p>
|
||||
</body>
|
||||
</html>
|
||||
|
637
utility.htm
637
utility.htm
@ -1,622 +1,19 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<title>Header boost/utility.hpp Documentation</title>
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF" text="#000000">
|
||||
<h1><img src="../../boost.png" alt="boost.png (6897 bytes)" align="center" WIDTH="277" HEIGHT="86">Header
|
||||
<a href="../../boost/utility.hpp">boost/utility.hpp</a></h1>
|
||||
<p>The entire contents of the header <code><a href="../../boost/utility.hpp"><boost/utility.hpp></a></code>
|
||||
are in <code>namespace boost</code>.</p>
|
||||
<h2>Contents</h2>
|
||||
<ul>
|
||||
<li>
|
||||
Class templates supporting the <a href="doc/html/base_from_member.html">
|
||||
base-from-member idiom</a></li>
|
||||
<li>
|
||||
Function templates <a href="../core/doc/html/core/checked_delete.html">checked_delete() and
|
||||
checked_array_delete()</a> (moved to the Boost.Core library)</li>
|
||||
<li>
|
||||
Function templates <a href="#functions_next_prior">next() and prior()</a></li>
|
||||
<li>
|
||||
Class <a href="../core/doc/html/core/noncopyable.html">noncopyable</a> (moved to the Boost.Core library)</li>
|
||||
<li>
|
||||
Function template <a href="../core/doc/html/core/addressof.html">addressof()</a> (moved to the Boost.Core library)</li>
|
||||
<li>Class template <a href="#result_of">result_of</a></li>
|
||||
<li>
|
||||
Macro <a href="#BOOST_BINARY">BOOST_BINARY</a></li>
|
||||
<li><a href="index.html">Other utilities not part of <code>utility.hpp</code></a></li>
|
||||
</ul>
|
||||
<h2>
|
||||
<a name="functions_next_prior">Function</a> templates next() and prior()</h2>
|
||||
<p>Certain data types, such as the C++ Standard Library's forward and bidirectional
|
||||
iterators, do not provide addition and subtraction via operator+() or
|
||||
operator-(). This means that non-modifying computation of the next or
|
||||
prior value requires a temporary, even though operator++() or operator--() is
|
||||
provided. It also means that writing code like <code>itr+1</code> inside
|
||||
a template restricts the iterator category to random access iterators.</p>
|
||||
<p>The next() and prior() functions provide a simple way around these problems:</p>
|
||||
<blockquote>
|
||||
<pre>template <class T>
|
||||
T next(T x) { return ++x; }
|
||||
|
||||
template <class T, class Distance>
|
||||
T next(T x, Distance n)
|
||||
{
|
||||
std::advance(x, n);
|
||||
return x;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T prior(T x) { return --x; }
|
||||
|
||||
template <class T, class Distance>
|
||||
T prior(T x, Distance n)
|
||||
{
|
||||
std::advance(x, -n);
|
||||
return x;
|
||||
}</pre>
|
||||
</blockquote>
|
||||
<p>Usage is simple:</p>
|
||||
<blockquote>
|
||||
<pre>const std::list<T>::iterator p = get_some_iterator();
|
||||
const std::list<T>::iterator prev = boost::prior(p);
|
||||
const std::list<T>::iterator next = boost::next(prev, 2);</pre>
|
||||
</blockquote>
|
||||
<p>The distance from the given iterator should be supplied as an absolute value. For
|
||||
example, the iterator four iterators prior to the given iterator <code>p</code>
|
||||
may be obtained by <code>prior(p, 4)</code>.</p>
|
||||
<p>Contributed by <a href="http://www.boost.org/people/dave_abrahams.htm">Dave Abrahams</a>. Two-argument versions by Daniel Walker.</p>
|
||||
|
||||
<h2><a name="result_of">Class template
|
||||
result_of</a></h2> <p>The class template
|
||||
<code>result_of</code> helps determine the type of a
|
||||
call expression. For example, given an lvalue <code>f</code> of
|
||||
type <code>F</code> and lvalues <code>t1</code>,
|
||||
<code>t2</code>, ..., <code>t<em>N</em></code> of
|
||||
types <code>T1</code>, <code>T2</code>, ...,
|
||||
<code>T<em>N</em></code>, respectively, the type
|
||||
<code>result_of<F(T1, T2, ...,
|
||||
T<em>N</em>)>::type</code> defines the result type
|
||||
of the expression <code>f(t1, t2,
|
||||
...,t<em>N</em>)</code>. This implementation permits
|
||||
the type <code>F</code> to be a function pointer,
|
||||
function reference, member function pointer, or class
|
||||
type. By default, <em>N</em> may be any value between 0 and
|
||||
16. To change the upper limit, define the macro
|
||||
<code>BOOST_RESULT_OF_NUM_ARGS</code> to the maximum
|
||||
value for <em>N</em>. Class template <code>result_of</code>
|
||||
resides in the header <code><<a
|
||||
href="../../boost/utility/result_of.hpp">boost/utility/result_of.hpp</a>></code>.</p>
|
||||
|
||||
<p>If your compiler's support for <code>decltype</code> is
|
||||
adequate, <code>result_of</code> automatically uses it to
|
||||
deduce the type of the call expression, in which case
|
||||
<code>result_of<F(T1, T2, ...,
|
||||
T<em>N</em>)>::type</code> names the type
|
||||
<code>decltype(boost::declval<F>()(boost::declval<T1>(),
|
||||
boost::declval<T2>(), ...,
|
||||
boost::declval<T<em>N</em>>()))</code>, as in the
|
||||
following example.</p>
|
||||
|
||||
<blockquote>
|
||||
<pre>struct functor {
|
||||
template<class T>
|
||||
T operator()(T x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
};
|
||||
|
||||
typedef boost::result_of<
|
||||
functor(int)
|
||||
>::type type; // type is int</pre>
|
||||
</blockquote>
|
||||
|
||||
<p>You can test whether <code>result_of</code> is using
|
||||
<code>decltype</code> by checking if the macro
|
||||
<code>BOOST_RESULT_OF_USE_DECLTYPE</code> is defined after
|
||||
including <code>result_of.hpp</code>. You can also force
|
||||
<code>result_of</code> to use <code>decltype</code> by
|
||||
defining <code>BOOST_RESULT_OF_USE_DECLTYPE</code> prior
|
||||
to including <code>result_of.hpp</code>.</p>
|
||||
|
||||
<p>If <code>decltype</code> is not used,
|
||||
then automatic result type deduction of function
|
||||
objects is not possible. Instead, <code>result_of</code>
|
||||
uses the following protocol to allow the programmer to
|
||||
specify a type. When <code>F</code> is a class type with a
|
||||
member type <code>result_type</code>,
|
||||
<code>result_of<F(T1, T2, ...,
|
||||
T<em>N</em>)>::type</code> is
|
||||
<code>F::result_type</code>. When <code>F</code> does
|
||||
not contain <code>result_type</code>,
|
||||
<code>result_of<F(T1, T2, ...,
|
||||
T<em>N</em>)>::type</code> is <code>F::result<F(T1,
|
||||
T2, ..., T<em>N</em>)>::type</code> when
|
||||
<code><em>N</em> > 0</code> or <code>void</code>
|
||||
when <code><em>N</em> = 0</code>. Note that it is the
|
||||
responsibility of the programmer to ensure that
|
||||
function objects accurately advertise their result
|
||||
type via this protocol, as in the following
|
||||
example.</p>
|
||||
|
||||
<blockquote>
|
||||
<pre>struct functor {
|
||||
template<class> struct result;
|
||||
|
||||
template<class F, class T>
|
||||
struct result<F(T)> {
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
T operator()(T x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
};
|
||||
|
||||
typedef boost::result_of<
|
||||
functor(int)
|
||||
>::type type; // type is int</pre>
|
||||
</blockquote>
|
||||
|
||||
<p>Since <code>decltype</code> is a new language
|
||||
feature recently standardized in C++11,
|
||||
if you are writing a function object
|
||||
to be used with <code>result_of</code>, for
|
||||
maximum portability, you might consider following
|
||||
the above protocol even if your compiler has
|
||||
proper <code>decltype</code> support. If you wish to continue to
|
||||
use the protocol on compilers that
|
||||
support <code>decltype</code>, there are two options:
|
||||
You can use <code>boost::tr1_result_of</code>, which is also
|
||||
defined in <code><<a href="../../boost/utility/result_of.hpp">boost/utility/result_of.hpp</a>></code>.
|
||||
Alternatively, you can define the macro
|
||||
<code>BOOST_RESULT_OF_USE_TR1</code>, which causes
|
||||
<code>result_of</code> to use the protocol described
|
||||
above instead of <code>decltype</code>. If you choose to
|
||||
follow the protocol, take care to ensure that the
|
||||
<code>result_type</code> and
|
||||
<code>result<></code> members accurately
|
||||
represent the return type of
|
||||
<code>operator()</code> given a call expression.</p>
|
||||
|
||||
<p>Additionally, <code>boost::result_of</code>
|
||||
provides a third mode of operation, which some users
|
||||
may find convenient. When
|
||||
<code>BOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK</code>
|
||||
is defined, <code>boost::result_of</code> behaves as
|
||||
follows. If the function object has a member
|
||||
type <code>result_type</code> or member
|
||||
template <code>result<></code>, then
|
||||
<code>boost::result_of</code> will use the TR1
|
||||
protocol. Otherwise,
|
||||
<code>boost::result_of</code> will
|
||||
use <code>decltype</code>. Using TR1 with
|
||||
a <code>declytpe</code> fallback may workaround
|
||||
certain problems at the cost of portability. For
|
||||
example:
|
||||
<ul>
|
||||
<li>Deficient compiler: If your code
|
||||
requires <code>boost::result_of</code> to work
|
||||
with incomplete return types but your
|
||||
compiler's <code>decltype</code> implementation
|
||||
does not support incomplete return types, then you
|
||||
can use the TR1 protocol as a workaround. Support
|
||||
for incomplete return types was added late in the
|
||||
C++11 standardization process
|
||||
(see <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3276.pdf">N3276</a>)
|
||||
and is not implemented by some compilers.</li>
|
||||
|
||||
<li>Deficient legacy code: If your existing TR1
|
||||
function object advertises a different type than
|
||||
the actual result type deduced
|
||||
by <code>decltype</code>, then using TR1 with a
|
||||
<code>decltype</code> fallback will allow you to
|
||||
work with both your existing TR1 function objects
|
||||
and new C++11 function object. This situation
|
||||
could occur if your legacy function objects
|
||||
misused the TR1 protocol. See the documentation on
|
||||
known <a href="#result_of_tr1_diff">differences</a>
|
||||
between <code>boost::result_of</code> and TR1.</li>
|
||||
</ul>
|
||||
|
||||
<a name="BOOST_NO_RESULT_OF"></a>
|
||||
<p>This implementation of <code>result_of</code>
|
||||
requires class template partial specialization, the
|
||||
ability to parse function types properly, and support
|
||||
for SFINAE. If <code>result_of</code> is not supported
|
||||
by your compiler, including the header
|
||||
<code>boost/utility/result_of.hpp</code> will
|
||||
define the macro <code>BOOST_NO_RESULT_OF</code>.</p>
|
||||
|
||||
<p>For additional information
|
||||
about <code>result_of</code>, see the C++ Library
|
||||
Technical Report,
|
||||
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf">N1836</a>,
|
||||
or, for motivation and design rationale,
|
||||
the <code>result_of</code> <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1454.html">proposal</a>.</p>
|
||||
|
||||
<a name="result_of_guidelines">
|
||||
<h3>Usage guidelines for boost::result_of</h3>
|
||||
</a>
|
||||
|
||||
<p>The following are general suggestions about when
|
||||
and how to use <code>boost::result_of</code>.</p>
|
||||
|
||||
<ol>
|
||||
<li> If you are targeting C++11 and are not concerned
|
||||
about portability to non-compliant compilers or
|
||||
previous versions of the standard, then use
|
||||
<code>std::result_of</code>. If <code>std::result_of</code>
|
||||
meets your needs, then there's no reason to stop using
|
||||
it.</li>
|
||||
|
||||
<li> If you are targeting C++11 but may port your code
|
||||
to legacy compilers at some time in the future, then
|
||||
use <code>boost::result_of</code> with
|
||||
<code>decltype</code>. When <code>decltype</code> is
|
||||
used <code>boost::result_of</code>
|
||||
and <code>std::result_of</code> are usually
|
||||
interchangeable. See the documentation on
|
||||
known <a href="#result_of_cxx11_diff">differences</a>
|
||||
between boost::result_of and C++11 result_of.</li>
|
||||
|
||||
<li> If compiler portability is required,
|
||||
use <code>boost::result_of</code> with the TR1 protocol.</li>
|
||||
</ol>
|
||||
|
||||
<p>Regardless of how you
|
||||
configure <code>boost::result_of</code>, it is
|
||||
important to bear in mind that the return type of a
|
||||
function may change depending on its arguments, and
|
||||
additionally, the return type of a member function may
|
||||
change depending on the cv-qualification of the
|
||||
object. <code>boost::result_of</code> must be passed
|
||||
the appropriately cv-qualified types in order to
|
||||
deduce the corresponding return type. For example:
|
||||
|
||||
<blockquote>
|
||||
<pre>struct functor {
|
||||
int& operator()(int);
|
||||
int const& operator()(int) const;
|
||||
|
||||
float& operator()(float&);
|
||||
float const& operator()(float const&);
|
||||
};
|
||||
|
||||
typedef boost::result_of<
|
||||
functor(int)
|
||||
>::type type1; // type1 is int &
|
||||
|
||||
typedef boost::result_of<
|
||||
const functor(int)
|
||||
>::type type2; // type2 is int const &
|
||||
|
||||
typedef boost::result_of<
|
||||
functor(float&)
|
||||
>::type type3; // type3 is float &
|
||||
|
||||
typedef boost::result_of<
|
||||
functor(float const&)
|
||||
>::type type4; // type4 is float const &</pre>
|
||||
</blockquote>
|
||||
|
||||
<a name="result_of_tr1_protocol_guidelines">
|
||||
<h3>Usage guidelines for the TR1 result_of protocol</h3>
|
||||
</a>
|
||||
|
||||
<p>On compliant C++11
|
||||
compilers, <code>boost::result_of</code> can
|
||||
use <code>decltype</code> to deduce the type of any
|
||||
call expression, including calls to function
|
||||
objects. However, on pre-C++11 compilers or on
|
||||
compilers without adequate decltype support,
|
||||
additional scaffolding is needed from function
|
||||
objects as described above. The following are
|
||||
suggestions about how to use the TR1 protocol.</p>
|
||||
|
||||
<ul>
|
||||
<li>When the return type does not depend on the
|
||||
argument types or the cv-qualification of the
|
||||
function object, simply
|
||||
define <code>result_type</code>. There is no need
|
||||
to use the <code>result</code> template unless the
|
||||
return type varies.</li>
|
||||
|
||||
<li>Use the protocol specified type when defining
|
||||
function prototypes. This can help ensure the
|
||||
actual return type does not get out of sync with
|
||||
the protocol specification. For example:
|
||||
|
||||
<blockquote>
|
||||
<pre>struct functor {
|
||||
typedef int result_type;
|
||||
result_type operator()(int);
|
||||
};</pre>
|
||||
</blockquote> </li>
|
||||
|
||||
<li>Always specify the <code>result</code>
|
||||
specialization near the corresponding
|
||||
<code>operator()</code> overload. This can make it
|
||||
easier to keep the specializations in sync with the
|
||||
overloads. For example:
|
||||
|
||||
<blockquote>
|
||||
<pre>struct functor {
|
||||
template<class> struct result;
|
||||
|
||||
template<class F>
|
||||
struct result<F(int)> {
|
||||
typedef int& type;
|
||||
};
|
||||
result<functor(int)>::type operator()(int);
|
||||
|
||||
template<class F>
|
||||
struct result<const F(int)> {
|
||||
typedef int const& type;
|
||||
};
|
||||
result<const functor(int)>::type operator()(int) const;
|
||||
};</pre>
|
||||
</blockquote> </li>
|
||||
|
||||
<li>Use type transformations to simplify
|
||||
the <code>result</code> template specialization. For
|
||||
example, the following uses
|
||||
<a href="../type_traits/doc/html/index.html">Boost.TypeTraits</a>
|
||||
to specialize the <code>result</code> template for
|
||||
a single <code>operator()</code> that can be called on
|
||||
both a const and non-const function object with
|
||||
either an lvalue or rvalue argument.
|
||||
|
||||
<blockquote>
|
||||
<pre>struct functor {
|
||||
template<class> struct result;
|
||||
|
||||
template<class F, class T>
|
||||
struct result<F(T)>
|
||||
: boost::remove_cv<
|
||||
typename boost::remove_reference<T>::type
|
||||
>
|
||||
{};
|
||||
|
||||
template<class T>
|
||||
T operator()(T const& x) const;
|
||||
};</pre>
|
||||
</blockquote></li>
|
||||
</ul>
|
||||
|
||||
<a name="result_of_tr1_diff">
|
||||
<h3>Known differences between boost::result_of and TR1 result_of</h3>
|
||||
</a>
|
||||
|
||||
When using <code>decltype</code>, <code>boost::result_of</code>
|
||||
ignores the TR1 protocol and instead deduces the
|
||||
return type of function objects directly
|
||||
via <code>decltype</code>. In most situations, users
|
||||
will not notice a difference, so long as they use the
|
||||
protocol correctly. The following are situations in
|
||||
which the type deduced
|
||||
by <code>boost::result_of</code> is known to differ depending on
|
||||
whether <code>decltype</code> or the TR1 protocol is
|
||||
used.
|
||||
|
||||
<ul>
|
||||
<li> TR1 protocol misusage
|
||||
|
||||
<p>When using the TR1
|
||||
protocol, <code>boost::result_of</code> cannot
|
||||
detect whether the actual type of a call to a
|
||||
function object is the same as the type specified
|
||||
by the protocol, which allows for the possibility
|
||||
of inadvertent mismatches between the specified
|
||||
type and the actual type. When
|
||||
using <code>decltype</code>, these subtle bugs
|
||||
may result in compilation errors. For example:</p>
|
||||
|
||||
<blockquote>
|
||||
<pre>struct functor {
|
||||
typedef short result_type;
|
||||
int operator()(short);
|
||||
};
|
||||
|
||||
#ifdef BOOST_RESULT_OF_USE_DECLTYPE
|
||||
|
||||
BOOST_STATIC_ASSERT((
|
||||
boost::is_same<boost::result_of<functor(short)>::type, int>::value
|
||||
));
|
||||
|
||||
#else
|
||||
|
||||
BOOST_STATIC_ASSERT((
|
||||
boost::is_same<boost::result_of<functor(short)>::type, short>::value
|
||||
));
|
||||
|
||||
#endif</pre>
|
||||
</blockquote>
|
||||
|
||||
<p>Note that the user can
|
||||
force <code>boost::result_of</code> to use the TR1
|
||||
protocol even on platforms that
|
||||
support <code>decltype</code> by
|
||||
defining <code>BOOST_RESULT_OF_USE_TR1</code>.</p></li>
|
||||
|
||||
<li> Nullary function objects
|
||||
|
||||
<p>When using the TR1 protocol, <code>boost::result_of</code>
|
||||
cannot always deduce the type of calls to
|
||||
nullary function objects, in which case the
|
||||
type defaults to void. When using <code>decltype</code>,
|
||||
<code>boost::result_of</code> always gives the actual type of the
|
||||
call expression. For example:</p>
|
||||
|
||||
<blockquote>
|
||||
<pre>struct functor {
|
||||
template<class> struct result {
|
||||
typedef int type;
|
||||
};
|
||||
int operator()();
|
||||
};
|
||||
|
||||
#ifdef BOOST_RESULT_OF_USE_DECLTYPE
|
||||
|
||||
BOOST_STATIC_ASSERT((
|
||||
boost::is_same<boost::result_of<functor()>::type, int>::value
|
||||
));
|
||||
|
||||
#else
|
||||
|
||||
BOOST_STATIC_ASSERT((
|
||||
boost::is_same<boost::result_of<functor()>::type, void>::value
|
||||
));
|
||||
|
||||
#endif</pre>
|
||||
</blockquote>
|
||||
|
||||
<p>Note that there are some workarounds for the
|
||||
nullary function problem. So long as the return
|
||||
type does not vary,
|
||||
<code>result_type</code> can always be used to
|
||||
specify the return type regardless of arity. If the
|
||||
return type does vary, then the user can
|
||||
specialize <code>boost::result_of</code> itself for
|
||||
nullary calls.</p></li>
|
||||
|
||||
<li> Non-class prvalues and cv-qualification
|
||||
|
||||
<p>When using the TR1
|
||||
protocol, <code>boost::result_of</code> will
|
||||
report the cv-qualified type specified
|
||||
by <code>result_type</code> or
|
||||
the <code>result</code> template regardless of
|
||||
the actual cv-qualification of the call
|
||||
expression. When using
|
||||
<code>decltype</code>, <code>boost::result_of</code>
|
||||
will report the actual type of the call expression,
|
||||
which is not cv-qualified when the expression is a
|
||||
non-class prvalue. For example:</p>
|
||||
|
||||
<blockquote>
|
||||
<pre>struct functor {
|
||||
template<class> struct result;
|
||||
template<class F, class T> struct result<F(const T)> {
|
||||
typedef const T type;
|
||||
};
|
||||
|
||||
const short operator()(const short);
|
||||
int const & operator()(int const &);
|
||||
};
|
||||
|
||||
// Non-prvalue call expressions work the same with or without decltype.
|
||||
|
||||
BOOST_STATIC_ASSERT((
|
||||
boost::is_same<
|
||||
boost::result_of<functor(int const &)>::type,
|
||||
int const &
|
||||
::value
|
||||
));
|
||||
|
||||
// Non-class prvalue call expressions are not actually cv-qualified,
|
||||
// but only the decltype-based result_of reports this accurately.
|
||||
|
||||
#ifdef BOOST_RESULT_OF_USE_DECLTYPE
|
||||
|
||||
BOOST_STATIC_ASSERT((
|
||||
boost::is_same<
|
||||
boost::result_of<functor(const short)>::type,
|
||||
short
|
||||
::value
|
||||
));
|
||||
|
||||
#else
|
||||
|
||||
BOOST_STATIC_ASSERT((
|
||||
boost::is_same<
|
||||
boost::result_of<functor(const short)>::type,
|
||||
const short
|
||||
::value
|
||||
));
|
||||
|
||||
#endif</pre>
|
||||
</blockquote></li>
|
||||
</ul>
|
||||
|
||||
<a name="result_of_cxx11_diff">
|
||||
<h3>Known differences between boost::result_of and C++11 result_of</h3>
|
||||
</a>
|
||||
|
||||
<p>When using <code>decltype</code>, <code>boost::result_of</code>
|
||||
implements most of the C++11 result_of
|
||||
specification. One known exception is that
|
||||
<code>boost::result_of</code> does not implement the
|
||||
requirements regarding pointers to member data.</p>
|
||||
|
||||
<p>Created by Doug Gregor. Contributions from Daniel Walker, Eric Niebler, Michel Morin and others</p>
|
||||
|
||||
<h2><a name="BOOST_BINARY">Macro BOOST_BINARY</a></h2>
|
||||
|
||||
<p>The macro <code>BOOST_BINARY</code> is used for the
|
||||
representation of binary literals. It takes as an argument
|
||||
a binary number arranged as an arbitrary amount of 1s and 0s in
|
||||
groupings of length 1 to 8, with groups separated
|
||||
by spaces. The type of the literal yielded is determined by
|
||||
the same rules as those of hex and octal
|
||||
literals (<i>2.13.1p1</i>). By implementation, this macro
|
||||
expands directly to an octal literal during preprocessing, so
|
||||
there is no overhead at runtime and the result is useable in
|
||||
any place that an octal literal would be.</p>
|
||||
|
||||
<p>In order to directly support binary literals with suffixes,
|
||||
additional macros of the form BOOST_BINARY_XXX are also
|
||||
provided, where XXX is a standard integer suffix in all capital
|
||||
letters. In addition, LL and ULL suffixes may be used for representing
|
||||
long long and unsigned long long types in compilers which provide
|
||||
them as an extension.</p>
|
||||
|
||||
|
||||
<p>The BOOST_BINARY family of macros resides in the header
|
||||
<a
|
||||
href="../../boost/utility/binary.hpp"><boost/utility/binary.hpp></a>
|
||||
which is automatically included by
|
||||
<a
|
||||
href="../../boost/utility.hpp"><boost/utility.hpp></a>.
|
||||
|
||||
<p>Contributed by Matt Calabrese.</p><p>
|
||||
</p><h3>Example</h3>
|
||||
<blockquote>
|
||||
<pre>
|
||||
void foo( int );
|
||||
|
||||
void foo( unsigned long );
|
||||
|
||||
void bar()
|
||||
{
|
||||
int value1 = BOOST_BINARY( 100 111000 01 1 110 );
|
||||
|
||||
unsigned long value2 = BOOST_BINARY_UL( 100 001 ); // unsigned long
|
||||
|
||||
long long value3 = BOOST_BINARY_LL( 11 000 ); // long long if supported
|
||||
|
||||
assert( BOOST_BINARY( 10010 )
|
||||
& BOOST_BINARY( 11000 )
|
||||
== BOOST_BINARY( 10000 )
|
||||
);
|
||||
|
||||
foo( BOOST_BINARY( 1010 ) ); // calls the first foo
|
||||
|
||||
foo( BOOST_BINARY_LU( 1010 ) ); // calls the second foo
|
||||
}
|
||||
</pre></blockquote>
|
||||
<hr>
|
||||
<p>Revised <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan
|
||||
-->04 September, 2008<!--webbot bot="Timestamp" endspan i-checksum="39369"
|
||||
-->
|
||||
</p>
|
||||
<p>© Copyright Beman Dawes 1999-2003.</p>
|
||||
<p>Distributed under the Boost Software License, Version 1.0. See
|
||||
<a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a></p>
|
||||
|
||||
</body>
|
||||
<head>
|
||||
<title>Boost.Utility</title>
|
||||
<meta http-equiv="refresh" content="0; URL=./doc/html/index.html">
|
||||
</head>
|
||||
<body>
|
||||
Automatic redirection failed, please go to
|
||||
<a href="./doc/html/index.html">./doc/html/index.html</a>
|
||||
<hr>
|
||||
<tt>
|
||||
Boost.Utility<br>
|
||||
<br>
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
<a href=http://www.boost.org/LICENSE_1_0.txt>http://www.boost.org/LICENSE_1_0.txt</a>) <br>
|
||||
<br>
|
||||
</tt>
|
||||
</body>
|
||||
</html>
|
||||
|
523
value_init.htm
523
value_init.htm
@ -1,514 +1,19 @@
|
||||
<html>
|
||||
<head>
|
||||
|
||||
<meta http-equiv="Content-Type"
|
||||
content="text/html; charset=iso-8859-1">
|
||||
<title>value_initialized</title>
|
||||
|
||||
<title>Boost.Utility</title>
|
||||
<meta http-equiv="refresh" content="0; URL=./doc/html/utility/utilities/value_init.html">
|
||||
</head>
|
||||
<body vlink="#800080" link="#0000ff" text="#000000" bgcolor="#ffffff">
|
||||
|
||||
<h2><img src="../../boost.png" width="276" height="86">
|
||||
Header <<a href="../../boost/utility/value_init.hpp">boost/utility/value_init.hpp</a>>
|
||||
</h2>
|
||||
|
||||
<h2>Contents</h2>
|
||||
|
||||
<dl>
|
||||
<dt><a href="#rationale">Rationale</a></dt>
|
||||
<dt><a href="#intro">Introduction</a></dt>
|
||||
<dt><a href="#details">Details</a></dt>
|
||||
</dl>
|
||||
|
||||
<ul>
|
||||
<li><a href="#valueinit">value-initialization</a></li>
|
||||
<li><a href="#valueinitsyn">value-initialization syntax</a></li>
|
||||
<li><a href="#compiler_issues">compiler issues</a></li>
|
||||
|
||||
</ul>
|
||||
|
||||
<dl class="page-index">
|
||||
<dt><a href="#types">Types and objects</a></dt>
|
||||
</dl>
|
||||
|
||||
<ul>
|
||||
<li><a href="#val_init"><code>template class value_initialized<T></code></a></li>
|
||||
<li><a href="#initialized"><code>template class initialized<T></code></a></li>
|
||||
<li><a href="#initialized_value"><code>initialized_value</code></a></li>
|
||||
|
||||
</ul>
|
||||
<a href="#acknowledgements">Acknowledgements</a><br>
|
||||
<br>
|
||||
|
||||
<hr>
|
||||
<h2><a name="rationale"></a>Rationale</h2>
|
||||
|
||||
<p>Constructing and initializing objects in a generic way is difficult in
|
||||
C++. The problem is that there are several different rules that apply
|
||||
for initialization. Depending on the type, the value of a newly constructed
|
||||
object can be zero-initialized (logically 0), default-constructed (using
|
||||
the default constructor), or indeterminate. When writing generic code,
|
||||
this problem must be addressed. The template <code>value_initialized</code> provides
|
||||
a solution with consistent syntax for value initialization of scalar,
|
||||
union and class types.
|
||||
Moreover, <code>value_initialized</code> offers a workaround to various
|
||||
compiler issues regarding value-initialization.
|
||||
|
||||
Furthermore, a <code>const</code> object, <code>initialized_value</code> is provided,
|
||||
to avoid repeating the type name when retrieving the value from a
|
||||
<code>value_initialized<T></code> object.
|
||||
<br>
|
||||
</p>
|
||||
|
||||
<h2><a name="intro"></a>Introduction</h2>
|
||||
|
||||
<p>
|
||||
There are various ways to initialize a variable, in C++. The following
|
||||
declarations all <em>may</em> have a local variable initialized to its default
|
||||
value:
|
||||
<pre>
|
||||
T1 var1;
|
||||
T2 var2 = 0;
|
||||
T3 var3 = {};
|
||||
T4 var4 = T4();
|
||||
</pre>
|
||||
Unfortunately, whether or not any of those declarations correctly
|
||||
initialize the variable very much depends on its type. The first
|
||||
declaration is valid for any <a href="http://www.sgi.com/tech/stl/DefaultConstructible.html">
|
||||
DefaultConstructible</a> type (by definition).
|
||||
However, it does not always do an initialization!
|
||||
It correctly initializes the variable when it's an instance of a
|
||||
class, and the author of the class has provided a proper default
|
||||
constructor. On the other hand, the value of <code>var1</code> is <em>indeterminate</em> when
|
||||
its type is an arithmetic type, like <code>int</code>, <code>float</code>, or <code>char</code>.
|
||||
An arithmetic variable
|
||||
is of course initialized properly by the second declaration, <code>T2
|
||||
var2 = 0</code>. But this initialization form usually won't work for a
|
||||
class type (unless the class was especially written to support being
|
||||
initialized that way). The third form, <code>T3 var3 = {}</code>
|
||||
initializes an aggregate, typically a "C-style" <code>struct</code> or a "C-style" array.
|
||||
However, the syntax is not allowed for a class that has an explicitly declared
|
||||
constructor. (But watch out for an upcoming C++ language change,
|
||||
by Bjarne Stroustrup et al [<a href="#references">1</a>]!)
|
||||
The fourth form is the most generic form of them, as it
|
||||
can be used to initialize arithmetic types, class types, aggregates, pointers, and
|
||||
other types. The declaration, <code>T4 var4 = T4()</code>, should be read
|
||||
as follows: First a temporary object is created, by <code>T4()</code>.
|
||||
This object is <a href="#valueinit">value-initialized</a>. Next the temporary
|
||||
object is copied to the named variable, <code>var4</code>. Afterwards, the temporary
|
||||
is destroyed. While the copying and the destruction are likely to
|
||||
be optimized away, C++ still requires the type <code>T4</code> to be
|
||||
<a href="CopyConstructible.html">CopyConstructible</a>.
|
||||
(So <code>T4</code> needs to be <em>both</em> DefaultConstructible <em>and</em> CopyConstructible.)
|
||||
A class may not be CopyConstructible, for example because it may have a
|
||||
private and undefined copy constructor,
|
||||
or because it may be derived from <a href="utility.htm#Class_noncopyable">boost::noncopyable</a>.
|
||||
Scott Meyers [<a href="#references">2</a>] explains why a class would be defined like that.
|
||||
</p>
|
||||
<p>
|
||||
There is another, less obvious disadvantage to the fourth form, <code>T4 var4 = T4()</code>:
|
||||
It suffers from various <a href="#compiler_issues">compiler issues</a>, causing
|
||||
a variable to be left uninitialized in some compiler specific cases.
|
||||
</p>
|
||||
<p>
|
||||
The template <a href="#val_init"><code>value_initialized</code></a>
|
||||
offers a generic way to initialize
|
||||
an object, like <code>T4 var4 = T4()</code>, but without requiring its type
|
||||
to be CopyConstructible. And it offers a workaround to those compiler issues
|
||||
regarding value-initialization as well! It allows getting an initialized
|
||||
variable of any type; it <em>only</em> requires the type to be DefaultConstructible.
|
||||
A properly <em>value-initialized</em> object of type <code>T</code> is
|
||||
constructed by the following declaration:
|
||||
<pre>
|
||||
value_initialized<T> var;
|
||||
</pre>
|
||||
</p>
|
||||
<p>
|
||||
The template <a href="#initialized"><code>initialized</code></a>
|
||||
offers both value-initialization and direct-initialization.
|
||||
It is especially useful as a data member type, allowing the very same object
|
||||
to be either direct-initialized or value-initialized.
|
||||
</p>
|
||||
<p>
|
||||
The <code>const</code> object <a href="#initialized_value"><code>initialized_value</code></a>
|
||||
allows value-initializing a variable as follows:
|
||||
<pre>
|
||||
T var = initialized_value ;
|
||||
</pre>
|
||||
This form of initialization is semantically equivalent to <code>T4 var4 = T4()</code>,
|
||||
but robust against the aforementioned compiler issues.
|
||||
|
||||
</p>
|
||||
|
||||
<h2><a name="details"></a>Details</h2>
|
||||
<p>The C++ standard [<a href="#references">3</a>] contains the definitions
|
||||
of <code>zero-initialization</code> and <code>default-initialization</code>.
|
||||
Informally, zero-initialization means that the object is given the initial
|
||||
value 0 (converted to the type) and default-initialization means that
|
||||
POD [<a href="#references">4</a>] types are zero-initialized, while non-POD class
|
||||
types are initialized with their corresponding default constructors. A
|
||||
<i>declaration</i> can contain an <i>initializer</i>, which specifies the
|
||||
object's initial value. The initializer can be just '()', which states that
|
||||
the object shall be value-initialized (but see below). However, if a <i>declaration</i>
|
||||
has no <i>initializer</i> and it is of a non-<code>const</code>, non-<code>static</code>
|
||||
POD type, the initial value is indeterminate: <cite>(see §8.5, [dcl.init], for the
|
||||
accurate definitions).</cite></p>
|
||||
|
||||
<pre>int x ; // no initializer. x value is indeterminate.<br>std::string s ; // no initializer, s is default-constructed.<br><br>int y = int() ; <br>// y is initialized using copy-initialization<br>// but the temporary uses an empty set of parentheses as the initializer,<br>// so it is default-constructed.<br>// A default constructed POD type is zero-initialized,<br>// therefore, y == 0.<br><br>void foo ( std::string ) ;<br>foo ( std::string() ) ; <br>// the temporary string is default constructed <br>// as indicated by the initializer () </pre>
|
||||
|
||||
<h3><a name="valueinit">value-initialization</a></h3>
|
||||
|
||||
<p>The first <a
|
||||
href="http://www.open-std.org/JTC1/SC22/WG21/docs/cwg_defects.html">Technical
|
||||
Corrigendum for the C++ Standard</a> (TC1), whose draft was released to
|
||||
the public in November 2001, introduced <a
|
||||
href="http://www.open-std.org/JTC1/SC22/WG21/docs/cwg_defects.html#178">Core
|
||||
Issue 178</a> (among many other issues, of course).</p>
|
||||
|
||||
<p> That issue introduced the new concept of <code>value-initialization</code>
|
||||
(it also fixed the wording for zero-initialization). Informally, value-initialization
|
||||
is similar to default-initialization with the exception that in some cases
|
||||
non-static data members and base class sub-objects are also value-initialized.
|
||||
The difference is that an object that is value-initialized won't have
|
||||
(or at least is less likely to have) indeterminate values for data members
|
||||
and base class sub-objects; unlike the case of an object default constructed.
|
||||
(see Core Issue 178 for a normative description).</p>
|
||||
|
||||
<p>In order to specify value-initialization of an object we need to use the
|
||||
empty-set initializer: (). </p>
|
||||
|
||||
<p>As before, a declaration with no intializer specifies default-initialization,
|
||||
and a declaration with a non-empty initializer specifies copy (=xxx) or
|
||||
direct (xxx) initialization. </p>
|
||||
|
||||
<pre>template<class T> void eat(T);<br>int x ; // indeterminate initial value.<br>std::string s; // default-initialized.<br>eat ( int() ) ; // value-initialized<br>eat ( std::string() ) ; // value-initialized</pre>
|
||||
|
||||
<h4><a name="valueinitsyn">value-initialization</a> syntax</h4>
|
||||
|
||||
<p>Value initialization is specified using (). However, the empty set of
|
||||
parentheses is not permitted by the syntax of initializers because it is
|
||||
parsed as the declaration of a function taking no arguments: </p>
|
||||
|
||||
<pre>int x() ; // declares function int(*)()</pre>
|
||||
|
||||
<p>Thus, the empty () must be put in some other initialization context.</p>
|
||||
|
||||
<p>One alternative is to use copy-initialization syntax:</p>
|
||||
|
||||
<pre>int x = int() ;</pre>
|
||||
|
||||
<p>This works perfectly fine for POD types. But for non-POD class types,
|
||||
copy-initialization searches for a suitable constructor, which could be,
|
||||
for instance, the copy-constructor (it also searches for a suitable conversion
|
||||
sequence but this doesn't apply in this context). For an arbitrary unknown
|
||||
type, using this syntax may not have the value-initialization effect intended
|
||||
because we don't know if a copy from a default constructed object is exactly
|
||||
the same as a default constructed object, and the compiler is allowed (in
|
||||
some cases), but never required to, optimize the copy away.</p>
|
||||
|
||||
<p>One possible generic solution is to use value-initialization of a non static
|
||||
data member:</p>
|
||||
|
||||
<pre>template<class T> <br>struct W <br>{<br> // value-initialization of 'data' here.<br> W() : data() {}<br> T data ;<br>} ;<br>W<int> w ;<br>// w.data is value-initialized for any type. </pre>
|
||||
|
||||
<p>This is the solution as it was supplied by earlier versions of the
|
||||
<code>value_initialized<T></code> template
|
||||
class. Unfortunately this approach suffered from various compiler issues.</p>
|
||||
|
||||
<h4><a name="compiler_issues">compiler issues</a> </h4>
|
||||
|
||||
Various compilers haven't yet fully implemented value-initialization.
|
||||
So when an object should be <em>value-initialized</em> (according to the C++ Standard),
|
||||
it <em>may</em> in practice still be left uninitialized, because of those
|
||||
compiler issues! It's hard to make a general statement on what those issues
|
||||
are like, because they depend on the compiler you are using, its version number,
|
||||
and the type of object you would like to have value-initialized.
|
||||
All compilers we have tested so far support value-initialization for arithmetic types properly.
|
||||
However, various compilers may leave some types of <em>aggregates</em> uninitialized, when they
|
||||
should be value-initialized. Value-initialization of objects of a pointer-to-member type may also
|
||||
go wrong on various compilers.
|
||||
</p>
|
||||
<p>
|
||||
At the moment of writing, May 2010, the following reported issues regarding
|
||||
value-initialization are still there in current compiler releases:
|
||||
<ul>
|
||||
<li>
|
||||
<a href="https://connect.microsoft.com/VisualStudio/feedback/details/100744">
|
||||
Microsoft Visual Studio Feedback ID 100744, Value-initialization in new-expression</a>
|
||||
<br>Reported by Pavel Kuznetsov (MetaCommunications Engineering), 2005
|
||||
</li><li>
|
||||
<a href="http://connect.microsoft.com/VisualStudio/feedback/details/484295">
|
||||
Microsoft Visual Studio Feedback ID 484295, VC++ does not value-initialize members of derived classes without user-declared constructor</a>
|
||||
<br>Reported by Sylvester Hesp, 2009
|
||||
</li><li>
|
||||
<a href="https://connect.microsoft.com/VisualStudio/feedback/details/499606">
|
||||
Microsoft Visual Studio Feedback ID 499606, Presence of copy constructor breaks member class initialization</a>
|
||||
<br>Reported by Alex Vakulenko, 2009
|
||||
</li><li>
|
||||
<a href="http://qc.embarcadero.com/wc/qcmain.aspx?d=83751">
|
||||
Embarcadero/C++Builder Report 83751, Value-initialization: arrays should have each element value-initialized</a>
|
||||
<br>Reported by Niels Dekker (LKEB), 2010
|
||||
</li><li>
|
||||
<a href="http://qc.embarcadero.com/wc/qcmain.aspx?d=83851">
|
||||
Embarcadero/C++Builder Report 83851, Value-initialized temporary triggers internal backend error C1798</a>
|
||||
<br>Reported by Niels Dekker, 2010
|
||||
</li><li>
|
||||
<a href="http://qc.embarcadero.com/wc/qcmain.aspx?d=84279">
|
||||
Embarcadero/C++Builder Report 84279, Internal compiler error (F1004), value-initializing member function pointer by "new T()"</a>
|
||||
<br>Reported by Niels Dekker, 2010
|
||||
</li><li>
|
||||
Sun CR 6947016, Sun 5.10 may fail to value-initialize an object of a non-POD aggregate.
|
||||
<br>Reported to Steve Clamage by Niels Dekker, 2010
|
||||
</li><li>
|
||||
IBM's XL V10.1 and V11.1 may fail to value-initialize a temporary of a non-POD aggregate.
|
||||
<br>Reported to Michael Wong by Niels Dekker, 2010
|
||||
</li><li>
|
||||
Intel support issue 589832, Attempt to value-initialize pointer-to-member triggers internal error
|
||||
on Intel 11.1.
|
||||
<br>Reported by John Maddock, 2010
|
||||
</li>
|
||||
</ul>
|
||||
Note that all known GCC issues regarding value-initialization are
|
||||
fixed with GCC version 4.4, including
|
||||
<a href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30111">GCC Bug 30111</a>.
|
||||
Clang also has completely implemented value-initialization, as far as we know,
|
||||
now that <a href="http://llvm.org/bugs/show_bug.cgi?id=7139">Clang Bug 7139</a> is fixed.
|
||||
</p><p>
|
||||
|
||||
New versions of <code>value_initialized</code>
|
||||
(Boost release version 1.35 or higher)
|
||||
offer a workaround to these issues: <code>value_initialized</code> may now clear
|
||||
its internal data, prior to constructing the object that it contains. It will do
|
||||
so for those compilers that need to have such a workaround, based on the
|
||||
<a href="../config/doc/html/boost_config/boost_macro_reference.html#boost_config.boost_macro_reference.macros_that_describe_defects"
|
||||
>compiler defect macro</a> BOOST_NO_COMPLETE_VALUE_INITIALIZATION.
|
||||
</p>
|
||||
|
||||
<h2><a name="types"></a>Types and objects</h2>
|
||||
|
||||
<h2><a name="val_init"><code>template class value_initialized<T></code></a></h2>
|
||||
|
||||
<pre>namespace boost {<br><br>template<class T><br>class value_initialized<br>{
|
||||
<br> public :
|
||||
<br> value_initialized() : x() {}
|
||||
<br> operator T const &() const { return x ; }
|
||||
<br> operator T&() { return x ; }
|
||||
<br> T const &data() const { return x ; }
|
||||
<br> T& data() { return x ; }
|
||||
<br> void swap( value_initialized& );
|
||||
<br>
|
||||
<br> private :
|
||||
<br> <i>unspecified</i> x ;
|
||||
<br>} ;
|
||||
<br>
|
||||
<br>template<class T>
|
||||
<br>T const& get ( value_initialized<T> const& x )
|
||||
<br>{
|
||||
<br> return x.data() ;
|
||||
<br>}
|
||||
<br>
|
||||
<br>template<class T>
|
||||
<br>T& get ( value_initialized<T>& x )
|
||||
<br>{
|
||||
<br> return x.data() ;
|
||||
<br>}
|
||||
<br>
|
||||
<br>template<class T>
|
||||
<br>void swap ( value_initialized<T>& lhs, value_initialized<T>& rhs )
|
||||
<br>{
|
||||
<br> lhs.swap(rhs) ;
|
||||
<br>}
|
||||
<br>
|
||||
<br>} // namespace boost
|
||||
<br></pre>
|
||||
|
||||
<p>An object of this template class is a <code>T</code>-wrapper convertible
|
||||
to <code>'T&'</code> whose wrapped object (data member of type <code>T</code>)
|
||||
is <a href="#valueinit">value-initialized</a> upon default-initialization
|
||||
of this wrapper class: </p>
|
||||
|
||||
<pre>int zero = 0 ;<br>value_initialized<int> x ;<br>assert ( x == zero ) ;<br><br>std::string def ;<br>value_initialized< std::string > y ;<br>assert ( y == def ) ;<br></pre>
|
||||
|
||||
<p>The purpose of this wrapper is to provide a consistent syntax for value
|
||||
initialization of scalar, union and class types (POD and non-POD) since
|
||||
the correct syntax for value initialization varies (see <a
|
||||
href="#valueinitsyn">value-initialization syntax</a>)</p>
|
||||
|
||||
<p>The wrapped object can be accessed either through the conversion operator
|
||||
<code>T&</code>, the member function <code>data()</code>, or the
|
||||
non-member function <code>get()</code>: </p>
|
||||
|
||||
<pre>void watch(int);<br>value_initialized<int> x;
|
||||
<br><br>watch(x) ; // operator T& used.<br>watch(x.data());<br>watch( get(x) ) // function get() used</pre>
|
||||
|
||||
<p>Both <code>const</code> and non-<code>const</code> objects can be wrapped.
|
||||
Mutable objects can be modified directly from within the wrapper but constant
|
||||
objects cannot:</p>
|
||||
|
||||
<p>When <code>T</code> is a <em>Swappable</em> type, <code>value_initialized<T></code>
|
||||
is swappable as well, by calling its <code>swap</code> member function
|
||||
as well as by calling <code>boost::swap</code>.</p>
|
||||
|
||||
<pre>value_initialized<int> x ; <br>static_cast<int&>(x) = 1 ; // OK<br>get(x) = 1 ; // OK
|
||||
<br><br>value_initialized<int const> y ; <br>static_cast<int&>(y) = 1 ; // ERROR: cannot cast to int&<br>static_cast<int const&>(y) = 1 ; // ERROR: cannot modify a const value<br>get(y) = 1 ; // ERROR: cannot modify a const value</pre>
|
||||
|
||||
<h3>Warning:</h3>
|
||||
|
||||
<p>The <code>value_initialized</code> implementation of Boost version 1.40.0 and older
|
||||
allowed <i>non-const</i> access to the wrapped object, from a constant wrapper,
|
||||
both by its conversion operator and its <code>data()</code> member function. For example:</p>
|
||||
|
||||
<pre>value_initialized<int> const x_c ;<br>int& xr = x_c ; // OK, conversion to int& available even though x_c is itself const.
|
||||
<br>xr = 2 ; </pre>
|
||||
|
||||
<p>The reason for this obscure behavior was that some compilers
|
||||
didn't accept the following valid code:</p>
|
||||
|
||||
<pre>struct X<br>{<br> operator int&() ;<br> operator int const&() const ; <br>};<br>X x ;<br>(x == 1 ) ; // ERROR HERE!</pre>
|
||||
|
||||
<p>The current version of <code>value_initialized</code> no longer has this obscure behavior.
|
||||
As compilers nowadays widely support overloading the conversion operator by having a <code>const</code> and a <code>non-const</code> version, we have decided to fix the issue accordingly. So the current version supports the idea of logical constness.
|
||||
<br>
|
||||
</p>
|
||||
|
||||
<h3>Recommended practice: The non-member get() idiom</h3>
|
||||
|
||||
<p>The obscure behavior of being able to modify a non-<code>const</code>
|
||||
wrapped object from within a constant wrapper (as was supported by previous
|
||||
versions of <code>value_initialized</code>)
|
||||
can be avoided if access to
|
||||
the wrapped object is always performed with the <code>get()</code> idiom:</p>
|
||||
|
||||
<pre>value_initialized<int> x ;<br>get(x) = 1 ; // OK<br><br>value_initialized<int const> cx ;<br>get(x) = 1 ; // ERROR: Cannot modify a const object<br><br>value_initialized<int> const x_c ;<br>get(x_c) = 1 ; // ERROR: Cannot modify a const object<br><br>value_initialized<int const> const cx_c ;<br>get(cx_c) = 1 ; // ERROR: Cannot modify a const object<br></pre>
|
||||
|
||||
<h2><a name="initialized"><code>template class initialized<T></code></a></h2>
|
||||
|
||||
<pre>namespace boost {<br><br>template<class T><br>class initialized<br>{
|
||||
<br> public :
|
||||
<br> initialized() : x() {}
|
||||
<br> explicit initialized(T const & arg) : x(arg) {}
|
||||
<br> operator T const &() const;
|
||||
<br> operator T&();
|
||||
<br> T const &data() const;
|
||||
<br> T& data();
|
||||
<br> void swap( initialized& );
|
||||
<br>
|
||||
<br> private :
|
||||
<br> <i>unspecified</i> x ;
|
||||
<br>} ;
|
||||
<br>
|
||||
<br>template<class T>
|
||||
<br>T const& get ( initialized<T> const& x );
|
||||
<br>
|
||||
<br>template<class T>
|
||||
<br>T& get ( initialized<T>& x );
|
||||
<br>
|
||||
<br>template<class T>
|
||||
<br>void swap ( initialized<T>& lhs, initialized<T>& rhs );
|
||||
<br>
|
||||
<br>} // namespace boost
|
||||
<br></pre>
|
||||
|
||||
The template class <code>boost::initialized<T></code> supports both value-initialization
|
||||
and direct-initialization, so its interface is a superset of the interface
|
||||
of <code>value_initialized<T></code>: Its default-constructor
|
||||
value-initializes the wrapped object just like the default-constructor of
|
||||
<code>value_initialized<T></code>, but <code>boost::initialized<T></code>
|
||||
also offers an extra <code>explicit</code>
|
||||
constructor, which direct-initializes the wrapped object by the specified value.
|
||||
<p>
|
||||
|
||||
<code>initialized<T></code> is especially useful when the wrapped
|
||||
object must be either value-initialized or direct-initialized, depending on
|
||||
runtime conditions. For example, <code>initialized<T></code> could
|
||||
hold the value of a data member that may be value-initialized by some
|
||||
constructors, and direct-initialized by others.
|
||||
On the other hand, if it is known beforehand that the
|
||||
object must <i>always</i> be value-initialized, <code>value_initialized<T></code>
|
||||
may be preferable. And if the object must always be
|
||||
direct-initialized, none of the two wrappers really needs to be used.
|
||||
</p>
|
||||
|
||||
|
||||
<h2><a name="initialized_value"><code>initialized_value</code></a></h2>
|
||||
|
||||
<pre>
|
||||
namespace boost {
|
||||
class initialized_value_t
|
||||
{
|
||||
public :
|
||||
template <class T> operator T() const ;
|
||||
};
|
||||
|
||||
initialized_value_t const initialized_value = {} ;
|
||||
|
||||
} // namespace boost
|
||||
</pre>
|
||||
|
||||
<code>initialized_value</code> provides a convenient way to get
|
||||
an initialized value: its conversion operator provides an appropriate
|
||||
<em>value-initialized</em> object for any CopyConstructible type.
|
||||
|
||||
Suppose you need to have an initialized variable of type <code>T</code>.
|
||||
You could do it as follows:
|
||||
<pre>
|
||||
T var = T();
|
||||
</pre>
|
||||
But as mentioned before, this form suffers from various compiler issues.
|
||||
The template <code>value_initialized</code> offers a workaround:
|
||||
<pre>
|
||||
T var = get( value_initialized<T>() );
|
||||
</pre>
|
||||
Unfortunately both forms repeat the type name, which
|
||||
is rather short now (<code>T</code>), but could of course be
|
||||
more like <code>Namespace::Template<Arg>::Type</code>.
|
||||
Instead, one could use <code>initialized_value</code> as follows:
|
||||
<pre>
|
||||
T var = initialized_value ;
|
||||
</pre>
|
||||
|
||||
<h3><a name="references">References</a></h3>
|
||||
[1] Bjarne Stroustrup, Gabriel Dos Reis, and J. Stephen Adamczyk wrote
|
||||
various papers, proposing to extend the support for brace-enclosed <em>initializer lists</em>
|
||||
in the next version of C++.
|
||||
This would allow a variable <code>var</code> of any DefaultConstructible type
|
||||
<code>T</code> to be <em>value-initialized</em> by doing <code>T var = {}</code>.
|
||||
The papers are listed at Bjarne's web page,
|
||||
<a href="http://www.research.att.com/~bs/WG21.html">My C++ Standards committee papers</a> <br>
|
||||
[2] Scott Meyers, Effective C++, Third Edition, item 6,
|
||||
<em>Explicitly disallow the use of compiler-generated functions you do not want</em>,
|
||||
<a href="http://www.aristeia.com/books.html">Scott Meyers: Books and CDs</a> <br>
|
||||
[3] The C++ Standard, Second edition (2003), ISO/IEC 14882:2003 <br>
|
||||
[4] POD stands for "Plain Old Data"
|
||||
|
||||
<h3><a name="acknowledgements"></a>Acknowledgements</h3>
|
||||
value_initialized was developed by Fernando Cacciola, with help and
|
||||
suggestions from David Abrahams and Darin Adler.<br>
|
||||
Special thanks to Björn Karlsson who carefully edited and completed this documentation.
|
||||
|
||||
<p>value_initialized was reimplemented by Fernando Cacciola and Niels Dekker
|
||||
for Boost release version 1.35 (2008), offering a workaround to various compiler issues.
|
||||
</p>
|
||||
<p><code>boost::initialized</code> was very much inspired by feedback from Edward Diener and
|
||||
Jeffrey Hellrung.
|
||||
</p>
|
||||
<p>initialized_value was written by Niels Dekker, and added to Boost release version 1.36 (2008).
|
||||
</p>
|
||||
<p>Developed by <a href="mailto:fernando_cacciola@hotmail.com">Fernando Cacciola</a>,
|
||||
the latest version of this file can be found at <a
|
||||
href="http://www.boost.org">www.boost.org</a>.
|
||||
</p>
|
||||
|
||||
<hr>
|
||||
<p>Revised 30 May 2010</p>
|
||||
|
||||
<p>© Copyright Fernando Cacciola, 2002 - 2010.</p>
|
||||
|
||||
<p>Distributed under the Boost Software License, Version 1.0. See
|
||||
<a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a></p>
|
||||
|
||||
<br>
|
||||
<br>
|
||||
|
||||
<body>
|
||||
Automatic redirection failed, please go to
|
||||
<a href="./doc/html/utility/utilities/value_init.html">./doc/html/utility/utilities/value_init.html</a>
|
||||
<hr>
|
||||
<tt>
|
||||
Boost.Utility<br>
|
||||
<br>
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
<a href=http://www.boost.org/LICENSE_1_0.txt>http://www.boost.org/LICENSE_1_0.txt</a>) <br>
|
||||
<br>
|
||||
</tt>
|
||||
</body>
|
||||
</html>
|
||||
|
Reference in New Issue
Block a user