mirror of
https://github.com/boostorg/algorithm.git
synced 2025-06-25 12:01:39 +02:00
Compare commits
126 Commits
boost-1.66
...
boost-1.81
Author | SHA1 | Date | |
---|---|---|---|
28dd87b90e | |||
7d8a063d35 | |||
0666c4ce35 | |||
6f4d74c6bb | |||
6d58f2b9d1 | |||
6a5ca4e89c | |||
e8ba63c4ad | |||
1c5f74ae25 | |||
6931736390 | |||
1cfd9592f7 | |||
12ade334e0 | |||
eec00d8421 | |||
055ebaa4cd | |||
559835eaa5 | |||
00c6f1d6c1 | |||
6b7a38f639 | |||
02f436c25d | |||
da8ea581eb | |||
a9cd6c353f | |||
2a05506d52 | |||
9d5ddb6a7a | |||
9031f17bb8 | |||
0c2e904c0d | |||
d717d999be | |||
2409048368 | |||
fe66d6211d | |||
c5f6f52560 | |||
ba3f706b1d | |||
aab7e1c121 | |||
02b05e5e24 | |||
4ad181f464 | |||
3b3bd8d3db | |||
c9077bd495 | |||
bcd55d9992 | |||
b139b72230 | |||
137c92dac0 | |||
bd81ca42a2 | |||
fc86cd34f7 | |||
ca77e55428 | |||
8c26a50a12 | |||
c16b8ffadd | |||
1e098f39d4 | |||
e4c3628f4d | |||
49d284392c | |||
68100d9198 | |||
1634b819b3 | |||
4547b1a5fe | |||
7f527f3c4d | |||
130e4da8cb | |||
7975c764bb | |||
8710bbd4b6 | |||
cfb7c429f7 | |||
ed4033f0cc | |||
6d86fb3aaa | |||
ce81930319 | |||
8e23ffde9e | |||
e59958cc4d | |||
a814721376 | |||
9ef3df0d0b | |||
44527f4c81 | |||
9093abbda9 | |||
1b65b8de02 | |||
77bbc6ce43 | |||
0a57ec30a2 | |||
ac1713e130 | |||
9477cd8be0 | |||
f39107f228 | |||
5af3e3b174 | |||
1cbe285841 | |||
b6c04d6dc5 | |||
bf2b49e57e | |||
01b0dd8648 | |||
6763d75683 | |||
435cc61af8 | |||
45baad2431 | |||
5408a17020 | |||
c6f784cb70 | |||
badf1b3f0c | |||
e4dfe0885f | |||
4f9afb0682 | |||
3659b18846 | |||
6bb5fa5ee0 | |||
ee7a0247be | |||
d1b0024aad | |||
ecb8bfab76 | |||
3f2a962ace | |||
6b2246468e | |||
ea7d35d949 | |||
c5c5d24ff3 | |||
6c68cf8624 | |||
8c9d5e858c | |||
86d26e7e2e | |||
94460b0ca5 | |||
45a4d2580c | |||
d7d91d431a | |||
7ec1c5c413 | |||
d574d1edd7 | |||
6d0126df8a | |||
3af7acabc7 | |||
509201f29f | |||
b0f04afcb0 | |||
df58b44581 | |||
c34713b983 | |||
aa8cce5bb4 | |||
d6c8b271b3 | |||
50a2115236 | |||
739d1ed8a2 | |||
298310f521 | |||
63c85e7c5e | |||
cb52d61054 | |||
4ac6b84cfa | |||
0539e0d84a | |||
7df35ffd56 | |||
554db2f07d | |||
f9583cfd39 | |||
8ae18ae455 | |||
32016b3c79 | |||
15c7ff3828 | |||
000040b3d9 | |||
e07e8e65c6 | |||
ba7655eb3a | |||
1970454ecb | |||
1ed284d696 | |||
968d30e9e3 | |||
dfa332e915 | |||
8d095e9d30 |
193
.travis.yml
Normal file
193
.travis.yml
Normal file
@ -0,0 +1,193 @@
|
||||
# Copyright 2016 - 2018 Peter Dimov
|
||||
# Copyright 2018 T. Zachary Laine
|
||||
# Copyright 2017 - 2019 James E. King III
|
||||
# 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)
|
||||
|
||||
#
|
||||
# Generic Travis CI build script for boostorg repositories
|
||||
# See: https://github.com/boostorg/boost-ci
|
||||
#
|
||||
# Instructions for customizing this script for your library:
|
||||
#
|
||||
# 1. Customize the compilers and language levels you want in the 'jobs'.
|
||||
# 2. If you have more than include/, src/, test/, example/, examples/, or
|
||||
# tools/ directories, modify your Travis CI project and add the environment
|
||||
# variable DEPINST. For example if your build uses code in "bench/" and
|
||||
# "fog/" directories, then set DEPINST to the following:
|
||||
# --include bench --include fog
|
||||
# 3. If you want to enable Coverity Scan, you need to provide the environment
|
||||
# variables COVERITY_SCAN_TOKEN and COVERITY_SCAN_NOTIFICATION_EMAIL in
|
||||
# your github settings.
|
||||
# 4. Enable pull request builds in your boostorg/<library> account.
|
||||
#
|
||||
# That's it - the scripts will do everything else for you.
|
||||
|
||||
dist: xenial
|
||||
language: cpp
|
||||
|
||||
env:
|
||||
global:
|
||||
# see: http://www.boost.org/build/doc/html/bbv2/overview/invocation.html#bbv2.overview.invocation.properties
|
||||
# to use the default for a given environment, comment it out; recommend you build debug and release however..
|
||||
# - B2_ADDRESS_MODEL=address-model=64,32
|
||||
# - B2_LINK=link=shared,static
|
||||
# - B2_THREADING=threading=multi,single
|
||||
- B2_VARIANT=variant=release,debug
|
||||
|
||||
install:
|
||||
- git clone https://github.com/boostorg/boost-ci.git boost-ci
|
||||
- cp -pr boost-ci/ci boost-ci/.codecov.yml .
|
||||
- source ci/travis/install.sh
|
||||
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- binutils-gold
|
||||
- gdb
|
||||
- libc6-dbg
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- develop
|
||||
- bugfix/*
|
||||
- feature/*
|
||||
- fix/*
|
||||
- pr/*
|
||||
|
||||
script:
|
||||
- cd $BOOST_ROOT/libs/$SELF
|
||||
- ci/travis/build.sh
|
||||
|
||||
#
|
||||
# Default toolsets in Ubuntu
|
||||
#
|
||||
# trusty xenial bionic
|
||||
# 14.04 16.04 18.04
|
||||
# ------ ------ ------
|
||||
# clang 3.4 3.8 6.0
|
||||
# gcc 4.8.2 5.3.1 7.3.0
|
||||
#
|
||||
|
||||
anchors:
|
||||
clang-38: &clang-38 { apt: { packages: [ "clang-3.8",
|
||||
"libstdc++-6-dev" ], sources: [ "llvm-toolchain-xenial-3.8",
|
||||
"ubuntu-toolchain-r-test" ] } }
|
||||
clang-4: &clang-4 { apt: { packages: [ "clang-4.0",
|
||||
"libstdc++-6-dev" ], sources: [ "llvm-toolchain-xenial-4.0",
|
||||
"ubuntu-toolchain-r-test" ] } }
|
||||
clang-5: &clang-5 { apt: { packages: [ "clang-5.0",
|
||||
"libstdc++-7-dev" ], sources: [ "llvm-toolchain-xenial-5.0",
|
||||
"ubuntu-toolchain-r-test" ] } }
|
||||
clang-6: &clang-6 { apt: { packages: [ "clang-6.0",
|
||||
"libc6-dbg",
|
||||
"libc++-dev",
|
||||
"libstdc++-8-dev" ], sources: [ "llvm-toolchain-xenial-6.0",
|
||||
"ubuntu-toolchain-r-test" ] } }
|
||||
clang-7: &clang-7 { apt: { packages: [ "clang-7",
|
||||
"libc6-dbg",
|
||||
"libc++-dev",
|
||||
"libstdc++-8-dev" ], sources: [ "llvm-toolchain-xenial-7",
|
||||
"ubuntu-toolchain-r-test" ] } }
|
||||
clang-8: &clang-8 { apt: { packages: [ "clang-8",
|
||||
"libc6-dbg",
|
||||
"libc++-dev",
|
||||
"libstdc++-8-dev" ], sources: [ "llvm-toolchain-xenial-8",
|
||||
"ubuntu-toolchain-r-test" ] } }
|
||||
gcc-48: &gcc-48 { apt: { packages: [ "g++-4.8" ] } }
|
||||
gcc-49: &gcc-49 { apt: { packages: [ "g++-4.9" ] } }
|
||||
gcc-5: &gcc-5 { apt: { packages: [ "g++-5" ] } }
|
||||
gcc-6: &gcc-6 { apt: { packages: [ "g++-6" ], sources: [ "ubuntu-toolchain-r-test" ] } }
|
||||
gcc-7: &gcc-7 { apt: { packages: [ "g++-7" ], sources: [ "ubuntu-toolchain-r-test" ] } }
|
||||
gcc-8: &gcc-8 { apt: { packages: [ "g++-8" ], sources: [ "ubuntu-toolchain-r-test" ] } }
|
||||
|
||||
jobs:
|
||||
allow_failures:
|
||||
- env:
|
||||
- COPY="all the environment settings from your job"
|
||||
|
||||
include:
|
||||
# libstdc++
|
||||
- { os: "linux", env: [ "B2_TOOLSET=gcc-4.8", "B2_CXXSTD=03,11" ], addons: *gcc-48 }
|
||||
- { os: "linux", env: [ "B2_TOOLSET=gcc-4.9", "B2_CXXSTD=03,11" ], addons: *gcc-49 }
|
||||
- { os: "linux", env: [ "B2_TOOLSET=gcc-5", "B2_CXXSTD=11" ], addons: *gcc-5 }
|
||||
- { os: "linux", env: [ "B2_TOOLSET=gcc-6", "B2_CXXSTD=11,14" ], addons: *gcc-6 }
|
||||
- { os: "linux", env: [ "B2_TOOLSET=gcc-7", "B2_CXXSTD=11,14,17" ], addons: *gcc-7 }
|
||||
- { os: "linux", env: [ "B2_TOOLSET=gcc-8", "B2_CXXSTD=14,17,2a" ], addons: *gcc-8 }
|
||||
- { os: "linux", env: [ "B2_TOOLSET=clang-3.8", "B2_CXXSTD=03,11,14" ], addons: *clang-38 }
|
||||
- { os: "linux", env: [ "B2_TOOLSET=clang-4.0", "B2_CXXSTD=11,14" ], addons: *clang-4 }
|
||||
- { os: "linux", env: [ "B2_TOOLSET=clang-5.0", "B2_CXXSTD=11,14,17" ], addons: *clang-5 }
|
||||
- { os: "linux", env: [ "B2_TOOLSET=clang-6.0", "B2_CXXSTD=14,17,2a" ], addons: *clang-6 }
|
||||
- { os: "linux", env: [ "B2_TOOLSET=clang-7", "B2_CXXSTD=14,17,2a" ], addons: *clang-7 }
|
||||
- { os: "linux", env: [ "B2_TOOLSET=clang-8", "B2_CXXSTD=14,17,2a" ], addons: *clang-8 }
|
||||
|
||||
# libc++
|
||||
- { os: "linux", env: [ "B2_TOOLSET=clang-6.0", "B2_CXXSTD=03,11,14,17,2a",
|
||||
"B2_CXXFLAGS=-stdlib=libc++" ], addons: *clang-6 }
|
||||
- { os: "osx" , env: [ "B2_TOOLSET=clang", "B2_CXXSTD=03,11,17" ] }
|
||||
|
||||
# to enable Intel ICC define INTEL_ICC_SERIAL_NUMBER and the following:
|
||||
# - { os: "linux", env: [ "B2_TOOLSET=intel-linux", "B2_CXXSTD=11,14,17" ], addons: *gcc-7,
|
||||
# script: cd $BOOST_ROOT/libs/$SELF && ci/travis/intelicc.sh }
|
||||
|
||||
- os: linux
|
||||
env:
|
||||
- COMMENT=codecov.io
|
||||
- B2_TOOLSET=03,11,14
|
||||
- B2_TOOLSET=gcc-8
|
||||
- B2_DEFINES="define=BOOST_NO_STRESS_TEST=1"
|
||||
addons: *gcc-8
|
||||
script:
|
||||
- pushd /tmp && git clone https://github.com/linux-test-project/lcov.git && export PATH=/tmp/lcov/bin:$PATH && which lcov && lcov --version && popd
|
||||
- cd $BOOST_ROOT/libs/$SELF
|
||||
- ci/travis/codecov.sh
|
||||
|
||||
- os: linux
|
||||
env:
|
||||
- COMMENT=cppcheck
|
||||
script:
|
||||
- cd $BOOST_ROOT/libs/$SELF
|
||||
- ci/travis/cppcheck.sh
|
||||
|
||||
- os: linux
|
||||
env:
|
||||
- COMMENT=ubsan
|
||||
- B2_VARIANT=variant=debug
|
||||
- B2_TOOLSET=gcc-8
|
||||
- B2_CXXSTD=03,11,14,17,2a
|
||||
- B2_DEFINES="define=BOOST_NO_STRESS_TEST=1"
|
||||
- B2_CXXFLAGS="cxxflags=-fno-omit-frame-pointer cxxflags=-fsanitize=undefined cxxflags=-fno-sanitize-recover=all"
|
||||
- B2_LINKFLAGS="linkflags=-fsanitize=undefined linkflags=-fno-sanitize-recover=all linkflags=-fuse-ld=gold"
|
||||
- UBSAN_OPTIONS=print_stacktrace=1
|
||||
addons: *gcc-8
|
||||
|
||||
- os: linux
|
||||
env:
|
||||
- COMMENT=valgrind
|
||||
- B2_TOOLSET=clang-6.0
|
||||
- B2_CXXSTD=03,11,14,17,2a
|
||||
- B2_DEFINES="define=BOOST_NO_STRESS_TEST=1"
|
||||
- B2_VARIANT=variant=debug
|
||||
- B2_TESTFLAGS=testing.launcher=valgrind
|
||||
- VALGRIND_OPTS=--error-exitcode=1
|
||||
addons: *clang-6
|
||||
script:
|
||||
- cd $BOOST_ROOT/libs/$SELF
|
||||
- ci/travis/valgrind.sh
|
||||
|
||||
#################### Jobs to run on pushes to master, develop ###################
|
||||
|
||||
# Coverity Scan
|
||||
- os: linux
|
||||
if: (env(COVERITY_SCAN_NOTIFICATION_EMAIL) IS present) AND (branch IN (develop, master)) AND (type IN (cron, push))
|
||||
env:
|
||||
- COMMENT="Coverity Scan"
|
||||
- B2_TOOLSET=clang
|
||||
script:
|
||||
- cd $BOOST_ROOT/libs/$SELF
|
||||
- ci/travis/coverity.sh
|
||||
|
||||
notifications:
|
||||
email:
|
||||
false
|
41
CMakeLists.txt
Normal file
41
CMakeLists.txt
Normal file
@ -0,0 +1,41 @@
|
||||
# Generated by `boostdep --cmake algorithm`
|
||||
# Copyright 2020 Peter Dimov
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
cmake_minimum_required(VERSION 3.5...3.16)
|
||||
|
||||
project(boost_algorithm VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)
|
||||
|
||||
add_library(boost_algorithm INTERFACE)
|
||||
add_library(Boost::algorithm ALIAS boost_algorithm)
|
||||
|
||||
target_include_directories(boost_algorithm INTERFACE include)
|
||||
|
||||
target_link_libraries(boost_algorithm
|
||||
INTERFACE
|
||||
Boost::array
|
||||
Boost::assert
|
||||
Boost::bind
|
||||
Boost::concept_check
|
||||
Boost::config
|
||||
Boost::core
|
||||
Boost::exception
|
||||
Boost::function
|
||||
Boost::iterator
|
||||
Boost::mpl
|
||||
Boost::range
|
||||
Boost::regex
|
||||
Boost::static_assert
|
||||
Boost::throw_exception
|
||||
Boost::tuple
|
||||
Boost::type_traits
|
||||
Boost::unordered
|
||||
)
|
||||
|
||||
if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")
|
||||
|
||||
add_subdirectory(test)
|
||||
|
||||
endif()
|
||||
|
11
Jamfile
Normal file
11
Jamfile
Normal file
@ -0,0 +1,11 @@
|
||||
# Boost.Algorithm Library Jamfile
|
||||
#
|
||||
# Copyright (c) 2018 James E. King III
|
||||
#
|
||||
# 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)
|
||||
|
||||
# please order by name to ease maintenance
|
||||
build-project example ;
|
||||
build-project test ;
|
23
LICENSE
Normal file
23
LICENSE
Normal file
@ -0,0 +1,23 @@
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
35
README.md
Normal file
35
README.md
Normal file
@ -0,0 +1,35 @@
|
||||
Algorithm, part of collection of the [Boost C++ Libraries](http://github.com/boostorg), is a collection of general purpose algorithms.
|
||||
|
||||
### License
|
||||
|
||||
Distributed under the [Boost Software License, Version 1.0](http://www.boost.org/LICENSE_1_0.txt).
|
||||
|
||||
### Properties
|
||||
|
||||
* C++03
|
||||
* Header-only
|
||||
|
||||
### Build Status
|
||||
|
||||
Branch | Travis | Appveyor | Coverity Scan | codecov.io | Deps | Docs | Tests |
|
||||
:-------------: | ------ | -------- | ------------- | ---------- | ---- | ---- | ----- |
|
||||
[`master`](https://github.com/boostorg/algorithm/tree/master) | [](https://travis-ci.org/boostorg/algorithm) | [](https://ci.appveyor.com/project/USER/PROJECT/branch/master) | [](https://scan.coverity.com/projects/boostorg-algorithm) | [](https://codecov.io/gh/boostorg/algorithm/branch/master)| [](https://pdimov.github.io/boostdep-report/master/algorithm.html) | [](http://www.boost.org/doc/libs/master/doc/html/algorithm.html) | [](http://www.boost.org/development/tests/master/developer/algorithm.html)
|
||||
[`develop`](https://github.com/boostorg/algorithm/tree/develop) | [](https://travis-ci.org/boostorg/algorithm) | [](https://ci.appveyor.com/project/USER/PROJECT/branch/develop) | [](https://scan.coverity.com/projects/boostorg-algorithm) | [](https://codecov.io/gh/boostorg/algorithm/branch/develop) | [](https://pdimov.github.io/boostdep-report/develop/algorithm.html) | [](http://www.boost.org/doc/libs/develop/doc/html/algorithm.html) | [](http://www.boost.org/development/tests/develop/developer/algorithm.html)
|
||||
|
||||
### Directories
|
||||
|
||||
| Name | Purpose |
|
||||
| ----------- | ------------------------------ |
|
||||
| `doc` | documentation |
|
||||
| `example` | examples |
|
||||
| `include` | headers |
|
||||
| `test` | unit tests |
|
||||
|
||||
### More information
|
||||
|
||||
* [Ask questions](http://stackoverflow.com/questions/ask?tags=c%2B%2B,boost,boost-algorithm)
|
||||
* [Report bugs](https://github.com/boostorg/algorithm/issues): Be sure to mention Boost version, 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](http://www.boost.org/LICENSE_1_0.txt).
|
||||
* Discussions about the library are held on the [Boost developers mailing list](http://www.boost.org/community/groups.html#main). Be sure to read the [discussion policy](http://www.boost.org/community/policy.html) before posting and add the `[algorithm]` tag at the beginning of the subject line.
|
||||
|
||||
|
130
appveyor.yml
Normal file
130
appveyor.yml
Normal file
@ -0,0 +1,130 @@
|
||||
# Copyright 2016, 2017 Peter Dimov
|
||||
# Copyright (C) 2017 - 2019 James E. King III
|
||||
# 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)
|
||||
|
||||
#
|
||||
# Generic Appveyor build script for boostorg repositories
|
||||
# See: https://github.com/boostorg/boost-ci/
|
||||
#
|
||||
# Instructions for customizing this script for your library:
|
||||
#
|
||||
# 1. Customize the compilers and language levels you want.
|
||||
# 2. If you have more than include/, src/, test/, example/, examples/,
|
||||
# benchmark/ or tools/ directories, set the environment variable DEPINST.
|
||||
# For example if your build uses code in "bench/" and "fog/" directories:
|
||||
# - DEPINST: --include bench --include fog
|
||||
# 3. Enable pull request builds in your boostorg/<library> account.
|
||||
#
|
||||
# That's it - the script will do everything else for you.
|
||||
#
|
||||
|
||||
version: 1.0.{build}-{branch}
|
||||
|
||||
shallow_clone: true
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- develop
|
||||
- bugfix/*
|
||||
- feature/*
|
||||
- fix/*
|
||||
- pr/*
|
||||
|
||||
matrix:
|
||||
# Adding MAYFAIL to any matrix job allows it to fail but the build stays green:
|
||||
allow_failures:
|
||||
- MAYFAIL: true
|
||||
|
||||
environment:
|
||||
global:
|
||||
# see: http://www.boost.org/build/doc/html/bbv2/overview/invocation.html#bbv2.overview.invocation.properties
|
||||
# to use the default for a given environment, comment it out; recommend you build debug and release however:
|
||||
# on Windows it is important to exercise all the possibilities, especially shared vs static, however most
|
||||
# libraries that care about this exercise it in their Jamfiles...
|
||||
# B2_ADDRESS_MODEL: address-model=64,32
|
||||
# B2_LINK: link=shared,static
|
||||
# B2_THREADING: threading=multi,single
|
||||
B2_VARIANT: variant=release,debug
|
||||
|
||||
matrix:
|
||||
- FLAVOR: Visual Studio 2017 C++2a Strict
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
B2_ADDRESS_MODEL: address-model=64
|
||||
B2_CXXFLAGS: cxxflags=-permissive-
|
||||
B2_CXXSTD: latest # 2a
|
||||
B2_TOOLSET: msvc-14.1
|
||||
|
||||
- FLAVOR: Visual Studio 2017 C++17
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
B2_ADDRESS_MODEL: address-model=64
|
||||
B2_CXXSTD: 17
|
||||
B2_TOOLSET: msvc-14.1
|
||||
|
||||
- FLAVOR: Visual Studio 2017 C++14 (Default)
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
B2_ADDRESS_MODEL: address-model=64,32
|
||||
B2_TOOLSET: msvc-14.1
|
||||
|
||||
- FLAVOR: Visual Studio 2015 C++14 (Default)
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
B2_ADDRESS_MODEL: address-model=64,32
|
||||
B2_TOOLSET: msvc-14.0
|
||||
|
||||
- FLAVOR: Visual Studio 2010, 2012, 2013
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
B2_TOOLSET: msvc-10.0,msvc-11.0,msvc-12.0
|
||||
|
||||
- FLAVOR: cygwin (32-bit)
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
ADDPATH: C:\cygwin\bin;
|
||||
B2_ADDRESS_MODEL: address-model=32
|
||||
B2_CXXSTD: 03,11
|
||||
# https://github.com/boostorg/test/issues/144
|
||||
B2_DEFINES: define=_POSIX_C_SOURCE=200112L
|
||||
B2_THREADING: threadapi=pthread
|
||||
B2_TOOLSET: gcc
|
||||
|
||||
- FLAVOR: cygwin (64-bit)
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
ADDPATH: C:\cygwin64\bin;
|
||||
B2_ADDRESS_MODEL: address-model=64
|
||||
B2_CXXSTD: 11,17
|
||||
# https://github.com/boostorg/test/issues/144
|
||||
B2_DEFINES: define=_POSIX_C_SOURCE=200112L define=__USE_ISOC99
|
||||
B2_THREADING: threadapi=pthread
|
||||
B2_TOOLSET: gcc
|
||||
|
||||
- FLAVOR: mingw32
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
ARCH: i686
|
||||
B2_ADDRESS_MODEL: address-model=32
|
||||
B2_CXXSTD: 03,11
|
||||
SCRIPT: ci\appveyor\mingw.bat
|
||||
|
||||
- FLAVOR: mingw64
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
ARCH: x86_64
|
||||
B2_ADDRESS_MODEL: address-model=64
|
||||
B2_CXXSTD: 11,17
|
||||
B2_DEFINES: define=__USE_ISOC99
|
||||
SCRIPT: ci\appveyor\mingw.bat
|
||||
|
||||
install:
|
||||
- set SELF=%APPVEYOR_PROJECT_NAME:-=_%
|
||||
- git clone https://github.com/boostorg/boost-ci.git C:\boost-ci
|
||||
- xcopy /s /e /q /i C:\boost-ci\ci .\ci
|
||||
- ci\appveyor\install.bat
|
||||
|
||||
build: off
|
||||
|
||||
test_script:
|
||||
- set SELF=%APPVEYOR_PROJECT_NAME:-=_%
|
||||
- PATH=%ADDPATH%%PATH%
|
||||
# The definition of B2_TOOLCXX omits B2_CXXSTD= if it was not defined above
|
||||
- IF NOT DEFINED B2_CXXSTD (SET B2_TOOLCXX=toolset=%B2_TOOLSET%) ELSE (SET B2_TOOLCXX=toolset=%B2_TOOLSET% cxxstd=%B2_CXXSTD%)
|
||||
# Echo the complete build command to the build log
|
||||
- IF NOT DEFINED SCRIPT (ECHO b2 libs/%SELF:\=/% %B2_TOOLCXX% %B2_CXXFLAGS% %B2_DEFINES% %B2_THREADING% %B2_ADDRESS_MODEL% %B2_LINK% %B2_THREADING% %B2_VARIANT% -j3)
|
||||
# Now go build...
|
||||
- IF DEFINED SCRIPT (call libs\%SELF%\%SCRIPT%) ELSE (b2 libs/%SELF:\=/% %B2_TOOLCXX% %B2_CXXFLAGS% %B2_DEFINES% %B2_THREADING% %B2_ADDRESS_MODEL% %B2_LINK% %B2_THREADING% %B2_VARIANT% -j3)
|
@ -22,6 +22,7 @@ doxygen autodoc
|
||||
../../../boost/algorithm/searching/*.hpp
|
||||
../../../boost/algorithm/cxx11/*.hpp
|
||||
../../../boost/algorithm/cxx14/*.hpp
|
||||
../../../boost/algorithm/cxx17/*.hpp
|
||||
]
|
||||
:
|
||||
<doxygen:param>"PREDEFINED=\"BOOST_ALGORITHM_DOXYGEN=1\""
|
||||
@ -40,8 +41,8 @@ boostbook standalone
|
||||
<xsl:param>"boost.doxygen.reftitle=Boost.Algorithms C++ Reference"
|
||||
<xsl:param>chapter.autolabel=0
|
||||
<xsl:param>chunk.section.depth=8
|
||||
<xsl:param>toc.section.depth=2
|
||||
<xsl:param>toc.max.depth=2
|
||||
<xsl:param>toc.section.depth=3
|
||||
<xsl:param>toc.max.depth=3
|
||||
<xsl:param>generate.section.toc.level=1
|
||||
;
|
||||
|
||||
|
@ -46,7 +46,11 @@ Thanks to all the people who have reviewed this library and made suggestions for
|
||||
[include knuth_morris_pratt.qbk]
|
||||
[endsect]
|
||||
|
||||
|
||||
[section:CXX11 C++11 Algorithms]
|
||||
|
||||
[section:CXX11_inner_algorithms]
|
||||
|
||||
[include all_of.qbk]
|
||||
[include any_of.qbk]
|
||||
[include none_of.qbk]
|
||||
@ -55,21 +59,231 @@ Thanks to all the people who have reviewed this library and made suggestions for
|
||||
[include is_partitioned.qbk]
|
||||
[include is_permutation.qbk]
|
||||
[include partition_point.qbk]
|
||||
[endsect]
|
||||
|
||||
[section:partition_copy partition_copy ]
|
||||
[*[^[link header.boost.algorithm.cxx11.partition_copy_hpp partition_copy] ] ]
|
||||
Copy a subset of a sequence to a new sequence
|
||||
[endsect:partition_copy]
|
||||
|
||||
[section:copy_if copy_if ]
|
||||
[*[^[link header.boost.algorithm.cxx11.copy_if_hpp copy_if] ] ]
|
||||
Copy a subset of a sequence to a new sequence
|
||||
[endsect:copy_if]
|
||||
|
||||
[section:copy_n copy_n ]
|
||||
[*[^[link header.boost.algorithm.cxx11.copy_n_hpp copy_n] ] ]
|
||||
Copy n items from one sequence to another
|
||||
[endsect:copy_n]
|
||||
|
||||
[section:iota iota ]
|
||||
[*[^[link header.boost.algorithm.cxx11.iota_hpp iota] ] ]
|
||||
Generate an increasing series
|
||||
[endsect:iota]
|
||||
|
||||
[endsect:CXX11_inner_algorithms]
|
||||
|
||||
[endsect:CXX11]
|
||||
|
||||
|
||||
[section:CXX14 C++14 Algorithms]
|
||||
|
||||
[section:CXX14_inner_algorithms]
|
||||
|
||||
[include equal.qbk]
|
||||
[include mismatch.qbk]
|
||||
[endsect]
|
||||
|
||||
[endsect:CXX14_inner_algorithms]
|
||||
|
||||
[endsect:CXX14]
|
||||
|
||||
|
||||
[section:CXX17 C++17 Algorithms]
|
||||
|
||||
[section:CXX17_inner_algorithms]
|
||||
|
||||
[section:for_each_n for_each_n]
|
||||
[*[^[link boost.algorithm.for_each_n for_each_n] ] ]
|
||||
Apply a functor to the elements of a sequence
|
||||
[endsect:for_each_n]
|
||||
|
||||
[section:transform_inclusive_scan transform_inclusive_scan]
|
||||
[*[^[link boost.algorithm.transform_inclusive_scan transform_inclusive_scan] ] ]
|
||||
Transform each element in a range then combine adjacent elements to create an output range. Inclusive scaning means that the nth input is present in the nth output.
|
||||
[endsect:transform_inclusive_scan]
|
||||
|
||||
[section:transform_exclusive_scan transform_exclusive_scan]
|
||||
[*[^[link boost.algorithm.transform_exclusive_scan transform_exclusive_scan] ] ]
|
||||
Transform each element in a range then combine adjacent elements to create an output range. Exclusive scanning means that the nth input is not present in the nth output.
|
||||
[endsect:transform_exclusive_scan]
|
||||
|
||||
[endsect:CXX17_inner_algorithms]
|
||||
|
||||
[endsect:CXX17]
|
||||
|
||||
|
||||
[section:Copy Variations on Copy]
|
||||
[section:variations_on_copy]
|
||||
|
||||
[section:copy_until copy_until ]
|
||||
[*[^[link header.boost.algorithm.cxx11.copy_if_hpp copy_until] ] ]
|
||||
Copy all the elements from the start of the input range to the output range until the predicate is satisfied
|
||||
[endsect:copy_until]
|
||||
|
||||
[section:copy_while copy_while ]
|
||||
[*[^[link header.boost.algorithm.cxx11.copy_if_hpp copy_while] ] ]
|
||||
Copy all the elements from the start of the input range to the output range while the predicate is satisfied
|
||||
[endsect:copy_while]
|
||||
|
||||
[section:copy_if_until copy_if_until ]
|
||||
[*[^[link header.boost.algorithm.cxx11.copy_if_hpp copy_if_until ] ]
|
||||
Copy all elements that satisfy the element predicate from the start of the input range to the output range until the termination predicate is satisfied
|
||||
|
||||
[endsect:copy_if_until]
|
||||
|
||||
[section:copy_if_while copy_if_while ]
|
||||
[*[^[link header.boost.algorithm.cxx11.copy_if_hpp copy_if_while ] ]
|
||||
Copy all elements that satisfy the element predicate from the start of the input range to the output range while the termination predicate is satisfied
|
||||
|
||||
[endsect:copy_if_while]
|
||||
|
||||
[endsect:variations_on_copy]
|
||||
[endsect:Copy]
|
||||
|
||||
|
||||
[section:Misc Other Algorithms]
|
||||
[include clamp-hpp.qbk]
|
||||
[include gather.qbk]
|
||||
[include hex.qbk]
|
||||
[include is_palindrome.qbk]
|
||||
[include is_partitioned_until.qbk]
|
||||
[endsect]
|
||||
|
||||
[section:misc_inner_algorithms]
|
||||
|
||||
[section:none_of_equal none_of_equal ]
|
||||
[*[^[link header.boost.algorithm.cxx11.none_of_hpp none_of_equal] ] ]
|
||||
Whether none of a range's elements matches a value
|
||||
[endsect:none_of_equal]
|
||||
|
||||
[section:one_of_equal one_of_equal ]
|
||||
[*[^[link header.boost.algorithm.cxx11.one_of_hpp one_of_equal] ] ]
|
||||
Whether only one of a range's elements matches a value
|
||||
[endsect:one_of_equal]
|
||||
|
||||
[section:is_decreasing is_decreasing ]
|
||||
[*[^[link header.boost.algorithm.cxx11.is_sorted_hpp is_decreasing] ] ]
|
||||
Whether an entire sequence is decreasing; i.e, each item is less than or equal to the previous one
|
||||
[endsect:is_decreasing]
|
||||
|
||||
[section:is_increasing is_increasing ]
|
||||
[*[^[link header.boost.algorithm.cxx11.is_sorted_hpp is_increasing] ] ]
|
||||
Whether an entire sequence is increasing; i.e, each item is greater than or equal to the previous one
|
||||
[endsect:is_increasing]
|
||||
|
||||
[section:is_strictly_decreasing is_strictly_decreasing ]
|
||||
[*[^[link header.boost.algorithm.cxx11.is_sorted_hpp is_strictly_decreasing] ] ]
|
||||
Whether an entire sequence is strictly decreasing; i.e, each item is less than the previous one
|
||||
[endsect:is_strictly_decreasing]
|
||||
|
||||
[section:is_strictly_increasing is_strictly_increasing ]
|
||||
[*[^[link header.boost.algorithm.cxx11.is_sorted_hpp is_strictly_increasing] ] ]
|
||||
Whether an entire sequence is strictly increasing; i.e, each item is greater than the previous one
|
||||
[endsect:is_strictly_increasing]
|
||||
|
||||
[include clamp-hpp.qbk]
|
||||
|
||||
[section:clamp_range clamp_range ]
|
||||
[*[^[link header.boost.algorithm.clamp_hpp clamp_range] ] ]
|
||||
Perform [^clamp] on the elements of a range and write the results into an output iterator
|
||||
[endsect:clamp_range]
|
||||
|
||||
[include find_not.qbk]
|
||||
|
||||
[include find_backward.qbk]
|
||||
|
||||
[section:find_not_backward find_not_backward ]
|
||||
[*[^[link header.boost.algorithm.find_backward_hpp find_not_backward] ] ]
|
||||
Find the last element in a sequence that does not equal a value.
|
||||
See [link the_boost_algorithm_library.Misc.misc_inner_algorithms.find_backward find_backward].
|
||||
[endsect:find_not_backward]
|
||||
|
||||
[section:find_if_backward find_if_backward ]
|
||||
[*[^[link header.boost.algorithm.find_backward_hpp find_if_backward] ] ]
|
||||
Find the last element in a sequence that satisfies a predicate.
|
||||
See [link the_boost_algorithm_library.Misc.misc_inner_algorithms.find_backward find_backward].
|
||||
[endsect:find_if_backward]
|
||||
|
||||
[section:find_if_not find_if_not ]
|
||||
[*[^[link header.boost.algorithm.cxx11.find_if_not_hpp find_if_not] ] ]
|
||||
Find the first element in a sequence that does not satisfy a predicate.
|
||||
See [link the_boost_algorithm_library.Misc.misc_inner_algorithms.find_not find_not].
|
||||
[endsect:find_if_not]
|
||||
|
||||
[section:find_if_not_backward find_if_not_backward ]
|
||||
[*[^[link header.boost.algorithm.find_backward_hpp find_if_not_backward] ] ]
|
||||
Find the last element in a sequence that does not satisfy a predicate.
|
||||
See [link the_boost_algorithm_library.Misc.misc_inner_algorithms.find_backward find_backward].
|
||||
[endsect:find_if_not_backward]
|
||||
|
||||
[include gather.qbk]
|
||||
|
||||
[include hex.qbk]
|
||||
|
||||
[section:unhex unhex ]
|
||||
[*[^[link header.boost.algorithm.hex_hpp unhex] ] ]
|
||||
Convert a sequence of hexadecimal characters into a sequence of integers or characters
|
||||
[endsect:unhex]
|
||||
|
||||
[section:hex_lower hex_lower ]
|
||||
[*[^[link header.boost.algorithm.hex_hpp hex_lower] ] ]
|
||||
Convert a sequence of integral types into a lower case hexadecimal sequence of characters
|
||||
[endsect:hex_lower]
|
||||
|
||||
[include is_palindrome.qbk]
|
||||
|
||||
[include is_partitioned_until.qbk]
|
||||
|
||||
[section:apply_reverse_permutation apply_reverse_permutation ]
|
||||
See below
|
||||
[endsect:apply_reverse_permutation]
|
||||
|
||||
[include apply_permutation.qbk]
|
||||
|
||||
[section:iota_n iota_n ]
|
||||
[*[^[link boost.algorithm.iota_n iota_n] ] ]
|
||||
Write a sequence of n increasing values to an output iterator
|
||||
[endsect:iota_n]
|
||||
|
||||
[section:power power ]
|
||||
[*[^[link header.boost.algorithm.algorithm_hpp power] ] ]
|
||||
Raise a value to an integral power ([^constexpr] since C++14)
|
||||
[endsect:power]
|
||||
|
||||
[endsect:misc_inner_algorithms]
|
||||
|
||||
[endsect:Misc]
|
||||
|
||||
|
||||
[section:not_yet_documented_cxx17_algos Not-yet-documented C++17 Algorithms]
|
||||
|
||||
* [*[^[link header.boost.algorithm.cxx17.exclusive_scan_hpp exclusive_scan] ] ]
|
||||
* [*[^[link header.boost.algorithm.cxx17.inclusive_scan_hpp inclusive_scan] ] ]
|
||||
* [*[^[link header.boost.algorithm.cxx17.reduce_hpp reduce] ] ]
|
||||
* [*[^[link header.boost.algorithm.cxx17.transform_reduce_hpp transform_reduce] ] ]
|
||||
|
||||
[endsect:not_yet_documented_cxx17_algos]
|
||||
|
||||
|
||||
[section:not_yet_documented_other_algos Not-yet-documented Other Algorithms]
|
||||
|
||||
* [*[^[link header.boost.algorithm.minmax_hpp minmax] ] ]
|
||||
* [*[^[link header.boost.algorithm.minmax_element_hpp first_max_element] ] ]
|
||||
* [*[^[link header.boost.algorithm.minmax_element_hpp first_min_element] ] ]
|
||||
* [*[^[link header.boost.algorithm.minmax_element_hpp first_min_first_max_element] ] ]
|
||||
* [*[^[link header.boost.algorithm.minmax_element_hpp first_min_last_max_element] ] ]
|
||||
* [*[^[link header.boost.algorithm.minmax_element_hpp last_max_element] ] ]
|
||||
* [*[^[link header.boost.algorithm.minmax_element_hpp last_min_element] ] ]
|
||||
* [*[^[link header.boost.algorithm.minmax_element_hpp last_min_first_max_element] ] ]
|
||||
* [*[^[link header.boost.algorithm.minmax_element_hpp last_min_last_max_element] ] ]
|
||||
* [*[^[link header.boost.algorithm.minmax_element_hpp minmax_element] ] ]
|
||||
* [*[^[link header.boost.algorithm.sort_subrange_hpp partition_subrange] ] ]
|
||||
* [*[^[link header.boost.algorithm.sort_subrange_hpp sort_subrange] ] ]
|
||||
|
||||
[endsect:not_yet_documented_other_algos]
|
||||
|
||||
|
||||
[xinclude autodoc.xml]
|
||||
|
96
doc/apply_permutation.qbk
Normal file
96
doc/apply_permutation.qbk
Normal file
@ -0,0 +1,96 @@
|
||||
[/ File apply_permutation.qbk]
|
||||
|
||||
[section:apply_permutation apply_permutation]
|
||||
|
||||
[/license
|
||||
Copyright (c) 2017 Alexander Zaitsev
|
||||
|
||||
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)
|
||||
]
|
||||
|
||||
The header file [^[link header.boost.algorithm.apply_permutation_hpp apply_permutation.hpp]] contains two algorithms, `apply_permutation` and `apply_reverse_permutation`. There are also range-based versions.
|
||||
The algorithms transform the item sequence according to index sequence order.
|
||||
|
||||
The routine `apply_permutation` takes a item sequence and a order sequence. It reshuffles item sequence according to order sequence. Every value in order sequence means where the item comes from. Order sequence needs to be exactly a permutation of the sequence [0, 1, ... , N], where N is the biggest index in the item sequence (zero-indexed).
|
||||
The routine `apply_reverse_permutation` takes a item sequence and a order sequence. It will reshuffle item sequence according to order sequence. Every value in order sequence means where the item goes to. Order sequence needs to be exactly a permutation of the sequence [0, 1, ... , N], where N is the biggest index in the item sequence (zero-indexed).
|
||||
|
||||
Implementations are based on these articles:
|
||||
https://devblogs.microsoft.com/oldnewthing/20170102-00/?p=95095
|
||||
https://devblogs.microsoft.com/oldnewthing/20170103-00/?p=95105
|
||||
https://devblogs.microsoft.com/oldnewthing/20170104-00/?p=95115
|
||||
https://devblogs.microsoft.com/oldnewthing/20170109-00/?p=95145
|
||||
https://devblogs.microsoft.com/oldnewthing/20170110-00/?p=95155
|
||||
https://devblogs.microsoft.com/oldnewthing/20170111-00/?p=95165
|
||||
|
||||
The routines come in 2 forms; the first one takes two iterators to define the item range and one iterator to define the beginning of index range. The second form takes range to define the item sequence and range to define index sequence.
|
||||
|
||||
|
||||
[heading interface]
|
||||
|
||||
There are two versions of algorithms:
|
||||
1) takes four iterators.
|
||||
2) takes two ranges.
|
||||
``
|
||||
template<typename RandomAccessIterator1, typename RandomAccessIterator2>
|
||||
void apply_permutation(RandomAccessIterator1 item_begin, RandomAccessIterator1 item_end,
|
||||
RandomAccessIterator2 ind_begin, RandomAccessIterator2 ind_end);
|
||||
template<typename Range1, typename Range2>
|
||||
void apply_permutation(Range1& item_range, Range2& ind_range);
|
||||
template<typename RandomAccessIterator1, typename RandomAccessIterator2>
|
||||
void apply_reverse_permutation(RandomAccessIterator1 item_begin, RandomAccessIterator1 item_end,
|
||||
RandomAccessIterator2 ind_begin, RandomAccessIterator2 ind_end);
|
||||
template<typename Range1, typename Range2>
|
||||
void apply_reverse_permutation(Range1& item_range, Range2& ind_range);
|
||||
``
|
||||
|
||||
|
||||
[heading Examples]
|
||||
|
||||
Given the containers:
|
||||
std::vector<int> emp_vec, emp_order,
|
||||
std::vector<int> one{1}, one_order{0},
|
||||
std::vector<int> two{1,2}, two_order{1,0},
|
||||
std::vector<int> vec{1, 2, 3, 4, 5},
|
||||
std::vector<int> order{4, 2, 3, 1, 0}, then
|
||||
``
|
||||
|
||||
apply_permutation(emp_vec, emp_order)) --> no changes
|
||||
apply_reverse_permutation(emp_vec, emp_order)) --> no changes
|
||||
apply_permutation(one, one_order) --> no changes
|
||||
apply_reverse_permutation(one, one_order) --> no changes
|
||||
apply_permutation(two, two_order) --> two:{2,1}
|
||||
apply_reverse_permutation(two, two_order) --> two:{2,1}
|
||||
apply_permutation(vec, order) --> vec:{5, 3, 4, 2, 1}
|
||||
apply_reverse_permutation(vec, order) --> vec:{5, 4, 2, 3, 1}
|
||||
``
|
||||
|
||||
[heading Iterator Requirements]
|
||||
|
||||
`apply_permutation` and 'apply_reverse_permutation' work only on RandomAccess iterators. RandomAccess iterators required both for item and index sequences.
|
||||
|
||||
[heading Complexity]
|
||||
|
||||
All of the variants of `apply_permutation` and `apply_reverse_permutation` run in ['O(N)] (linear) time.
|
||||
More
|
||||
|
||||
[heading Exception Safety]
|
||||
|
||||
All of the variants of `apply_permutation` and `apply_reverse_permutation` take their parameters by iterators or reference, and do not depend upon any global state. Therefore, all the routines in this file provide the strong exception guarantee.
|
||||
|
||||
[heading Notes]
|
||||
* If ItemSequence and IndexSequence are not equal, behavior is undefined.
|
||||
|
||||
* `apply_permutation` and `apply_reverse_permutation` work also on empty sequences.
|
||||
|
||||
* Order sequence must be zero-indexed.
|
||||
|
||||
* Order sequence gets permuted.
|
||||
|
||||
[endsect]
|
||||
|
||||
[/ File apply_permutation.qbk
|
||||
Copyright 2017 Alexander Zaitsev
|
||||
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).
|
||||
]
|
116
doc/find_backward.qbk
Normal file
116
doc/find_backward.qbk
Normal file
@ -0,0 +1,116 @@
|
||||
[/ File find_backward.qbk]
|
||||
|
||||
[section:find_backward find_backward ]
|
||||
|
||||
[/license
|
||||
Copyright (c) 2018 T. Zachary Laine
|
||||
|
||||
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)
|
||||
]
|
||||
|
||||
The header file 'find_backward.hpp' contains variants of the stl algorithm
|
||||
`find`. These variants are like `find`, except that the evaluate the elements
|
||||
of the given sequence in reverse order.
|
||||
|
||||
Consider how finding the last element that is equal to `x` in a range is
|
||||
typically done:
|
||||
|
||||
// Assume a valid range if elements delimited by [first, last).
|
||||
while (last-- != first) {
|
||||
if (*last == x) {
|
||||
// Use last here...
|
||||
}
|
||||
}
|
||||
|
||||
Raw loops are icky though. Perhaps we should do a bit of extra work to allow
|
||||
the use of `std::find()`:
|
||||
|
||||
auto rfirst = std::make_reverse_iterator(last);
|
||||
auto rlast = std::make_reverse_iterator(first);
|
||||
auto it = std::find(rfirst, rlast, x);
|
||||
// Use it here...
|
||||
|
||||
That seems nicer in that there is no raw loop, but it has two major drawbacks.
|
||||
First, it requires an unpleasant amount of typing. Second, it is less
|
||||
efficient than forward-iterator `find` , since `std::reverse_iterator` calls
|
||||
its base-iterator's `operator--()` in most of its member functions before
|
||||
doing the work that the member function requires.
|
||||
|
||||
[heading interface]
|
||||
|
||||
template<typename BidiIter, typename T>
|
||||
BidiIter find_backward(BidiIter first, BidiIter last, const T & x);
|
||||
|
||||
template<typename Range, typename T>
|
||||
boost::range_iterator<Range> find_backward(Range & range, const T & x);
|
||||
|
||||
These overloads of `find_backward` return an iterator to the last element that
|
||||
is equal to `x` in `[first, last)` or `r`, respectively.
|
||||
|
||||
template<typename BidiIter, typename T>
|
||||
BidiIter find_not_backward(BidiIter first, BidiIter last, const T & x);
|
||||
|
||||
template<typename Range, typename T>
|
||||
boost::range_iterator<Range> find_not_backward(Range & range, const T & x);
|
||||
|
||||
These overloads of `find_not_backward` return an iterator to the last element
|
||||
that is not equal to `x` in `[first, last)` or `r`, respectively.
|
||||
|
||||
template<typename BidiIter, typename Pred>
|
||||
BidiIter find_if_backward(BidiIter first, BidiIter last, Pred p);
|
||||
|
||||
template<typename Range, typename Pred>
|
||||
boost::range_iterator<Range> find_if_backward(Range & range, Pred p);
|
||||
|
||||
These overloads of `find_if_backward` return an iterator to the last element
|
||||
for which `pred` returns `true` in `[first, last)` or `r`, respectively.
|
||||
|
||||
template<typename BidiIter, typename Pred>
|
||||
BidiIter find_if_not_backward(BidiIter first, BidiIter last, Pred p);
|
||||
|
||||
template<typename Range, typename Pred>
|
||||
boost::range_iterator<Range> find_if_not_backward(Range & range, Pred p);
|
||||
|
||||
These overloads of `find_if_not_backward` return an iterator to the last
|
||||
element for which `pred` returns `false` in `[first, last)` or `r`,
|
||||
respectively.
|
||||
|
||||
[heading Examples]
|
||||
|
||||
Given the container `c1` containing `{ 2, 1, 2 }`, then
|
||||
|
||||
find_backward ( c1.begin(), c1.end(), 2 ) --> --c1.end()
|
||||
find_backward ( c1.begin(), c1.end(), 3 ) --> c1.end()
|
||||
find_if_backward ( c1.begin(), c1.end(), [](int i) {return i == 2;} ) --> --c1.end()
|
||||
find_if_backward ( c1.begin(), c1.end(), [](int i) {return i == 3;} ) --> c1.end()
|
||||
find_not_backward ( c1.begin(), c1.end(), 2 ) --> std::prev(c1.end(), 2)
|
||||
find_not_backward ( c1.begin(), c1.end(), 1 ) --> c1.end()
|
||||
find_if_not_backward ( c1.begin(), c1.end(), [](int i) {return i == 2;} ) --> std::prev(c1.end(), 2)
|
||||
find_if_not_backward ( c1.begin(), c1.end(), [](int i) {return i == 1;} ) --> c1.end()
|
||||
|
||||
[heading Iterator Requirements]
|
||||
|
||||
All variants work on bidirectional iterators.
|
||||
|
||||
[heading Complexity]
|
||||
|
||||
Linear.
|
||||
|
||||
[heading Exception Safety]
|
||||
|
||||
All of the variants take their parameters by value and do not depend upon any
|
||||
global state. Therefore, all the routines in this file provide the strong
|
||||
exception guarantee.
|
||||
|
||||
[heading Notes]
|
||||
|
||||
All variants are `constexpr` in C++14 or later.
|
||||
|
||||
[endsect]
|
||||
|
||||
[/ File equal.qbk
|
||||
Copyright 2018 T. Zachary Laine
|
||||
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).
|
||||
]
|
83
doc/find_not.qbk
Normal file
83
doc/find_not.qbk
Normal file
@ -0,0 +1,83 @@
|
||||
[/ File find_not.qbk]
|
||||
|
||||
[section:find_not find_not ]
|
||||
|
||||
[/license
|
||||
Copyright (c) 2018 T. Zachary Laine
|
||||
|
||||
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)
|
||||
]
|
||||
|
||||
The header file 'find_not.hpp' contains a variants of a the stl algorithm
|
||||
`find`. The algorithm finds the first value in the given sequence that is not
|
||||
equal to the given value.
|
||||
|
||||
Consider this use of `find()`:
|
||||
|
||||
std::vector<int> vec = { 1, 1, 2 };
|
||||
auto it = std::find(vec.begin(), vec.end(), 1);
|
||||
|
||||
This gives us the first occurance of `1` in `vec`. What if we want to find
|
||||
the first occurrance of any number besides `1` in `vec`? We have to write an
|
||||
unfortunate amount of code:
|
||||
|
||||
std::vector<int> vec = { 1, 1, 2 };
|
||||
auto it = std::find_if(vec.begin(), vec.end(), [](int i) { return i != 1; });
|
||||
|
||||
With `find_not()` the code gets much more terse:
|
||||
|
||||
std::vector<int> vec = { 1, 1, 2 };
|
||||
auto it = find_not(vec.begin(), vec.end(), 1);
|
||||
|
||||
The existing `find` variants are: `find()`, `find_if()`, and `find_if_not()`.
|
||||
It seems natural to also have `find_not()`, for the very reason that we have
|
||||
`find_if_not()` -- to avoid having to write a lambda to wrap the negation of
|
||||
the find condition.
|
||||
|
||||
[heading interface]
|
||||
|
||||
template<typename InputIter, typename Sentinel, typename T>
|
||||
InputIter find_not(InputIter first, Sentinel last, const T & x);
|
||||
|
||||
template<typename Range, typename T>
|
||||
boost::range_iterator<Range> find_not(Range & r, const T & x);
|
||||
|
||||
These overloads of `find_not` return the first value that is not equal to `x`
|
||||
in the sequence `[first, last)` or `r`, respectively.
|
||||
|
||||
[heading Examples]
|
||||
|
||||
Given the container `c1` containing `{ 0, 1, 2 }`, then
|
||||
|
||||
find_not ( c1.begin(), c1.end(), 1 ) --> c1.begin()
|
||||
find_not ( c1.begin(), c1.end(), 0 ) --> std::next(c1.begin())
|
||||
|
||||
[heading Iterator Requirements]
|
||||
|
||||
`find_not` works on all iterators except output iterators.
|
||||
|
||||
The template parameter `Sentinel` is allowed to be different from `InputIter`,
|
||||
or they may be the same. For an `InputIter` `it` and a `Sentinel` `end`, `it
|
||||
== end` and `it != end` must be well-formed expressions.
|
||||
|
||||
[heading Complexity]
|
||||
|
||||
Linear.
|
||||
|
||||
[heading Exception Safety]
|
||||
|
||||
`find_not` takes its parameters by value and do not depend upon any global
|
||||
state. Therefore, it provides the strong exception guarantee.
|
||||
|
||||
[heading Notes]
|
||||
|
||||
`constexpr` in C++14 or later.
|
||||
|
||||
[endsect]
|
||||
|
||||
[/ File equal.qbk
|
||||
Copyright 2018 T. Zachary Laine
|
||||
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).
|
||||
]
|
@ -15,7 +15,7 @@ http://www.boost.org/LICENSE_1_0.txt)
|
||||
The header file `<boost/algorithm/cxx11/is_sorted.hpp>` contains functions for determining if a sequence is ordered.
|
||||
|
||||
[heading is_sorted]
|
||||
The function `is_sorted(sequence)` determines whether or not a sequence is completely sorted according so some criteria. If no comparison predicate is specified, then std::less_equal is used (i.e, the test is to see if the sequence is non-decreasing)
|
||||
The function `is_sorted(sequence)` determines whether or not a sequence is completely sorted according so some criteria. If no comparison predicate is specified, then `std::less` is used (i.e, the test is to see if the sequence is non-decreasing)
|
||||
|
||||
``
|
||||
namespace boost { namespace algorithm {
|
||||
|
@ -18,8 +18,8 @@ project /boost/algorithm/example
|
||||
:
|
||||
;
|
||||
|
||||
exe clamp_example : clamp_example.cpp ;
|
||||
exe clamp_example : clamp_example.cpp : ;
|
||||
exe search_example : search_example.cpp ;
|
||||
exe is_palindrome_example : is_palindrome_example.cpp;
|
||||
exe is_partitioned_until_example : is_partitioned_until_example.cpp;
|
||||
|
||||
exe is_palindrome_example : is_palindrome_example.cpp : <cxxstd>11 ;
|
||||
exe is_partitioned_until_example : is_partitioned_until_example.cpp : <cxxstd>11 ;
|
||||
exe apply_permutation_example : apply_permutation_example.cpp : <cxxstd>11 ;
|
||||
|
69
example/apply_permutation_example.cpp
Normal file
69
example/apply_permutation_example.cpp
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
Copyright (c) Alexander Zaitsev <zamazan4ik@gmail.com>, 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)
|
||||
|
||||
See http://www.boost.org/ for latest version.
|
||||
*/
|
||||
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/algorithm/apply_permutation.hpp>
|
||||
|
||||
|
||||
namespace ba = boost::algorithm;
|
||||
|
||||
int main ( int /*argc*/, char * /*argv*/ [] )
|
||||
{
|
||||
// WARNING: Example require C++11 or newer compiler
|
||||
{
|
||||
std::cout << "apply_permutation with iterators:\n";
|
||||
std::vector<int> vec{1, 2, 3, 4, 5}, order{4, 2, 3, 1, 0};
|
||||
|
||||
ba::apply_permutation(vec.begin(), vec.end(), order.begin(), order.end());
|
||||
for (const auto& x : vec)
|
||||
{
|
||||
std::cout << x << ", ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
{
|
||||
std::cout << "apply_reverse_permutation with iterators:\n";
|
||||
std::vector<int> vec{1, 2, 3, 4, 5}, order{4, 2, 3, 1, 0};
|
||||
|
||||
ba::apply_reverse_permutation(vec.begin(), vec.end(), order.begin(), order.end());
|
||||
for (const auto& x : vec)
|
||||
{
|
||||
std::cout << x << ", ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
{
|
||||
std::cout << "apply_reverse_permutation with ranges:\n";
|
||||
std::vector<int> vec{1, 2, 3, 4, 5}, order{4, 2, 3, 1, 0};
|
||||
|
||||
ba::apply_reverse_permutation(vec, order);
|
||||
for (const auto& x : vec)
|
||||
{
|
||||
std::cout << x << ", ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
{
|
||||
std::cout << "apply_permutation with ranges:\n";
|
||||
std::vector<int> vec{1, 2, 3, 4, 5}, order{4, 2, 3, 1, 0};
|
||||
|
||||
ba::apply_permutation(vec, order);
|
||||
for (const auto& x : vec)
|
||||
{
|
||||
std::cout << x << ", ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -32,8 +32,8 @@ struct isOddComp
|
||||
|
||||
int main ( int /*argc*/, char * /*argv*/ [] )
|
||||
{
|
||||
std::vector<int> good({1, 2, 4});
|
||||
std::vector<int> bad({1, 2, 3});
|
||||
std::vector<int> good{1, 2, 4};
|
||||
std::vector<int> bad{1, 2, 3};
|
||||
|
||||
//Use custom function
|
||||
auto it1 = ba::is_partitioned_until(good.begin(), good.end(), isOdd);
|
||||
|
@ -27,7 +27,7 @@ int main ( int /*argc*/, char * /*argv*/ [] ) {
|
||||
// algorithms. They all have the same (dual) interface.
|
||||
|
||||
// There is a procedural interface, based on std::search:
|
||||
if ( ba::boyer_moore_search ( haystack.begin (), haystack.end (), needle1.begin (), needle1.end ()) != haystack.end ())
|
||||
if ( ba::boyer_moore_search ( haystack.begin (), haystack.end (), needle1.begin (), needle1.end ()) != std::make_pair(haystack.end(), haystack.end()))
|
||||
std::cout << "Found '" << needle1 << "' in '" << haystack << "' (boyer-moore 1)" << std::endl;
|
||||
else
|
||||
std::cout << "Did NOT find '" << needle1 << "' in '" << haystack << "' (boyer-moore 1)" << std::endl;
|
||||
@ -36,19 +36,19 @@ int main ( int /*argc*/, char * /*argv*/ [] ) {
|
||||
// you can create a search object and use that over and over again - amortizing the setup
|
||||
// costs across several searches
|
||||
ba::boyer_moore<std::string::const_iterator> search1 ( needle1.begin (), needle1.end ());
|
||||
if ( search1 ( haystack.begin (), haystack.end ()) != haystack.end ())
|
||||
if ( search1 ( haystack.begin (), haystack.end ()) != std::make_pair(haystack.end(), haystack.end()))
|
||||
std::cout << "Found '" << needle1 << "' in '" << haystack << "' (boyer-moore 2)" << std::endl;
|
||||
else
|
||||
std::cout << "Did NOT find '" << needle1 << "' in '" << haystack << "' (boyer-moore 2)" << std::endl;
|
||||
|
||||
// There is also an implementation of boyer-moore-horspool searching
|
||||
if ( ba::boyer_moore_horspool_search ( haystack.begin (), haystack.end (), needle1.begin (), needle1.end ()) != haystack.end ())
|
||||
if ( ba::boyer_moore_horspool_search ( haystack.begin (), haystack.end (), needle1.begin (), needle1.end ()) != std::make_pair(haystack.end(), haystack.end()))
|
||||
std::cout << "Found '" << needle1 << "' in '" << haystack << "' (boyer-moore-horspool)" << std::endl;
|
||||
else
|
||||
std::cout << "Did NOT find '" << needle1 << "' in '" << haystack << "' (boyer-moore-horspool)" << std::endl;
|
||||
|
||||
// And also the knuth-pratt-morris search algorithm
|
||||
if ( ba::knuth_morris_pratt_search ( haystack.begin (), haystack.end (), needle1.begin (), needle1.end ()) != haystack.end ())
|
||||
if ( ba::knuth_morris_pratt_search ( haystack.begin (), haystack.end (), needle1.begin (), needle1.end ()) != std::make_pair(haystack.end(), haystack.end()))
|
||||
std::cout << "Found '" << needle1 << "' in '" << haystack << "' (knuth_morris_pratt)" << std::endl;
|
||||
else
|
||||
std::cout << "Did NOT find '" << needle1 << "' in '" << haystack << "' (knuth_morris_pratt)" << std::endl;
|
||||
|
@ -19,16 +19,17 @@
|
||||
|
||||
#include <functional> // for plus and multiplies
|
||||
|
||||
#include <boost/utility/enable_if.hpp> // for boost::disable_if
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/core/enable_if.hpp> // for boost::disable_if
|
||||
#include <boost/type_traits/is_integral.hpp>
|
||||
|
||||
namespace boost { namespace algorithm {
|
||||
|
||||
template <typename T>
|
||||
T identity_operation ( std::multiplies<T> ) { return T(1); }
|
||||
BOOST_CXX14_CONSTEXPR T identity_operation ( std::multiplies<T> ) { return T(1); }
|
||||
|
||||
template <typename T>
|
||||
T identity_operation ( std::plus<T> ) { return T(0); }
|
||||
BOOST_CXX14_CONSTEXPR T identity_operation ( std::plus<T> ) { return T(0); }
|
||||
|
||||
|
||||
/// \fn power ( T x, Integer n )
|
||||
@ -40,7 +41,7 @@ T identity_operation ( std::plus<T> ) { return T(0); }
|
||||
// \remark Taken from Knuth, The Art of Computer Programming, Volume 2:
|
||||
// Seminumerical Algorithms, Section 4.6.3
|
||||
template <typename T, typename Integer>
|
||||
typename boost::enable_if<boost::is_integral<Integer>, T>::type
|
||||
BOOST_CXX14_CONSTEXPR typename boost::enable_if<boost::is_integral<Integer>, T>::type
|
||||
power (T x, Integer n) {
|
||||
T y = 1; // Should be "T y{1};"
|
||||
if (n == 0) return y;
|
||||
@ -67,7 +68,7 @@ power (T x, Integer n) {
|
||||
// \remark Taken from Knuth, The Art of Computer Programming, Volume 2:
|
||||
// Seminumerical Algorithms, Section 4.6.3
|
||||
template <typename T, typename Integer, typename Operation>
|
||||
typename boost::enable_if<boost::is_integral<Integer>, T>::type
|
||||
BOOST_CXX14_CONSTEXPR typename boost::enable_if<boost::is_integral<Integer>, T>::type
|
||||
power (T x, Integer n, Operation op) {
|
||||
T y = identity_operation(op);
|
||||
if (n == 0) return y;
|
||||
|
126
include/boost/algorithm/apply_permutation.hpp
Normal file
126
include/boost/algorithm/apply_permutation.hpp
Normal file
@ -0,0 +1,126 @@
|
||||
/*
|
||||
Copyright (c) Alexander Zaitsev <zamazan4ik@gmail.com>, 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)
|
||||
|
||||
See http://www.boost.org/ for latest version.
|
||||
|
||||
|
||||
Based on https://blogs.msdn.microsoft.com/oldnewthing/20170104-00/?p=95115
|
||||
*/
|
||||
|
||||
/// \file apply_permutation.hpp
|
||||
/// \brief Apply permutation to a sequence.
|
||||
/// \author Alexander Zaitsev
|
||||
|
||||
#ifndef BOOST_ALGORITHM_APPLY_PERMUTATION_HPP
|
||||
#define BOOST_ALGORITHM_APPLY_PERMUTATION_HPP
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
|
||||
namespace boost { namespace algorithm
|
||||
{
|
||||
|
||||
/// \fn apply_permutation ( RandomAccessIterator1 item_begin, RandomAccessIterator1 item_end, RandomAccessIterator2 ind_begin )
|
||||
/// \brief Reorder item sequence with index sequence order
|
||||
///
|
||||
/// \param item_begin The start of the item sequence
|
||||
/// \param item_end One past the end of the item sequence
|
||||
/// \param ind_begin The start of the index sequence.
|
||||
///
|
||||
/// \note Item sequence size should be equal to index size. Otherwise behavior is undefined.
|
||||
/// Complexity: O(N).
|
||||
template<typename RandomAccessIterator1, typename RandomAccessIterator2>
|
||||
void
|
||||
apply_permutation(RandomAccessIterator1 item_begin, RandomAccessIterator1 item_end,
|
||||
RandomAccessIterator2 ind_begin, RandomAccessIterator2 ind_end)
|
||||
{
|
||||
typedef typename std::iterator_traits<RandomAccessIterator1>::difference_type Diff;
|
||||
typedef typename std::iterator_traits<RandomAccessIterator2>::difference_type Index;
|
||||
using std::swap;
|
||||
Diff size = std::distance(item_begin, item_end);
|
||||
for (Diff i = 0; i < size; i++)
|
||||
{
|
||||
Diff current = i;
|
||||
while (i != ind_begin[current])
|
||||
{
|
||||
Index next = ind_begin[current];
|
||||
swap(item_begin[current], item_begin[next]);
|
||||
ind_begin[current] = current;
|
||||
current = next;
|
||||
}
|
||||
ind_begin[current] = current;
|
||||
}
|
||||
}
|
||||
|
||||
/// \fn apply_reverse_permutation ( RandomAccessIterator1 item_begin, RandomAccessIterator1 item_end, RandomAccessIterator2 ind_begin )
|
||||
/// \brief Reorder item sequence with index sequence order
|
||||
///
|
||||
/// \param item_begin The start of the item sequence
|
||||
/// \param item_end One past the end of the item sequence
|
||||
/// \param ind_begin The start of the index sequence.
|
||||
///
|
||||
/// \note Item sequence size should be equal to index size. Otherwise behavior is undefined.
|
||||
/// Complexity: O(N).
|
||||
template<typename RandomAccessIterator1, typename RandomAccessIterator2>
|
||||
void
|
||||
apply_reverse_permutation(
|
||||
RandomAccessIterator1 item_begin,
|
||||
RandomAccessIterator1 item_end,
|
||||
RandomAccessIterator2 ind_begin,
|
||||
RandomAccessIterator2 ind_end)
|
||||
{
|
||||
typedef typename std::iterator_traits<RandomAccessIterator2>::difference_type Diff;
|
||||
using std::swap;
|
||||
Diff length = std::distance(item_begin, item_end);
|
||||
for (Diff i = 0; i < length; i++)
|
||||
{
|
||||
while (i != ind_begin[i])
|
||||
{
|
||||
Diff next = ind_begin[i];
|
||||
swap(item_begin[i], item_begin[next]);
|
||||
swap(ind_begin[i], ind_begin[next]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// \fn apply_permutation ( Range1 item_range, Range2 ind_range )
|
||||
/// \brief Reorder item sequence with index sequence order
|
||||
///
|
||||
/// \param item_range The item sequence
|
||||
/// \param ind_range The index sequence
|
||||
///
|
||||
/// \note Item sequence size should be equal to index size. Otherwise behavior is undefined.
|
||||
/// Complexity: O(N).
|
||||
template<typename Range1, typename Range2>
|
||||
void
|
||||
apply_permutation(Range1& item_range, Range2& ind_range)
|
||||
{
|
||||
apply_permutation(boost::begin(item_range), boost::end(item_range),
|
||||
boost::begin(ind_range), boost::end(ind_range));
|
||||
}
|
||||
|
||||
/// \fn apply_reverse_permutation ( Range1 item_range, Range2 ind_range )
|
||||
/// \brief Reorder item sequence with index sequence order
|
||||
///
|
||||
/// \param item_range The item sequence
|
||||
/// \param ind_range The index sequence
|
||||
///
|
||||
/// \note Item sequence size should be equal to index size. Otherwise behavior is undefined.
|
||||
/// Complexity: O(N).
|
||||
template<typename Range1, typename Range2>
|
||||
void
|
||||
apply_reverse_permutation(Range1& item_range, Range2& ind_range)
|
||||
{
|
||||
apply_reverse_permutation(boost::begin(item_range), boost::end(item_range),
|
||||
boost::begin(ind_range), boost::end(ind_range));
|
||||
}
|
||||
|
||||
}}
|
||||
#endif //BOOST_ALGORITHM_APPLY_PERMUTATION_HPP
|
@ -23,16 +23,17 @@
|
||||
#include <iterator> // For std::iterator_traits
|
||||
#include <cassert>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
#include <boost/mpl/identity.hpp> // for identity
|
||||
#include <boost/utility/enable_if.hpp> // for boost::disable_if
|
||||
#include <boost/type_traits/type_identity.hpp> // for boost::type_identity
|
||||
#include <boost/core/enable_if.hpp> // for boost::disable_if
|
||||
|
||||
namespace boost { namespace algorithm {
|
||||
|
||||
/// \fn clamp ( T const& val,
|
||||
/// typename boost::mpl::identity<T>::type const & lo,
|
||||
/// typename boost::mpl::identity<T>::type const & hi, Pred p )
|
||||
/// typename boost::type_identity<T>::type const & lo,
|
||||
/// typename boost::type_identity<T>::type const & hi, Pred p )
|
||||
/// \return the value "val" brought into the range [ lo, hi ]
|
||||
/// using the comparison predicate p.
|
||||
/// If p ( val, lo ) return lo.
|
||||
@ -46,9 +47,9 @@ namespace boost { namespace algorithm {
|
||||
/// p ( a, b ) returns a boolean.
|
||||
///
|
||||
template<typename T, typename Pred>
|
||||
T const & clamp ( T const& val,
|
||||
typename boost::mpl::identity<T>::type const & lo,
|
||||
typename boost::mpl::identity<T>::type const & hi, Pred p )
|
||||
BOOST_CXX14_CONSTEXPR T const & clamp ( T const& val,
|
||||
typename boost::type_identity<T>::type const & lo,
|
||||
typename boost::type_identity<T>::type const & hi, Pred p )
|
||||
{
|
||||
// assert ( !p ( hi, lo )); // Can't assert p ( lo, hi ) b/c they might be equal
|
||||
return p ( val, lo ) ? lo : p ( hi, val ) ? hi : val;
|
||||
@ -56,8 +57,8 @@ namespace boost { namespace algorithm {
|
||||
|
||||
|
||||
/// \fn clamp ( T const& val,
|
||||
/// typename boost::mpl::identity<T>::type const & lo,
|
||||
/// typename boost::mpl::identity<T>::type const & hi )
|
||||
/// typename boost::identity<T>::type const & lo,
|
||||
/// typename boost::identity<T>::type const & hi )
|
||||
/// \return the value "val" brought into the range [ lo, hi ].
|
||||
/// If the value is less than lo, return lo.
|
||||
/// If the value is greater than "hi", return hi.
|
||||
@ -68,11 +69,11 @@ namespace boost { namespace algorithm {
|
||||
/// \param hi The upper bound of the range to be clamped to
|
||||
///
|
||||
template<typename T>
|
||||
T const& clamp ( const T& val,
|
||||
typename boost::mpl::identity<T>::type const & lo,
|
||||
typename boost::mpl::identity<T>::type const & hi )
|
||||
BOOST_CXX14_CONSTEXPR T const& clamp ( const T& val,
|
||||
typename boost::type_identity<T>::type const & lo,
|
||||
typename boost::type_identity<T>::type const & hi )
|
||||
{
|
||||
return (clamp) ( val, lo, hi, std::less<T>());
|
||||
return boost::algorithm::clamp ( val, lo, hi, std::less<T>());
|
||||
}
|
||||
|
||||
/// \fn clamp_range ( InputIterator first, InputIterator last, OutputIterator out,
|
||||
@ -87,13 +88,13 @@ namespace boost { namespace algorithm {
|
||||
/// \param hi The upper bound of the range to be clamped to
|
||||
///
|
||||
template<typename InputIterator, typename OutputIterator>
|
||||
OutputIterator clamp_range ( InputIterator first, InputIterator last, OutputIterator out,
|
||||
BOOST_CXX14_CONSTEXPR OutputIterator clamp_range ( InputIterator first, InputIterator last, OutputIterator out,
|
||||
typename std::iterator_traits<InputIterator>::value_type const & lo,
|
||||
typename std::iterator_traits<InputIterator>::value_type const & hi )
|
||||
{
|
||||
// this could also be written with bind and std::transform
|
||||
while ( first != last )
|
||||
*out++ = clamp ( *first++, lo, hi );
|
||||
*out++ = boost::algorithm::clamp ( *first++, lo, hi );
|
||||
return out;
|
||||
}
|
||||
|
||||
@ -108,12 +109,12 @@ namespace boost { namespace algorithm {
|
||||
/// \param hi The upper bound of the range to be clamped to
|
||||
///
|
||||
template<typename Range, typename OutputIterator>
|
||||
typename boost::disable_if_c<boost::is_same<Range, OutputIterator>::value, OutputIterator>::type
|
||||
BOOST_CXX14_CONSTEXPR typename boost::disable_if_c<boost::is_same<Range, OutputIterator>::value, OutputIterator>::type
|
||||
clamp_range ( const Range &r, OutputIterator out,
|
||||
typename std::iterator_traits<typename boost::range_iterator<const Range>::type>::value_type const & lo,
|
||||
typename std::iterator_traits<typename boost::range_iterator<const Range>::type>::value_type const & hi )
|
||||
{
|
||||
return clamp_range ( boost::begin ( r ), boost::end ( r ), out, lo, hi );
|
||||
return boost::algorithm::clamp_range ( boost::begin ( r ), boost::end ( r ), out, lo, hi );
|
||||
}
|
||||
|
||||
|
||||
@ -133,13 +134,13 @@ namespace boost { namespace algorithm {
|
||||
|
||||
///
|
||||
template<typename InputIterator, typename OutputIterator, typename Pred>
|
||||
OutputIterator clamp_range ( InputIterator first, InputIterator last, OutputIterator out,
|
||||
BOOST_CXX14_CONSTEXPR OutputIterator clamp_range ( InputIterator first, InputIterator last, OutputIterator out,
|
||||
typename std::iterator_traits<InputIterator>::value_type const & lo,
|
||||
typename std::iterator_traits<InputIterator>::value_type const & hi, Pred p )
|
||||
{
|
||||
// this could also be written with bind and std::transform
|
||||
while ( first != last )
|
||||
*out++ = clamp ( *first++, lo, hi, p );
|
||||
*out++ = boost::algorithm::clamp ( *first++, lo, hi, p );
|
||||
return out;
|
||||
}
|
||||
|
||||
@ -160,13 +161,13 @@ namespace boost { namespace algorithm {
|
||||
// Disable this template if the first two parameters are the same type;
|
||||
// In that case, the user will get the two iterator version.
|
||||
template<typename Range, typename OutputIterator, typename Pred>
|
||||
typename boost::disable_if_c<boost::is_same<Range, OutputIterator>::value, OutputIterator>::type
|
||||
BOOST_CXX14_CONSTEXPR typename boost::disable_if_c<boost::is_same<Range, OutputIterator>::value, OutputIterator>::type
|
||||
clamp_range ( const Range &r, OutputIterator out,
|
||||
typename std::iterator_traits<typename boost::range_iterator<const Range>::type>::value_type const & lo,
|
||||
typename std::iterator_traits<typename boost::range_iterator<const Range>::type>::value_type const & hi,
|
||||
Pred p )
|
||||
{
|
||||
return clamp_range ( boost::begin ( r ), boost::end ( r ), out, lo, hi, p );
|
||||
return boost::algorithm::clamp_range ( boost::begin ( r ), boost::end ( r ), out, lo, hi, p );
|
||||
}
|
||||
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
#ifndef BOOST_ALGORITHM_ALL_OF_HPP
|
||||
#define BOOST_ALGORITHM_ALL_OF_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
|
||||
@ -27,7 +28,7 @@ namespace boost { namespace algorithm {
|
||||
///
|
||||
/// \note This function is part of the C++2011 standard library.
|
||||
template<typename InputIterator, typename Predicate>
|
||||
bool all_of ( InputIterator first, InputIterator last, Predicate p )
|
||||
BOOST_CXX14_CONSTEXPR bool all_of ( InputIterator first, InputIterator last, Predicate p )
|
||||
{
|
||||
for ( ; first != last; ++first )
|
||||
if ( !p(*first))
|
||||
@ -43,7 +44,7 @@ bool all_of ( InputIterator first, InputIterator last, Predicate p )
|
||||
/// \param p A predicate for testing the elements of the range
|
||||
///
|
||||
template<typename Range, typename Predicate>
|
||||
bool all_of ( const Range &r, Predicate p )
|
||||
BOOST_CXX14_CONSTEXPR bool all_of ( const Range &r, Predicate p )
|
||||
{
|
||||
return boost::algorithm::all_of ( boost::begin (r), boost::end (r), p );
|
||||
}
|
||||
@ -57,7 +58,7 @@ bool all_of ( const Range &r, Predicate p )
|
||||
/// \param val A value to compare against
|
||||
///
|
||||
template<typename InputIterator, typename T>
|
||||
bool all_of_equal ( InputIterator first, InputIterator last, const T &val )
|
||||
BOOST_CXX14_CONSTEXPR bool all_of_equal ( InputIterator first, InputIterator last, const T &val )
|
||||
{
|
||||
for ( ; first != last; ++first )
|
||||
if ( val != *first )
|
||||
@ -73,7 +74,7 @@ bool all_of_equal ( InputIterator first, InputIterator last, const T &val )
|
||||
/// \param val A value to compare against
|
||||
///
|
||||
template<typename Range, typename T>
|
||||
bool all_of_equal ( const Range &r, const T &val )
|
||||
BOOST_CXX14_CONSTEXPR bool all_of_equal ( const Range &r, const T &val )
|
||||
{
|
||||
return boost::algorithm::all_of_equal ( boost::begin (r), boost::end (r), val );
|
||||
}
|
||||
|
@ -14,6 +14,7 @@
|
||||
#ifndef BOOST_ALGORITHM_ANY_OF_HPP
|
||||
#define BOOST_ALGORITHM_ANY_OF_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
|
||||
@ -28,7 +29,7 @@ namespace boost { namespace algorithm {
|
||||
/// \param p A predicate for testing the elements of the sequence
|
||||
///
|
||||
template<typename InputIterator, typename Predicate>
|
||||
bool any_of ( InputIterator first, InputIterator last, Predicate p )
|
||||
BOOST_CXX14_CONSTEXPR bool any_of ( InputIterator first, InputIterator last, Predicate p )
|
||||
{
|
||||
for ( ; first != last; ++first )
|
||||
if ( p(*first))
|
||||
@ -44,7 +45,7 @@ bool any_of ( InputIterator first, InputIterator last, Predicate p )
|
||||
/// \param p A predicate for testing the elements of the range
|
||||
///
|
||||
template<typename Range, typename Predicate>
|
||||
bool any_of ( const Range &r, Predicate p )
|
||||
BOOST_CXX14_CONSTEXPR bool any_of ( const Range &r, Predicate p )
|
||||
{
|
||||
return boost::algorithm::any_of (boost::begin (r), boost::end (r), p);
|
||||
}
|
||||
@ -58,7 +59,7 @@ bool any_of ( const Range &r, Predicate p )
|
||||
/// \param val A value to compare against
|
||||
///
|
||||
template<typename InputIterator, typename V>
|
||||
bool any_of_equal ( InputIterator first, InputIterator last, const V &val )
|
||||
BOOST_CXX14_CONSTEXPR bool any_of_equal ( InputIterator first, InputIterator last, const V &val )
|
||||
{
|
||||
for ( ; first != last; ++first )
|
||||
if ( val == *first )
|
||||
@ -74,7 +75,7 @@ bool any_of_equal ( InputIterator first, InputIterator last, const V &val )
|
||||
/// \param val A value to compare against
|
||||
///
|
||||
template<typename Range, typename V>
|
||||
bool any_of_equal ( const Range &r, const V &val )
|
||||
BOOST_CXX14_CONSTEXPR bool any_of_equal ( const Range &r, const V &val )
|
||||
{
|
||||
return boost::algorithm::any_of_equal (boost::begin (r), boost::end (r), val);
|
||||
}
|
||||
|
@ -13,6 +13,8 @@
|
||||
#define BOOST_ALGORITHM_COPY_IF_HPP
|
||||
|
||||
#include <utility> // for std::pair, std::make_pair
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
|
||||
@ -29,7 +31,7 @@ namespace boost { namespace algorithm {
|
||||
/// \param p A predicate for testing the elements of the range
|
||||
/// \note This function is part of the C++2011 standard library.
|
||||
template<typename InputIterator, typename OutputIterator, typename Predicate>
|
||||
OutputIterator copy_if ( InputIterator first, InputIterator last, OutputIterator result, Predicate p )
|
||||
BOOST_CXX14_CONSTEXPR OutputIterator copy_if ( InputIterator first, InputIterator last, OutputIterator result, Predicate p )
|
||||
{
|
||||
for ( ; first != last; ++first )
|
||||
if (p(*first))
|
||||
@ -47,7 +49,7 @@ OutputIterator copy_if ( InputIterator first, InputIterator last, OutputIterator
|
||||
/// \param p A predicate for testing the elements of the range
|
||||
///
|
||||
template<typename Range, typename OutputIterator, typename Predicate>
|
||||
OutputIterator copy_if ( const Range &r, OutputIterator result, Predicate p )
|
||||
BOOST_CXX14_CONSTEXPR OutputIterator copy_if ( const Range &r, OutputIterator result, Predicate p )
|
||||
{
|
||||
return boost::algorithm::copy_if (boost::begin (r), boost::end(r), result, p);
|
||||
}
|
||||
@ -64,7 +66,7 @@ OutputIterator copy_if ( const Range &r, OutputIterator result, Predicate p )
|
||||
/// \param p A predicate for testing the elements of the range
|
||||
///
|
||||
template<typename InputIterator, typename OutputIterator, typename Predicate>
|
||||
std::pair<InputIterator, OutputIterator>
|
||||
BOOST_CXX14_CONSTEXPR std::pair<InputIterator, OutputIterator>
|
||||
copy_while ( InputIterator first, InputIterator last, OutputIterator result, Predicate p )
|
||||
{
|
||||
for ( ; first != last && p(*first); ++first )
|
||||
@ -82,7 +84,7 @@ copy_while ( InputIterator first, InputIterator last, OutputIterator result, Pre
|
||||
/// \param p A predicate for testing the elements of the range
|
||||
///
|
||||
template<typename Range, typename OutputIterator, typename Predicate>
|
||||
std::pair<typename boost::range_iterator<const Range>::type, OutputIterator>
|
||||
BOOST_CXX14_CONSTEXPR std::pair<typename boost::range_iterator<const Range>::type, OutputIterator>
|
||||
copy_while ( const Range &r, OutputIterator result, Predicate p )
|
||||
{
|
||||
return boost::algorithm::copy_while (boost::begin (r), boost::end(r), result, p);
|
||||
@ -100,7 +102,7 @@ copy_while ( const Range &r, OutputIterator result, Predicate p )
|
||||
/// \param p A predicate for testing the elements of the range
|
||||
///
|
||||
template<typename InputIterator, typename OutputIterator, typename Predicate>
|
||||
std::pair<InputIterator, OutputIterator>
|
||||
BOOST_CXX14_CONSTEXPR std::pair<InputIterator, OutputIterator>
|
||||
copy_until ( InputIterator first, InputIterator last, OutputIterator result, Predicate p )
|
||||
{
|
||||
for ( ; first != last && !p(*first); ++first )
|
||||
@ -118,12 +120,92 @@ copy_until ( InputIterator first, InputIterator last, OutputIterator result, Pre
|
||||
/// \param p A predicate for testing the elements of the range
|
||||
///
|
||||
template<typename Range, typename OutputIterator, typename Predicate>
|
||||
std::pair<typename boost::range_iterator<const Range>::type, OutputIterator>
|
||||
BOOST_CXX14_CONSTEXPR std::pair<typename boost::range_iterator<const Range>::type, OutputIterator>
|
||||
copy_until ( const Range &r, OutputIterator result, Predicate p )
|
||||
{
|
||||
return boost::algorithm::copy_until (boost::begin (r), boost::end(r), result, p);
|
||||
}
|
||||
|
||||
/// \fn copy_if_while ( InputIterator first, InputIterator last, OutputIterator result, CopyPredicate copy_pred, TerminatePred term_pred )
|
||||
/// \brief Copies all the elements from the input range that satisfy the
|
||||
/// copy predicate to the output range while the termination predicate is
|
||||
/// satisfied.
|
||||
/// \return The updated output iterator
|
||||
///
|
||||
/// \param first The start of the input sequence
|
||||
/// \param last One past the end of the input sequence
|
||||
/// \param result An output iterator to write the results into
|
||||
/// \param copy_pred A predicate for testing whether to the current element
|
||||
/// \param term_pred A predicate for testing whether to end the copy operation
|
||||
template<typename InputIterator, typename OutputIterator, typename CopyPredicate, typename TerminatePred>
|
||||
BOOST_CXX14_CONSTEXPR std::pair<InputIterator, OutputIterator>
|
||||
copy_if_while ( InputIterator first, InputIterator last, OutputIterator result, CopyPredicate copy_pred, TerminatePred term_pred)
|
||||
{
|
||||
for ( ; first != last && term_pred(*first); ++first ) {
|
||||
if (copy_pred(*first)) {
|
||||
*result++ = *first;
|
||||
}
|
||||
}
|
||||
return std::make_pair(first, result);
|
||||
}
|
||||
|
||||
/// \fn copy_if_while ( const Range& r, OutputIterator result, CopyPredicate copy_pred, TerminatePred term_pred )
|
||||
/// \brief Copies all the elements from the input range that satisfy the
|
||||
/// copy predicate to the output range while the termination predicate is
|
||||
/// satisfied.
|
||||
/// \return The updated output iterator
|
||||
///
|
||||
/// \param r The input range
|
||||
/// \param result An output iterator to write the results into
|
||||
/// \param copy_pred A predicate for testing whether to the current element
|
||||
/// \param term_pred A predicate for testing whether to end the copy operation
|
||||
template<typename Range, typename OutputIterator, typename CopyPredicate, typename TerminatePred>
|
||||
BOOST_CXX14_CONSTEXPR std::pair<typename boost::range_iterator<const Range>::type, OutputIterator>
|
||||
copy_if_while ( const Range& r, OutputIterator result, CopyPredicate copy_pred, TerminatePred term_pred)
|
||||
{
|
||||
return boost::algorithm::copy_if_while(boost::begin(r), boost::end(r), result, copy_pred, term_pred);
|
||||
}
|
||||
|
||||
/// \fn copy_if_until ( InputIterator first, InputIterator last, OutputIterator result, CopyPredicate copy_pred, TerminatePred term_pred )
|
||||
/// \brief Copies all the elements from the input range that satisfy the
|
||||
/// copy predicate to the output range until the termination predicate is
|
||||
/// satisfied.
|
||||
/// \return The updated output iterator
|
||||
///
|
||||
/// \param first The start of the input sequence
|
||||
/// \param last One past the end of the input sequence
|
||||
/// \param result An output iterator to write the results into
|
||||
/// \param copy_pred A predicate for testing whether to the current element
|
||||
/// \param term_pred A predicate for testing whether to end the copy operation
|
||||
template<typename InputIterator, typename OutputIterator, typename CopyPredicate, typename TerminatePred>
|
||||
BOOST_CXX14_CONSTEXPR std::pair<InputIterator, OutputIterator>
|
||||
copy_if_until ( InputIterator first, InputIterator last, OutputIterator result, CopyPredicate copy_pred, TerminatePred term_pred)
|
||||
{
|
||||
for ( ; first != last && !term_pred(*first); ++first ) {
|
||||
if (copy_pred(*first)) {
|
||||
*result++ = *first;
|
||||
}
|
||||
}
|
||||
return std::make_pair(first, result);
|
||||
}
|
||||
|
||||
/// \fn copy_if_until ( const Range& r, OutputIterator result, CopyPredicate copy_pred, TerminatePred term_pred )
|
||||
/// \brief Copies all the elements from the input range that satisfy the
|
||||
/// copy predicate to the output range until the termination predicate is
|
||||
/// satisfied.
|
||||
/// \return The updated output iterator
|
||||
///
|
||||
/// \param r The input range
|
||||
/// \param result An output iterator to write the results into
|
||||
/// \param copy_pred A predicate for testing whether to the current element
|
||||
/// \param term_pred A predicate for testing whether to end the copy operation
|
||||
template<typename Range, typename OutputIterator, typename CopyPredicate, typename TerminatePred>
|
||||
BOOST_CXX14_CONSTEXPR std::pair<typename boost::range_iterator<const Range>::type, OutputIterator>
|
||||
copy_if_until ( const Range& r, OutputIterator result, CopyPredicate copy_pred, TerminatePred term_pred)
|
||||
{
|
||||
return boost::algorithm::copy_if_until(boost::begin(r), boost::end(r), result, copy_pred, term_pred);
|
||||
}
|
||||
|
||||
}} // namespace boost and algorithm
|
||||
|
||||
#endif // BOOST_ALGORITHM_COPY_IF_HPP
|
||||
|
@ -12,6 +12,8 @@
|
||||
#ifndef BOOST_ALGORITHM_COPY_N_HPP
|
||||
#define BOOST_ALGORITHM_COPY_N_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
namespace boost { namespace algorithm {
|
||||
|
||||
/// \fn copy_n ( InputIterator first, Size n, OutputIterator result )
|
||||
@ -24,7 +26,7 @@ namespace boost { namespace algorithm {
|
||||
/// \param result An output iterator to write the results into
|
||||
/// \note This function is part of the C++2011 standard library.
|
||||
template <typename InputIterator, typename Size, typename OutputIterator>
|
||||
OutputIterator copy_n ( InputIterator first, Size n, OutputIterator result )
|
||||
BOOST_CXX14_CONSTEXPR OutputIterator copy_n ( InputIterator first, Size n, OutputIterator result )
|
||||
{
|
||||
for ( ; n > 0; --n, ++first, ++result )
|
||||
*result = *first;
|
||||
|
@ -12,6 +12,7 @@
|
||||
#ifndef BOOST_ALGORITHM_FIND_IF_NOT_HPP
|
||||
#define BOOST_ALGORITHM_FIND_IF_NOT_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
|
||||
@ -26,7 +27,7 @@ namespace boost { namespace algorithm {
|
||||
/// \param p A predicate for testing the elements of the range
|
||||
/// \note This function is part of the C++2011 standard library.
|
||||
template<typename InputIterator, typename Predicate>
|
||||
InputIterator find_if_not ( InputIterator first, InputIterator last, Predicate p )
|
||||
BOOST_CXX14_CONSTEXPR InputIterator find_if_not ( InputIterator first, InputIterator last, Predicate p )
|
||||
{
|
||||
for ( ; first != last; ++first )
|
||||
if ( !p(*first))
|
||||
@ -42,7 +43,7 @@ InputIterator find_if_not ( InputIterator first, InputIterator last, Predicate p
|
||||
/// \param p A predicate for testing the elements of the range
|
||||
///
|
||||
template<typename Range, typename Predicate>
|
||||
typename boost::range_iterator<const Range>::type find_if_not ( const Range &r, Predicate p )
|
||||
BOOST_CXX14_CONSTEXPR typename boost::range_iterator<const Range>::type find_if_not ( const Range &r, Predicate p )
|
||||
{
|
||||
return boost::algorithm::find_if_not (boost::begin (r), boost::end(r), p);
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
#ifndef BOOST_ALGORITHM_IOTA_HPP
|
||||
#define BOOST_ALGORITHM_IOTA_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
|
||||
@ -25,7 +26,7 @@ namespace boost { namespace algorithm {
|
||||
/// \param value The initial value of the sequence to be generated
|
||||
/// \note This function is part of the C++2011 standard library.
|
||||
template <typename ForwardIterator, typename T>
|
||||
void iota ( ForwardIterator first, ForwardIterator last, T value )
|
||||
BOOST_CXX14_CONSTEXPR void iota ( ForwardIterator first, ForwardIterator last, T value )
|
||||
{
|
||||
for ( ; first != last; ++first, ++value )
|
||||
*first = value;
|
||||
@ -38,7 +39,7 @@ void iota ( ForwardIterator first, ForwardIterator last, T value )
|
||||
/// \param value The initial value of the sequence to be generated
|
||||
///
|
||||
template <typename Range, typename T>
|
||||
void iota ( Range &r, T value )
|
||||
BOOST_CXX14_CONSTEXPR void iota ( Range &r, T value )
|
||||
{
|
||||
boost::algorithm::iota (boost::begin(r), boost::end(r), value);
|
||||
}
|
||||
@ -52,7 +53,7 @@ void iota ( Range &r, T value )
|
||||
/// \param n The number of items to write
|
||||
///
|
||||
template <typename OutputIterator, typename T>
|
||||
OutputIterator iota_n ( OutputIterator out, T value, std::size_t n )
|
||||
BOOST_CXX14_CONSTEXPR OutputIterator iota_n ( OutputIterator out, T value, std::size_t n )
|
||||
{
|
||||
for ( ; n > 0; --n, ++value )
|
||||
*out++ = value;
|
||||
|
@ -12,6 +12,7 @@
|
||||
#ifndef BOOST_ALGORITHM_IS_PARTITIONED_HPP
|
||||
#define BOOST_ALGORITHM_IS_PARTITIONED_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
|
||||
@ -26,7 +27,7 @@ namespace boost { namespace algorithm {
|
||||
/// \param p The predicate to test the values with
|
||||
/// \note This function is part of the C++2011 standard library.
|
||||
template <typename InputIterator, typename UnaryPredicate>
|
||||
bool is_partitioned ( InputIterator first, InputIterator last, UnaryPredicate p )
|
||||
BOOST_CXX14_CONSTEXPR bool is_partitioned ( InputIterator first, InputIterator last, UnaryPredicate p )
|
||||
{
|
||||
// Run through the part that satisfy the predicate
|
||||
for ( ; first != last; ++first )
|
||||
@ -47,7 +48,7 @@ bool is_partitioned ( InputIterator first, InputIterator last, UnaryPredicate p
|
||||
/// \param p The predicate to test the values with
|
||||
///
|
||||
template <typename Range, typename UnaryPredicate>
|
||||
bool is_partitioned ( const Range &r, UnaryPredicate p )
|
||||
BOOST_CXX14_CONSTEXPR bool is_partitioned ( const Range &r, UnaryPredicate p )
|
||||
{
|
||||
return boost::algorithm::is_partitioned (boost::begin(r), boost::end(r), p);
|
||||
}
|
||||
|
@ -17,9 +17,10 @@
|
||||
#include <functional> // for std::equal_to
|
||||
#include <iterator>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/core/enable_if.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
|
||||
namespace boost { namespace algorithm {
|
||||
|
@ -16,12 +16,13 @@
|
||||
#include <functional>
|
||||
#include <iterator>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/core/enable_if.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/mpl/identity.hpp>
|
||||
#include <boost/type_traits/type_identity.hpp> // for boost::type_identity
|
||||
|
||||
namespace boost { namespace algorithm {
|
||||
|
||||
@ -34,7 +35,7 @@ namespace boost { namespace algorithm {
|
||||
/// \param p A binary predicate that returns true if two elements are ordered.
|
||||
///
|
||||
template <typename ForwardIterator, typename Pred>
|
||||
ForwardIterator is_sorted_until ( ForwardIterator first, ForwardIterator last, Pred p )
|
||||
BOOST_CXX14_CONSTEXPR ForwardIterator is_sorted_until ( ForwardIterator first, ForwardIterator last, Pred p )
|
||||
{
|
||||
if ( first == last ) return last; // the empty sequence is ordered
|
||||
ForwardIterator next = first;
|
||||
@ -54,7 +55,7 @@ namespace boost { namespace algorithm {
|
||||
/// \param last One past the end of the sequence
|
||||
///
|
||||
template <typename ForwardIterator>
|
||||
ForwardIterator is_sorted_until ( ForwardIterator first, ForwardIterator last )
|
||||
BOOST_CXX14_CONSTEXPR ForwardIterator is_sorted_until ( ForwardIterator first, ForwardIterator last )
|
||||
{
|
||||
typedef typename std::iterator_traits<ForwardIterator>::value_type value_type;
|
||||
return boost::algorithm::is_sorted_until ( first, last, std::less<value_type>());
|
||||
@ -69,7 +70,7 @@ namespace boost { namespace algorithm {
|
||||
/// \param p A binary predicate that returns true if two elements are ordered.
|
||||
///
|
||||
template <typename ForwardIterator, typename Pred>
|
||||
bool is_sorted ( ForwardIterator first, ForwardIterator last, Pred p )
|
||||
BOOST_CXX14_CONSTEXPR bool is_sorted ( ForwardIterator first, ForwardIterator last, Pred p )
|
||||
{
|
||||
return boost::algorithm::is_sorted_until (first, last, p) == last;
|
||||
}
|
||||
@ -81,7 +82,7 @@ namespace boost { namespace algorithm {
|
||||
/// \param last One past the end of the sequence
|
||||
///
|
||||
template <typename ForwardIterator>
|
||||
bool is_sorted ( ForwardIterator first, ForwardIterator last )
|
||||
BOOST_CXX14_CONSTEXPR bool is_sorted ( ForwardIterator first, ForwardIterator last )
|
||||
{
|
||||
return boost::algorithm::is_sorted_until (first, last) == last;
|
||||
}
|
||||
@ -98,7 +99,7 @@ namespace boost { namespace algorithm {
|
||||
/// \param p A binary predicate that returns true if two elements are ordered.
|
||||
///
|
||||
template <typename R, typename Pred>
|
||||
typename boost::lazy_disable_if_c<
|
||||
BOOST_CXX14_CONSTEXPR typename boost::lazy_disable_if_c<
|
||||
boost::is_same<R, Pred>::value,
|
||||
typename boost::range_iterator<const R>
|
||||
>::type is_sorted_until ( const R &range, Pred p )
|
||||
@ -113,7 +114,7 @@ namespace boost { namespace algorithm {
|
||||
/// \param range The range to be tested.
|
||||
///
|
||||
template <typename R>
|
||||
typename boost::range_iterator<const R>::type is_sorted_until ( const R &range )
|
||||
BOOST_CXX14_CONSTEXPR typename boost::range_iterator<const R>::type is_sorted_until ( const R &range )
|
||||
{
|
||||
return boost::algorithm::is_sorted_until ( boost::begin ( range ), boost::end ( range ));
|
||||
}
|
||||
@ -126,7 +127,7 @@ namespace boost { namespace algorithm {
|
||||
/// \param p A binary predicate that returns true if two elements are ordered.
|
||||
///
|
||||
template <typename R, typename Pred>
|
||||
typename boost::lazy_disable_if_c< boost::is_same<R, Pred>::value, boost::mpl::identity<bool> >::type
|
||||
BOOST_CXX14_CONSTEXPR typename boost::lazy_disable_if_c< boost::is_same<R, Pred>::value, boost::type_identity<bool> >::type
|
||||
is_sorted ( const R &range, Pred p )
|
||||
{
|
||||
return boost::algorithm::is_sorted ( boost::begin ( range ), boost::end ( range ), p );
|
||||
@ -139,7 +140,7 @@ namespace boost { namespace algorithm {
|
||||
/// \param range The range to be tested.
|
||||
///
|
||||
template <typename R>
|
||||
bool is_sorted ( const R &range )
|
||||
BOOST_CXX14_CONSTEXPR bool is_sorted ( const R &range )
|
||||
{
|
||||
return boost::algorithm::is_sorted ( boost::begin ( range ), boost::end ( range ));
|
||||
}
|
||||
@ -159,7 +160,7 @@ namespace boost { namespace algorithm {
|
||||
/// \note This function will return true for sequences that contain items that compare
|
||||
/// equal. If that is not what you intended, you should use is_strictly_increasing instead.
|
||||
template <typename ForwardIterator>
|
||||
bool is_increasing ( ForwardIterator first, ForwardIterator last )
|
||||
BOOST_CXX14_CONSTEXPR bool is_increasing ( ForwardIterator first, ForwardIterator last )
|
||||
{
|
||||
typedef typename std::iterator_traits<ForwardIterator>::value_type value_type;
|
||||
return boost::algorithm::is_sorted (first, last, std::less<value_type>());
|
||||
@ -175,7 +176,7 @@ namespace boost { namespace algorithm {
|
||||
/// \note This function will return true for sequences that contain items that compare
|
||||
/// equal. If that is not what you intended, you should use is_strictly_increasing instead.
|
||||
template <typename R>
|
||||
bool is_increasing ( const R &range )
|
||||
BOOST_CXX14_CONSTEXPR bool is_increasing ( const R &range )
|
||||
{
|
||||
return is_increasing ( boost::begin ( range ), boost::end ( range ));
|
||||
}
|
||||
@ -192,7 +193,7 @@ namespace boost { namespace algorithm {
|
||||
/// \note This function will return true for sequences that contain items that compare
|
||||
/// equal. If that is not what you intended, you should use is_strictly_decreasing instead.
|
||||
template <typename ForwardIterator>
|
||||
bool is_decreasing ( ForwardIterator first, ForwardIterator last )
|
||||
BOOST_CXX14_CONSTEXPR bool is_decreasing ( ForwardIterator first, ForwardIterator last )
|
||||
{
|
||||
typedef typename std::iterator_traits<ForwardIterator>::value_type value_type;
|
||||
return boost::algorithm::is_sorted (first, last, std::greater<value_type>());
|
||||
@ -207,7 +208,7 @@ namespace boost { namespace algorithm {
|
||||
/// \note This function will return true for sequences that contain items that compare
|
||||
/// equal. If that is not what you intended, you should use is_strictly_decreasing instead.
|
||||
template <typename R>
|
||||
bool is_decreasing ( const R &range )
|
||||
BOOST_CXX14_CONSTEXPR bool is_decreasing ( const R &range )
|
||||
{
|
||||
return is_decreasing ( boost::begin ( range ), boost::end ( range ));
|
||||
}
|
||||
@ -224,7 +225,7 @@ namespace boost { namespace algorithm {
|
||||
/// \note This function will return false for sequences that contain items that compare
|
||||
/// equal. If that is not what you intended, you should use is_increasing instead.
|
||||
template <typename ForwardIterator>
|
||||
bool is_strictly_increasing ( ForwardIterator first, ForwardIterator last )
|
||||
BOOST_CXX14_CONSTEXPR bool is_strictly_increasing ( ForwardIterator first, ForwardIterator last )
|
||||
{
|
||||
typedef typename std::iterator_traits<ForwardIterator>::value_type value_type;
|
||||
return boost::algorithm::is_sorted (first, last, std::less_equal<value_type>());
|
||||
@ -239,7 +240,7 @@ namespace boost { namespace algorithm {
|
||||
/// \note This function will return false for sequences that contain items that compare
|
||||
/// equal. If that is not what you intended, you should use is_increasing instead.
|
||||
template <typename R>
|
||||
bool is_strictly_increasing ( const R &range )
|
||||
BOOST_CXX14_CONSTEXPR bool is_strictly_increasing ( const R &range )
|
||||
{
|
||||
return is_strictly_increasing ( boost::begin ( range ), boost::end ( range ));
|
||||
}
|
||||
@ -255,7 +256,7 @@ namespace boost { namespace algorithm {
|
||||
/// \note This function will return false for sequences that contain items that compare
|
||||
/// equal. If that is not what you intended, you should use is_decreasing instead.
|
||||
template <typename ForwardIterator>
|
||||
bool is_strictly_decreasing ( ForwardIterator first, ForwardIterator last )
|
||||
BOOST_CXX14_CONSTEXPR bool is_strictly_decreasing ( ForwardIterator first, ForwardIterator last )
|
||||
{
|
||||
typedef typename std::iterator_traits<ForwardIterator>::value_type value_type;
|
||||
return boost::algorithm::is_sorted (first, last, std::greater_equal<value_type>());
|
||||
@ -270,7 +271,7 @@ namespace boost { namespace algorithm {
|
||||
/// \note This function will return false for sequences that contain items that compare
|
||||
/// equal. If that is not what you intended, you should use is_decreasing instead.
|
||||
template <typename R>
|
||||
bool is_strictly_decreasing ( const R &range )
|
||||
BOOST_CXX14_CONSTEXPR bool is_strictly_decreasing ( const R &range )
|
||||
{
|
||||
return is_strictly_decreasing ( boost::begin ( range ), boost::end ( range ));
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
#ifndef BOOST_ALGORITHM_NONE_OF_HPP
|
||||
#define BOOST_ALGORITHM_NONE_OF_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
|
||||
@ -26,7 +27,7 @@ namespace boost { namespace algorithm {
|
||||
/// \param p A predicate for testing the elements of the sequence
|
||||
///
|
||||
template<typename InputIterator, typename Predicate>
|
||||
bool none_of ( InputIterator first, InputIterator last, Predicate p )
|
||||
BOOST_CXX14_CONSTEXPR bool none_of ( InputIterator first, InputIterator last, Predicate p )
|
||||
{
|
||||
for ( ; first != last; ++first )
|
||||
if ( p(*first))
|
||||
@ -42,7 +43,7 @@ bool none_of ( InputIterator first, InputIterator last, Predicate p )
|
||||
/// \param p A predicate for testing the elements of the range
|
||||
///
|
||||
template<typename Range, typename Predicate>
|
||||
bool none_of ( const Range &r, Predicate p )
|
||||
BOOST_CXX14_CONSTEXPR bool none_of ( const Range &r, Predicate p )
|
||||
{
|
||||
return boost::algorithm::none_of (boost::begin (r), boost::end (r), p );
|
||||
}
|
||||
@ -56,7 +57,7 @@ bool none_of ( const Range &r, Predicate p )
|
||||
/// \param val A value to compare against
|
||||
///
|
||||
template<typename InputIterator, typename V>
|
||||
bool none_of_equal ( InputIterator first, InputIterator last, const V &val )
|
||||
BOOST_CXX14_CONSTEXPR bool none_of_equal ( InputIterator first, InputIterator last, const V &val )
|
||||
{
|
||||
for ( ; first != last; ++first )
|
||||
if ( val == *first )
|
||||
@ -72,7 +73,7 @@ bool none_of_equal ( InputIterator first, InputIterator last, const V &val )
|
||||
/// \param val A value to compare against
|
||||
///
|
||||
template<typename Range, typename V>
|
||||
bool none_of_equal ( const Range &r, const V & val )
|
||||
BOOST_CXX14_CONSTEXPR bool none_of_equal ( const Range &r, const V & val )
|
||||
{
|
||||
return boost::algorithm::none_of_equal (boost::begin (r), boost::end (r), val);
|
||||
}
|
||||
|
@ -12,12 +12,13 @@
|
||||
#ifndef BOOST_ALGORITHM_ONE_OF_HPP
|
||||
#define BOOST_ALGORITHM_ONE_OF_HPP
|
||||
|
||||
#include <algorithm> // for std::find and std::find_if
|
||||
#include <boost/algorithm/cxx11/none_of.hpp>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
|
||||
#include <boost/algorithm/cxx11/none_of.hpp>
|
||||
|
||||
|
||||
namespace boost { namespace algorithm {
|
||||
|
||||
/// \fn one_of ( InputIterator first, InputIterator last, Predicate p )
|
||||
@ -28,12 +29,16 @@ namespace boost { namespace algorithm {
|
||||
/// \param p A predicate for testing the elements of the sequence
|
||||
///
|
||||
template<typename InputIterator, typename Predicate>
|
||||
bool one_of ( InputIterator first, InputIterator last, Predicate p )
|
||||
BOOST_CXX14_CONSTEXPR bool one_of ( InputIterator first, InputIterator last, Predicate p )
|
||||
{
|
||||
InputIterator i = std::find_if (first, last, p);
|
||||
if (i == last)
|
||||
// find_if
|
||||
for (; first != last; ++first)
|
||||
if (p(*first))
|
||||
break;
|
||||
|
||||
if (first == last)
|
||||
return false; // Didn't occur at all
|
||||
return boost::algorithm::none_of (++i, last, p);
|
||||
return boost::algorithm::none_of (++first, last, p);
|
||||
}
|
||||
|
||||
/// \fn one_of ( const Range &r, Predicate p )
|
||||
@ -43,7 +48,7 @@ bool one_of ( InputIterator first, InputIterator last, Predicate p )
|
||||
/// \param p A predicate for testing the elements of the range
|
||||
///
|
||||
template<typename Range, typename Predicate>
|
||||
bool one_of ( const Range &r, Predicate p )
|
||||
BOOST_CXX14_CONSTEXPR bool one_of ( const Range &r, Predicate p )
|
||||
{
|
||||
return boost::algorithm::one_of ( boost::begin (r), boost::end (r), p );
|
||||
}
|
||||
@ -57,12 +62,16 @@ bool one_of ( const Range &r, Predicate p )
|
||||
/// \param val A value to compare against
|
||||
///
|
||||
template<typename InputIterator, typename V>
|
||||
bool one_of_equal ( InputIterator first, InputIterator last, const V &val )
|
||||
BOOST_CXX14_CONSTEXPR bool one_of_equal ( InputIterator first, InputIterator last, const V &val )
|
||||
{
|
||||
InputIterator i = std::find (first, last, val); // find first occurrence of 'val'
|
||||
if (i == last)
|
||||
// find
|
||||
for (; first != last; ++first)
|
||||
if (*first == val)
|
||||
break;
|
||||
|
||||
if (first == last)
|
||||
return false; // Didn't occur at all
|
||||
return boost::algorithm::none_of_equal (++i, last, val);
|
||||
return boost::algorithm::none_of_equal (++first, last, val);
|
||||
}
|
||||
|
||||
/// \fn one_of_equal ( const Range &r, const V &val )
|
||||
@ -72,7 +81,7 @@ bool one_of_equal ( InputIterator first, InputIterator last, const V &val )
|
||||
/// \param val A value to compare against
|
||||
///
|
||||
template<typename Range, typename V>
|
||||
bool one_of_equal ( const Range &r, const V &val )
|
||||
BOOST_CXX14_CONSTEXPR bool one_of_equal ( const Range &r, const V &val )
|
||||
{
|
||||
return boost::algorithm::one_of_equal ( boost::begin (r), boost::end (r), val );
|
||||
}
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
#include <utility> // for std::pair
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
|
||||
@ -35,7 +36,7 @@ namespace boost { namespace algorithm {
|
||||
/// \note This function is part of the C++2011 standard library.
|
||||
template <typename InputIterator,
|
||||
typename OutputIterator1, typename OutputIterator2, typename UnaryPredicate>
|
||||
std::pair<OutputIterator1, OutputIterator2>
|
||||
BOOST_CXX14_CONSTEXPR std::pair<OutputIterator1, OutputIterator2>
|
||||
partition_copy ( InputIterator first, InputIterator last,
|
||||
OutputIterator1 out_true, OutputIterator2 out_false, UnaryPredicate p )
|
||||
{
|
||||
@ -57,7 +58,7 @@ partition_copy ( InputIterator first, InputIterator last,
|
||||
///
|
||||
template <typename Range, typename OutputIterator1, typename OutputIterator2,
|
||||
typename UnaryPredicate>
|
||||
std::pair<OutputIterator1, OutputIterator2>
|
||||
BOOST_CXX14_CONSTEXPR std::pair<OutputIterator1, OutputIterator2>
|
||||
partition_copy ( const Range &r, OutputIterator1 out_true, OutputIterator2 out_false,
|
||||
UnaryPredicate p )
|
||||
{
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
#include <iterator> // for std::distance, advance
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
|
||||
|
@ -12,19 +12,21 @@
|
||||
#ifndef BOOST_ALGORITHM_EQUAL_HPP
|
||||
#define BOOST_ALGORITHM_EQUAL_HPP
|
||||
|
||||
#include <algorithm> // for std::equal
|
||||
#include <iterator>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
namespace boost { namespace algorithm {
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <class T1, class T2>
|
||||
struct eq {
|
||||
bool operator () ( const T1& v1, const T2& v2 ) const { return v1 == v2 ;}
|
||||
BOOST_CONSTEXPR bool operator () ( const T1& v1, const T2& v2 ) const { return v1 == v2 ;}
|
||||
};
|
||||
|
||||
template <class RandomAccessIterator1, class RandomAccessIterator2, class BinaryPredicate>
|
||||
BOOST_CXX14_CONSTEXPR
|
||||
bool equal ( RandomAccessIterator1 first1, RandomAccessIterator1 last1,
|
||||
RandomAccessIterator2 first2, RandomAccessIterator2 last2, BinaryPredicate pred,
|
||||
std::random_access_iterator_tag, std::random_access_iterator_tag )
|
||||
@ -32,11 +34,16 @@ namespace detail {
|
||||
// Random-access iterators let is check the sizes in constant time
|
||||
if ( std::distance ( first1, last1 ) != std::distance ( first2, last2 ))
|
||||
return false;
|
||||
// If we know that the sequences are the same size, the original version is fine
|
||||
return std::equal ( first1, last1, first2, pred );
|
||||
|
||||
// std::equal
|
||||
for (; first1 != last1; ++first1, ++first2)
|
||||
if (!pred(*first1, *first2))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class InputIterator1, class InputIterator2, class BinaryPredicate>
|
||||
BOOST_CXX14_CONSTEXPR
|
||||
bool equal ( InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2, InputIterator2 last2, BinaryPredicate pred,
|
||||
std::input_iterator_tag, std::input_iterator_tag )
|
||||
@ -60,6 +67,7 @@ namespace detail {
|
||||
/// \param last2 One past the end of the second range.
|
||||
/// \param pred A predicate for comparing the elements of the ranges
|
||||
template <class InputIterator1, class InputIterator2, class BinaryPredicate>
|
||||
BOOST_CXX14_CONSTEXPR
|
||||
bool equal ( InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2, InputIterator2 last2, BinaryPredicate pred )
|
||||
{
|
||||
@ -78,6 +86,7 @@ bool equal ( InputIterator1 first1, InputIterator1 last1,
|
||||
/// \param first2 The start of the second range.
|
||||
/// \param last2 One past the end of the second range.
|
||||
template <class InputIterator1, class InputIterator2>
|
||||
BOOST_CXX14_CONSTEXPR
|
||||
bool equal ( InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2, InputIterator2 last2 )
|
||||
{
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <functional> // for std::equal_to
|
||||
#include <iterator>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/algorithm/cxx11/is_permutation.hpp>
|
||||
#include <boost/algorithm/cxx14/mismatch.hpp>
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
Copyright (c) Marshall Clow 2008-2012.
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE10.txt or copy at http://www.boost.org/LICENSE10.txt)
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
|
||||
/// \file mismatch.hpp
|
||||
@ -14,6 +14,8 @@
|
||||
|
||||
#include <utility> // for std::pair
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
namespace boost { namespace algorithm {
|
||||
|
||||
/// \fn mismatch ( InputIterator1 first1, InputIterator1 last1,
|
||||
@ -27,7 +29,7 @@ namespace boost { namespace algorithm {
|
||||
/// \param last2 One past the end of the second range.
|
||||
/// \param pred A predicate for comparing the elements of the ranges
|
||||
template <class InputIterator1, class InputIterator2, class BinaryPredicate>
|
||||
std::pair<InputIterator1, InputIterator2> mismatch (
|
||||
BOOST_CXX14_CONSTEXPR std::pair<InputIterator1, InputIterator2> mismatch (
|
||||
InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2, InputIterator2 last2,
|
||||
BinaryPredicate pred )
|
||||
@ -47,7 +49,7 @@ std::pair<InputIterator1, InputIterator2> mismatch (
|
||||
/// \param first2 The start of the second range.
|
||||
/// \param last2 One past the end of the second range.
|
||||
template <class InputIterator1, class InputIterator2>
|
||||
std::pair<InputIterator1, InputIterator2> mismatch (
|
||||
BOOST_CXX14_CONSTEXPR std::pair<InputIterator1, InputIterator2> mismatch (
|
||||
InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2, InputIterator2 last2 )
|
||||
{
|
||||
|
@ -2,7 +2,7 @@
|
||||
Copyright (c) Marshall Clow 2017.
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE10.txt or copy at http://www.boost.org/LICENSE10.txt)
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
|
||||
/// \file exclusive_scan.hpp
|
||||
@ -15,6 +15,7 @@
|
||||
#include <functional> // for std::plus
|
||||
#include <iterator> // for std::iterator_traits
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
#include <boost/range/value_type.hpp>
|
||||
@ -44,7 +45,7 @@ OutputIterator exclusive_scan(InputIterator first, InputIterator last,
|
||||
OutputIterator result, T init)
|
||||
{
|
||||
typedef typename std::iterator_traits<InputIterator>::value_type VT;
|
||||
return exclusive_scan(first, last, result, init, std::plus<VT>());
|
||||
return boost::algorithm::exclusive_scan(first, last, result, init, std::plus<VT>());
|
||||
}
|
||||
|
||||
}} // namespace boost and algorithm
|
||||
|
@ -2,7 +2,7 @@
|
||||
Copyright (c) Marshall Clow 2017.
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE10.txt or copy at http://www.boost.org/LICENSE10.txt)
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
|
||||
/// \file for_each_n.hpp
|
||||
@ -14,6 +14,8 @@
|
||||
|
||||
#include <utility> // for std::pair
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
namespace boost { namespace algorithm {
|
||||
|
||||
/// \fn for_each_n(InputIterator first, Size n, Function f);
|
||||
|
@ -2,19 +2,20 @@
|
||||
Copyright (c) Marshall Clow 2017.
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE10.txt or copy at http://www.boost.org/LICENSE10.txt)
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
|
||||
/// \file transform_reduce.hpp
|
||||
/// \brief Combine the (transformed) elements of a sequence (or two) into a single value.
|
||||
/// \author Marshall Clow
|
||||
|
||||
#ifndef BOOST_ALGORITHM_TRANSFORM_REDUCE_HPP
|
||||
#define BOOST_ALGORITHM_TRANSFORM_REDUCE_HPP
|
||||
#ifndef BOOST_ALGORITHM_INCLUSIVE_SCAN_HPP
|
||||
#define BOOST_ALGORITHM_INCLUSIVE_SCAN_HPP
|
||||
|
||||
#include <functional> // for std::plus
|
||||
#include <iterator> // for std::iterator_traits
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
#include <boost/range/value_type.hpp>
|
||||
@ -41,7 +42,7 @@ OutputIterator inclusive_scan(InputIterator first, InputIterator last,
|
||||
typename std::iterator_traits<InputIterator>::value_type init = *first;
|
||||
*result++ = init;
|
||||
if (++first != last)
|
||||
return inclusive_scan(first, last, result, bOp, init);
|
||||
return boost::algorithm::inclusive_scan(first, last, result, bOp, init);
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -52,9 +53,9 @@ OutputIterator inclusive_scan(InputIterator first, InputIterator last,
|
||||
OutputIterator result)
|
||||
{
|
||||
typedef typename std::iterator_traits<InputIterator>::value_type VT;
|
||||
return inclusive_scan(first, last, result, std::plus<VT>());
|
||||
return boost::algorithm::inclusive_scan(first, last, result, std::plus<VT>());
|
||||
}
|
||||
|
||||
}} // namespace boost and algorithm
|
||||
|
||||
#endif // BOOST_ALGORITHM_TRANSFORM_REDUCE_HPP
|
||||
#endif // BOOST_ALGORITHM_INCLUSIVE_SCAN_HPP
|
||||
|
@ -2,7 +2,7 @@
|
||||
Copyright (c) Marshall Clow 2017.
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE10.txt or copy at http://www.boost.org/LICENSE10.txt)
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
|
||||
/// \file reduce.hpp
|
||||
@ -15,6 +15,7 @@
|
||||
#include <functional> // for std::plus
|
||||
#include <iterator> // for std::iterator_traits
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
#include <boost/range/value_type.hpp>
|
||||
@ -34,14 +35,14 @@ template<class InputIterator, class T>
|
||||
T reduce(InputIterator first, InputIterator last, T init)
|
||||
{
|
||||
typedef typename std::iterator_traits<InputIterator>::value_type VT;
|
||||
return reduce(first, last, init, std::plus<VT>());
|
||||
return boost::algorithm::reduce(first, last, init, std::plus<VT>());
|
||||
}
|
||||
|
||||
template<class InputIterator>
|
||||
typename std::iterator_traits<InputIterator>::value_type
|
||||
reduce(InputIterator first, InputIterator last)
|
||||
{
|
||||
return reduce(first, last,
|
||||
return boost::algorithm::reduce(first, last,
|
||||
typename std::iterator_traits<InputIterator>::value_type());
|
||||
}
|
||||
|
||||
@ -49,14 +50,14 @@ template<class Range>
|
||||
typename boost::range_value<Range>::type
|
||||
reduce(const Range &r)
|
||||
{
|
||||
return reduce(boost::begin(r), boost::end(r));
|
||||
return boost::algorithm::reduce(boost::begin(r), boost::end(r));
|
||||
}
|
||||
|
||||
// Not sure that this won't be ambiguous (1)
|
||||
template<class Range, class T>
|
||||
T reduce(const Range &r, T init)
|
||||
{
|
||||
return reduce(boost::begin (r), boost::end (r), init);
|
||||
return boost::algorithm::reduce(boost::begin (r), boost::end (r), init);
|
||||
}
|
||||
|
||||
|
||||
@ -64,7 +65,7 @@ T reduce(const Range &r, T init)
|
||||
template<class Range, class T, class BinaryOperation>
|
||||
T reduce(const Range &r, T init, BinaryOperation bOp)
|
||||
{
|
||||
return reduce(boost::begin(r), boost::end(r), init, bOp);
|
||||
return boost::algorithm::reduce(boost::begin(r), boost::end(r), init, bOp);
|
||||
}
|
||||
|
||||
}} // namespace boost and algorithm
|
||||
|
@ -2,7 +2,7 @@
|
||||
Copyright (c) Marshall Clow 2017.
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE10.txt or copy at http://www.boost.org/LICENSE10.txt)
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
|
||||
/// \file transform_exclusive_scan.hpp
|
||||
@ -15,12 +15,28 @@
|
||||
#include <functional> // for std::plus
|
||||
#include <iterator> // for std::iterator_traits
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
#include <boost/range/value_type.hpp>
|
||||
|
||||
namespace boost { namespace algorithm {
|
||||
|
||||
/// \fn transform_exclusive_scan ( InputIterator first, InputIterator last, OutputIterator result, BinaryOperation bOp, UnaryOperation uOp, T init )
|
||||
/// \brief Transforms elements from the input range with uOp and then combines
|
||||
/// those transformed elements with bOp such that the n-1th element and the nth
|
||||
/// element are combined. Exclusivity means that the nth element is not
|
||||
/// included in the nth combination.
|
||||
/// \return The updated output iterator
|
||||
///
|
||||
/// \param first The start of the input sequence
|
||||
/// \param last The end of the input sequence
|
||||
/// \param result The output iterator to write the results into
|
||||
/// \param bOp The operation for combining transformed input elements
|
||||
/// \param uOp The operation for transforming input elements
|
||||
/// \param init The initial value
|
||||
///
|
||||
/// \note This function is part of the C++17 standard library
|
||||
template<class InputIterator, class OutputIterator, class T,
|
||||
class BinaryOperation, class UnaryOperation>
|
||||
OutputIterator transform_exclusive_scan(InputIterator first, InputIterator last,
|
||||
|
@ -2,7 +2,7 @@
|
||||
Copyright (c) Marshall Clow 2017.
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE10.txt or copy at http://www.boost.org/LICENSE10.txt)
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
|
||||
/// \file transform_reduce.hpp
|
||||
@ -15,12 +15,28 @@
|
||||
#include <functional> // for std::plus
|
||||
#include <iterator> // for std::iterator_traits
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
#include <boost/range/value_type.hpp>
|
||||
|
||||
namespace boost { namespace algorithm {
|
||||
|
||||
/// \fn transform_inclusive_scan ( InputIterator first, InputIterator last, OutputIterator result, BinaryOperation bOp, UnaryOperation uOp, T init )
|
||||
/// \brief Transforms elements from the input range with uOp and then combines
|
||||
/// those transformed elements with bOp such that the n-1th element and the nth
|
||||
/// element are combined. Inclusivity means that the nth element is included in
|
||||
/// the nth combination.
|
||||
/// \return The updated output iterator
|
||||
///
|
||||
/// \param first The start of the input sequence
|
||||
/// \param last The end of the input sequence
|
||||
/// \param result The output iterator to write the results into
|
||||
/// \param bOp The operation for combining transformed input elements
|
||||
/// \param uOp The operation for transforming input elements
|
||||
/// \param init The initial value
|
||||
///
|
||||
/// \note This function is part of the C++17 standard library
|
||||
template<class InputIterator, class OutputIterator,
|
||||
class BinaryOperation, class UnaryOperation, class T>
|
||||
OutputIterator transform_inclusive_scan(InputIterator first, InputIterator last,
|
||||
@ -36,6 +52,20 @@ OutputIterator transform_inclusive_scan(InputIterator first, InputIterator last,
|
||||
return result;
|
||||
}
|
||||
|
||||
/// \fn transform_inclusive_scan ( InputIterator first, InputIterator last, OutputIterator result, BinaryOperation bOp, UnaryOperation uOp, T init )
|
||||
/// \brief Transforms elements from the input range with uOp and then combines
|
||||
/// those transformed elements with bOp such that the n-1th element and the nth
|
||||
/// element are combined. Inclusivity means that the nth element is included in
|
||||
/// the nth combination. The first value will be used as the init.
|
||||
/// \return The updated output iterator
|
||||
///
|
||||
/// \param first The start of the input sequence
|
||||
/// \param last The end of the input sequence
|
||||
/// \param result The output iterator to write the results into
|
||||
/// \param bOp The operation for combining transformed input elements
|
||||
/// \param uOp The operation for transforming input elements
|
||||
///
|
||||
/// \note This function is part of the C++17 standard library
|
||||
template<class InputIterator, class OutputIterator,
|
||||
class BinaryOperation, class UnaryOperation>
|
||||
OutputIterator transform_inclusive_scan(InputIterator first, InputIterator last,
|
||||
@ -46,7 +76,8 @@ OutputIterator transform_inclusive_scan(InputIterator first, InputIterator last,
|
||||
typename std::iterator_traits<InputIterator>::value_type init = uOp(*first);
|
||||
*result++ = init;
|
||||
if (++first != last)
|
||||
return transform_inclusive_scan(first, last, result, bOp, uOp, init);
|
||||
return boost::algorithm::transform_inclusive_scan
|
||||
(first, last, result, bOp, uOp, init);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -2,7 +2,7 @@
|
||||
Copyright (c) Marshall Clow 2017.
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE10.txt or copy at http://www.boost.org/LICENSE10.txt)
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
|
||||
/// \file transform_reduce.hpp
|
||||
@ -15,6 +15,7 @@
|
||||
#include <functional> // for std::plus
|
||||
#include <iterator> // for std::iterator_traits
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
#include <boost/range/value_type.hpp>
|
||||
@ -46,7 +47,7 @@ template<class InputIterator1, class InputIterator2, class T>
|
||||
T transform_reduce(InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2, T init)
|
||||
{
|
||||
return transform_reduce(first1, last1, first2, init,
|
||||
return boost::algorithm::transform_reduce(first1, last1, first2, init,
|
||||
std::plus<T>(), std::multiplies<T>());
|
||||
}
|
||||
|
||||
|
96
include/boost/algorithm/find_backward.hpp
Normal file
96
include/boost/algorithm/find_backward.hpp
Normal file
@ -0,0 +1,96 @@
|
||||
/*
|
||||
Copyright (c) T. Zachary Laine 2018.
|
||||
|
||||
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)
|
||||
*/
|
||||
#ifndef BOOST_ALGORITHM_FIND_BACKWARD_HPP
|
||||
#define BOOST_ALGORITHM_FIND_BACKWARD_HPP
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
|
||||
namespace boost { namespace algorithm {
|
||||
|
||||
template<typename BidiIter, typename T>
|
||||
BOOST_CXX14_CONSTEXPR
|
||||
BidiIter find_backward(BidiIter first, BidiIter last, const T & x)
|
||||
{
|
||||
BidiIter it = last;
|
||||
while (it != first) {
|
||||
if (*--it == x)
|
||||
return it;
|
||||
}
|
||||
return last;
|
||||
}
|
||||
|
||||
template<typename Range, typename T>
|
||||
BOOST_CXX14_CONSTEXPR
|
||||
typename boost::range_iterator<Range>::type find_backward(Range & range, const T & x)
|
||||
{
|
||||
return ::boost::algorithm::find_backward(boost::begin(range), boost::end(range), x);
|
||||
}
|
||||
|
||||
template<typename BidiIter, typename T>
|
||||
BOOST_CXX14_CONSTEXPR
|
||||
BidiIter find_not_backward(BidiIter first, BidiIter last, const T & x)
|
||||
{
|
||||
BidiIter it = last;
|
||||
while (it != first) {
|
||||
if (*--it != x)
|
||||
return it;
|
||||
}
|
||||
return last;
|
||||
}
|
||||
|
||||
template<typename Range, typename T>
|
||||
BOOST_CXX14_CONSTEXPR
|
||||
typename boost::range_iterator<Range>::type find_not_backward(Range & range, const T & x)
|
||||
{
|
||||
return ::boost::algorithm::find_not_backward(boost::begin(range), boost::end(range), x);
|
||||
}
|
||||
|
||||
template<typename BidiIter, typename Pred>
|
||||
BOOST_CXX14_CONSTEXPR
|
||||
BidiIter find_if_backward(BidiIter first, BidiIter last, Pred p)
|
||||
{
|
||||
BidiIter it = last;
|
||||
while (it != first) {
|
||||
if (p(*--it))
|
||||
return it;
|
||||
}
|
||||
return last;
|
||||
}
|
||||
|
||||
template<typename Range, typename Pred>
|
||||
BOOST_CXX14_CONSTEXPR
|
||||
typename boost::range_iterator<Range>::type find_if_backward(Range & range, Pred p)
|
||||
{
|
||||
return ::boost::algorithm::find_if_backward(boost::begin(range), boost::end(range), p);
|
||||
}
|
||||
|
||||
template<typename BidiIter, typename Pred>
|
||||
BOOST_CXX14_CONSTEXPR
|
||||
BidiIter find_if_not_backward(BidiIter first, BidiIter last, Pred p)
|
||||
{
|
||||
BidiIter it = last;
|
||||
while (it != first) {
|
||||
if (!p(*--it))
|
||||
return it;
|
||||
}
|
||||
return last;
|
||||
}
|
||||
|
||||
template<typename Range, typename Pred>
|
||||
BOOST_CXX14_CONSTEXPR
|
||||
typename boost::range_iterator<Range>::type find_if_not_backward(Range & range, Pred p)
|
||||
{
|
||||
return ::boost::algorithm::find_if_not_backward(boost::begin(range), boost::end(range), p);
|
||||
}
|
||||
|
||||
}} // namespace boost and algorithm
|
||||
|
||||
#endif // BOOST_ALGORITHM_FIND_BACKWARD_HPP
|
38
include/boost/algorithm/find_not.hpp
Normal file
38
include/boost/algorithm/find_not.hpp
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
Copyright (c) T. Zachary Laine 2018.
|
||||
|
||||
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)
|
||||
*/
|
||||
#ifndef BOOST_ALGORITHM_FIND_NOT_HPP
|
||||
#define BOOST_ALGORITHM_FIND_NOT_HPP
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
|
||||
namespace boost { namespace algorithm {
|
||||
|
||||
template<typename InputIter, typename Sentinel, typename T>
|
||||
BOOST_CXX14_CONSTEXPR
|
||||
InputIter find_not(InputIter first, Sentinel last, const T & x)
|
||||
{
|
||||
for (; first != last; ++first) {
|
||||
if (*first != x)
|
||||
break;
|
||||
}
|
||||
return first;
|
||||
}
|
||||
|
||||
template<typename Range, typename T>
|
||||
BOOST_CXX14_CONSTEXPR
|
||||
typename boost::range_iterator<Range>::type find_not(Range & r, const T & x)
|
||||
{
|
||||
return ::boost::algorithm::find_not(boost::begin(r), boost::end(r), x);
|
||||
}
|
||||
|
||||
}} // namespace boost and algorithm
|
||||
|
||||
#endif // BOOST_ALGORITHM_FIND_NOT_HPP
|
@ -22,8 +22,10 @@
|
||||
|
||||
#include <algorithm> // for std::stable_partition
|
||||
#include <functional>
|
||||
#include <utility> // for std::make_pair
|
||||
|
||||
#include <boost/bind.hpp> // for boost::bind
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/bind/bind.hpp> // for boost::bind
|
||||
#include <boost/range/begin.hpp> // for boost::begin(range)
|
||||
#include <boost/range/end.hpp> // for boost::end(range)
|
||||
|
||||
@ -80,13 +82,14 @@ namespace boost { namespace algorithm {
|
||||
*/
|
||||
|
||||
template <
|
||||
typename BidirectionalIterator, // Iter models BidirectionalIterator
|
||||
typename Pred> // Pred models UnaryPredicate
|
||||
typename BidirectionalIterator, // models BidirectionalIterator
|
||||
typename Pred> // models UnaryPredicate
|
||||
std::pair<BidirectionalIterator, BidirectionalIterator> gather
|
||||
( BidirectionalIterator first, BidirectionalIterator last, BidirectionalIterator pivot, Pred pred )
|
||||
{
|
||||
// The first call partitions everything up to (but not including) the pivot element,
|
||||
// while the second call partitions the rest of the sequence.
|
||||
using namespace boost::placeholders;
|
||||
return std::make_pair (
|
||||
std::stable_partition ( first, pivot, !boost::bind<bool> ( pred, _1 )),
|
||||
std::stable_partition ( pivot, last, boost::bind<bool> ( pred, _1 )));
|
||||
|
@ -23,13 +23,14 @@
|
||||
#include <iterator> // for std::iterator_traits
|
||||
#include <stdexcept>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
#include <boost/exception/exception.hpp>
|
||||
#include <boost/exception/info.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/core/enable_if.hpp>
|
||||
#include <boost/type_traits/is_integral.hpp>
|
||||
|
||||
|
||||
@ -47,9 +48,9 @@ namespace boost { namespace algorithm {
|
||||
\brief Thrown when the input sequence unexpectedly ends
|
||||
|
||||
*/
|
||||
struct hex_decode_error : virtual boost::exception, virtual std::exception {};
|
||||
struct not_enough_input : virtual hex_decode_error {};
|
||||
struct non_hex_input : virtual hex_decode_error {};
|
||||
struct BOOST_SYMBOL_VISIBLE hex_decode_error : virtual boost::exception, virtual std::exception {};
|
||||
struct BOOST_SYMBOL_VISIBLE not_enough_input : virtual hex_decode_error {};
|
||||
struct BOOST_SYMBOL_VISIBLE non_hex_input : virtual hex_decode_error {};
|
||||
typedef boost::error_info<struct bad_char_,char> bad_char;
|
||||
|
||||
namespace detail {
|
||||
|
72
include/boost/algorithm/is_clamped.hpp
Normal file
72
include/boost/algorithm/is_clamped.hpp
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
Copyright (c) Ivan Matek, Marshall Clow 2021.
|
||||
|
||||
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)
|
||||
|
||||
*/
|
||||
|
||||
/// \file is_clamped.hpp
|
||||
/// \brief IsClamped algorithm
|
||||
/// \authors Ivan Matek, Marshall Clow
|
||||
///
|
||||
|
||||
#ifndef BOOST_ALGORITHM_IS_CLAMPED_HPP
|
||||
#define BOOST_ALGORITHM_IS_CLAMPED_HPP
|
||||
|
||||
#include <functional> // for std::less
|
||||
#include <cassert>
|
||||
|
||||
#include <boost/type_traits/type_identity.hpp> // for boost::type_identity
|
||||
|
||||
namespace boost { namespace algorithm {
|
||||
|
||||
/// \fn is_clamped ( T const& val,
|
||||
/// typename boost::type_identity<T>::type const & lo,
|
||||
/// typename boost::type_identity<T>::type const & hi, Pred p )
|
||||
/// \returns true if value "val" is in the range [ lo, hi ]
|
||||
/// using the comparison predicate p.
|
||||
/// If p ( val, lo ) return false.
|
||||
/// If p ( hi, val ) return false.
|
||||
/// Otherwise, returns true.
|
||||
///
|
||||
/// \param val The value to be checked
|
||||
/// \param lo The lower bound of the range
|
||||
/// \param hi The upper bound of the range
|
||||
/// \param p A predicate to use to compare the values.
|
||||
/// p ( a, b ) returns a boolean.
|
||||
///
|
||||
template <typename T, typename Pred>
|
||||
BOOST_CXX14_CONSTEXPR bool is_clamped(
|
||||
T const& val, typename boost::type_identity<T>::type const& lo,
|
||||
typename boost::type_identity<T>::type const& hi, Pred p) {
|
||||
// assert ( !p ( hi, lo )); // Can't assert p ( lo, hi ) b/c they
|
||||
// might be equal
|
||||
return p(val, lo) ? false : p(hi, val) ? false : true;
|
||||
}
|
||||
|
||||
/// \fn is_clamped ( T const& val,
|
||||
/// typename boost::type_identity<T>::type const & lo,
|
||||
/// typename boost::type_identity<T>::type const & hi)
|
||||
/// \returns true if value "val" is in the range [ lo, hi ]
|
||||
/// using operator < for comparison.
|
||||
/// If the value is less than lo, return false.
|
||||
/// If the value is greater than hi, return false.
|
||||
/// Otherwise, returns true.
|
||||
///
|
||||
/// \param val The value to be checked
|
||||
/// \param lo The lower bound of the range
|
||||
/// \param hi The upper bound of the range
|
||||
///
|
||||
|
||||
template<typename T>
|
||||
BOOST_CXX14_CONSTEXPR bool is_clamped ( const T& val,
|
||||
typename boost::type_identity<T>::type const & lo,
|
||||
typename boost::type_identity<T>::type const & hi )
|
||||
{
|
||||
return boost::algorithm::is_clamped ( val, lo, hi, std::less<T>());
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#endif // BOOST_ALGORITHM_CLAMP_HPP
|
@ -19,6 +19,7 @@
|
||||
#include <functional>
|
||||
#include <cstring>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
|
||||
@ -112,7 +113,7 @@ bool is_palindrome(const R& range, Predicate p)
|
||||
/// \note This function will return true for empty sequences and for palindromes.
|
||||
/// For other sequences function will return false.
|
||||
/// Complexity: O(N).
|
||||
bool is_palindrome(const char* str)
|
||||
inline bool is_palindrome(const char* str)
|
||||
{
|
||||
if(!str)
|
||||
return true;
|
||||
|
@ -12,6 +12,7 @@
|
||||
#ifndef BOOST_ALGORITHM_IS_PARTITIONED_UNTIL_HPP
|
||||
#define BOOST_ALGORITHM_IS_PARTITIONED_UNTIL_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/tuple/tuple.hpp> // for using pairs with boost::cref
|
||||
#include <boost/ref.hpp>
|
||||
|
||||
|
@ -28,6 +28,8 @@
|
||||
|
||||
#include <utility> // for std::pair and std::make_pair
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
namespace boost {
|
||||
|
||||
namespace detail { // for obtaining a uniform version of minmax_element
|
||||
|
@ -12,13 +12,14 @@
|
||||
|
||||
#include <iterator> // for std::iterator_traits
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/core/enable_if.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
|
||||
#include <boost/algorithm/searching/detail/bm_traits.hpp>
|
||||
|
@ -12,13 +12,14 @@
|
||||
|
||||
#include <iterator> // for std::iterator_traits
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/core/enable_if.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
|
||||
#include <boost/algorithm/searching/detail/bm_traits.hpp>
|
||||
|
@ -13,13 +13,14 @@
|
||||
#include <vector>
|
||||
#include <iterator> // for std::iterator_traits
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/core/enable_if.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
|
||||
#include <boost/algorithm/searching/detail/debugging.hpp>
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <iterator> // For std::iterator_traits
|
||||
#include <algorithm> // For nth_element and partial_sort
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
|
||||
|
@ -65,7 +65,7 @@ namespace boost {
|
||||
template< typename T1, typename T2 >
|
||||
bool operator()( const T1& Arg1, const T2& Arg2 ) const
|
||||
{
|
||||
#if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL)
|
||||
#if defined(BOOST_BORLANDC) && (BOOST_BORLANDC >= 0x560) && (BOOST_BORLANDC <= 0x564) && !defined(_USE_OLD_RW_STL)
|
||||
return std::toupper(Arg1)==std::toupper(Arg2);
|
||||
#else
|
||||
return std::toupper<T1>(Arg1,m_Loc)==std::toupper<T2>(Arg2,m_Loc);
|
||||
@ -118,7 +118,7 @@ namespace boost {
|
||||
template< typename T1, typename T2 >
|
||||
bool operator()( const T1& Arg1, const T2& Arg2 ) const
|
||||
{
|
||||
#if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL)
|
||||
#if defined(BOOST_BORLANDC) && (BOOST_BORLANDC >= 0x560) && (BOOST_BORLANDC <= 0x564) && !defined(_USE_OLD_RW_STL)
|
||||
return std::toupper(Arg1)<std::toupper(Arg2);
|
||||
#else
|
||||
return std::toupper<T1>(Arg1,m_Loc)<std::toupper<T2>(Arg2,m_Loc);
|
||||
@ -171,7 +171,7 @@ namespace boost {
|
||||
template< typename T1, typename T2 >
|
||||
bool operator()( const T1& Arg1, const T2& Arg2 ) const
|
||||
{
|
||||
#if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL)
|
||||
#if defined(BOOST_BORLANDC) && (BOOST_BORLANDC >= 0x560) && (BOOST_BORLANDC <= 0x564) && !defined(_USE_OLD_RW_STL)
|
||||
return std::toupper(Arg1)<=std::toupper(Arg2);
|
||||
#else
|
||||
return std::toupper<T1>(Arg1,m_Loc)<=std::toupper<T2>(Arg2,m_Loc);
|
||||
|
@ -15,6 +15,9 @@
|
||||
#include <locale>
|
||||
#include <functional>
|
||||
|
||||
#include <boost/iterator/transform_iterator.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
#include <boost/type_traits/make_unsigned.hpp>
|
||||
|
||||
namespace boost {
|
||||
@ -40,7 +43,7 @@ namespace boost {
|
||||
// Operation
|
||||
CharT operator ()( CharT Ch ) const
|
||||
{
|
||||
#if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL)
|
||||
#if defined(BOOST_BORLANDC) && (BOOST_BORLANDC >= 0x560) && (BOOST_BORLANDC <= 0x564) && !defined(_USE_OLD_RW_STL)
|
||||
return std::tolower( static_cast<typename boost::make_unsigned <CharT>::type> ( Ch ));
|
||||
#else
|
||||
return std::tolower<CharT>( Ch, *m_Loc );
|
||||
@ -62,7 +65,7 @@ namespace boost {
|
||||
// Operation
|
||||
CharT operator ()( CharT Ch ) const
|
||||
{
|
||||
#if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL)
|
||||
#if defined(BOOST_BORLANDC) && (BOOST_BORLANDC >= 0x560) && (BOOST_BORLANDC <= 0x564) && !defined(_USE_OLD_RW_STL)
|
||||
return std::toupper( static_cast<typename boost::make_unsigned <CharT>::type> ( Ch ));
|
||||
#else
|
||||
return std::toupper<CharT>( Ch, *m_Loc );
|
||||
|
@ -13,10 +13,12 @@
|
||||
|
||||
#include <boost/algorithm/string/config.hpp>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <functional>
|
||||
#include <locale>
|
||||
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/distance.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
|
||||
#include <boost/algorithm/string/predicate_facade.hpp>
|
||||
@ -45,7 +47,7 @@ namespace boost {
|
||||
return std::use_facet< std::ctype<CharT> >(m_Locale).is( m_Type, Ch );
|
||||
}
|
||||
|
||||
#if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x582) && !defined(_USE_OLD_RW_STL)
|
||||
#if defined(BOOST_BORLANDC) && (BOOST_BORLANDC >= 0x560) && (BOOST_BORLANDC <= 0x582) && !defined(_USE_OLD_RW_STL)
|
||||
template<>
|
||||
bool operator()( char const Ch ) const
|
||||
{
|
||||
|
@ -18,6 +18,8 @@
|
||||
#include <boost/algorithm/string/detail/find_format_store.hpp>
|
||||
#include <boost/algorithm/string/detail/replace_storage.hpp>
|
||||
|
||||
#include <deque>
|
||||
|
||||
namespace boost {
|
||||
namespace algorithm {
|
||||
namespace detail {
|
||||
|
@ -40,10 +40,18 @@ namespace boost {
|
||||
// Protected construction/destruction
|
||||
|
||||
// Default constructor
|
||||
find_iterator_base() {}
|
||||
BOOST_DEFAULTED_FUNCTION(find_iterator_base(), {})
|
||||
|
||||
// Copy construction
|
||||
find_iterator_base( const find_iterator_base& Other ) :
|
||||
BOOST_DEFAULTED_FUNCTION(find_iterator_base( const find_iterator_base& Other ), :
|
||||
m_Finder(Other.m_Finder) {}
|
||||
)
|
||||
|
||||
// Assignment
|
||||
BOOST_DEFAULTED_FUNCTION(find_iterator_base& operator=( const find_iterator_base& Other ), {
|
||||
m_Finder = Other.m_Finder;
|
||||
return *this;
|
||||
})
|
||||
|
||||
// Constructor
|
||||
template<typename FinderT>
|
||||
@ -51,7 +59,7 @@ namespace boost {
|
||||
m_Finder(Finder) {}
|
||||
|
||||
// Destructor
|
||||
~find_iterator_base() {}
|
||||
BOOST_DEFAULTED_FUNCTION(~find_iterator_base(), {})
|
||||
|
||||
// Find operation
|
||||
match_type do_find(
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
#include <boost/algorithm/string/config.hpp>
|
||||
#include <boost/algorithm/string/constants.hpp>
|
||||
#include <boost/detail/iterator.hpp>
|
||||
#include <iterator>
|
||||
|
||||
#include <boost/range/iterator_range_core.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
@ -127,8 +127,8 @@ namespace boost {
|
||||
if( boost::empty(m_Search) )
|
||||
return result_type( End, End );
|
||||
|
||||
typedef BOOST_STRING_TYPENAME boost::detail::
|
||||
iterator_traits<ForwardIteratorT>::iterator_category category;
|
||||
typedef BOOST_STRING_TYPENAME
|
||||
std::iterator_traits<ForwardIteratorT>::iterator_category category;
|
||||
|
||||
return findit( Begin, End, category() );
|
||||
}
|
||||
@ -344,9 +344,8 @@ namespace boost {
|
||||
typedef iterator_range<ForwardIteratorT> result_type;
|
||||
|
||||
input_iterator_type It=Begin;
|
||||
for(
|
||||
unsigned int Index=0;
|
||||
Index<N && It!=End; ++Index,++It ) {};
|
||||
for( unsigned int Index=0; Index<N && It!=End; ++Index,++It )
|
||||
;
|
||||
|
||||
return result_type( Begin, It );
|
||||
}
|
||||
@ -375,8 +374,8 @@ namespace boost {
|
||||
ForwardIteratorT End,
|
||||
unsigned int N )
|
||||
{
|
||||
typedef BOOST_STRING_TYPENAME boost::detail::
|
||||
iterator_traits<ForwardIteratorT>::iterator_category category;
|
||||
typedef BOOST_STRING_TYPENAME
|
||||
std::iterator_traits<ForwardIteratorT>::iterator_category category;
|
||||
|
||||
return ::boost::algorithm::detail::find_head_impl( Begin, End, N, category() );
|
||||
}
|
||||
@ -397,10 +396,12 @@ namespace boost {
|
||||
input_iterator_type It2=Begin;
|
||||
|
||||
// Advance It2 by N increments
|
||||
for( Index=0; Index<N && It2!=End; ++Index,++It2 ) {};
|
||||
for( Index=0; Index<N && It2!=End; ++Index,++It2 )
|
||||
;
|
||||
|
||||
// Advance It, It2 to the end
|
||||
for(; It2!=End; ++It,++It2 ) {};
|
||||
for(; It2!=End; ++It,++It2 )
|
||||
;
|
||||
|
||||
return result_type( It, It2 );
|
||||
}
|
||||
@ -417,9 +418,8 @@ namespace boost {
|
||||
typedef iterator_range<ForwardIteratorT> result_type;
|
||||
|
||||
input_iterator_type It=End;
|
||||
for(
|
||||
unsigned int Index=0;
|
||||
Index<N && It!=Begin; ++Index,--It ) {};
|
||||
for( unsigned int Index=0; Index<N && It!=Begin; ++Index,--It )
|
||||
;
|
||||
|
||||
return result_type( It, End );
|
||||
}
|
||||
@ -448,8 +448,8 @@ namespace boost {
|
||||
ForwardIteratorT End,
|
||||
unsigned int N )
|
||||
{
|
||||
typedef BOOST_STRING_TYPENAME boost::detail::
|
||||
iterator_traits<ForwardIteratorT>::iterator_category category;
|
||||
typedef BOOST_STRING_TYPENAME
|
||||
std::iterator_traits<ForwardIteratorT>::iterator_category category;
|
||||
|
||||
return ::boost::algorithm::detail::find_tail_impl( Begin, End, N, category() );
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ namespace boost {
|
||||
m_Format(::boost::begin(Format), ::boost::end(Format)) {}
|
||||
|
||||
// Operation
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
#if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564))
|
||||
template<typename Range2T>
|
||||
result_type& operator()(const Range2T&)
|
||||
{
|
||||
|
@ -12,7 +12,7 @@
|
||||
#define BOOST_STRING_TRIM_DETAIL_HPP
|
||||
|
||||
#include <boost/algorithm/string/config.hpp>
|
||||
#include <boost/detail/iterator.hpp>
|
||||
#include <iterator>
|
||||
|
||||
namespace boost {
|
||||
namespace algorithm {
|
||||
@ -80,8 +80,8 @@ namespace boost {
|
||||
ForwardIteratorT InEnd,
|
||||
PredicateT IsSpace )
|
||||
{
|
||||
typedef BOOST_STRING_TYPENAME boost::detail::
|
||||
iterator_traits<ForwardIteratorT>::iterator_category category;
|
||||
typedef BOOST_STRING_TYPENAME
|
||||
std::iterator_traits<ForwardIteratorT>::iterator_category category;
|
||||
|
||||
return ::boost::algorithm::detail::trim_end_iter_select( InBegin, InEnd, IsSpace, category() );
|
||||
}
|
||||
|
@ -12,7 +12,6 @@
|
||||
#define BOOST_STRING_FIND_FORMAT_HPP
|
||||
|
||||
#include <deque>
|
||||
#include <boost/detail/iterator.hpp>
|
||||
#include <boost/range/iterator_range_core.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
@ -40,7 +39,7 @@ namespace boost {
|
||||
this substring and replace it in the input.
|
||||
The result is a modified copy of the input. It is returned as a sequence
|
||||
or copied to the output iterator.
|
||||
|
||||
|
||||
\param Output An output iterator to which the result will be copied
|
||||
\param Input An input sequence
|
||||
\param Finder A Finder object used to search for a match to be replaced
|
||||
|
@ -74,7 +74,7 @@ namespace boost {
|
||||
|
||||
\post eof()==true
|
||||
*/
|
||||
find_iterator() {}
|
||||
BOOST_DEFAULTED_FUNCTION(find_iterator(), {})
|
||||
|
||||
//! Copy constructor
|
||||
/*!
|
||||
@ -85,6 +85,18 @@ namespace boost {
|
||||
m_Match(Other.m_Match),
|
||||
m_End(Other.m_End) {}
|
||||
|
||||
//! Copy assignment
|
||||
/*!
|
||||
Assigns a copy of the find_iterator
|
||||
*/
|
||||
BOOST_DEFAULTED_FUNCTION(find_iterator& operator=( const find_iterator& Other ), {
|
||||
if (this == &Other) return *this;
|
||||
this->base_type::operator=(Other);
|
||||
m_Match = Other.m_Match;
|
||||
m_End = Other.m_End;
|
||||
return *this;
|
||||
})
|
||||
|
||||
//! Constructor
|
||||
/*!
|
||||
Construct new find_iterator for a given finder
|
||||
@ -248,6 +260,20 @@ namespace boost {
|
||||
m_bEof(Other.m_bEof)
|
||||
{}
|
||||
|
||||
//! Assignment operator
|
||||
/*!
|
||||
Assigns a copy of the split_iterator
|
||||
*/
|
||||
BOOST_DEFAULTED_FUNCTION(split_iterator& operator=( const split_iterator& Other ), {
|
||||
if (this == &Other) return *this;
|
||||
this->base_type::operator=(Other);
|
||||
m_Match = Other.m_Match;
|
||||
m_Next = Other.m_Next;
|
||||
m_End = Other.m_End;
|
||||
m_bEof = Other.m_bEof;
|
||||
return *this;
|
||||
})
|
||||
|
||||
//! Constructor
|
||||
/*!
|
||||
Construct new split_iterator for a given finder
|
||||
|
@ -43,7 +43,6 @@ namespace boost {
|
||||
The result is given as an \c iterator_range delimiting the match.
|
||||
|
||||
\param Search A substring to be searched for.
|
||||
\param Comp An element comparison predicate
|
||||
\return An instance of the \c first_finder object
|
||||
*/
|
||||
template<typename RangeT>
|
||||
@ -84,7 +83,6 @@ namespace boost {
|
||||
The result is given as an \c iterator_range delimiting the match.
|
||||
|
||||
\param Search A substring to be searched for.
|
||||
\param Comp An element comparison predicate
|
||||
\return An instance of the \c last_finder object
|
||||
*/
|
||||
template<typename RangeT>
|
||||
@ -124,7 +122,6 @@ namespace boost {
|
||||
|
||||
\param Search A substring to be searched for.
|
||||
\param Nth An index of the match to be find
|
||||
\param Comp An element comparison predicate
|
||||
\return An instance of the \c nth_finder object
|
||||
*/
|
||||
template<typename RangeT>
|
||||
@ -230,7 +227,6 @@ namespace boost {
|
||||
|
||||
\param Begin Beginning of the range
|
||||
\param End End of the range
|
||||
\param Range The range.
|
||||
\return An instance of the \c range_finger object
|
||||
*/
|
||||
template< typename ForwardIteratorT >
|
||||
|
@ -11,7 +11,6 @@
|
||||
#ifndef BOOST_STRING_FORMATTER_HPP
|
||||
#define BOOST_STRING_FORMATTER_HPP
|
||||
|
||||
#include <boost/detail/iterator.hpp>
|
||||
#include <boost/range/value_type.hpp>
|
||||
#include <boost/range/iterator_range_core.hpp>
|
||||
#include <boost/range/as_literal.hpp>
|
||||
|
@ -71,7 +71,11 @@ namespace boost {
|
||||
inline SequenceSequenceT&
|
||||
iter_find(
|
||||
SequenceSequenceT& Result,
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
RangeT&& Input,
|
||||
#else
|
||||
RangeT& Input,
|
||||
#endif
|
||||
FinderT Finder )
|
||||
{
|
||||
BOOST_CONCEPT_ASSERT((
|
||||
@ -142,7 +146,11 @@ namespace boost {
|
||||
inline SequenceSequenceT&
|
||||
iter_split(
|
||||
SequenceSequenceT& Result,
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
RangeT&& Input,
|
||||
#else
|
||||
RangeT& Input,
|
||||
#endif
|
||||
FinderT Finder )
|
||||
{
|
||||
BOOST_CONCEPT_ASSERT((
|
||||
|
@ -11,6 +11,7 @@
|
||||
#ifndef BOOST_STRING_PREDICATE_HPP
|
||||
#define BOOST_STRING_PREDICATE_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <boost/algorithm/string/config.hpp>
|
||||
#include <boost/range/begin.hpp>
|
||||
#include <boost/range/end.hpp>
|
||||
@ -144,10 +145,10 @@ namespace boost {
|
||||
iterator_range<BOOST_STRING_TYPENAME range_const_iterator<Range1T>::type> lit_input(::boost::as_literal(Input));
|
||||
iterator_range<BOOST_STRING_TYPENAME range_const_iterator<Range2T>::type> lit_test(::boost::as_literal(Test));
|
||||
|
||||
typedef BOOST_STRING_TYPENAME
|
||||
typedef BOOST_STRING_TYPENAME
|
||||
range_const_iterator<Range1T>::type Iterator1T;
|
||||
typedef BOOST_STRING_TYPENAME boost::detail::
|
||||
iterator_traits<Iterator1T>::iterator_category category;
|
||||
typedef BOOST_STRING_TYPENAME
|
||||
std::iterator_traits<Iterator1T>::iterator_category category;
|
||||
|
||||
return detail::
|
||||
ends_with_iter_select(
|
||||
|
@ -61,7 +61,11 @@ namespace boost {
|
||||
template< typename SequenceSequenceT, typename Range1T, typename Range2T >
|
||||
inline SequenceSequenceT& find_all(
|
||||
SequenceSequenceT& Result,
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
Range1T&& Input,
|
||||
#else
|
||||
Range1T& Input,
|
||||
#endif
|
||||
const Range2T& Search)
|
||||
{
|
||||
return ::boost::algorithm::iter_find(
|
||||
@ -96,7 +100,11 @@ namespace boost {
|
||||
template< typename SequenceSequenceT, typename Range1T, typename Range2T >
|
||||
inline SequenceSequenceT& ifind_all(
|
||||
SequenceSequenceT& Result,
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
Range1T&& Input,
|
||||
#else
|
||||
Range1T& Input,
|
||||
#endif
|
||||
const Range2T& Search,
|
||||
const std::locale& Loc=std::locale() )
|
||||
{
|
||||
@ -139,7 +147,11 @@ namespace boost {
|
||||
template< typename SequenceSequenceT, typename RangeT, typename PredicateT >
|
||||
inline SequenceSequenceT& split(
|
||||
SequenceSequenceT& Result,
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
RangeT&& Input,
|
||||
#else
|
||||
RangeT& Input,
|
||||
#endif
|
||||
PredicateT Pred,
|
||||
token_compress_mode_type eCompress=token_compress_off )
|
||||
{
|
||||
|
@ -11,7 +11,8 @@
|
||||
],
|
||||
"maintainers": [
|
||||
"Marshall Clow <marshall -at- idio.com>"
|
||||
]
|
||||
],
|
||||
"cxxstd": "03"
|
||||
},
|
||||
{
|
||||
"key": "algorithm/minmax",
|
||||
@ -26,7 +27,8 @@
|
||||
],
|
||||
"maintainers": [
|
||||
"Marshall Clow <marshall -at- idio.com>"
|
||||
]
|
||||
],
|
||||
"cxxstd": "03"
|
||||
},
|
||||
{
|
||||
"key": "algorithm/string",
|
||||
@ -42,6 +44,7 @@
|
||||
],
|
||||
"maintainers": [
|
||||
"Marshall Clow <marshall -at- idio.com>"
|
||||
]
|
||||
],
|
||||
"cxxstd": "03"
|
||||
}
|
||||
]
|
@ -24,7 +24,7 @@ namespace boost {
|
||||
tuple<T const&, T const&> >
|
||||
minmax(const T& a, const T& b);
|
||||
|
||||
template <class T, class <a href="http://www.sgi.com/tech/stl/ BinaryPredicate.html">BinaryPredicate</a>>
|
||||
template <class T, class <a href="https://www.boost.org/sgi/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
tuple<T const&, T const&> >
|
||||
minmax(const T& a, const T& b, BinaryPredicate comp);
|
||||
|
||||
@ -38,77 +38,77 @@ Synopsis of <tt><boost/algorithm/minmax_element.hpp></tt></h3>
|
||||
|
||||
namespace boost {
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
std::pair<ForwardIterator,ForwardIterator>
|
||||
minmax_element(ForwardIterator first, ForwardIterator last);
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="http://www.sgi.com/tech/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="https://www.boost.org/sgi/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
std::pair<ForwardIterator,ForwardIterator>
|
||||
minmax_element(ForwardIterator first, ForwardIterator last,
|
||||
BinaryPredicate comp);
|
||||
|
||||
// Variants
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
ForwardIterator first_min_element(ForwardIterator first, ForwardIterator last);
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="http://www.sgi.com/tech/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="https://www.boost.org/sgi/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
ForwardIterator first_min_element(ForwardIterator first, ForwardIterator last,
|
||||
BinaryPredicate comp);
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
ForwardIterator last_min_element(ForwardIterator first, ForwardIterator last);
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="http://www.sgi.com/tech/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="https://www.boost.org/sgi/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
ForwardIterator last_min_element(ForwardIterator first, ForwardIterator last,
|
||||
BinaryPredicate comp);
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
ForwardIterator first_max_element(ForwardIterator first, ForwardIterator last);
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="http://www.sgi.com/tech/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="https://www.boost.org/sgi/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
ForwardIterator first_max_element(ForwardIterator first, ForwardIterator last,
|
||||
BinaryPredicate comp);
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
ForwardIterator last_max_element(ForwardIterator first, ForwardIterator last);
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="http://www.sgi.com/tech/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="https://www.boost.org/sgi/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
ForwardIterator last_max_element(ForwardIterator first, ForwardIterator last,
|
||||
BinaryPredicate comp);
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
std::pair<ForwardIterator,ForwardIterator>
|
||||
first_min_first_max_element(ForwardIterator first, ForwardIterator last);
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="http://www.sgi.com/tech/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="https://www.boost.org/sgi/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
std::pair<ForwardIterator,ForwardIterator>
|
||||
first_min_first_max_element(ForwardIterator first, ForwardIterator last,
|
||||
BinaryPredicate comp);
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
std::pair<ForwardIterator,ForwardIterator>
|
||||
first_min_last_max_element(ForwardIterator first, ForwardIterator last);
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="http://www.sgi.com/tech/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="https://www.boost.org/sgi/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
std::pair<ForwardIterator,ForwardIterator>
|
||||
first_min_last_max_element(ForwardIterator first, ForwardIterator last,
|
||||
BinaryPredicate comp);
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
std::pair<ForwardIterator,ForwardIterator>
|
||||
last_min_first_max_element(ForwardIterator first, ForwardIterator last);
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="http://www.sgi.com/tech/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="https://www.boost.org/sgi/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
std::pair<ForwardIterator,ForwardIterator>
|
||||
last_min_first_max_element(ForwardIterator first, ForwardIterator last,
|
||||
BinaryPredicate comp);
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
std::pair<ForwardIterator,ForwardIterator>
|
||||
last_min_last_max_element(ForwardIterator first, ForwardIterator last);
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="http://www.sgi.com/tech/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="https://www.boost.org/sgi/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
std::pair<ForwardIterator,ForwardIterator>
|
||||
last_min_last_max_element(ForwardIterator first, ForwardIterator last,
|
||||
BinaryPredicate comp);
|
||||
|
81
minmax/fuzzing/minmax_element.fuzz.cpp
Normal file
81
minmax/fuzzing/minmax_element.fuzz.cpp
Normal file
@ -0,0 +1,81 @@
|
||||
// (C) Copyright Marshall Clow 2018
|
||||
// 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)
|
||||
|
||||
#include <iterator> // for std::distance
|
||||
#include <cassert> // for assert
|
||||
|
||||
#include <boost/algorithm/minmax_element.hpp>
|
||||
#include <boost/algorithm/cxx11/none_of.hpp>
|
||||
|
||||
// Fuzzing tests for:
|
||||
//
|
||||
// template <class ForwardIterator>
|
||||
// std::pair<ForwardIterator,ForwardIterator>
|
||||
// minmax_element(ForwardIterator first, ForwardIterator last);
|
||||
//
|
||||
// template <class ForwardIterator, class BinaryPredicate>
|
||||
// std::pair<ForwardIterator,ForwardIterator>
|
||||
// minmax_element(ForwardIterator first, ForwardIterator last,
|
||||
// BinaryPredicate comp);
|
||||
|
||||
|
||||
bool greater(uint8_t lhs, uint8_t rhs) { return lhs > rhs; }
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t sz) {
|
||||
typedef std::pair<const uint8_t *, const uint8_t *> result_t;
|
||||
if (sz == 0) return 0; // we need at least one element
|
||||
|
||||
{
|
||||
// Find the min and max
|
||||
result_t result = boost::minmax_element(data, data + sz);
|
||||
|
||||
// The iterators have to be in the sequence - and not at the end!
|
||||
assert(std::distance(data, result.first) < sz);
|
||||
assert(std::distance(data, result.second) < sz);
|
||||
|
||||
// the minimum element can't be bigger than the max element
|
||||
uint8_t min_value = *result.first;
|
||||
uint8_t max_value = *result.second;
|
||||
|
||||
assert(min_value <= max_value);
|
||||
|
||||
// None of the elements in the sequence can be less than the min, nor greater than the max
|
||||
for (size_t i = 0; i < sz; ++i) {
|
||||
assert(min_value <= data[i]);
|
||||
assert(data[i] <= max_value);
|
||||
}
|
||||
|
||||
// We returned the first min element, and the first max element
|
||||
assert(boost::algorithm::none_of_equal(data, result.first, min_value));
|
||||
assert(boost::algorithm::none_of_equal(data, result.second, max_value));
|
||||
}
|
||||
|
||||
{
|
||||
// Find the min and max
|
||||
result_t result = boost::minmax_element(data, data + sz, greater);
|
||||
|
||||
// The iterators have to be in the sequence - and not at the end!
|
||||
assert(std::distance(data, result.first) < sz);
|
||||
assert(std::distance(data, result.second) < sz);
|
||||
|
||||
// the minimum element can't be bigger than the max element
|
||||
uint8_t min_value = *result.first;
|
||||
uint8_t max_value = *result.second;
|
||||
|
||||
assert (!greater(max_value, min_value));
|
||||
|
||||
// None of the elements in the sequence can be less than the min, nor greater than the max
|
||||
for (size_t i = 0; i < sz; ++i) {
|
||||
assert(!greater(data[i], min_value));
|
||||
assert(!greater(max_value, data[i]));
|
||||
}
|
||||
|
||||
// We returned the first min element, and the first max element
|
||||
assert(boost::algorithm::none_of_equal(data, result.first, min_value));
|
||||
assert(boost::algorithm::none_of_equal(data, result.second, max_value));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
141
minmax/fuzzing/minmax_element_variants.fuzz.cpp
Normal file
141
minmax/fuzzing/minmax_element_variants.fuzz.cpp
Normal file
@ -0,0 +1,141 @@
|
||||
// (C) Copyright Marshall Clow 2018
|
||||
// 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)
|
||||
|
||||
#include <iterator> // for std::distance
|
||||
#include <cassert> // for assert
|
||||
|
||||
#include <boost/algorithm/minmax_element.hpp>
|
||||
#include <boost/algorithm/cxx11/none_of.hpp>
|
||||
|
||||
// Fuzzing tests for:
|
||||
//
|
||||
// template <class ForwardIterator>
|
||||
// std::pair<ForwardIterator,ForwardIterator>
|
||||
// first_min_first_max_element(ForwardIterator first, ForwardIterator last);
|
||||
//
|
||||
// template <class ForwardIterator, class BinaryPredicate>
|
||||
// std::pair<ForwardIterator,ForwardIterator>
|
||||
// first_min_first_max_element(ForwardIterator first, ForwardIterator last,
|
||||
// BinaryPredicate comp);
|
||||
//
|
||||
// identical signatures for:
|
||||
// first_min_last_max_element
|
||||
// last_min_first_max_element
|
||||
// last_min_last_max_element
|
||||
|
||||
bool greater(uint8_t lhs, uint8_t rhs) { return lhs > rhs; }
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t sz) {
|
||||
typedef std::pair<const uint8_t *, const uint8_t *> result_t;
|
||||
const uint8_t * const dend = data + sz;
|
||||
if (sz == 0) return 0; // we need at least one element
|
||||
|
||||
{
|
||||
// Find the min and max
|
||||
result_t resultff = boost::first_min_first_max_element(data, dend);
|
||||
result_t resultfl = boost::first_min_last_max_element (data, dend);
|
||||
result_t resultlf = boost::last_min_first_max_element (data, dend);
|
||||
result_t resultll = boost::last_min_last_max_element (data, dend);
|
||||
|
||||
// The iterators have to be in the sequence - and not at the end!
|
||||
assert(std::distance(data, resultff.first) < sz);
|
||||
assert(std::distance(data, resultff.second) < sz);
|
||||
assert(std::distance(data, resultfl.first) < sz);
|
||||
assert(std::distance(data, resultfl.second) < sz);
|
||||
assert(std::distance(data, resultlf.first) < sz);
|
||||
assert(std::distance(data, resultlf.second) < sz);
|
||||
assert(std::distance(data, resultll.first) < sz);
|
||||
assert(std::distance(data, resultll.second) < sz);
|
||||
|
||||
// the minimum element can't be bigger than the max element
|
||||
|
||||
// Did we find the same min value and max value?
|
||||
uint8_t min_value = *resultff.first;
|
||||
uint8_t max_value = *resultff.second;
|
||||
assert(min_value <= max_value);
|
||||
|
||||
// Each variant should have found the same min/max values
|
||||
assert(*resultff.first == min_value);
|
||||
assert(*resultfl.first == min_value);
|
||||
assert(*resultlf.first == min_value);
|
||||
assert(*resultll.first == min_value);
|
||||
|
||||
assert(*resultff.second == max_value);
|
||||
assert(*resultfl.second == max_value);
|
||||
assert(*resultlf.second == max_value);
|
||||
assert(*resultll.second == max_value);
|
||||
|
||||
// None of the elements in the sequence can be less than the min, nor greater than the max
|
||||
for (size_t i = 0; i < sz; ++i) {
|
||||
assert(min_value <= data[i]);
|
||||
assert(data[i] <= max_value);
|
||||
}
|
||||
|
||||
// Make sure we returned the "right" first and last element
|
||||
assert(boost::algorithm::none_of_equal(data, resultff.first, min_value));
|
||||
assert(boost::algorithm::none_of_equal(data, resultfl.first, min_value));
|
||||
assert(boost::algorithm::none_of_equal(resultlf.first + 1, dend, min_value));
|
||||
assert(boost::algorithm::none_of_equal(resultll.first + 1, dend, min_value));
|
||||
|
||||
assert(boost::algorithm::none_of_equal(data, resultff.second, max_value));
|
||||
assert(boost::algorithm::none_of_equal(resultfl.second + 1, dend, max_value));
|
||||
assert(boost::algorithm::none_of_equal(data, resultlf.second, max_value));
|
||||
assert(boost::algorithm::none_of_equal(resultll.second + 1, dend, max_value));
|
||||
}
|
||||
|
||||
{
|
||||
// Find the min and max
|
||||
result_t resultff = boost::first_min_first_max_element(data, dend, greater);
|
||||
result_t resultfl = boost::first_min_last_max_element (data, dend, greater);
|
||||
result_t resultlf = boost::last_min_first_max_element (data, dend, greater);
|
||||
result_t resultll = boost::last_min_last_max_element (data, dend, greater);
|
||||
|
||||
// The iterators have to be in the sequence - and not at the end!
|
||||
assert(std::distance(data, resultff.first) < sz);
|
||||
assert(std::distance(data, resultff.second) < sz);
|
||||
assert(std::distance(data, resultfl.first) < sz);
|
||||
assert(std::distance(data, resultfl.second) < sz);
|
||||
assert(std::distance(data, resultlf.first) < sz);
|
||||
assert(std::distance(data, resultlf.second) < sz);
|
||||
assert(std::distance(data, resultll.first) < sz);
|
||||
assert(std::distance(data, resultll.second) < sz);
|
||||
|
||||
// the minimum element can't be bigger than the max element
|
||||
uint8_t min_value = *resultff.first;
|
||||
uint8_t max_value = *resultff.second;
|
||||
|
||||
assert (!greater(max_value, min_value));
|
||||
|
||||
// Each variant should have found the same min/max values
|
||||
assert(*resultff.first == min_value);
|
||||
assert(*resultfl.first == min_value);
|
||||
assert(*resultlf.first == min_value);
|
||||
assert(*resultll.first == min_value);
|
||||
|
||||
assert(*resultff.second == max_value);
|
||||
assert(*resultfl.second == max_value);
|
||||
assert(*resultlf.second == max_value);
|
||||
assert(*resultll.second == max_value);
|
||||
|
||||
// None of the elements in the sequence can be less than the min, nor greater than the max
|
||||
for (size_t i = 0; i < sz; ++i) {
|
||||
assert(!greater(data[i], min_value));
|
||||
assert(!greater(max_value, data[i]));
|
||||
}
|
||||
|
||||
// We returned the first min element, and the first max element
|
||||
assert(boost::algorithm::none_of_equal(data, resultff.first, min_value));
|
||||
assert(boost::algorithm::none_of_equal(data, resultfl.first, min_value));
|
||||
assert(boost::algorithm::none_of_equal(resultlf.first + 1, dend, min_value));
|
||||
assert(boost::algorithm::none_of_equal(resultll.first + 1, dend, min_value));
|
||||
|
||||
assert(boost::algorithm::none_of_equal(data, resultff.second, max_value));
|
||||
assert(boost::algorithm::none_of_equal(resultfl.second + 1, dend, max_value));
|
||||
assert(boost::algorithm::none_of_equal(data, resultlf.second, max_value));
|
||||
assert(boost::algorithm::none_of_equal(resultll.second + 1, dend, max_value));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -95,7 +95,7 @@ namespace boost {
|
||||
tuple<T const&, T const&>
|
||||
minmax(const T& a, const T& b);
|
||||
|
||||
template <class T, class <a href="http://www.sgi.com/tech/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
template <class T, class <a href="https://www.boost.org/sgi/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
tuple<T const&, T const&>
|
||||
minmax(const T& a, const T& b, BinaryPredicate comp);
|
||||
|
||||
@ -109,11 +109,11 @@ Synopsis of <tt><boost/algorithm/minmax_element.hpp></tt></h3>
|
||||
|
||||
namespace boost {
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>>
|
||||
std::pair<ForwardIterator,ForwardIterator>
|
||||
minmax_element(ForwardIterator first, ForwardIterator last);
|
||||
|
||||
template <class <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="http://www.sgi.com/tech/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
template <class <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">ForwardIterator</a>, class <a href="https://www.boost.org/sgi/stl/BinaryPredicate.html">BinaryPredicate</a>>
|
||||
std::pair<ForwardIterator,ForwardIterator>
|
||||
minmax_element(ForwardIterator first, ForwardIterator last,
|
||||
BinaryPredicate comp);
|
||||
@ -190,26 +190,26 @@ in <a href="../../../boost/algorithm/minmax_element.hpp">minmax_element.hpp</a>.
|
||||
<a name="reqs">
|
||||
<h3>
|
||||
Requirements on types</h3>
|
||||
For minmax, <tt>T</tt> must be a model of <a href="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThan
|
||||
For minmax, <tt>T</tt> must be a model of <a href="https://www.boost.org/sgi/stl/LessThanComparable.html">LessThan
|
||||
Comparable</a>.
|
||||
<p>For all the other function templates, versions with two template parameters:
|
||||
<ul>
|
||||
<li>
|
||||
<tt>ForwardIterator</tt> is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">Forward
|
||||
<tt>ForwardIterator</tt> is a model of <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">Forward
|
||||
Iterator</a>.</li>
|
||||
|
||||
<li>
|
||||
<tt>ForwardIterator</tt>'s value type is <a href="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThan
|
||||
<tt>ForwardIterator</tt>'s value type is <a href="https://www.boost.org/sgi/stl/LessThanComparable.html">LessThan
|
||||
Comparable</a>.</li>
|
||||
</ul>
|
||||
For the versions with three template parameters:
|
||||
<ul>
|
||||
<li>
|
||||
<tt>ForwardIterator</tt> is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator.html">Forward
|
||||
<tt>ForwardIterator</tt> is a model of <a href="https://www.boost.org/sgi/stl/ForwardIterator.html">Forward
|
||||
Iterator</a>.</li>
|
||||
|
||||
<li>
|
||||
<tt>BinaryPredicate</tt> is a model of <a href="http://www.sgi.com/tech/stl/BinaryPredicate.html">Binary
|
||||
<tt>BinaryPredicate</tt> is a model of <a href="https://www.boost.org/sgi/stl/BinaryPredicate.html">Binary
|
||||
Predicate</a>.</li>
|
||||
|
||||
<li>
|
||||
@ -285,8 +285,8 @@ the library under
|
||||
assert( result1.get<0>() == 0 );
|
||||
assert( result1.get<1>() == 1 );
|
||||
|
||||
<a href="http://www.sgi.com/tech/stl/List.html">list</a><int> L;
|
||||
<a href="http://www.sgi.com/tech/stl/generate_n.html">generate_n</a>(<a href="http://www.sgi.com/tech/stl/front_insert_iterator.html">front_inserter</a>(L), 1000, rand);
|
||||
<a href="https://www.boost.org/sgi/stl/List.html">list</a><int> L;
|
||||
<a href="https://www.boost.org/sgi/stl/generate_n.html">generate_n</a>(<a href="https://www.boost.org/sgi/stl/front_insert_iterator.html">front_inserter</a>(L), 1000, rand);
|
||||
|
||||
typedef list<int>::const_iterator iterator;
|
||||
pair< iterator, iterator > result2 = boost::minmax_element(L.begin(), L.end());
|
||||
@ -512,13 +512,13 @@ release, Eric Niebler noted the bad behavior of <tt>std::pair</tt> for
|
||||
All my thanks for the excellent advice and reviews from all.
|
||||
<h3>
|
||||
See also</h3>
|
||||
<tt><a href="http://www.sgi.com/tech/stl/min.html">min</a></tt>, <tt><a href="http://www.sgi.com/tech/stl/max.html">max</a></tt>,
|
||||
<tt><a href="http://www.sgi.com/tech/stl/min_element.html">min_element</a></tt>,
|
||||
<tt><a href="http://www.sgi.com/tech/stl/max_element.html">max_element</a></tt>,
|
||||
<tt><a href="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThan
|
||||
<tt><a href="https://www.boost.org/sgi/stl/min.html">min</a></tt>, <tt><a href="https://www.boost.org/sgi/stl/max.html">max</a></tt>,
|
||||
<tt><a href="https://www.boost.org/sgi/stl/min_element.html">min_element</a></tt>,
|
||||
<tt><a href="https://www.boost.org/sgi/stl/max_element.html">max_element</a></tt>,
|
||||
<tt><a href="https://www.boost.org/sgi/stl/LessThanComparable.html">LessThan
|
||||
Comparable</a></tt>,
|
||||
<tt><a href="http://www.sgi.com/tech/stl/sort.html">sort</a></tt>,
|
||||
<tt><a href="http://www.sgi.com/tech/stl/nth_element.html">nth_element</a></tt>
|
||||
<tt><a href="https://www.boost.org/sgi/stl/sort.html">sort</a></tt>,
|
||||
<tt><a href="https://www.boost.org/sgi/stl/nth_element.html">nth_element</a></tt>
|
||||
.
|
||||
<hr SIZE="6">
|
||||
<br>Last modified 2012-12-10
|
||||
|
@ -15,7 +15,7 @@ alias unit_test_framework
|
||||
;
|
||||
|
||||
{
|
||||
test-suite algorithm/minmax:
|
||||
test-suite algorithm/minmax
|
||||
: [ run minmax_element_test.cpp unit_test_framework
|
||||
: : : : minmax_element ]
|
||||
[ run minmax_test.cpp unit_test_framework
|
||||
|
@ -20,6 +20,19 @@
|
||||
#define BOOST_TEST_MAIN
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#if (__cplusplus >= 201103L) || defined(BOOST_NO_CXX98_RANDOM_SHUFFLE)
|
||||
#include <random>
|
||||
|
||||
std::default_random_engine gen;
|
||||
template<typename RandomIt>
|
||||
void do_shuffle(RandomIt first, RandomIt last)
|
||||
{ std::shuffle(first, last, gen); }
|
||||
#else
|
||||
template<typename RandomIt>
|
||||
void do_shuffle(RandomIt first, RandomIt last)
|
||||
{ std::random_shuffle(first, last); }
|
||||
#endif
|
||||
|
||||
class custom {
|
||||
int m_x;
|
||||
friend bool operator<(custom const& x, custom const& y);
|
||||
@ -117,7 +130,7 @@ void test_minmax(CIterator first, CIterator last, int n)
|
||||
|
||||
CHECK_EQUAL_ITERATORS( min, std::min_element(first, last), first );
|
||||
CHECK_EQUAL_ITERATORS( max, std::max_element(first, last), first );
|
||||
|
||||
|
||||
// second version, comp function object (keeps a counter!)
|
||||
lc.reset();
|
||||
tie( boost::minmax_element(first, last, lc), min, max );
|
||||
@ -183,7 +196,7 @@ void test_minmax(CIterator first, CIterator last, int n)
|
||||
|
||||
template <class Container, class Iterator, class Value>
|
||||
void test_container(Iterator first, Iterator last, int n,
|
||||
Container* dummy = 0
|
||||
Container* /* dummy */ = 0
|
||||
BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Value) )
|
||||
{
|
||||
Container c(first, last);
|
||||
@ -223,7 +236,7 @@ void test(int n BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Value))
|
||||
test_range(first, last, n);
|
||||
|
||||
// Populate test vector with random values
|
||||
std::random_shuffle(first, last);
|
||||
do_shuffle(first, last);
|
||||
test_range(first, last, n);
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@
|
||||
typedef <i>implementation defined </i> foo_type;</code><p >The corresponding external concept is the ExternalFooConcept.</p><p >A type <code>T</code> fullfills the ExternalFooConcept if these
|
||||
free-standing functions and type-generators exists:</p><code>void foo( const T&, int ); <br>
|
||||
int bar( T& ); <br>
|
||||
foo_type_of< T >::type;</code> <br> <br><hr size="1" ><h3 >Literature</h3><ul ><li > <a href="http://www.boost.org/more/generic_programming.html#type_generator" target="_self" >Type Generators</a> </li><li > <a href="http://www.boost.org/more/generic_programming.html#concept" target="_self" >Concepts</a> </li><li > <a href="http://www.sgi.com/tech/stl/stl_introduction.html" target="_self" >Concepts and SGI STL</a> </li></ul><hr size="1" ><p >© Thorsten Ottosen 2003-2004 (nesotto_AT_cs.auc.dk).
|
||||
foo_type_of< T >::type;</code> <br> <br><hr size="1" ><h3 >Literature</h3><ul ><li > <a href="http://www.boost.org/more/generic_programming.html#type_generator" target="_self" >Type Generators</a> </li><li > <a href="http://www.boost.org/more/generic_programming.html#concept" target="_self" >Concepts</a> </li><li > <a href="https://www.boost.org/sgi/stl/stl_introduction.html" target="_self" >Concepts and SGI STL</a> </li></ul><hr size="1" ><p >© Thorsten Ottosen 2003-2004 (nesotto_AT_cs.auc.dk).
|
||||
<br>Use, modification and distribution is subject to the Boost
|
||||
Software License, Version 1.0. (See accompanying file
|
||||
<code class="filename">LICENSE_1_0.txt</code> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
|
@ -265,7 +265,7 @@
|
||||
<title>Find Iterator</title>
|
||||
|
||||
<para>
|
||||
An extension to find algorithms it the Find Iterator. Instead of searching for just a one part of a string,
|
||||
An extension to find algorithms is the Find Iterator. Instead of searching for just a one part of a string,
|
||||
the find iterator allows us to iterate over the substrings matching the specified criteria.
|
||||
This facility is using the <link linkend="string_algo.finder_concept">Finder</link> to incrementally
|
||||
search the string.
|
||||
|
@ -12,8 +12,6 @@
|
||||
#include <functional>
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/algorithm/string/classification.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
|
||||
using namespace std;
|
||||
using namespace boost;
|
||||
|
@ -16,7 +16,7 @@
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
#include <boost/detail/iterator.hpp>
|
||||
#include <iterator>
|
||||
#include <boost/algorithm/string/find_format.hpp>
|
||||
#include <boost/algorithm/string/finder.hpp>
|
||||
|
||||
@ -46,7 +46,7 @@ struct find_compressF
|
||||
ForwardIteratorT End ) const
|
||||
{
|
||||
typedef ForwardIteratorT input_iterator_type;
|
||||
typedef typename boost::detail::iterator_traits<input_iterator_type>::value_type value_type;
|
||||
typedef typename std::iterator_traits<input_iterator_type>::value_type value_type;
|
||||
typedef iterator_range<input_iterator_type> result_type;
|
||||
|
||||
// begin of the matching segment
|
||||
@ -144,7 +144,7 @@ struct find_decompressF
|
||||
ForwardIteratorT End ) const
|
||||
{
|
||||
typedef ForwardIteratorT input_iterator_type;
|
||||
typedef typename boost::detail::iterator_traits<input_iterator_type>::value_type value_type;
|
||||
typedef typename std::iterator_traits<input_iterator_type>::value_type value_type;
|
||||
typedef iterator_range<input_iterator_type> result_type;
|
||||
|
||||
for(input_iterator_type It=Begin; It!=End; It++)
|
||||
@ -153,12 +153,12 @@ struct find_decompressF
|
||||
{
|
||||
// Repeat mark found, extract body
|
||||
input_iterator_type It2=It++;
|
||||
|
||||
|
||||
if ( It==End ) break;
|
||||
It++;
|
||||
if ( It==End ) break;
|
||||
It++;
|
||||
|
||||
|
||||
return result_type( It2, It );
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,8 @@
|
||||
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
|
||||
#include <boost/algorithm/string/config.hpp>
|
||||
|
||||
#include <boost/algorithm/string/split.hpp>
|
||||
#include <boost/algorithm/string/classification.hpp>
|
||||
// equals predicate is used for result comparison
|
||||
@ -82,6 +84,28 @@ void iterator_test()
|
||||
string("xx") );
|
||||
deep_compare( tokens, vtokens );
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
// If using a compiler that supports forwarding references, we should be able to use rvalues, too
|
||||
find_all(
|
||||
tokens,
|
||||
string("xx-abc--xx-abb"),
|
||||
"xx" );
|
||||
|
||||
BOOST_REQUIRE( tokens.size()==2 );
|
||||
BOOST_CHECK( tokens[0]==string("xx") );
|
||||
BOOST_CHECK( tokens[1]==string("xx") );
|
||||
|
||||
ifind_all(
|
||||
tokens,
|
||||
string("Xx-abc--xX-abb-xx"),
|
||||
"xx" );
|
||||
|
||||
BOOST_REQUIRE( tokens.size()==3 );
|
||||
BOOST_CHECK( tokens[0]==string("Xx") );
|
||||
BOOST_CHECK( tokens[1]==string("xX") );
|
||||
BOOST_CHECK( tokens[2]==string("xx") );
|
||||
#endif
|
||||
|
||||
// split tests
|
||||
split(
|
||||
tokens,
|
||||
@ -144,6 +168,21 @@ void iterator_test()
|
||||
BOOST_REQUIRE( tokens.size()==1 );
|
||||
BOOST_CHECK( tokens[0]==string("") );
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
|
||||
// If using a compiler that supports forwarding references, we should be able to use rvalues, too
|
||||
split(
|
||||
tokens,
|
||||
string("Xx-abc--xX-abb-xx"),
|
||||
is_any_of("xX"),
|
||||
token_compress_on );
|
||||
|
||||
BOOST_REQUIRE( tokens.size()==4 );
|
||||
BOOST_CHECK( tokens[0]==string("") );
|
||||
BOOST_CHECK( tokens[1]==string("-abc--") );
|
||||
BOOST_CHECK( tokens[2]==string("-abb-") );
|
||||
BOOST_CHECK( tokens[3]==string("") );
|
||||
#endif
|
||||
|
||||
|
||||
find_iterator<string::iterator> fiter=make_find_iterator(str1, first_finder("xx"));
|
||||
find_iterator<string::iterator> fiter2;
|
||||
|
@ -16,7 +16,7 @@ alias unit_test_framework
|
||||
|
||||
|
||||
{
|
||||
test-suite algorithm:
|
||||
test-suite algorithm
|
||||
# Search tests
|
||||
: [ run empty_search_test.cpp unit_test_framework : : : : empty_search_test ]
|
||||
[ run search_test1.cpp unit_test_framework : : : : search_test1 ]
|
||||
@ -29,6 +29,7 @@ alias unit_test_framework
|
||||
|
||||
# Misc tests
|
||||
[ run clamp_test.cpp unit_test_framework : : : : clamp_test ]
|
||||
[ run is_clamped_test.cpp unit_test_framework : : : : is_clamped_test ]
|
||||
[ run power_test.cpp unit_test_framework : : : : power_test ]
|
||||
[ compile-fail power_fail1.cpp : : : : ]
|
||||
|
||||
@ -68,6 +69,7 @@ alias unit_test_framework
|
||||
[ run hex_test2.cpp unit_test_framework : : : : hex_test2 ]
|
||||
[ run hex_test3.cpp unit_test_framework : : : : hex_test3 ]
|
||||
[ run hex_test4.cpp unit_test_framework : : : : hex_test4 ]
|
||||
[ run mclow.cpp unit_test_framework : : : : mclow ]
|
||||
[ compile-fail hex_fail1.cpp ]
|
||||
|
||||
# Gather tests
|
||||
@ -83,6 +85,12 @@ alias unit_test_framework
|
||||
|
||||
# Is_partitioned_until tests
|
||||
[ run is_partitioned_until_test.cpp unit_test_framework : : : : is_partitioned_until_test ]
|
||||
|
||||
# Apply_permutation tests
|
||||
[ run apply_permutation_test.cpp unit_test_framework : : : : apply_permutation_test ]
|
||||
# Find tests
|
||||
[ run find_not_test.cpp unit_test_framework : : : : find_not_test ]
|
||||
[ run find_backward_test.cpp unit_test_framework : : : : find_backward_test ]
|
||||
;
|
||||
}
|
||||
|
||||
|
@ -19,9 +19,8 @@
|
||||
|
||||
template<typename T>
|
||||
struct is_ {
|
||||
is_ ( T v ) : val_ ( v ) {}
|
||||
~is_ () {}
|
||||
bool operator () ( T comp ) const { return val_ == comp; }
|
||||
BOOST_CXX14_CONSTEXPR is_ ( T v ) : val_ ( v ) {}
|
||||
BOOST_CXX14_CONSTEXPR bool operator () ( T comp ) const { return val_ == comp; }
|
||||
private:
|
||||
is_ (); // need a value
|
||||
|
||||
@ -33,7 +32,7 @@ namespace ba = boost::algorithm;
|
||||
void test_all ()
|
||||
{
|
||||
// Note: The literal values here are tested against directly, careful if you change them:
|
||||
int some_numbers[] = { 1, 1, 1, 18, 10 };
|
||||
BOOST_CXX14_CONSTEXPR int some_numbers[] = { 1, 1, 1, 18, 10 };
|
||||
std::vector<int> vi(some_numbers, some_numbers + 5);
|
||||
std::list<int> li(vi.begin(), vi.end ());
|
||||
|
||||
@ -77,7 +76,15 @@ void test_all ()
|
||||
l_iter++; l_iter++; l_iter++;
|
||||
BOOST_CHECK ( ba::all_of_equal ( li.begin(), l_iter, 1 ));
|
||||
BOOST_CHECK ( ba::all_of ( li.begin(), l_iter, is_<int> ( 1 )));
|
||||
|
||||
|
||||
BOOST_CXX14_CONSTEXPR bool constexpr_res =
|
||||
!ba::all_of_equal ( some_numbers, 1 ) &&
|
||||
!ba::all_of ( some_numbers, is_<int> ( 1 )) &&
|
||||
ba::all_of_equal ( some_numbers, some_numbers + 3, 1 ) &&
|
||||
ba::all_of ( some_numbers, some_numbers + 3, is_<int> ( 1 )) &&
|
||||
true;
|
||||
|
||||
BOOST_CHECK ( constexpr_res );
|
||||
}
|
||||
|
||||
|
||||
|
@ -19,9 +19,8 @@
|
||||
|
||||
template<typename T>
|
||||
struct is_ {
|
||||
is_ ( T v ) : val_ ( v ) {}
|
||||
~is_ () {}
|
||||
bool operator () ( T comp ) const { return val_ == comp; }
|
||||
BOOST_CXX14_CONSTEXPR is_ ( T v ) : val_ ( v ) {}
|
||||
BOOST_CXX14_CONSTEXPR bool operator () ( T comp ) const { return val_ == comp; }
|
||||
private:
|
||||
is_ (); // need a value
|
||||
|
||||
@ -33,7 +32,7 @@ namespace ba = boost::algorithm;
|
||||
void test_any ()
|
||||
{
|
||||
// Note: The literal values here are tested against directly, careful if you change them:
|
||||
int some_numbers[] = { 1, 5, 0, 18, 10 };
|
||||
BOOST_CXX14_CONSTEXPR int some_numbers[] = { 1, 5, 0, 18, 10 };
|
||||
std::vector<int> vi(some_numbers, some_numbers + 5);
|
||||
std::list<int> li(vi.begin(), vi.end ());
|
||||
|
||||
@ -97,6 +96,15 @@ void test_any ()
|
||||
BOOST_CHECK ( ba::any_of ( li.begin(), l_iter, is_<int> ( 5 )));
|
||||
BOOST_CHECK (!ba::any_of_equal ( li.begin(), l_iter, 18 ));
|
||||
BOOST_CHECK (!ba::any_of ( li.begin(), l_iter, is_<int> ( 18 )));
|
||||
|
||||
BOOST_CXX14_CONSTEXPR bool constexpr_res =
|
||||
ba::any_of_equal ( some_numbers, 1 ) &&
|
||||
ba::any_of ( some_numbers, is_<int> ( 1 )) &&
|
||||
!ba::any_of_equal ( some_numbers, some_numbers + 3, 777 ) &&
|
||||
!ba::any_of ( some_numbers, some_numbers + 3, is_<int> ( 777 )) &&
|
||||
true;
|
||||
|
||||
BOOST_CHECK ( constexpr_res );
|
||||
}
|
||||
|
||||
|
||||
|
162
test/apply_permutation_test.cpp
Normal file
162
test/apply_permutation_test.cpp
Normal file
@ -0,0 +1,162 @@
|
||||
/*
|
||||
Copyright (c) Alexander Zaitsev <zamazan4ik@gmail.com>, 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)
|
||||
|
||||
See http://www.boost.org/ for latest version.
|
||||
*/
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <boost/algorithm/apply_permutation.hpp>
|
||||
|
||||
#define BOOST_TEST_MAIN
|
||||
|
||||
#include <boost/test/included/unit_test.hpp>
|
||||
|
||||
namespace ba = boost::algorithm;
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_apply_permutation)
|
||||
{
|
||||
//Empty
|
||||
{
|
||||
std::vector<int> vec, order, result;
|
||||
|
||||
ba::apply_permutation(vec.begin(), vec.end(), order.begin(), order.end());
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
|
||||
}
|
||||
//1 element
|
||||
{
|
||||
std::vector<int> vec, order, result;
|
||||
vec.push_back(1);
|
||||
order.push_back(0);
|
||||
result = vec;
|
||||
|
||||
ba::apply_permutation(vec.begin(), vec.end(), order.begin(), order.end());
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
|
||||
}
|
||||
//2 elements, no changes
|
||||
{
|
||||
std::vector<int> vec, order, result;
|
||||
vec.push_back(1); vec.push_back(2);
|
||||
order.push_back(0); order.push_back(1);
|
||||
result = vec;
|
||||
|
||||
ba::apply_permutation(vec.begin(), vec.end(), order.begin(), order.end());
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
|
||||
}
|
||||
//2 elements, changed
|
||||
{
|
||||
std::vector<int> vec, order, result;
|
||||
vec.push_back(1); vec.push_back(2);
|
||||
order.push_back(1); order.push_back(0);
|
||||
result.push_back(2); result.push_back(1);
|
||||
|
||||
ba::apply_permutation(vec.begin(), vec.end(), order.begin(), order.end());
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
|
||||
}
|
||||
//Multiple elements, no changes
|
||||
{
|
||||
std::vector<int> vec, order, result;
|
||||
vec.push_back(1); vec.push_back(2); vec.push_back(3); vec.push_back(4); vec.push_back(5);
|
||||
order.push_back(0); order.push_back(1); order.push_back(2); order.push_back(3); order.push_back(4);
|
||||
result = vec;
|
||||
|
||||
ba::apply_permutation(vec.begin(), vec.end(), order.begin(), order.end());
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
|
||||
}
|
||||
//Multiple elements, changed
|
||||
{
|
||||
std::vector<int> vec, order, result;
|
||||
vec.push_back(1); vec.push_back(2); vec.push_back(3); vec.push_back(4); vec.push_back(5);
|
||||
order.push_back(4); order.push_back(3); order.push_back(2); order.push_back(1); order.push_back(0);
|
||||
result.push_back(5); result.push_back(4); result.push_back(3); result.push_back(2); result.push_back(1);
|
||||
|
||||
ba::apply_permutation(vec.begin(), vec.end(), order.begin(), order.end());
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
|
||||
}
|
||||
//Just test range interface
|
||||
{
|
||||
std::vector<int> vec, order, result;
|
||||
vec.push_back(1); vec.push_back(2); vec.push_back(3); vec.push_back(4); vec.push_back(5);
|
||||
order.push_back(0); order.push_back(1); order.push_back(2); order.push_back(3); order.push_back(4);
|
||||
result = vec;
|
||||
|
||||
ba::apply_permutation(vec, order);
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_apply_reverse_permutation)
|
||||
{
|
||||
//Empty
|
||||
{
|
||||
std::vector<int> vec, order, result;
|
||||
|
||||
ba::apply_reverse_permutation(vec.begin(), vec.end(), order.begin(), order.end());
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
|
||||
}
|
||||
//1 element
|
||||
{
|
||||
std::vector<int> vec, order, result;
|
||||
vec.push_back(1);
|
||||
order.push_back(0);
|
||||
result = vec;
|
||||
|
||||
ba::apply_reverse_permutation(vec.begin(), vec.end(), order.begin(), order.end());
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
|
||||
}
|
||||
//2 elements, no changes
|
||||
{
|
||||
std::vector<int> vec, order, result;
|
||||
vec.push_back(1); vec.push_back(2);
|
||||
order.push_back(0); order.push_back(1);
|
||||
result = vec;
|
||||
|
||||
ba::apply_reverse_permutation(vec.begin(), vec.end(), order.begin(), order.end());
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
|
||||
}
|
||||
//2 elements, changed
|
||||
{
|
||||
std::vector<int> vec, order, result;
|
||||
vec.push_back(1); vec.push_back(2);
|
||||
order.push_back(1); order.push_back(0);
|
||||
result.push_back(2); result.push_back(1);
|
||||
|
||||
ba::apply_reverse_permutation(vec.begin(), vec.end(), order.begin(), order.end());
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
|
||||
}
|
||||
//Multiple elements, no changes
|
||||
{
|
||||
std::vector<int> vec, order, result;
|
||||
vec.push_back(1); vec.push_back(2); vec.push_back(3); vec.push_back(4); vec.push_back(5);
|
||||
order.push_back(0); order.push_back(1); order.push_back(2); order.push_back(3); order.push_back(4);
|
||||
result = vec;
|
||||
|
||||
ba::apply_reverse_permutation(vec.begin(), vec.end(), order.begin(), order.end());
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
|
||||
}
|
||||
//Multiple elements, changed
|
||||
{
|
||||
std::vector<int> vec, order, result;
|
||||
vec.push_back(1); vec.push_back(2); vec.push_back(3); vec.push_back(4); vec.push_back(5);
|
||||
order.push_back(4); order.push_back(3); order.push_back(2); order.push_back(1); order.push_back(0);
|
||||
result.push_back(5); result.push_back(4); result.push_back(3); result.push_back(2); result.push_back(1);
|
||||
|
||||
ba::apply_reverse_permutation(vec.begin(), vec.end(), order.begin(), order.end());
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
|
||||
}
|
||||
//Just test range interface
|
||||
{
|
||||
std::vector<int> vec, order, result;
|
||||
vec.push_back(1); vec.push_back(2); vec.push_back(3); vec.push_back(4); vec.push_back(5);
|
||||
order.push_back(0); order.push_back(1); order.push_back(2); order.push_back(3); order.push_back(4);
|
||||
result = vec;
|
||||
|
||||
ba::apply_reverse_permutation(vec, order);
|
||||
BOOST_CHECK_EQUAL_COLLECTIONS(vec.begin(), vec.end(), result.begin(), result.end());
|
||||
}
|
||||
}
|
@ -14,8 +14,8 @@
|
||||
|
||||
namespace ba = boost::algorithm;
|
||||
|
||||
bool intGreater ( int lhs, int rhs ) { return lhs > rhs; }
|
||||
bool doubleGreater ( double lhs, double rhs ) { return lhs > rhs; }
|
||||
BOOST_CONSTEXPR bool intGreater ( int lhs, int rhs ) { return lhs > rhs; }
|
||||
BOOST_CONSTEXPR bool doubleGreater ( double lhs, double rhs ) { return lhs > rhs; }
|
||||
|
||||
class custom {
|
||||
public:
|
||||
@ -45,6 +45,10 @@ void test_ints()
|
||||
BOOST_CHECK_EQUAL ( 1, ba::clamp ( 0, 1, 10 ));
|
||||
BOOST_CHECK_EQUAL ( 10, ba::clamp ( 10, 1, 10 ));
|
||||
BOOST_CHECK_EQUAL ( 10, ba::clamp ( 11, 1, 10 ));
|
||||
BOOST_CXX14_CONSTEXPR bool constexpr_res = (
|
||||
ba::clamp ( 3, 1, 10 ) == 3
|
||||
);
|
||||
BOOST_CHECK( constexpr_res );
|
||||
|
||||
BOOST_CHECK_EQUAL ( 3, ba::clamp ( 3, 10, 1, intGreater ));
|
||||
BOOST_CHECK_EQUAL ( 1, ba::clamp ( 1, 10, 1, intGreater ));
|
||||
@ -206,6 +210,110 @@ void test_int_range ()
|
||||
BOOST_CHECK ( std::equal ( b_e(junk), outputs ));
|
||||
}
|
||||
|
||||
void test_constexpr()
|
||||
{
|
||||
|
||||
// Inside the range, equal to the endpoints, and outside the endpoints.
|
||||
{
|
||||
BOOST_CXX14_CONSTEXPR bool check_inside = (3 == ba::clamp ( 3, 1, 10 ));
|
||||
BOOST_CHECK(check_inside);
|
||||
BOOST_CXX14_CONSTEXPR bool check_min = (1 == ba::clamp ( 1, 1, 10 ));
|
||||
BOOST_CHECK(check_min);
|
||||
BOOST_CXX14_CONSTEXPR bool check_min_out = (1 == ba::clamp ( 0, 1, 10 ));
|
||||
BOOST_CHECK(check_min_out);
|
||||
BOOST_CXX14_CONSTEXPR bool check_max = (10 == ba::clamp ( 10, 1, 10 ));
|
||||
BOOST_CHECK(check_max);
|
||||
BOOST_CXX14_CONSTEXPR bool check_max_out = (10 == ba::clamp ( 11, 1, 10 ));
|
||||
BOOST_CHECK(check_max_out);
|
||||
}
|
||||
{
|
||||
BOOST_CXX14_CONSTEXPR bool check_inside = (3 == ba::clamp ( 3, 10, 1, intGreater ));
|
||||
BOOST_CHECK(check_inside);
|
||||
BOOST_CXX14_CONSTEXPR bool check_min = (1 == ba::clamp ( 1, 10, 1, intGreater ));
|
||||
BOOST_CHECK(check_min);
|
||||
BOOST_CXX14_CONSTEXPR bool check_min_out = (1 == ba::clamp ( 0, 10, 1, intGreater ));
|
||||
BOOST_CHECK(check_min_out);
|
||||
BOOST_CXX14_CONSTEXPR bool check_max = (10 == ba::clamp ( 10, 10, 1, intGreater ));
|
||||
BOOST_CHECK(check_max);
|
||||
BOOST_CXX14_CONSTEXPR bool check_max_out = (10 == ba::clamp ( 11, 10, 1, intGreater ));
|
||||
BOOST_CHECK(check_max_out);
|
||||
}
|
||||
|
||||
// Negative numbers
|
||||
{
|
||||
BOOST_CXX14_CONSTEXPR bool check_inside = (-3 == ba::clamp ( -3, -10, -1 ));
|
||||
BOOST_CHECK(check_inside);
|
||||
BOOST_CXX14_CONSTEXPR bool check_max = (-1 == ba::clamp ( -1, -10, -1 ));
|
||||
BOOST_CHECK(check_max);
|
||||
BOOST_CXX14_CONSTEXPR bool check_max_out = (-1 == ba::clamp ( 0, -10, -1 ));
|
||||
BOOST_CHECK(check_max_out);
|
||||
BOOST_CXX14_CONSTEXPR bool check_min = (-10 == ba::clamp ( -10, -10, -1 ));
|
||||
BOOST_CHECK(check_min);
|
||||
BOOST_CXX14_CONSTEXPR bool check_min_out = (-10 == ba::clamp ( -11, -10, -1 ));
|
||||
BOOST_CHECK(check_min_out);
|
||||
}
|
||||
|
||||
// Mixed positive and negative numbers
|
||||
{
|
||||
BOOST_CXX14_CONSTEXPR bool check_inside = (5 == ba::clamp ( 5, -10, 10 ));
|
||||
BOOST_CHECK(check_inside);
|
||||
BOOST_CXX14_CONSTEXPR bool check_min = (-10 == ba::clamp ( -10, -10, 10 ));
|
||||
BOOST_CHECK(check_min);
|
||||
BOOST_CXX14_CONSTEXPR bool check_min_out = (-10 == ba::clamp ( -15, -10, 10 ));
|
||||
BOOST_CHECK(check_min_out);
|
||||
BOOST_CXX14_CONSTEXPR bool check_max = (10 == ba::clamp ( 10, -10, 10 ));
|
||||
BOOST_CHECK(check_max);
|
||||
BOOST_CXX14_CONSTEXPR bool check_max_out = (10 == ba::clamp ( 15, -10, 10 ));
|
||||
BOOST_CHECK(check_max_out);
|
||||
}
|
||||
// Unsigned
|
||||
{
|
||||
BOOST_CXX14_CONSTEXPR bool check_inside = (5U == ba::clamp ( 5U, 1U, 10U ));
|
||||
BOOST_CHECK(check_inside);
|
||||
BOOST_CXX14_CONSTEXPR bool check_min = (1U == ba::clamp ( 1U, 1U, 10U ));
|
||||
BOOST_CHECK(check_min);
|
||||
BOOST_CXX14_CONSTEXPR bool check_min_out = (1U == ba::clamp ( 0U, 1U, 10U ));
|
||||
BOOST_CHECK(check_min_out);
|
||||
BOOST_CXX14_CONSTEXPR bool check_max = (10U == ba::clamp ( 10U, 1U, 10U ));
|
||||
BOOST_CHECK(check_max);
|
||||
BOOST_CXX14_CONSTEXPR bool check_max_out = (10U == ba::clamp ( 15U, 1U, 10U ));
|
||||
BOOST_CHECK(check_max_out);
|
||||
}
|
||||
// Mixed (1)
|
||||
{
|
||||
BOOST_CXX14_CONSTEXPR bool check_inside = (5U == ba::clamp ( 5U, 1, 10 ));
|
||||
BOOST_CHECK(check_inside);
|
||||
BOOST_CXX14_CONSTEXPR bool check_min = (1U == ba::clamp ( 1U, 1, 10 ));
|
||||
BOOST_CHECK(check_min);
|
||||
BOOST_CXX14_CONSTEXPR bool check_min_out = (1U == ba::clamp ( 0U, 1, 10 ));
|
||||
BOOST_CHECK(check_min_out);
|
||||
BOOST_CXX14_CONSTEXPR bool check_max = (10U == ba::clamp ( 10U, 1, 10 ));
|
||||
BOOST_CHECK(check_max);
|
||||
BOOST_CXX14_CONSTEXPR bool check_max_out = (10U == ba::clamp ( 15U, 1, 10 ));
|
||||
BOOST_CHECK(check_max_out);
|
||||
}
|
||||
// Mixed (3)
|
||||
{
|
||||
BOOST_CXX14_CONSTEXPR bool check_inside = (5U == ba::clamp ( 5U, 1, 10. ));
|
||||
BOOST_CHECK(check_inside);
|
||||
BOOST_CXX14_CONSTEXPR bool check_min = (1U == ba::clamp ( 1U, 1, 10. ));
|
||||
BOOST_CHECK(check_min);
|
||||
BOOST_CXX14_CONSTEXPR bool check_min_out = (1U == ba::clamp ( 0U, 1, 10. ));
|
||||
BOOST_CHECK(check_min_out);
|
||||
BOOST_CXX14_CONSTEXPR bool check_max = (10U == ba::clamp ( 10U, 1, 10. ));
|
||||
BOOST_CHECK(check_max);
|
||||
BOOST_CXX14_CONSTEXPR bool check_max_out = (10U == ba::clamp ( 15U, 1, 10. ));
|
||||
BOOST_CHECK(check_max_out);
|
||||
}
|
||||
{
|
||||
BOOST_CXX14_CONSTEXPR short foo = 50;
|
||||
BOOST_CXX14_CONSTEXPR bool check_float = ( 56 == ba::clamp ( foo, 56.9, 129 ));
|
||||
BOOST_CHECK(check_float);
|
||||
BOOST_CXX14_CONSTEXPR bool check_over = ( 24910 == ba::clamp ( foo, 12345678, 123456999 ));
|
||||
BOOST_CHECK(check_over);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( test_main )
|
||||
{
|
||||
test_ints ();
|
||||
@ -213,6 +321,8 @@ BOOST_AUTO_TEST_CASE( test_main )
|
||||
test_custom ();
|
||||
|
||||
test_int_range ();
|
||||
|
||||
test_constexpr ();
|
||||
// test_float_range ();
|
||||
// test_custom_range ();
|
||||
}
|
||||
|
@ -10,6 +10,8 @@
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/algorithm/cxx11/copy_if.hpp>
|
||||
|
||||
#include "iterator_test.hpp"
|
||||
|
||||
#define BOOST_TEST_MAIN
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
@ -20,22 +22,27 @@
|
||||
#include <list>
|
||||
|
||||
#include <boost/algorithm/cxx11/all_of.hpp>
|
||||
#include <boost/algorithm/cxx14/equal.hpp>
|
||||
#include <boost/algorithm/cxx11/none_of.hpp>
|
||||
|
||||
namespace ba = boost::algorithm;
|
||||
// namespace ba = boost;
|
||||
|
||||
bool is_true ( int v ) { return true; }
|
||||
bool is_false ( int v ) { return false; }
|
||||
bool is_even ( int v ) { return v % 2 == 0; }
|
||||
bool is_odd ( int v ) { return v % 2 == 1; }
|
||||
BOOST_CXX14_CONSTEXPR bool is_true ( int v ) { return true; }
|
||||
BOOST_CXX14_CONSTEXPR bool is_false ( int v ) { return false; }
|
||||
BOOST_CXX14_CONSTEXPR bool is_even ( int v ) { return v % 2 == 0; }
|
||||
BOOST_CXX14_CONSTEXPR bool is_odd ( int v ) { return v % 2 == 1; }
|
||||
BOOST_CXX14_CONSTEXPR bool is_zero ( int v ) { return v == 0; }
|
||||
|
||||
BOOST_CXX14_CONSTEXPR bool less_than_ten ( int v ) { return v < 10; }
|
||||
BOOST_CXX14_CONSTEXPR bool greater_than_ten ( int v ) { return v > 10; }
|
||||
|
||||
template <typename Container>
|
||||
void test_copy_if ( Container const &c ) {
|
||||
|
||||
typedef typename Container::value_type value_type;
|
||||
std::vector<value_type> v;
|
||||
|
||||
|
||||
// None of the elements
|
||||
v.clear ();
|
||||
ba::copy_if ( c.begin (), c.end (), back_inserter ( v ), is_false);
|
||||
@ -113,6 +120,160 @@ void test_copy_while ( Container const &c ) {
|
||||
BOOST_CHECK ( std::equal ( v.begin (), v.end (), c.begin ()));
|
||||
}
|
||||
|
||||
template <typename Container>
|
||||
void test_copy_if_while ( Container const &c ) {
|
||||
|
||||
typedef typename Container::value_type value_type;
|
||||
typename Container::const_iterator it;
|
||||
|
||||
// Terminate immediately
|
||||
{
|
||||
std::vector<value_type> v;
|
||||
ba::copy_if_while ( c.begin (), c.end (), back_inserter ( v ), is_true, is_false);
|
||||
BOOST_CHECK ( v.size () == 0 );
|
||||
}
|
||||
{
|
||||
std::vector<value_type> v;
|
||||
ba::copy_if_while ( c, back_inserter ( v ), is_true, is_false);
|
||||
BOOST_CHECK ( v.size () == 0 );
|
||||
}
|
||||
|
||||
// Copy nothing - never terminate
|
||||
{
|
||||
std::vector<value_type> v;
|
||||
ba::copy_if_while ( c.begin (), c.end (), back_inserter ( v ), is_false, is_true);
|
||||
BOOST_CHECK ( v.size () == 0 );
|
||||
}
|
||||
{
|
||||
std::vector<value_type> v;
|
||||
ba::copy_if_while ( c, back_inserter ( v ), is_false, is_true);
|
||||
BOOST_CHECK ( v.size () == 0 );
|
||||
}
|
||||
|
||||
// Copy everything
|
||||
{
|
||||
std::vector<value_type> v;
|
||||
ba::copy_if_while ( c.begin (), c.end (), back_inserter ( v ), is_true, is_true);
|
||||
BOOST_CHECK ( v.size () == c.size() );
|
||||
BOOST_CHECK ( std::equal ( v.begin (), v.end (), c.begin ()));
|
||||
}
|
||||
{
|
||||
std::vector<value_type> v;
|
||||
ba::copy_if_while ( c, back_inserter ( v ), is_true, is_true);
|
||||
BOOST_CHECK ( v.size () == c.size() );
|
||||
BOOST_CHECK ( std::equal ( v.begin (), v.end (), c.begin ()));
|
||||
}
|
||||
|
||||
// Copy all evens
|
||||
{
|
||||
std::vector<value_type> v;
|
||||
ba::copy_if_while ( c.begin (), c.end (), back_inserter ( v ), is_even, is_true);
|
||||
BOOST_CHECK ( v.size () == (size_t) std::count_if ( c.begin (), c.end (), is_even ));
|
||||
BOOST_CHECK ( ba::all_of ( v.begin (), v.end (), is_even ));
|
||||
}
|
||||
{
|
||||
std::vector<value_type> v;
|
||||
ba::copy_if_while ( c, back_inserter ( v ), is_even, is_true);
|
||||
BOOST_CHECK ( v.size () == (size_t) std::count_if ( c.begin (), c.end (), is_even ));
|
||||
BOOST_CHECK ( ba::all_of ( v.begin (), v.end (), is_even ));
|
||||
}
|
||||
|
||||
// Copy some until termination
|
||||
{
|
||||
std::vector<value_type> v;
|
||||
typename Container::const_iterator it = ba::copy_if_while (
|
||||
c.begin (), c.end (), back_inserter ( v ), is_even, less_than_ten).first;
|
||||
BOOST_CHECK ( it == std::find_if ( c.begin(), c.end(), greater_than_ten ));
|
||||
BOOST_CHECK ( v.size () == std::count_if ( c.begin(), it, is_even ));
|
||||
BOOST_CHECK ( ba::all_of ( v.begin (), v.end (), is_even ));
|
||||
}
|
||||
{
|
||||
std::vector<value_type> v;
|
||||
typename Container::const_iterator it = ba::copy_if_while (
|
||||
c, back_inserter ( v ), is_even, less_than_ten).first;
|
||||
BOOST_CHECK ( it == std::find_if ( c.begin(), c.end(), greater_than_ten ));
|
||||
BOOST_CHECK ( v.size () == std::count_if ( c.begin(), it, is_even ));
|
||||
BOOST_CHECK ( ba::all_of ( v.begin (), v.end (), is_even ));
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Container>
|
||||
void test_copy_if_until ( Container const &c ) {
|
||||
|
||||
typedef typename Container::value_type value_type;
|
||||
typename Container::const_iterator it;
|
||||
|
||||
// Terminate immediately
|
||||
{
|
||||
std::vector<value_type> v;
|
||||
ba::copy_if_until ( c.begin (), c.end (), back_inserter ( v ), is_true, is_true);
|
||||
BOOST_CHECK ( v.size () == 0 );
|
||||
}
|
||||
{
|
||||
std::vector<value_type> v;
|
||||
ba::copy_if_until ( c, back_inserter ( v ), is_true, is_true);
|
||||
BOOST_CHECK ( v.size () == 0 );
|
||||
}
|
||||
|
||||
// Copy nothing - never terminate
|
||||
{
|
||||
std::vector<value_type> v;
|
||||
ba::copy_if_until ( c.begin (), c.end (), back_inserter ( v ), is_false, is_false);
|
||||
BOOST_CHECK ( v.size () == 0 );
|
||||
}
|
||||
{
|
||||
std::vector<value_type> v;
|
||||
ba::copy_if_until ( c, back_inserter ( v ), is_false, is_false);
|
||||
BOOST_CHECK ( v.size () == 0 );
|
||||
}
|
||||
|
||||
// Copy everything
|
||||
{
|
||||
std::vector<value_type> v;
|
||||
ba::copy_if_until ( c.begin (), c.end (), back_inserter ( v ), is_true, is_false);
|
||||
BOOST_CHECK ( v.size () == c.size() );
|
||||
BOOST_CHECK ( std::equal ( v.begin (), v.end (), c.begin ()));
|
||||
}
|
||||
{
|
||||
std::vector<value_type> v;
|
||||
ba::copy_if_until ( c, back_inserter ( v ), is_true, is_false);
|
||||
BOOST_CHECK ( v.size () == c.size() );
|
||||
BOOST_CHECK ( std::equal ( v.begin (), v.end (), c.begin ()));
|
||||
}
|
||||
|
||||
// Copy all evens
|
||||
{
|
||||
std::vector<value_type> v;
|
||||
ba::copy_if_until ( c.begin (), c.end (), back_inserter ( v ), is_even, is_false);
|
||||
BOOST_CHECK ( v.size () == (size_t) std::count_if ( c.begin (), c.end (), is_even ));
|
||||
BOOST_CHECK ( ba::all_of ( v.begin (), v.end (), is_even ));
|
||||
}
|
||||
{
|
||||
std::vector<value_type> v;
|
||||
ba::copy_if_until ( c, back_inserter ( v ), is_even, is_false);
|
||||
BOOST_CHECK ( v.size () == (size_t) std::count_if ( c.begin (), c.end (), is_even ));
|
||||
BOOST_CHECK ( ba::all_of ( v.begin (), v.end (), is_even ));
|
||||
}
|
||||
|
||||
// Copy some until termination
|
||||
{
|
||||
std::vector<value_type> v;
|
||||
typename Container::const_iterator it = ba::copy_if_until (
|
||||
c.begin (), c.end (), back_inserter ( v ), is_even, greater_than_ten).first;
|
||||
BOOST_CHECK ( it == std::find_if ( c.begin(), c.end(), greater_than_ten ));
|
||||
BOOST_CHECK ( v.size () == std::count_if ( c.begin(), it, is_even ));
|
||||
BOOST_CHECK ( ba::all_of ( v.begin (), v.end (), is_even ));
|
||||
}
|
||||
{
|
||||
std::vector<value_type> v;
|
||||
typename Container::const_iterator it = ba::copy_if_until (
|
||||
c, back_inserter ( v ), is_even, greater_than_ten).first;
|
||||
BOOST_CHECK ( it == std::find_if ( c.begin(), c.end(), greater_than_ten ));
|
||||
BOOST_CHECK ( v.size () == std::count_if ( c.begin(), it, is_even ));
|
||||
BOOST_CHECK ( ba::all_of ( v.begin (), v.end (), is_even ));
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Container>
|
||||
void test_copy_until ( Container const &c ) {
|
||||
|
||||
@ -155,7 +316,141 @@ void test_copy_until ( Container const &c ) {
|
||||
BOOST_CHECK ( ba::none_of ( v.begin (), v.end (), is_even ));
|
||||
BOOST_CHECK ( std::equal ( v.begin (), v.end (), c.begin ()));
|
||||
}
|
||||
|
||||
|
||||
BOOST_CXX14_CONSTEXPR inline bool constexpr_test_copy_if() {
|
||||
const int sz = 64;
|
||||
int in_data[sz] = {0};
|
||||
bool res = true;
|
||||
|
||||
const int* from = in_data;
|
||||
const int* to = in_data + sz;
|
||||
|
||||
int out_data[sz] = {0};
|
||||
int* out = out_data;
|
||||
out = ba::copy_if ( from, to, out, is_false ); // copy none
|
||||
res = (res && out == out_data);
|
||||
|
||||
out = ba::copy_if ( from, to, out, is_true ); // copy all
|
||||
res = (res && out == out_data + sz
|
||||
&& ba::equal( input_iterator<const int *>(out_data), input_iterator<const int *>(out_data + sz),
|
||||
input_iterator<const int *>(from), input_iterator<const int *>(to)));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR inline bool constexpr_test_copy_while() {
|
||||
const int sz = 64;
|
||||
int in_data[sz] = {0};
|
||||
bool res = true;
|
||||
|
||||
const int* from = in_data;
|
||||
const int* to = in_data + sz;
|
||||
|
||||
int out_data[sz] = {0};
|
||||
int* out = out_data;
|
||||
out = ba::copy_while ( from, to, out, is_false ).second; // copy none
|
||||
res = (res && out == out_data && ba::all_of(out, out + sz, is_zero));
|
||||
|
||||
out = ba::copy_while ( from, to, out, is_true ).second; // copy all
|
||||
res = (res && out == out_data + sz
|
||||
&& ba::equal( input_iterator<const int *>(out_data), input_iterator<const int *>(out_data + sz),
|
||||
input_iterator<const int *>(from), input_iterator<const int *>(to)));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR inline bool constexpr_test_copy_until() {
|
||||
const int sz = 64;
|
||||
int in_data[sz] = {0};
|
||||
bool res = true;
|
||||
|
||||
const int* from = in_data;
|
||||
const int* to = in_data + sz;
|
||||
|
||||
int out_data[sz] = {0};
|
||||
int* out = out_data;
|
||||
out = ba::copy_until ( from, to, out, is_true ).second; // copy none
|
||||
res = (res && out == out_data && ba::all_of(out, out + sz, is_zero));
|
||||
|
||||
out = ba::copy_until ( from, to, out, is_false ).second; // copy all
|
||||
res = (res && out == out_data + sz
|
||||
&& ba::equal( input_iterator<const int *>(out_data), input_iterator<const int *>(out_data + sz),
|
||||
input_iterator<const int *>(from), input_iterator<const int *>(to)));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR inline bool constexpr_test_copy_if_while() {
|
||||
const int sz = 64;
|
||||
int in_data[sz] = {0};
|
||||
bool res = true;
|
||||
|
||||
const int* from = in_data;
|
||||
const int* to = in_data + sz;
|
||||
|
||||
// Terminate immediately
|
||||
{
|
||||
int out_data[sz] = {0};
|
||||
int* out = out_data;
|
||||
out = ba::copy_if_while ( from, to, out, is_true, is_false ).second;
|
||||
res = (res && out == out_data && ba::all_of(out, out + sz, is_zero));
|
||||
}
|
||||
// Copy nothing
|
||||
{
|
||||
int out_data[sz] = {0};
|
||||
int* out = out_data;
|
||||
out = ba::copy_if_while ( from, to, out, is_false, is_true ).second;
|
||||
res = (res && out == out_data && ba::all_of(out, out + sz, is_zero));
|
||||
}
|
||||
// Copy everything
|
||||
{
|
||||
int out_data[sz] = {0};
|
||||
int* out = out_data;
|
||||
out = ba::copy_if_while ( from, to, out, is_true, is_true ).second;
|
||||
res = (res && out == out_data + sz
|
||||
&& ba::equal( input_iterator<const int *>(out_data), input_iterator<const int *>(out_data + sz),
|
||||
input_iterator<const int *>(from), input_iterator<const int *>(to)));
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR inline bool constexpr_test_copy_if_until() {
|
||||
const int sz = 64;
|
||||
int in_data[sz] = {0};
|
||||
bool res = true;
|
||||
|
||||
const int* from = in_data;
|
||||
const int* to = in_data + sz;
|
||||
|
||||
// Terminate immediately
|
||||
{
|
||||
int out_data[sz] = {0};
|
||||
int* out = out_data;
|
||||
out = ba::copy_if_until ( from, to, out, is_true, is_true ).second;
|
||||
res = (res && out == out_data && ba::all_of(out, out + sz, is_zero));
|
||||
}
|
||||
// Copy nothing
|
||||
{
|
||||
int out_data[sz] = {0};
|
||||
int* out = out_data;
|
||||
out = ba::copy_if_until ( from, to, out, is_false, is_false ).second;
|
||||
res = (res && out == out_data && ba::all_of(out, out + sz, is_zero));
|
||||
}
|
||||
// Copy everything
|
||||
{
|
||||
int out_data[sz] = {0};
|
||||
int* out = out_data;
|
||||
out = ba::copy_if_until ( from, to, out, is_true, is_false ).second;
|
||||
res = (res && out == out_data + sz
|
||||
&& ba::equal( input_iterator<const int *>(out_data), input_iterator<const int *>(out_data + sz),
|
||||
input_iterator<const int *>(from), input_iterator<const int *>(to)));
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void test_sequence1 () {
|
||||
std::vector<int> v;
|
||||
for ( int i = 5; i < 15; ++i )
|
||||
@ -163,13 +458,26 @@ void test_sequence1 () {
|
||||
test_copy_if ( v );
|
||||
test_copy_while ( v );
|
||||
test_copy_until ( v );
|
||||
|
||||
|
||||
BOOST_CXX14_CONSTEXPR bool constexpr_res_if = constexpr_test_copy_if();
|
||||
BOOST_CHECK ( constexpr_res_if );
|
||||
BOOST_CXX14_CONSTEXPR bool constexpr_res_while = constexpr_test_copy_while();
|
||||
BOOST_CHECK ( constexpr_res_while );
|
||||
BOOST_CXX14_CONSTEXPR bool constexpr_res_until = constexpr_test_copy_until();
|
||||
BOOST_CHECK ( constexpr_res_until );
|
||||
BOOST_CXX14_CONSTEXPR bool constexpr_res_if_while = constexpr_test_copy_if_while();
|
||||
BOOST_CHECK ( constexpr_res_if_while );
|
||||
BOOST_CXX14_CONSTEXPR bool constexpr_res_if_until = constexpr_test_copy_if_until();
|
||||
BOOST_CHECK ( constexpr_res_if_until );
|
||||
|
||||
std::list<int> l;
|
||||
for ( int i = 25; i > 15; --i )
|
||||
l.push_back ( i );
|
||||
test_copy_if ( l );
|
||||
test_copy_while ( l );
|
||||
test_copy_until ( l );
|
||||
test_copy_if_while ( l );
|
||||
test_copy_if_until ( l );
|
||||
}
|
||||
|
||||
|
||||
|
@ -9,6 +9,10 @@
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/algorithm/cxx11/copy_n.hpp>
|
||||
#include <boost/algorithm/cxx14/equal.hpp>
|
||||
#include <boost/algorithm/cxx11/all_of.hpp>
|
||||
|
||||
#include "iterator_test.hpp"
|
||||
|
||||
#define BOOST_TEST_MAIN
|
||||
#include <boost/test/unit_test.hpp>
|
||||
@ -21,6 +25,8 @@
|
||||
namespace ba = boost::algorithm;
|
||||
// namespace ba = boost;
|
||||
|
||||
BOOST_CXX14_CONSTEXPR bool is_zero( int v ) { return v == 0; }
|
||||
|
||||
template <typename Container>
|
||||
void test_sequence ( Container const &c ) {
|
||||
|
||||
@ -67,12 +73,38 @@ void test_sequence ( Container const &c ) {
|
||||
}
|
||||
|
||||
|
||||
BOOST_CXX14_CONSTEXPR inline bool test_constexpr() {
|
||||
const size_t sz = 64;
|
||||
int in_data[sz] = {0};
|
||||
bool res = true;
|
||||
|
||||
const int* from = in_data;
|
||||
const int* to = in_data + sz;
|
||||
|
||||
int out_data[sz] = {0};
|
||||
int* out = out_data;
|
||||
|
||||
out = ba::copy_n ( from, 0, out ); // Copy none
|
||||
res = (res && out == out_data && ba::all_of(out, out + sz, is_zero));
|
||||
|
||||
out = ba::copy_n ( from, sz, out ); // Copy all
|
||||
res = (res && out == out_data + sz
|
||||
&& ba::equal( input_iterator<const int *>(out_data), input_iterator<const int *>(out_data + sz),
|
||||
input_iterator<const int *>(from), input_iterator<const int *>(to)));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
void test_sequence1 () {
|
||||
std::vector<int> v;
|
||||
for ( int i = 5; i < 15; ++i )
|
||||
v.push_back ( i );
|
||||
test_sequence ( v );
|
||||
|
||||
BOOST_CXX14_CONSTEXPR bool constexpr_res = test_constexpr();
|
||||
BOOST_CHECK(constexpr_res);
|
||||
|
||||
std::list<int> l;
|
||||
for ( int i = 25; i > 15; --i )
|
||||
l.push_back ( i );
|
||||
|
@ -16,7 +16,7 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
template <typename T>
|
||||
bool eq ( const T& a, const T& b ) { return a == b; }
|
||||
BOOST_CXX14_CONSTEXPR bool eq ( const T& a, const T& b ) { return a == b; }
|
||||
|
||||
template <typename T>
|
||||
bool never_eq ( const T&, const T& ) { return false; }
|
||||
@ -123,7 +123,43 @@ void test_equal ()
|
||||
}
|
||||
|
||||
|
||||
BOOST_CXX14_CONSTEXPR bool test_constexpr_equal() {
|
||||
int num[] = { 1, 1, 2, 3, 5};
|
||||
const int sz = sizeof (num)/sizeof(num[0]);
|
||||
bool res = true;
|
||||
// Empty sequences are equal to each other
|
||||
res = ( ba::equal ( input_iterator<int *>(num), input_iterator<int *>(num),
|
||||
input_iterator<int *>(num), input_iterator<int *>(num))
|
||||
// Identical long sequences are equal
|
||||
&& ba::equal ( input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
||||
input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
||||
eq<int> )
|
||||
// Different sequences are different
|
||||
&& !ba::equal ( input_iterator<int *>(num + 1), input_iterator<int *>(num + sz),
|
||||
input_iterator<int *>(num), input_iterator<int *>(num + sz))
|
||||
);
|
||||
#ifdef __cpp_lib_array_constexpr // or cpp17 compiler
|
||||
// Turn on tests for random_access_iterator, because std functions used in equal are marked constexpr_res
|
||||
res = ( res
|
||||
// Empty sequences are equal to each other
|
||||
&& ba::equal ( random_access_iterator<int *>(num), random_access_iterator<int *>(num),
|
||||
random_access_iterator<int *>(num), random_access_iterator<int *>(num))
|
||||
// Identical long sequences are equal
|
||||
&& ba::equal ( random_access_iterator<int *>(num), random_access_iterator<int *>(num + sz),
|
||||
random_access_iterator<int *>(num), random_access_iterator<int *>(num + sz),
|
||||
eq<int> )
|
||||
// Different sequences are different
|
||||
&& !ba::equal ( random_access_iterator<int *>(num + 1), random_access_iterator<int *>(num + sz),
|
||||
random_access_iterator<int *>(num), random_access_iterator<int *>(num + sz))
|
||||
);
|
||||
#endif
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE( test_main )
|
||||
{
|
||||
test_equal ();
|
||||
BOOST_CXX14_CONSTEXPR bool constexpr_res = test_constexpr_equal ();
|
||||
BOOST_CHECK (constexpr_res);
|
||||
}
|
||||
|
420
test/find_backward_test.cpp
Normal file
420
test/find_backward_test.cpp
Normal file
@ -0,0 +1,420 @@
|
||||
/*
|
||||
Copyright (c) T. Zachary Laine 2018.
|
||||
|
||||
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 <boost/algorithm/find_backward.hpp>
|
||||
|
||||
#define BOOST_TEST_MAIN
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <list>
|
||||
|
||||
|
||||
namespace ba = boost::algorithm;
|
||||
|
||||
template <typename Container>
|
||||
struct dist_t
|
||||
{
|
||||
dist_t(Container & cont) : cont_(cont) {}
|
||||
template<typename Iter>
|
||||
std::ptrdiff_t operator()(Iter it) const
|
||||
{
|
||||
return std::distance(cont_.begin(), it);
|
||||
}
|
||||
|
||||
Container & cont_;
|
||||
};
|
||||
|
||||
BOOST_CXX14_CONSTEXPR bool check_constexpr_backward()
|
||||
{
|
||||
int in_data[] = {1, 2, 3, 4, 5};
|
||||
bool res = true;
|
||||
|
||||
const int* from = in_data;
|
||||
const int* to = in_data + 5;
|
||||
|
||||
const int* start = ba::find_backward(from, to, 1); // stops on first
|
||||
res = (res && start == from);
|
||||
|
||||
start = ba::find_backward(in_data, 1); // stops on first
|
||||
res = (res && start == from);
|
||||
|
||||
const int* end = ba::find_backward(from, to, 6); // stops on the end
|
||||
res = (res && end == to);
|
||||
|
||||
end = ba::find_backward(in_data, 6); // stops on the end
|
||||
res = (res && end == to);
|
||||
|
||||
const int* three = ba::find_backward(from, to, 3); // stops on third element
|
||||
res = (res && three == in_data + 2);
|
||||
|
||||
three = ba::find_backward(in_data, 3); // stops on third element
|
||||
res = (res && three == in_data + 2);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void test_find_backward()
|
||||
{
|
||||
{
|
||||
std::vector<int> v1;
|
||||
const dist_t<std::vector<int> > dist(v1);
|
||||
|
||||
for (int i = 5; i < 15; ++i)
|
||||
v1.push_back(i);
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_backward(v1.begin(), v1.end(), 0)), v1.size());
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_backward(v1.begin(), v1.end(), 100)), v1.size());
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_backward(v1.begin(), v1.end(), v1.back())),
|
||||
v1.size() - 1);
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_backward(v1.begin(), v1.end(), v1.front())), 0);
|
||||
|
||||
BOOST_CHECK_EQUAL(dist(ba::find_backward(v1, 0)), v1.size());
|
||||
BOOST_CHECK_EQUAL(dist(ba::find_backward(v1, 100)), v1.size());
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_backward(v1, v1.back())), v1.size() - 1);
|
||||
BOOST_CHECK_EQUAL(dist(ba::find_backward(v1, v1.front())), 0);
|
||||
}
|
||||
|
||||
// With bidirectional iterators.
|
||||
{
|
||||
std::list<int> l1;
|
||||
const dist_t<std::list<int> > dist(l1);
|
||||
|
||||
for (int i = 5; i < 15; ++i)
|
||||
l1.push_back(i);
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_backward(l1.begin(), l1.end(), 0)), l1.size());
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_backward(l1.begin(), l1.end(), 100)), l1.size());
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_backward(l1.begin(), l1.end(), l1.back())),
|
||||
l1.size() - 1);
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_backward(l1.begin(), l1.end(), l1.front())), 0);
|
||||
|
||||
BOOST_CHECK_EQUAL(dist(ba::find_backward(l1, 0)), l1.size());
|
||||
BOOST_CHECK_EQUAL(dist(ba::find_backward(l1, 100)), l1.size());
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_backward(l1, l1.back())), l1.size() - 1);
|
||||
BOOST_CHECK_EQUAL(dist(ba::find_backward(l1, l1.front())), 0);
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR bool ce_result = check_constexpr_backward();
|
||||
BOOST_CHECK(ce_result);
|
||||
}
|
||||
|
||||
struct equals
|
||||
{
|
||||
BOOST_CXX14_CONSTEXPR equals(int n) : n_(n) {}
|
||||
BOOST_CXX14_CONSTEXPR bool operator()(int i) { return i == n_; }
|
||||
int n_;
|
||||
};
|
||||
|
||||
BOOST_CXX14_CONSTEXPR bool check_constexpr_if_backward()
|
||||
{
|
||||
int in_data[] = {1, 2, 3, 4, 5};
|
||||
bool res = true;
|
||||
|
||||
const int* from = in_data;
|
||||
const int* to = in_data + 5;
|
||||
|
||||
const int* start = ba::find_if_backward(from, to, equals(1)); // stops on first
|
||||
res = (res && start == from);
|
||||
|
||||
start = ba::find_if_backward(in_data, equals(1)); // stops on first
|
||||
res = (res && start == from);
|
||||
|
||||
const int* end = ba::find_if_backward(from, to, equals(6)); // stops on the end
|
||||
res = (res && end == to);
|
||||
|
||||
end = ba::find_if_backward(in_data, equals(6)); // stops on the end
|
||||
res = (res && end == to);
|
||||
|
||||
const int* three = ba::find_if_backward(from, to, equals(3)); // stops on third element
|
||||
res = (res && three == in_data + 2);
|
||||
|
||||
three = ba::find_if_backward(in_data, equals(3)); // stops on third element
|
||||
res = (res && three == in_data + 2);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void test_find_if_backward()
|
||||
{
|
||||
{
|
||||
std::vector<int> v1;
|
||||
const dist_t<std::vector<int> > dist(v1);
|
||||
|
||||
for (int i = 5; i < 15; ++i)
|
||||
v1.push_back(i);
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_if_backward(v1.begin(), v1.end(), equals(0))),
|
||||
v1.size());
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_if_backward(v1.begin(), v1.end(), equals(100))),
|
||||
v1.size());
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_if_backward(v1.begin(), v1.end(), equals(v1.back()))),
|
||||
v1.size() - 1);
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(
|
||||
ba::find_if_backward(v1.begin(), v1.end(), equals(v1.front()))),
|
||||
0);
|
||||
|
||||
BOOST_CHECK_EQUAL(dist(ba::find_if_backward(v1, equals(0))), v1.size());
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_if_backward(v1, equals(100))), v1.size());
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_if_backward(v1, equals(v1.back()))), v1.size() - 1);
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_if_backward(v1, equals(v1.front()))), 0);
|
||||
}
|
||||
|
||||
// With bidirectional iterators.
|
||||
{
|
||||
std::list<int> l1;
|
||||
const dist_t<std::list<int> > dist(l1);
|
||||
|
||||
for (int i = 5; i < 15; ++i)
|
||||
l1.push_back(i);
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_if_backward(l1.begin(), l1.end(), equals(0))),
|
||||
l1.size());
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_if_backward(l1.begin(), l1.end(), equals(100))),
|
||||
l1.size());
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_if_backward(l1.begin(), l1.end(), equals(l1.back()))),
|
||||
l1.size() - 1);
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(
|
||||
ba::find_if_backward(l1.begin(), l1.end(), equals(l1.front()))),
|
||||
0);
|
||||
|
||||
BOOST_CHECK_EQUAL(dist(ba::find_if_backward(l1, equals(0))), l1.size());
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_if_backward(l1, equals(100))), l1.size());
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_if_backward(l1, equals(l1.back()))), l1.size() - 1);
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_if_backward(l1, equals(l1.front()))), 0);
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR bool ce_result = check_constexpr_if_backward();
|
||||
BOOST_CHECK(ce_result);
|
||||
}
|
||||
|
||||
struct not_equals
|
||||
{
|
||||
BOOST_CXX14_CONSTEXPR not_equals(int n) : n_(n) {}
|
||||
BOOST_CXX14_CONSTEXPR bool operator()(int i) { return i != n_; }
|
||||
int n_;
|
||||
};
|
||||
|
||||
BOOST_CXX14_CONSTEXPR bool check_constexpr_if_not_backward()
|
||||
{
|
||||
int in_data[] = {1, 2, 3, 4, 5};
|
||||
bool res = true;
|
||||
|
||||
const int* from = in_data;
|
||||
const int* to = in_data + 5;
|
||||
|
||||
const int* start = ba::find_if_not_backward(from, to, not_equals(1)); // stops on first
|
||||
res = (res && start == from);
|
||||
|
||||
start = ba::find_if_not_backward(in_data, not_equals(1)); // stops on first
|
||||
res = (res && start == from);
|
||||
|
||||
const int* end = ba::find_if_not_backward(from, to, not_equals(6)); // stops on the end
|
||||
res = (res && end == to);
|
||||
|
||||
end = ba::find_if_not_backward(in_data, not_equals(6)); // stops on the end
|
||||
res = (res && end == to);
|
||||
|
||||
const int* three = ba::find_if_not_backward(from, to, not_equals(3)); // stops on third element
|
||||
res = (res && three == in_data + 2);
|
||||
|
||||
three = ba::find_if_not_backward(in_data, not_equals(3)); // stops on third element
|
||||
res = (res && three == in_data + 2);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void test_find_if_not_backward()
|
||||
{
|
||||
{
|
||||
std::vector<int> v1;
|
||||
const dist_t<std::vector<int> > dist(v1);
|
||||
|
||||
for (int i = 5; i < 15; ++i)
|
||||
v1.push_back(i);
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_if_not_backward(v1.begin(), v1.end(), not_equals(0))),
|
||||
v1.size());
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_if_not_backward(
|
||||
v1.begin(), v1.end(), not_equals(100))),
|
||||
v1.size());
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_if_not_backward(
|
||||
v1.begin(), v1.end(), not_equals(v1.back()))),
|
||||
v1.size() - 1);
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_if_not_backward(
|
||||
v1.begin(), v1.end(), not_equals(v1.front()))),
|
||||
0);
|
||||
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_if_not_backward(v1, not_equals(0))), v1.size());
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_if_not_backward(v1, not_equals(100))), v1.size());
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_if_not_backward(v1, not_equals(v1.back()))),
|
||||
v1.size() - 1);
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_if_not_backward(v1, not_equals(v1.front()))), 0);
|
||||
}
|
||||
|
||||
// With bidirectional iterators.
|
||||
{
|
||||
std::list<int> l1;
|
||||
const dist_t<std::list<int> > dist(l1);
|
||||
|
||||
for (int i = 5; i < 15; ++i)
|
||||
l1.push_back(i);
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_if_not_backward(l1.begin(), l1.end(), not_equals(0))),
|
||||
l1.size());
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_if_not_backward(
|
||||
l1.begin(), l1.end(), not_equals(100))),
|
||||
l1.size());
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_if_not_backward(
|
||||
l1.begin(), l1.end(), not_equals(l1.back()))),
|
||||
l1.size() - 1);
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_if_not_backward(
|
||||
l1.begin(), l1.end(), not_equals(l1.front()))),
|
||||
0);
|
||||
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_if_not_backward(l1, not_equals(0))), l1.size());
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_if_not_backward(l1, not_equals(100))), l1.size());
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_if_not_backward(l1, not_equals(l1.back()))),
|
||||
l1.size() - 1);
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_if_not_backward(l1, not_equals(l1.front()))), 0);
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR bool ce_result = check_constexpr_if_not_backward();
|
||||
BOOST_CHECK(ce_result);
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR bool check_constexpr_not_backward()
|
||||
{
|
||||
int in_data[] = {1, 5, 5, 5, 5};
|
||||
bool res = true;
|
||||
|
||||
const int* from = in_data;
|
||||
const int* to = in_data + 5;
|
||||
|
||||
const int* start = ba::find_not_backward(from, to, 5); // stops on first
|
||||
res = (res && start == from);
|
||||
|
||||
start = ba::find_not_backward(in_data, 5); // stops on first
|
||||
res = (res && start == from);
|
||||
|
||||
const int in_data_2[] = {6, 6, 6, 6, 6};
|
||||
const int* end = ba::find_not_backward(in_data_2, in_data_2 + 5, 6); // stops on the end
|
||||
res = (res && end == in_data_2 + 5);
|
||||
|
||||
end = ba::find_not_backward(in_data_2, 6); // stops on the end
|
||||
res = (res && end == in_data_2 + 5);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void test_find_not_backward()
|
||||
{
|
||||
{
|
||||
std::vector<int> v1;
|
||||
const dist_t<std::vector<int> > dist(v1);
|
||||
|
||||
for (int i = 0; i < 5; ++i)
|
||||
v1.push_back(0);
|
||||
for (int i = 0; i < 5; ++i)
|
||||
v1.push_back(1);
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_not_backward(v1.begin(), v1.end(), 1)), 4);
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_not_backward(v1.begin(), v1.end(), 0)),
|
||||
v1.size() - 1);
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_not_backward(v1.begin(), v1.end(), 2)),
|
||||
v1.size() - 1);
|
||||
|
||||
BOOST_CHECK_EQUAL(dist(ba::find_not_backward(v1, 1)), 4);
|
||||
BOOST_CHECK_EQUAL(dist(ba::find_not_backward(v1, 0)), v1.size() - 1);
|
||||
BOOST_CHECK_EQUAL(dist(ba::find_not_backward(v1, 2)), v1.size() - 1);
|
||||
|
||||
v1.resize(5);
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_not_backward(v1.begin(), v1.end(), 0)), v1.size());
|
||||
|
||||
BOOST_CHECK_EQUAL(dist(ba::find_not_backward(v1, 0)), v1.size());
|
||||
}
|
||||
|
||||
// With bidirectional iterators.
|
||||
{
|
||||
std::list<int> l1;
|
||||
const dist_t<std::list<int> > dist(l1);
|
||||
|
||||
for (int i = 0; i < 5; ++i)
|
||||
l1.push_back(0);
|
||||
for (int i = 0; i < 5; ++i)
|
||||
l1.push_back(1);
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_not_backward(l1.begin(), l1.end(), 1)), 4);
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_not_backward(l1.begin(), l1.end(), 0)),
|
||||
l1.size() - 1);
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_not_backward(l1.begin(), l1.end(), 2)),
|
||||
l1.size() - 1);
|
||||
|
||||
BOOST_CHECK_EQUAL(dist(ba::find_not_backward(l1, 1)), 4);
|
||||
BOOST_CHECK_EQUAL(dist(ba::find_not_backward(l1, 0)), l1.size() - 1);
|
||||
BOOST_CHECK_EQUAL(dist(ba::find_not_backward(l1, 2)), l1.size() - 1);
|
||||
|
||||
l1.resize(5);
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_not_backward(l1.begin(), l1.end(), 0)), l1.size());
|
||||
|
||||
BOOST_CHECK_EQUAL(dist(ba::find_not_backward(l1, 0)), l1.size());
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR bool ce_result = check_constexpr_not_backward();
|
||||
BOOST_CHECK(ce_result);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_main)
|
||||
{
|
||||
test_find_backward();
|
||||
test_find_if_backward();
|
||||
test_find_if_not_backward();
|
||||
test_find_not_backward();
|
||||
}
|
@ -22,6 +22,29 @@
|
||||
namespace ba = boost::algorithm;
|
||||
// namespace ba = boost;
|
||||
|
||||
BOOST_CXX14_CONSTEXPR bool is_true ( int v ) { return true; }
|
||||
BOOST_CXX14_CONSTEXPR bool is_false ( int v ) { return false; }
|
||||
BOOST_CXX14_CONSTEXPR bool is_not_three ( int v ) { return v != 3; }
|
||||
|
||||
BOOST_CXX14_CONSTEXPR bool check_constexpr() {
|
||||
int in_data[] = {1, 2, 3, 4, 5};
|
||||
bool res = true;
|
||||
|
||||
const int* from = in_data;
|
||||
const int* to = in_data + 5;
|
||||
|
||||
const int* start = ba::find_if_not (from, to, is_false); // stops on first
|
||||
res = (res && start == from);
|
||||
|
||||
const int* end = ba::find_if_not(from, to, is_true); // stops on the end
|
||||
res = (res && end == to);
|
||||
|
||||
const int* three = ba::find_if_not(from, to, is_not_three); // stops on third element
|
||||
res = (res && three == in_data + 2);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
template <typename Container>
|
||||
typename Container::iterator offset_to_iter ( Container &v, int offset ) {
|
||||
typename Container::iterator retval;
|
||||
|
134
test/find_not_test.cpp
Normal file
134
test/find_not_test.cpp
Normal file
@ -0,0 +1,134 @@
|
||||
/*
|
||||
Copyright (c) T. Zachary Laine 2018.
|
||||
|
||||
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 <boost/algorithm/find_not.hpp>
|
||||
|
||||
#define BOOST_TEST_MAIN
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <list>
|
||||
|
||||
|
||||
namespace ba = boost::algorithm;
|
||||
|
||||
template <typename Container>
|
||||
struct dist_t
|
||||
{
|
||||
dist_t(Container & cont) : cont_(cont) {}
|
||||
template<typename Iter>
|
||||
std::ptrdiff_t operator()(Iter it) const
|
||||
{
|
||||
return std::distance(cont_.begin(), it);
|
||||
}
|
||||
|
||||
Container & cont_;
|
||||
};
|
||||
|
||||
BOOST_CXX14_CONSTEXPR bool check_constexpr()
|
||||
{
|
||||
int in_data[] = {2, 2, 3, 4, 5};
|
||||
bool res = true;
|
||||
|
||||
const int* from = in_data;
|
||||
const int* to = in_data + 5;
|
||||
|
||||
const int* start = ba::find_not(from, to, 1); // stops on first
|
||||
res = (res && start == from);
|
||||
|
||||
start = ba::find_not(in_data, 1); // stops on first
|
||||
res = (res && start == from);
|
||||
|
||||
int in_data_2[] = {6, 6, 6, 6, 6};
|
||||
const int* end = ba::find_not(in_data_2, in_data_2 + 5, 6); // stops on the end
|
||||
res = (res && end == in_data_2 + 5);
|
||||
|
||||
end = ba::find_not(in_data_2, 6); // stops on the end
|
||||
res = (res && end == in_data_2 + 5);
|
||||
|
||||
const int* three = ba::find_not(from, to, 2); // stops on third element
|
||||
res = (res && three == in_data + 2);
|
||||
|
||||
three = ba::find_not(in_data, 2); // stops on third element
|
||||
res = (res && three == in_data + 2);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void test_sequence()
|
||||
{
|
||||
{
|
||||
std::vector<int> v1;
|
||||
const dist_t<std::vector<int> > dist(v1);
|
||||
|
||||
for (int i = 5; i < 15; ++i)
|
||||
v1.push_back(i);
|
||||
BOOST_CHECK_EQUAL(dist(ba::find_not(v1.begin(), v1.end(), 0)), 0);
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_not(v1.begin(), v1.end(), v1.back())), 0);
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_not(v1.begin(), v1.end(), v1.front())), 1);
|
||||
|
||||
BOOST_CHECK_EQUAL(dist(ba::find_not(v1, 0)), 0);
|
||||
BOOST_CHECK_EQUAL(dist(ba::find_not(v1, v1.back())), 0);
|
||||
BOOST_CHECK_EQUAL(dist(ba::find_not(v1, v1.front())), 1);
|
||||
|
||||
v1 = std::vector<int>(10, 2);
|
||||
BOOST_CHECK_EQUAL(dist(ba::find_not(v1.begin(), v1.end(), 0)), 0);
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_not(v1.begin(), v1.end(), v1.back())), v1.size());
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_not(v1.begin(), v1.end(), v1.front())), v1.size());
|
||||
|
||||
BOOST_CHECK_EQUAL(dist(ba::find_not(v1, 0)), 0);
|
||||
BOOST_CHECK_EQUAL(dist(ba::find_not(v1, v1.back())), v1.size());
|
||||
BOOST_CHECK_EQUAL(dist(ba::find_not(v1, v1.front())), v1.size());
|
||||
}
|
||||
|
||||
// With bidirectional iterators.
|
||||
{
|
||||
std::list<int> l1;
|
||||
const dist_t<std::list<int> > dist(l1);
|
||||
|
||||
for (int i = 5; i < 15; ++i)
|
||||
l1.push_back(i);
|
||||
BOOST_CHECK_EQUAL(dist(ba::find_not(l1.begin(), l1.end(), 0)), 0);
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_not(l1.begin(), l1.end(), l1.back())), 0);
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_not(l1.begin(), l1.end(), l1.front())), 1);
|
||||
|
||||
BOOST_CHECK_EQUAL(dist(ba::find_not(l1, 0)), 0);
|
||||
BOOST_CHECK_EQUAL(dist(ba::find_not(l1, l1.back())), 0);
|
||||
BOOST_CHECK_EQUAL(dist(ba::find_not(l1, l1.front())), 1);
|
||||
|
||||
l1.clear();
|
||||
for (int i = 0; i < 10; ++i)
|
||||
l1.push_back(2);
|
||||
BOOST_CHECK_EQUAL(dist(ba::find_not(l1.begin(), l1.end(), 0)), 0);
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_not(l1.begin(), l1.end(), l1.back())), l1.size());
|
||||
BOOST_CHECK_EQUAL(
|
||||
dist(ba::find_not(l1.begin(), l1.end(), l1.front())), l1.size());
|
||||
|
||||
BOOST_CHECK_EQUAL(dist(ba::find_not(l1, 0)), 0);
|
||||
BOOST_CHECK_EQUAL(dist(ba::find_not(l1, l1.back())), l1.size());
|
||||
BOOST_CHECK_EQUAL(dist(ba::find_not(l1, l1.front())), l1.size());
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR bool ce_result = check_constexpr();
|
||||
BOOST_CHECK(ce_result);
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_main)
|
||||
{
|
||||
test_sequence();
|
||||
}
|
@ -20,7 +20,7 @@
|
||||
|
||||
// Test to make sure a sequence is "correctly formed"; i.e, ascending by one
|
||||
template <typename Iterator, typename T>
|
||||
bool test_iota_results ( Iterator first, Iterator last, T initial_value ) {
|
||||
BOOST_CXX14_CONSTEXPR bool test_iota_results ( Iterator first, Iterator last, T initial_value ) {
|
||||
if ( first == last ) return true;
|
||||
if ( initial_value != *first ) return false;
|
||||
Iterator prev = first;
|
||||
@ -32,12 +32,13 @@ bool test_iota_results ( Iterator first, Iterator last, T initial_value ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template <typename Range, typename T>
|
||||
bool test_iota_results ( const Range &r, T initial_value ) {
|
||||
BOOST_CXX14_CONSTEXPR bool test_iota_results ( const Range &r, T initial_value ) {
|
||||
return test_iota_results (boost::begin (r), boost::end (r), initial_value );
|
||||
}
|
||||
|
||||
|
||||
|
||||
void test_ints () {
|
||||
std::vector<int> v;
|
||||
std::list<int> l;
|
||||
@ -76,9 +77,38 @@ void test_ints () {
|
||||
boost::algorithm::iota_n ( std::front_inserter(l), 123, 20 );
|
||||
BOOST_CHECK ( test_iota_results ( l.rbegin (), l.rend (), 123 ));
|
||||
}
|
||||
|
||||
BOOST_CXX14_CONSTEXPR inline bool test_constexpr_iota() {
|
||||
bool res = true;
|
||||
int data[] = {0, 0, 0};
|
||||
boost::algorithm::iota(data, data, 1); // fill none
|
||||
res = (res && data[0] == 0);
|
||||
|
||||
boost::algorithm::iota(data, data + 3, 1); // fill all
|
||||
res = (res && test_iota_results(data, data + 3, 1));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
BOOST_CXX14_CONSTEXPR inline bool test_constexpr_iota_n() {
|
||||
bool res = true;
|
||||
int data[] = {0, 0, 0};
|
||||
boost::algorithm::iota_n(data, 1, 0); // fill none
|
||||
res = (res && data[0] == 0);
|
||||
|
||||
boost::algorithm::iota_n(data, 1, 3); // fill all
|
||||
res = (res && test_iota_results(data, 1));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE( test_main )
|
||||
{
|
||||
test_ints ();
|
||||
BOOST_CXX14_CONSTEXPR bool constexpr_iota_res = test_constexpr_iota ();
|
||||
BOOST_CHECK(constexpr_iota_res);
|
||||
BOOST_CXX14_CONSTEXPR bool constexpr_iota_n_res = test_constexpr_iota_n ();
|
||||
BOOST_CHECK(constexpr_iota_n_res);
|
||||
}
|
||||
|
246
test/is_clamped_test.cpp
Normal file
246
test/is_clamped_test.cpp
Normal file
@ -0,0 +1,246 @@
|
||||
// (C) Copyright Ivan Matek, Marshall Clow 2021.
|
||||
// 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)
|
||||
|
||||
#include <boost/algorithm/is_clamped.hpp>
|
||||
#include <boost/algorithm/clamp.hpp>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#ifdef __cpp_impl_three_way_comparison
|
||||
#if __has_include(<compare>)
|
||||
#define BOOST_IS_CLAMPED_TEST_SPACESHIP
|
||||
#endif
|
||||
#ifdef BOOST_IS_CLAMPED_TEST_SPACESHIP
|
||||
#include <compare>
|
||||
#endif
|
||||
#endif
|
||||
#include <limits>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
|
||||
#define BOOST_TEST_MAIN
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
namespace ba = boost::algorithm;
|
||||
|
||||
BOOST_CONSTEXPR bool intGreater(int lhs, int rhs) { return lhs > rhs; }
|
||||
|
||||
class custom {
|
||||
public:
|
||||
custom(int x) : v(x) {}
|
||||
custom(const custom &rhs) : v(rhs.v) {}
|
||||
|
||||
bool operator<(const custom &rhs) const { return v < rhs.v; }
|
||||
bool operator==(const custom &rhs) const {
|
||||
return v == rhs.v;
|
||||
} // need this for the test
|
||||
int v;
|
||||
};
|
||||
|
||||
static bool customLess(const custom &lhs, const custom &rhs) { return lhs.v < rhs.v; }
|
||||
|
||||
void test_ints() {
|
||||
// Inside the range, equal to the endpoints, and outside the endpoints.
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( 3, 1, 6 ));
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( 1, 1, 6 ));
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( 6, 1, 6 ));
|
||||
BOOST_CHECK_EQUAL ( false, ba::is_clamped ( 0, 1, 6 ));
|
||||
BOOST_CHECK_EQUAL ( false, ba::is_clamped ( 7, 1, 6 ));
|
||||
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( 3, 6, 1, intGreater ));
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( 1, 6, 1, intGreater ));
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( 6, 6, 1, intGreater ));
|
||||
BOOST_CHECK_EQUAL ( false, ba::is_clamped ( 0, 6, 1, intGreater ));
|
||||
BOOST_CHECK_EQUAL ( false, ba::is_clamped ( 7, 6, 1, intGreater ));
|
||||
|
||||
// Negative numbers
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( -3, -6, -1 ));
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( -1, -6, -1 ));
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( -6, -6, -1 ));
|
||||
BOOST_CHECK_EQUAL ( false, ba::is_clamped ( 0, -6, -1 ));
|
||||
BOOST_CHECK_EQUAL ( false, ba::is_clamped ( -7, -6, -1 ));
|
||||
|
||||
// Mixed positive and negative numbers
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( 1, -5, 5 ));
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( -5, -5, 5 ));
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( 5, -5, 5 ));
|
||||
BOOST_CHECK_EQUAL ( false, ba::is_clamped ( -6, -5, 5 ));
|
||||
BOOST_CHECK_EQUAL ( false, ba::is_clamped ( 6, -5, 5 ));
|
||||
|
||||
// Unsigned
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( 5U, 1U, 6U ));
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( 1U, 1U, 6U ));
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( 6U, 1U, 6U ));
|
||||
BOOST_CHECK_EQUAL ( false, ba::is_clamped ( 0U, 1U, 6U ));
|
||||
BOOST_CHECK_EQUAL ( false, ba::is_clamped ( 8U, 1U, 6U ));
|
||||
|
||||
// Mixed (1)
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( 5U, 1, 6 ));
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( 1U, 1, 6 ));
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( 6U, 1, 6 ));
|
||||
BOOST_CHECK_EQUAL ( false, ba::is_clamped ( 0U, 1, 6 ));
|
||||
BOOST_CHECK_EQUAL ( false, ba::is_clamped ( 8U, 1, 6 ));
|
||||
|
||||
// Mixed (2)
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( 5U, 1, 6. ));
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( 1U, 1, 6. ));
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( 6U, 1, 6. ));
|
||||
BOOST_CHECK_EQUAL ( false, ba::is_clamped ( 0U, 1, 6. ));
|
||||
BOOST_CHECK_EQUAL ( false, ba::is_clamped ( 8U, 1, 6. ));
|
||||
|
||||
// float->short conversion does not round
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( 50, 50.999, 100 ));
|
||||
BOOST_CHECK_EQUAL ( false, ba::is_clamped ( 50, 51.001, 100 ));
|
||||
}
|
||||
|
||||
void test_floats() {
|
||||
// If floats are IEEE754 certain floats have exact representations.
|
||||
if (std::numeric_limits<float>::is_iec559) {
|
||||
const float lo = 0.125;
|
||||
const float hi = 0.625;
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( lo, lo, hi ));
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( hi, lo, hi ));
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( lo + 0.01, lo, hi ));
|
||||
BOOST_CHECK_EQUAL ( false, ba::is_clamped ( lo - 0.01, lo, hi ));
|
||||
BOOST_CHECK_EQUAL ( false, ba::is_clamped ( hi + 0.01, lo, hi ));
|
||||
// If we have nextafterf we can be more precise.
|
||||
#if __cplusplus >= 201103L
|
||||
assert(lo < hi);
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( hi, lo, hi ));
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( std::nextafterf( lo, hi ), lo, hi ));
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( std::nextafterf( hi, lo ), lo, hi ));
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( (lo + hi) / 2, lo, hi ));
|
||||
// 1.0 is just for direction of nextafterf, value of 1.0 is not significant.
|
||||
BOOST_CHECK_EQUAL ( false, ba::is_clamped ( std::nextafterf( lo, lo - 1.0f ), lo, hi ));
|
||||
BOOST_CHECK_EQUAL ( false, ba::is_clamped ( std::nextafterf( hi, hi + 1.0f ), lo, hi ));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void test_std_string() {
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( std::string("a3"), std::string("a1"), std::string("a6") ));
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( std::string("a1"), std::string("a1"), std::string("a6") ));
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( std::string("a6"), std::string("a1"), std::string("a6") ));
|
||||
BOOST_CHECK_EQUAL ( false, ba::is_clamped ( std::string("a7"), std::string("a1"), std::string("a6") ));
|
||||
BOOST_CHECK_EQUAL ( false, ba::is_clamped ( std::string("a0"), std::string("a1"), std::string("a6") ));
|
||||
}
|
||||
|
||||
void test_custom() {
|
||||
// Inside the range, equal to the endpoints, and outside the endpoints.
|
||||
const custom c0(0);
|
||||
const custom c1(1);
|
||||
const custom c3(3);
|
||||
const custom c6(6);
|
||||
const custom c7(7);
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( c3, c1, c6 ));
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( c1, c1, c6 ));
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( c6, c1, c6 ));
|
||||
BOOST_CHECK_EQUAL ( false, ba::is_clamped ( c0, c1, c6 ));
|
||||
BOOST_CHECK_EQUAL ( false, ba::is_clamped ( c7, c1, c6 ));
|
||||
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( c3, c1, c6, customLess ));
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( c1, c1, c6, customLess ));
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped ( c6, c1, c6, customLess ));
|
||||
BOOST_CHECK_EQUAL ( false, ba::is_clamped ( c0, c1, c6, customLess ));
|
||||
BOOST_CHECK_EQUAL ( false, ba::is_clamped ( c7, c1, c6, customLess ));
|
||||
}
|
||||
|
||||
void test_point_interval() {
|
||||
BOOST_CHECK_EQUAL(true, ba::is_clamped(1, 1, 1));
|
||||
BOOST_CHECK_EQUAL(false, ba::is_clamped(0, 1, 1));
|
||||
BOOST_CHECK_EQUAL(false, ba::is_clamped(2, 1, 1));
|
||||
}
|
||||
|
||||
void test_first_argument_determines_types() {
|
||||
// all arguments are int
|
||||
BOOST_CHECK_EQUAL(true, ba::is_clamped(5, 5.9, 6.1));
|
||||
BOOST_CHECK_EQUAL(true, ba::is_clamped(6, 5.9, 6.1));
|
||||
// all arguments are double
|
||||
BOOST_CHECK_EQUAL(false, ba::is_clamped(5.0, 5.9, 6.1));
|
||||
BOOST_CHECK_EQUAL(false, ba::is_clamped(6.2, 5.9, 6.1));
|
||||
}
|
||||
|
||||
void test_constexpr() {
|
||||
#if __cplusplus >= 201402L
|
||||
{
|
||||
constexpr bool is_clamped = (ba::is_clamped ( 3, 1, 6 ));
|
||||
BOOST_CHECK_EQUAL (true, is_clamped );
|
||||
}
|
||||
{
|
||||
constexpr bool is_clamped = (ba::is_clamped ( 1, 1, 6 ));
|
||||
BOOST_CHECK_EQUAL (true, is_clamped );
|
||||
}
|
||||
{
|
||||
constexpr bool is_clamped = (ba::is_clamped ( 6, 1, 6 ));
|
||||
BOOST_CHECK_EQUAL (true, is_clamped );
|
||||
}
|
||||
{
|
||||
constexpr bool is_clamped = (ba::is_clamped ( 0, 1, 6 ));
|
||||
BOOST_CHECK_EQUAL(false, is_clamped );
|
||||
}
|
||||
{
|
||||
constexpr bool is_clamped = (ba::is_clamped ( 7, 1, 6 ));
|
||||
BOOST_CHECK_EQUAL(false, is_clamped );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#ifdef BOOST_IS_CLAMPED_TEST_SPACESHIP
|
||||
struct custom_with_spaceship {
|
||||
int v;
|
||||
auto operator<=>(const custom_with_spaceship&) const = default;
|
||||
};
|
||||
#endif
|
||||
|
||||
void test_spaceship() {
|
||||
#ifdef BOOST_IS_CLAMPED_TEST_SPACESHIP
|
||||
// Inside the range, equal to the endpoints, and outside the endpoints.
|
||||
const custom_with_spaceship c0(0);
|
||||
const custom_with_spaceship c1(1);
|
||||
const custom_with_spaceship c3(3);
|
||||
const custom_with_spaceship c6(6);
|
||||
const custom_with_spaceship c7(7);
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped (c3, c1, c6 ));
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped (c1, c1, c6 ));
|
||||
BOOST_CHECK_EQUAL ( true, ba::is_clamped (c6, c1, c6 ));
|
||||
BOOST_CHECK_EQUAL ( false, ba::is_clamped (c0, c1, c6 ));
|
||||
BOOST_CHECK_EQUAL ( false, ba::is_clamped (c7, c1, c6 ));
|
||||
{
|
||||
constexpr custom_with_spaceship c1(1);
|
||||
constexpr custom_with_spaceship c3(3);
|
||||
constexpr custom_with_spaceship c6(6);
|
||||
constexpr bool clamped = ba::is_clamped (c3, c1, c6 );
|
||||
BOOST_CHECK_EQUAL ( true, clamped );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_main) {
|
||||
test_ints();
|
||||
test_floats();
|
||||
test_std_string();
|
||||
test_custom();
|
||||
test_point_interval();
|
||||
test_first_argument_determines_types();
|
||||
test_constexpr();
|
||||
test_spaceship();
|
||||
}
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
typedef std::tuple<std::uint8_t, std::int8_t, std::uint16_t, std::int16_t,
|
||||
std::int32_t, std::uint32_t, std::int64_t, std::uint64_t> test_types_tuple;
|
||||
|
||||
BOOST_AUTO_TEST_CASE_TEMPLATE(test_extremes, T, test_types_tuple) {
|
||||
const T max = std::numeric_limits<T>::max();
|
||||
BOOST_CHECK_EQUAL(true, ba::is_clamped( max, max, max ));
|
||||
BOOST_CHECK_EQUAL(true, ba::is_clamped( max, max - 1, max ));
|
||||
BOOST_CHECK_EQUAL(false, ba::is_clamped( max - 1, max, max ));
|
||||
|
||||
const T min = std::numeric_limits<T>::min();
|
||||
BOOST_CHECK_EQUAL(true, ba::is_clamped( min, min, min ));
|
||||
BOOST_CHECK_EQUAL(true, ba::is_clamped( min, min, min + 1 ));
|
||||
BOOST_CHECK_EQUAL(false, ba::is_clamped( min, min + 1, min + 1 ));
|
||||
}
|
||||
#endif
|
@ -25,16 +25,27 @@ namespace ba = boost::algorithm;
|
||||
template <typename T>
|
||||
struct less_than {
|
||||
public:
|
||||
less_than ( T foo ) : val ( foo ) {}
|
||||
less_than ( const less_than &rhs ) : val ( rhs.val ) {}
|
||||
BOOST_CXX14_CONSTEXPR less_than ( T foo ) : val ( foo ) {}
|
||||
BOOST_CXX14_CONSTEXPR less_than ( const less_than &rhs ) : val ( rhs.val ) {}
|
||||
|
||||
bool operator () ( const T &v ) const { return v < val; }
|
||||
BOOST_CXX14_CONSTEXPR bool operator () ( const T &v ) const { return v < val; }
|
||||
private:
|
||||
less_than ();
|
||||
less_than operator = ( const less_than &rhs );
|
||||
T val;
|
||||
};
|
||||
|
||||
|
||||
BOOST_CXX14_CONSTEXPR bool test_constexpr() {
|
||||
int v[] = { 4, 5, 6, 7, 8, 9, 10 };
|
||||
bool res = true;
|
||||
res = ( res && ba::is_partitioned ( v, less_than<int>(3))); // no elements
|
||||
res = ( res && ba::is_partitioned ( v, less_than<int>(5))); // only the first element
|
||||
res = ( res && ba::is_partitioned ( v, less_than<int>(8))); // in the middle somewhere
|
||||
res = ( res && ba::is_partitioned ( v, less_than<int>(99))); // all elements
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
void test_sequence1 () {
|
||||
std::vector<int> v;
|
||||
@ -61,4 +72,6 @@ void test_sequence1 () {
|
||||
BOOST_AUTO_TEST_CASE( test_main )
|
||||
{
|
||||
test_sequence1 ();
|
||||
BOOST_CXX14_CONSTEXPR bool constexpr_res = test_constexpr ();
|
||||
BOOST_CHECK ( constexpr_res );
|
||||
}
|
||||
|
@ -30,23 +30,23 @@ public:
|
||||
typedef It pointer;
|
||||
typedef typename std::iterator_traits<It>::reference reference;
|
||||
|
||||
It base() const {return it_;}
|
||||
BOOST_CXX14_CONSTEXPR It base() const {return it_;}
|
||||
|
||||
input_iterator() : it_() {}
|
||||
explicit input_iterator(It it) : it_(it) {}
|
||||
BOOST_CXX14_CONSTEXPR input_iterator() : it_() {}
|
||||
BOOST_CXX14_CONSTEXPR explicit input_iterator(It it) : it_(it) {}
|
||||
|
||||
template <typename U>
|
||||
input_iterator(const input_iterator<U>& u) :it_(u.it_) {}
|
||||
BOOST_CXX14_CONSTEXPR input_iterator(const input_iterator<U>& u) :it_(u.it_) {}
|
||||
|
||||
reference operator*() const {return *it_;}
|
||||
pointer operator->() const {return it_;}
|
||||
BOOST_CXX14_CONSTEXPR reference operator*() const {return *it_;}
|
||||
BOOST_CXX14_CONSTEXPR pointer operator->() const {return it_;}
|
||||
|
||||
input_iterator& operator++() {++it_; return *this;}
|
||||
input_iterator operator++(int) {input_iterator tmp(*this); ++(*this); return tmp;}
|
||||
BOOST_CXX14_CONSTEXPR input_iterator& operator++() {++it_; return *this;}
|
||||
BOOST_CXX14_CONSTEXPR input_iterator operator++(int) {input_iterator tmp(*this); ++(*this); return tmp;}
|
||||
|
||||
friend bool operator==(const input_iterator& x, const input_iterator& y)
|
||||
BOOST_CXX14_CONSTEXPR friend bool operator==(const input_iterator& x, const input_iterator& y)
|
||||
{return x.it_ == y.it_;}
|
||||
friend bool operator!=(const input_iterator& x, const input_iterator& y)
|
||||
BOOST_CXX14_CONSTEXPR friend bool operator!=(const input_iterator& x, const input_iterator& y)
|
||||
{return !(x == y);}
|
||||
|
||||
private:
|
||||
@ -55,14 +55,14 @@ private:
|
||||
};
|
||||
|
||||
template <typename T, typename U>
|
||||
inline bool
|
||||
BOOST_CXX14_CONSTEXPR inline bool
|
||||
operator==(const input_iterator<T>& x, const input_iterator<U>& y)
|
||||
{
|
||||
return x.base() == y.base();
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
inline bool
|
||||
BOOST_CXX14_CONSTEXPR inline bool
|
||||
operator!=(const input_iterator<T>& x, const input_iterator<U>& y)
|
||||
{
|
||||
return !(x == y);
|
||||
@ -79,22 +79,22 @@ public:
|
||||
typedef It pointer;
|
||||
typedef typename std::iterator_traits<It>::reference reference;
|
||||
|
||||
It base() const {return it_;}
|
||||
BOOST_CXX14_CONSTEXPR It base() const {return it_;}
|
||||
|
||||
forward_iterator() : it_() {}
|
||||
explicit forward_iterator(It it) : it_(it) {}
|
||||
BOOST_CXX14_CONSTEXPR forward_iterator() : it_() {}
|
||||
BOOST_CXX14_CONSTEXPR explicit forward_iterator(It it) : it_(it) {}
|
||||
template <typename U>
|
||||
forward_iterator(const forward_iterator<U>& u) :it_(u.it_) {}
|
||||
BOOST_CXX14_CONSTEXPR forward_iterator(const forward_iterator<U>& u) :it_(u.it_) {}
|
||||
|
||||
reference operator*() const {return *it_;}
|
||||
pointer operator->() const {return it_;}
|
||||
BOOST_CXX14_CONSTEXPR reference operator*() const {return *it_;}
|
||||
BOOST_CXX14_CONSTEXPR pointer operator->() const {return it_;}
|
||||
|
||||
forward_iterator& operator++() {++it_; return *this;}
|
||||
forward_iterator operator++(int) {forward_iterator tmp(*this); ++(*this); return tmp;}
|
||||
BOOST_CXX14_CONSTEXPR forward_iterator& operator++() {++it_; return *this;}
|
||||
BOOST_CXX14_CONSTEXPR forward_iterator operator++(int) {forward_iterator tmp(*this); ++(*this); return tmp;}
|
||||
|
||||
friend bool operator==(const forward_iterator& x, const forward_iterator& y)
|
||||
BOOST_CXX14_CONSTEXPR friend bool operator==(const forward_iterator& x, const forward_iterator& y)
|
||||
{return x.it_ == y.it_;}
|
||||
friend bool operator!=(const forward_iterator& x, const forward_iterator& y)
|
||||
BOOST_CXX14_CONSTEXPR friend bool operator!=(const forward_iterator& x, const forward_iterator& y)
|
||||
{return !(x == y);}
|
||||
private:
|
||||
It it_;
|
||||
@ -103,14 +103,14 @@ private:
|
||||
};
|
||||
|
||||
template <typename T, typename U>
|
||||
inline bool
|
||||
BOOST_CXX14_CONSTEXPR inline bool
|
||||
operator==(const forward_iterator<T>& x, const forward_iterator<U>& y)
|
||||
{
|
||||
return x.base() == y.base();
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
inline bool
|
||||
BOOST_CXX14_CONSTEXPR inline bool
|
||||
operator!=(const forward_iterator<T>& x, const forward_iterator<U>& y)
|
||||
{
|
||||
return !(x == y);
|
||||
@ -127,35 +127,35 @@ public:
|
||||
typedef It pointer;
|
||||
typedef typename std::iterator_traits<It>::reference reference;
|
||||
|
||||
It base() const {return it_;}
|
||||
BOOST_CXX14_CONSTEXPR It base() const {return it_;}
|
||||
|
||||
bidirectional_iterator() : it_() {}
|
||||
explicit bidirectional_iterator(It it) : it_(it) {}
|
||||
BOOST_CXX14_CONSTEXPR bidirectional_iterator() : it_() {}
|
||||
BOOST_CXX14_CONSTEXPR explicit bidirectional_iterator(It it) : it_(it) {}
|
||||
template <typename U>
|
||||
bidirectional_iterator(const bidirectional_iterator<U>& u) :it_(u.it_) {}
|
||||
BOOST_CXX14_CONSTEXPR bidirectional_iterator(const bidirectional_iterator<U>& u) :it_(u.it_) {}
|
||||
|
||||
reference operator*() const {return *it_;}
|
||||
pointer operator->() const {return it_;}
|
||||
BOOST_CXX14_CONSTEXPR reference operator*() const {return *it_;}
|
||||
BOOST_CXX14_CONSTEXPR pointer operator->() const {return it_;}
|
||||
|
||||
bidirectional_iterator& operator++() {++it_; return *this;}
|
||||
bidirectional_iterator operator++(int) {bidirectional_iterator tmp(*this); ++(*this); return tmp;}
|
||||
BOOST_CXX14_CONSTEXPR bidirectional_iterator& operator++() {++it_; return *this;}
|
||||
BOOST_CXX14_CONSTEXPR bidirectional_iterator operator++(int) {bidirectional_iterator tmp(*this); ++(*this); return tmp;}
|
||||
|
||||
bidirectional_iterator& operator--() {--it_; return *this;}
|
||||
bidirectional_iterator operator--(int) {bidirectional_iterator tmp(*this); --(*this); return tmp;}
|
||||
BOOST_CXX14_CONSTEXPR bidirectional_iterator& operator--() {--it_; return *this;}
|
||||
BOOST_CXX14_CONSTEXPR bidirectional_iterator operator--(int) {bidirectional_iterator tmp(*this); --(*this); return tmp;}
|
||||
private:
|
||||
It it_;
|
||||
template <typename U> friend class bidirectional_iterator;
|
||||
};
|
||||
|
||||
template <typename T, typename U>
|
||||
inline bool
|
||||
BOOST_CXX14_CONSTEXPR inline bool
|
||||
operator==(const bidirectional_iterator<T>& x, const bidirectional_iterator<U>& y)
|
||||
{
|
||||
return x.base() == y.base();
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
inline bool
|
||||
BOOST_CXX14_CONSTEXPR inline bool
|
||||
operator!=(const bidirectional_iterator<T>& x, const bidirectional_iterator<U>& y)
|
||||
{
|
||||
return !(x == y);
|
||||
@ -172,30 +172,30 @@ public:
|
||||
typedef It pointer;
|
||||
typedef typename std::iterator_traits<It>::reference reference;
|
||||
|
||||
It base() const {return it_;}
|
||||
BOOST_CXX14_CONSTEXPR It base() const {return it_;}
|
||||
|
||||
random_access_iterator() : it_() {}
|
||||
explicit random_access_iterator(It it) : it_(it) {}
|
||||
BOOST_CXX14_CONSTEXPR random_access_iterator() : it_() {}
|
||||
BOOST_CXX14_CONSTEXPR explicit random_access_iterator(It it) : it_(it) {}
|
||||
template <typename U>
|
||||
random_access_iterator(const random_access_iterator<U>& u) :it_(u.it_) {}
|
||||
BOOST_CXX14_CONSTEXPR random_access_iterator(const random_access_iterator<U>& u) :it_(u.it_) {}
|
||||
|
||||
reference operator*() const {return *it_;}
|
||||
pointer operator->() const {return it_;}
|
||||
BOOST_CXX14_CONSTEXPR reference operator*() const {return *it_;}
|
||||
BOOST_CXX14_CONSTEXPR pointer operator->() const {return it_;}
|
||||
|
||||
random_access_iterator& operator++() {++it_; return *this;}
|
||||
random_access_iterator operator++(int) {random_access_iterator tmp(*this); ++(*this); return tmp;}
|
||||
BOOST_CXX14_CONSTEXPR random_access_iterator& operator++() {++it_; return *this;}
|
||||
BOOST_CXX14_CONSTEXPR random_access_iterator operator++(int) {random_access_iterator tmp(*this); ++(*this); return tmp;}
|
||||
|
||||
random_access_iterator& operator--() {--it_; return *this;}
|
||||
random_access_iterator operator--(int) {random_access_iterator tmp(*this); --(*this); return tmp;}
|
||||
BOOST_CXX14_CONSTEXPR random_access_iterator& operator--() {--it_; return *this;}
|
||||
BOOST_CXX14_CONSTEXPR random_access_iterator operator--(int) {random_access_iterator tmp(*this); --(*this); return tmp;}
|
||||
|
||||
random_access_iterator& operator+=(difference_type n) {it_ += n; return *this;}
|
||||
random_access_iterator operator+ (difference_type n) const {random_access_iterator tmp(*this); tmp += n; return tmp;}
|
||||
friend random_access_iterator operator+(difference_type n, random_access_iterator x) {x += n; return x;}
|
||||
BOOST_CXX14_CONSTEXPR random_access_iterator& operator+=(difference_type n) {it_ += n; return *this;}
|
||||
BOOST_CXX14_CONSTEXPR random_access_iterator operator+ (difference_type n) const {random_access_iterator tmp(*this); tmp += n; return tmp;}
|
||||
BOOST_CXX14_CONSTEXPR friend random_access_iterator operator+(difference_type n, random_access_iterator x) {x += n; return x;}
|
||||
|
||||
random_access_iterator& operator-=(difference_type n) {return *this += -n;}
|
||||
random_access_iterator operator- (difference_type n) const {random_access_iterator tmp(*this); tmp -= n; return tmp;}
|
||||
BOOST_CXX14_CONSTEXPR random_access_iterator& operator-=(difference_type n) {return *this += -n;}
|
||||
BOOST_CXX14_CONSTEXPR random_access_iterator operator- (difference_type n) const {random_access_iterator tmp(*this); tmp -= n; return tmp;}
|
||||
|
||||
reference operator[](difference_type n) const {return it_[n];}
|
||||
BOOST_CXX14_CONSTEXPR reference operator[](difference_type n) const {return it_[n];}
|
||||
private:
|
||||
It it_;
|
||||
|
||||
@ -203,49 +203,49 @@ private:
|
||||
};
|
||||
|
||||
template <typename T, typename U>
|
||||
inline bool
|
||||
BOOST_CXX14_CONSTEXPR inline bool
|
||||
operator==(const random_access_iterator<T>& x, const random_access_iterator<U>& y)
|
||||
{
|
||||
return x.base() == y.base();
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
inline bool
|
||||
BOOST_CXX14_CONSTEXPR inline bool
|
||||
operator!=(const random_access_iterator<T>& x, const random_access_iterator<U>& y)
|
||||
{
|
||||
return !(x == y);
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
inline bool
|
||||
BOOST_CXX14_CONSTEXPR inline bool
|
||||
operator<(const random_access_iterator<T>& x, const random_access_iterator<U>& y)
|
||||
{
|
||||
return x.base() < y.base();
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
inline bool
|
||||
BOOST_CXX14_CONSTEXPR inline bool
|
||||
operator<=(const random_access_iterator<T>& x, const random_access_iterator<U>& y)
|
||||
{
|
||||
return !(y < x);
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
inline bool
|
||||
BOOST_CXX14_CONSTEXPR inline bool
|
||||
operator>(const random_access_iterator<T>& x, const random_access_iterator<U>& y)
|
||||
{
|
||||
return y < x;
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
inline bool
|
||||
BOOST_CXX14_CONSTEXPR inline bool
|
||||
operator>=(const random_access_iterator<T>& x, const random_access_iterator<U>& y)
|
||||
{
|
||||
return !(x < y);
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
inline typename std::iterator_traits<T>::difference_type
|
||||
BOOST_CXX14_CONSTEXPR inline typename std::iterator_traits<T>::difference_type
|
||||
operator-(const random_access_iterator<T>& x, const random_access_iterator<U>& y)
|
||||
{
|
||||
return x.base() - y.base();
|
||||
@ -262,18 +262,18 @@ public:
|
||||
typedef It pointer;
|
||||
typedef typename std::iterator_traits<It>::reference reference;
|
||||
|
||||
It base() const {return it_;}
|
||||
BOOST_CXX14_CONSTEXPR It base() const {return it_;}
|
||||
|
||||
output_iterator () {}
|
||||
explicit output_iterator(It it) : it_(it) {}
|
||||
BOOST_CXX14_CONSTEXPR output_iterator () {}
|
||||
BOOST_CXX14_CONSTEXPR explicit output_iterator(It it) : it_(it) {}
|
||||
|
||||
template <typename U>
|
||||
output_iterator(const output_iterator<U>& u) :it_(u.it_) {}
|
||||
BOOST_CXX14_CONSTEXPR output_iterator(const output_iterator<U>& u) :it_(u.it_) {}
|
||||
|
||||
reference operator*() const {return *it_;}
|
||||
BOOST_CXX14_CONSTEXPR reference operator*() const {return *it_;}
|
||||
|
||||
output_iterator& operator++() {++it_; return *this;}
|
||||
output_iterator operator++(int) {output_iterator tmp(*this); ++(*this); return tmp;}
|
||||
BOOST_CXX14_CONSTEXPR output_iterator& operator++() {++it_; return *this;}
|
||||
BOOST_CXX14_CONSTEXPR output_iterator operator++(int) {output_iterator tmp(*this); ++(*this); return tmp;}
|
||||
|
||||
private:
|
||||
It it_;
|
||||
@ -285,21 +285,21 @@ private:
|
||||
|
||||
// == Get the base of an iterator; used for comparisons ==
|
||||
template <typename Iter>
|
||||
inline Iter base(output_iterator<Iter> i) { return i.base(); }
|
||||
BOOST_CXX14_CONSTEXPR inline Iter base(output_iterator<Iter> i) { return i.base(); }
|
||||
|
||||
template <typename Iter>
|
||||
inline Iter base(input_iterator<Iter> i) { return i.base(); }
|
||||
BOOST_CXX14_CONSTEXPR inline Iter base(input_iterator<Iter> i) { return i.base(); }
|
||||
|
||||
template <typename Iter>
|
||||
inline Iter base(forward_iterator<Iter> i) { return i.base(); }
|
||||
BOOST_CXX14_CONSTEXPR inline Iter base(forward_iterator<Iter> i) { return i.base(); }
|
||||
|
||||
template <typename Iter>
|
||||
inline Iter base(bidirectional_iterator<Iter> i) { return i.base(); }
|
||||
BOOST_CXX14_CONSTEXPR inline Iter base(bidirectional_iterator<Iter> i) { return i.base(); }
|
||||
|
||||
template <typename Iter>
|
||||
inline Iter base(random_access_iterator<Iter> i) { return i.base(); }
|
||||
BOOST_CXX14_CONSTEXPR inline Iter base(random_access_iterator<Iter> i) { return i.base(); }
|
||||
|
||||
template <typename Iter> // everything else
|
||||
inline Iter base(Iter i) { return i; }
|
||||
BOOST_CXX14_CONSTEXPR inline Iter base(Iter i) { return i; }
|
||||
|
||||
#endif // ITERATORS_H
|
||||
|
15
test/mclow.cpp
Normal file
15
test/mclow.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
#include <stdexcept>
|
||||
|
||||
#include <boost/exception/exception.hpp>
|
||||
#include <boost/throw_exception.hpp>
|
||||
|
||||
struct hex_decode_error : virtual boost::exception, virtual std::exception {};
|
||||
struct not_enough_input : virtual hex_decode_error {};
|
||||
struct non_hex_input : virtual hex_decode_error {};
|
||||
|
||||
void toss() { BOOST_THROW_EXCEPTION(not_enough_input()); }
|
||||
|
||||
int main () {
|
||||
try { toss(); }
|
||||
catch ( const hex_decode_error & /*ex*/ ) {}
|
||||
}
|
@ -16,149 +16,176 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
template <typename T>
|
||||
bool eq ( const T& a, const T& b ) { return a == b; }
|
||||
BOOST_CXX14_CONSTEXPR bool eq ( const T& a, const T& b ) { return a == b; }
|
||||
|
||||
template <typename T>
|
||||
bool never_eq ( const T&, const T& ) { return false; }
|
||||
BOOST_CXX14_CONSTEXPR bool never_eq ( const T&, const T& ) { return false; }
|
||||
|
||||
namespace ba = boost::algorithm;
|
||||
|
||||
template <typename Iter1, typename Iter2>
|
||||
bool iter_eq ( std::pair<Iter1, Iter2> pr, Iter1 first, Iter2 second ) {
|
||||
BOOST_CXX14_CONSTEXPR bool iter_eq ( std::pair<Iter1, Iter2> pr, Iter1 first, Iter2 second ) {
|
||||
return pr.first == first && pr.second == second;
|
||||
}
|
||||
|
||||
void test_mismatch ()
|
||||
{
|
||||
// Note: The literal values here are tested against directly, careful if you change them:
|
||||
int num[] = { 1, 1, 2, 3, 5 };
|
||||
BOOST_CXX14_CONSTEXPR int num[] = { 1, 1, 2, 3, 5 };
|
||||
const int sz = sizeof (num)/sizeof(num[0]);
|
||||
|
||||
|
||||
// No mismatch for empty sequences
|
||||
BOOST_CHECK ( iter_eq (
|
||||
ba::mismatch ( input_iterator<int *>(num), input_iterator<int *>(num),
|
||||
input_iterator<int *>(num), input_iterator<int *>(num)),
|
||||
input_iterator<int *>(num), input_iterator<int *>(num)));
|
||||
ba::mismatch ( input_iterator<const int *>(num), input_iterator<const int *>(num),
|
||||
input_iterator<const int *>(num), input_iterator<const int *>(num)),
|
||||
input_iterator<const int *>(num), input_iterator<const int *>(num)));
|
||||
BOOST_CHECK ( iter_eq (
|
||||
ba::mismatch ( input_iterator<int *>(num), input_iterator<int *>(num),
|
||||
input_iterator<int *>(num), input_iterator<int *>(num),
|
||||
ba::mismatch ( input_iterator<const int *>(num), input_iterator<const int *>(num),
|
||||
input_iterator<const int *>(num), input_iterator<const int *>(num),
|
||||
never_eq<int> ),
|
||||
input_iterator<int *>(num), input_iterator<int *>(num)));
|
||||
input_iterator<const int *>(num), input_iterator<const int *>(num)));
|
||||
|
||||
BOOST_CHECK ( iter_eq (
|
||||
ba::mismatch ( random_access_iterator<int *>(num), random_access_iterator<int *>(num),
|
||||
random_access_iterator<int *>(num), random_access_iterator<int *>(num),
|
||||
ba::mismatch ( random_access_iterator<const int *>(num), random_access_iterator<const int *>(num),
|
||||
random_access_iterator<const int *>(num), random_access_iterator<const int *>(num),
|
||||
never_eq<int> ),
|
||||
random_access_iterator<int *>(num), random_access_iterator<int *>(num)));
|
||||
random_access_iterator<const int *>(num), random_access_iterator<const int *>(num)));
|
||||
|
||||
// Empty vs. non-empty mismatch immediately
|
||||
BOOST_CHECK ( iter_eq (
|
||||
ba::mismatch ( input_iterator<int *>(num), input_iterator<int *>(num),
|
||||
input_iterator<int *>(num), input_iterator<int *>(num + 1)),
|
||||
input_iterator<int *>(num), input_iterator<int *>(num)));
|
||||
ba::mismatch ( input_iterator<const int *>(num), input_iterator<const int *>(num),
|
||||
input_iterator<const int *>(num), input_iterator<const int *>(num + 1)),
|
||||
input_iterator<const int *>(num), input_iterator<const int *>(num)));
|
||||
|
||||
BOOST_CHECK ( iter_eq (
|
||||
ba::mismatch ( input_iterator<int *>(num + 1), input_iterator<int *>(num + 2),
|
||||
input_iterator<int *>(num), input_iterator<int *>(num)),
|
||||
input_iterator<int *>(num + 1), input_iterator<int *>(num)));
|
||||
ba::mismatch ( input_iterator<const int *>(num + 1), input_iterator<const int *>(num + 2),
|
||||
input_iterator<const int *>(num), input_iterator<const int *>(num)),
|
||||
input_iterator<const int *>(num + 1), input_iterator<const int *>(num)));
|
||||
|
||||
BOOST_CHECK ( iter_eq (
|
||||
ba::mismatch ( random_access_iterator<int *>(num + 1), random_access_iterator<int *>(num + 2),
|
||||
random_access_iterator<int *>(num), random_access_iterator<int *>(num)),
|
||||
random_access_iterator<int *>(num + 1), random_access_iterator<int *>(num)));
|
||||
ba::mismatch ( random_access_iterator<const int *>(num + 1), random_access_iterator<const int *>(num + 2),
|
||||
random_access_iterator<const int *>(num), random_access_iterator<const int *>(num)),
|
||||
random_access_iterator<const int *>(num + 1), random_access_iterator<const int *>(num)));
|
||||
|
||||
// Single element sequences are equal if they contain the same value
|
||||
BOOST_CHECK ( iter_eq (
|
||||
ba::mismatch ( input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
||||
input_iterator<int *>(num), input_iterator<int *>(num + 1)),
|
||||
input_iterator<int *>(num + 1), input_iterator<int *>(num + 1)));
|
||||
ba::mismatch ( input_iterator<const int *>(num), input_iterator<const int *>(num + 1),
|
||||
input_iterator<const int *>(num), input_iterator<const int *>(num + 1)),
|
||||
input_iterator<const int *>(num + 1), input_iterator<const int *>(num + 1)));
|
||||
|
||||
BOOST_CHECK ( iter_eq (
|
||||
ba::mismatch ( input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
||||
input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
||||
ba::mismatch ( input_iterator<const int *>(num), input_iterator<const int *>(num + 1),
|
||||
input_iterator<const int *>(num), input_iterator<const int *>(num + 1),
|
||||
eq<int> ),
|
||||
input_iterator<int *>(num + 1), input_iterator<int *>(num + 1)));
|
||||
input_iterator<const int *>(num + 1), input_iterator<const int *>(num + 1)));
|
||||
|
||||
BOOST_CHECK ( iter_eq (
|
||||
ba::mismatch ( random_access_iterator<int *>(num), random_access_iterator<int *>(num + 1),
|
||||
random_access_iterator<int *>(num), random_access_iterator<int *>(num + 1),
|
||||
ba::mismatch ( random_access_iterator<const int *>(num), random_access_iterator<const int *>(num + 1),
|
||||
random_access_iterator<const int *>(num), random_access_iterator<const int *>(num + 1),
|
||||
eq<int> ),
|
||||
random_access_iterator<int *>(num + 1), random_access_iterator<int *>(num + 1)));
|
||||
random_access_iterator<const int *>(num + 1), random_access_iterator<const int *>(num + 1)));
|
||||
|
||||
|
||||
BOOST_CHECK ( iter_eq (
|
||||
ba::mismatch ( input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
||||
input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
||||
ba::mismatch ( input_iterator<const int *>(num), input_iterator<const int *>(num + 1),
|
||||
input_iterator<const int *>(num), input_iterator<const int *>(num + 1),
|
||||
never_eq<int> ),
|
||||
input_iterator<int *>(num), input_iterator<int *>(num)));
|
||||
input_iterator<const int *>(num), input_iterator<const int *>(num)));
|
||||
|
||||
BOOST_CHECK ( iter_eq (
|
||||
ba::mismatch ( random_access_iterator<int *>(num), random_access_iterator<int *>(num + 1),
|
||||
random_access_iterator<int *>(num), random_access_iterator<int *>(num + 1),
|
||||
ba::mismatch ( random_access_iterator<const int *>(num), random_access_iterator<const int *>(num + 1),
|
||||
random_access_iterator<const int *>(num), random_access_iterator<const int *>(num + 1),
|
||||
never_eq<int> ),
|
||||
random_access_iterator<int *>(num), random_access_iterator<int *>(num)));
|
||||
random_access_iterator<const int *>(num), random_access_iterator<const int *>(num)));
|
||||
|
||||
BOOST_CHECK ( iter_eq (
|
||||
ba::mismatch ( input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
||||
input_iterator<int *>(num + 1), input_iterator<int *>(num + 2)),
|
||||
input_iterator<int *>(num + 1), input_iterator<int *>(num + 2)));
|
||||
ba::mismatch ( input_iterator<const int *>(num), input_iterator<const int *>(num + 1),
|
||||
input_iterator<const int *>(num + 1), input_iterator<const int *>(num + 2)),
|
||||
input_iterator<const int *>(num + 1), input_iterator<const int *>(num + 2)));
|
||||
|
||||
BOOST_CHECK ( iter_eq (
|
||||
ba::mismatch ( input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
||||
input_iterator<int *>(num + 1), input_iterator<int *>(num + 2),
|
||||
ba::mismatch ( input_iterator<const int *>(num), input_iterator<const int *>(num + 1),
|
||||
input_iterator<const int *>(num + 1), input_iterator<const int *>(num + 2),
|
||||
eq<int> ),
|
||||
input_iterator<int *>(num + 1), input_iterator<int *>(num + 2)));
|
||||
input_iterator<const int *>(num + 1), input_iterator<const int *>(num + 2)));
|
||||
|
||||
BOOST_CHECK ( iter_eq (
|
||||
ba::mismatch ( input_iterator<int *>(num + 2), input_iterator<int *>(num + 3),
|
||||
input_iterator<int *>(num), input_iterator<int *>(num + 1)),
|
||||
input_iterator<int *>(num + 2), input_iterator<int *>(num)));
|
||||
ba::mismatch ( input_iterator<const int *>(num + 2), input_iterator<const int *>(num + 3),
|
||||
input_iterator<const int *>(num), input_iterator<const int *>(num + 1)),
|
||||
input_iterator<const int *>(num + 2), input_iterator<const int *>(num)));
|
||||
|
||||
BOOST_CHECK ( iter_eq (
|
||||
ba::mismatch ( input_iterator<int *>(num + 2), input_iterator<int *>(num + 3),
|
||||
input_iterator<int *>(num), input_iterator<int *>(num + 1),
|
||||
ba::mismatch ( input_iterator<const int *>(num + 2), input_iterator<const int *>(num + 3),
|
||||
input_iterator<const int *>(num), input_iterator<const int *>(num + 1),
|
||||
eq<int> ),
|
||||
input_iterator<int *>(num + 2), input_iterator<int *>(num)));
|
||||
input_iterator<const int *>(num + 2), input_iterator<const int *>(num)));
|
||||
|
||||
|
||||
|
||||
// Identical long sequences are equal.
|
||||
BOOST_CHECK ( iter_eq (
|
||||
ba::mismatch ( input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
||||
input_iterator<int *>(num), input_iterator<int *>(num + sz)),
|
||||
input_iterator<int *>(num + sz), input_iterator<int *>(num + sz)));
|
||||
ba::mismatch ( input_iterator<const int *>(num), input_iterator<const int *>(num + sz),
|
||||
input_iterator<const int *>(num), input_iterator<const int *>(num + sz)),
|
||||
input_iterator<const int *>(num + sz), input_iterator<const int *>(num + sz)));
|
||||
|
||||
BOOST_CHECK ( iter_eq (
|
||||
ba::mismatch ( input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
||||
input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
||||
ba::mismatch ( input_iterator<const int *>(num), input_iterator<const int *>(num + sz),
|
||||
input_iterator<const int *>(num), input_iterator<const int *>(num + sz),
|
||||
eq<int> ),
|
||||
input_iterator<int *>(num + sz), input_iterator<int *>(num + sz)));
|
||||
input_iterator<const int *>(num + sz), input_iterator<const int *>(num + sz)));
|
||||
|
||||
BOOST_CHECK ( iter_eq (
|
||||
ba::mismatch ( input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
||||
input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
||||
ba::mismatch ( input_iterator<const int *>(num), input_iterator<const int *>(num + sz),
|
||||
input_iterator<const int *>(num), input_iterator<const int *>(num + sz),
|
||||
never_eq<int> ),
|
||||
input_iterator<int *>(num), input_iterator<int *>(num)));
|
||||
input_iterator<const int *>(num), input_iterator<const int *>(num)));
|
||||
|
||||
BOOST_CHECK ( iter_eq (
|
||||
ba::mismatch ( input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
||||
random_access_iterator<int *>(num), random_access_iterator<int *>(num + sz),
|
||||
ba::mismatch ( input_iterator<const int *>(num), input_iterator<const int *>(num + sz),
|
||||
random_access_iterator<const int *>(num), random_access_iterator<const int *>(num + sz),
|
||||
never_eq<int> ),
|
||||
input_iterator<int *>(num), random_access_iterator<int *>(num)));
|
||||
input_iterator<const int *>(num), random_access_iterator<const int *>(num)));
|
||||
|
||||
// different sequences are different
|
||||
// Different sequences are different
|
||||
BOOST_CHECK ( iter_eq (
|
||||
ba::mismatch ( input_iterator<int *>(num + 1), input_iterator<int *>(num + sz),
|
||||
input_iterator<int *>(num), input_iterator<int *>(num + sz)),
|
||||
input_iterator<int *>(num + 2), input_iterator<int *>(num + 1)));
|
||||
ba::mismatch ( input_iterator<const int *>(num + 1), input_iterator<const int *>(num + sz),
|
||||
input_iterator<const int *>(num), input_iterator<const int *>(num + sz)),
|
||||
input_iterator<const int *>(num + 2), input_iterator<const int *>(num + 1)));
|
||||
|
||||
BOOST_CHECK ( iter_eq (
|
||||
ba::mismatch ( input_iterator<int *>(num + 1), input_iterator<int *>(num + sz),
|
||||
input_iterator<int *>(num), input_iterator<int *>(num + sz),
|
||||
ba::mismatch ( input_iterator<const int *>(num + 1), input_iterator<const int *>(num + sz),
|
||||
input_iterator<const int *>(num), input_iterator<const int *>(num + sz),
|
||||
eq<int> ),
|
||||
input_iterator<int *>(num + 2), input_iterator<int *>(num + 1)));
|
||||
|
||||
input_iterator<const int *>(num + 2), input_iterator<const int *>(num + 1)));
|
||||
|
||||
// Checks constexpr
|
||||
BOOST_CXX14_CONSTEXPR bool res = (
|
||||
// No mismatch for empty
|
||||
iter_eq (
|
||||
ba::mismatch ( input_iterator<const int *>(num), input_iterator<const int *>(num),
|
||||
input_iterator<const int *>(num), input_iterator<const int *>(num)),
|
||||
input_iterator<const int *>(num), input_iterator<const int *>(num))
|
||||
// Empty vs. non-empty mismatch immediately
|
||||
&& iter_eq (
|
||||
ba::mismatch ( input_iterator<const int *>(num), input_iterator<const int *>(num),
|
||||
input_iterator<const int *>(num), input_iterator<const int *>(num + 1)),
|
||||
input_iterator<const int *>(num), input_iterator<const int *>(num))
|
||||
// Single element sequences are equal if they contain the same value
|
||||
&& iter_eq (
|
||||
ba::mismatch ( input_iterator<const int *>(num), input_iterator<const int *>(num + 1),
|
||||
input_iterator<const int *>(num), input_iterator<const int *>(num + 1),
|
||||
eq<int>),
|
||||
input_iterator<const int *>(num + 1), input_iterator<const int *>(num + 1))
|
||||
// Identical long sequences are equal.
|
||||
&& iter_eq (
|
||||
ba::mismatch ( input_iterator<const int *>(num), input_iterator<const int *>(num + sz),
|
||||
input_iterator<const int *>(num), input_iterator<const int *>(num + sz),
|
||||
eq<int> ),
|
||||
input_iterator<const int *>(num + sz), input_iterator<const int *>(num + sz))
|
||||
);
|
||||
|
||||
BOOST_CHECK ( res );
|
||||
}
|
||||
|
||||
|
||||
|
@ -19,9 +19,8 @@
|
||||
|
||||
template<typename T>
|
||||
struct is_ {
|
||||
is_ ( T v ) : val_ ( v ) {}
|
||||
~is_ () {}
|
||||
bool operator () ( T comp ) const { return val_ == comp; }
|
||||
BOOST_CXX14_CONSTEXPR is_ ( T v ) : val_ ( v ) {}
|
||||
BOOST_CXX14_CONSTEXPR bool operator () ( T comp ) const { return val_ == comp; }
|
||||
private:
|
||||
is_ (); // need a value
|
||||
|
||||
@ -33,7 +32,7 @@ namespace ba = boost::algorithm;
|
||||
void test_none()
|
||||
{
|
||||
// Note: The literal values here are tested against directly, careful if you change them:
|
||||
int some_numbers[] = { 1, 5, 0, 18, 1 };
|
||||
BOOST_CXX14_CONSTEXPR int some_numbers[] = { 1, 5, 0, 18, 1 };
|
||||
std::vector<int> vi(some_numbers, some_numbers + 5);
|
||||
std::list<int> li(vi.begin(), vi.end ());
|
||||
|
||||
@ -89,6 +88,15 @@ void test_none()
|
||||
BOOST_CHECK ( ba::none_of_equal ( li.begin(), l_iter, 18 ));
|
||||
BOOST_CHECK ( ba::none_of ( li.begin(), l_iter, is_<int> ( 18 )));
|
||||
BOOST_CHECK (!ba::none_of ( li.begin(), l_iter, is_<int> ( 5 )));
|
||||
|
||||
BOOST_CXX14_CONSTEXPR bool constexpr_res =
|
||||
!ba::none_of_equal ( some_numbers, 1 ) &&
|
||||
!ba::none_of ( some_numbers, is_<int> ( 1 )) &&
|
||||
ba::none_of_equal ( some_numbers, some_numbers + 3, 100 ) &&
|
||||
ba::none_of ( some_numbers, some_numbers + 3, is_<int> ( 100 )) &&
|
||||
true;
|
||||
|
||||
BOOST_CHECK ( constexpr_res );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( test_main )
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user