├── .appveyor.yml ├── .codecov.yml ├── .gitattributes ├── .github └── workflows │ └── ci.yml ├── CMakeLists.txt ├── LICENSE ├── README.md ├── build.jam ├── doc ├── email_example.html ├── index.html ├── multi_index_container.html ├── my_vector_example.html └── style.css ├── include └── boost │ ├── assign.hpp │ └── assign │ ├── assignment_exception.hpp │ ├── list_inserter.hpp │ ├── list_of.hpp │ ├── ptr_list_inserter.hpp │ ├── ptr_list_of.hpp │ ├── ptr_map_inserter.hpp │ ├── std.hpp │ └── std │ ├── deque.hpp │ ├── list.hpp │ ├── map.hpp │ ├── queue.hpp │ ├── set.hpp │ ├── slist.hpp │ ├── stack.hpp │ └── vector.hpp ├── index.html ├── meta └── libraries.json └── test ├── Jamfile.v2 ├── array.cpp ├── basic.cpp ├── cmake_test ├── CMakeLists.txt └── main.cpp ├── compile └── decl_header.cpp ├── email_example.cpp ├── list_inserter.cpp ├── list_of.cpp ├── list_of_workaround.cpp ├── multi_index_container.cpp ├── my_vector_example.cpp ├── ptr_list_inserter.cpp ├── ptr_list_of.cpp ├── ptr_map_inserter.cpp ├── static_list_of.cpp ├── std.cpp └── tuple_list_of.cpp /.appveyor.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2016, 2017 Peter Dimov 2 | # Copyright 2017 - 2019 James E. King III 3 | # Copyright 2019 - 2021 Alexander Grund 4 | # Distributed under the Boost Software License, Version 1.0. 5 | # (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt) 6 | 7 | # 8 | # Generic Appveyor build script for boostorg repositories 9 | # See: https://github.com/boostorg/boost-ci/ 10 | # 11 | # Instructions for customizing this script for your library: 12 | # 13 | # 1. Customize the compilers and language levels you want. 14 | # 2. If you have more than include/, src/, test/, example/, examples/, 15 | # benchmark/ or tools/ directories, set the environment variable DEPINST. 16 | # For example if your build uses code in "bench/" and "fog/" directories: 17 | # - DEPINST: --include bench --include fog 18 | # 3. Enable pull request builds in your boostorg/ account. 19 | # 20 | # That's it - the script will do everything else for you. 21 | # 22 | 23 | version: 1.0.{build}-{branch} 24 | 25 | shallow_clone: true 26 | 27 | branches: 28 | only: 29 | - master 30 | - develop 31 | - /bugfix\/.*/ 32 | - /feature\/.*/ 33 | - /fix\/.*/ 34 | - /pr\/.*/ 35 | 36 | skip_commits: 37 | files: 38 | - LICENSE 39 | - meta/* 40 | - README.md 41 | 42 | matrix: 43 | fast_finish: false 44 | # Adding MAYFAIL to any matrix job allows it to fail but the build stays green: 45 | allow_failures: 46 | - MAYFAIL: true 47 | 48 | environment: 49 | global: 50 | B2_CI_VERSION: 1 51 | GIT_FETCH_JOBS: 4 52 | # see: http://www.boost.org/build/doc/html/bbv2/overview/invocation.html#bbv2.overview.invocation.properties 53 | # to use the default for a given environment, comment it out; recommend you build debug and release however: 54 | # on Windows it is important to exercise all the possibilities, especially shared vs static, however most 55 | # libraries that care about this exercise it in their Jamfiles... 56 | B2_ADDRESS_MODEL: 32,64 57 | B2_LINK: shared,static 58 | # B2_THREADING: threading=multi,single 59 | B2_VARIANT: release 60 | 61 | matrix: 62 | - FLAVOR: Visual Studio 2017 C++2a Strict 63 | APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 64 | B2_CXXFLAGS: -permissive- 65 | B2_CXXSTD: 2a 66 | B2_TOOLSET: msvc-14.1 67 | 68 | - FLAVOR: Visual Studio 2017 C++14/17 69 | APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 70 | B2_CXXSTD: 14,17 71 | B2_TOOLSET: msvc-14.1 72 | 73 | - FLAVOR: cygwin (32-bit) 74 | APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 75 | ADDPATH: C:\cygwin\bin; 76 | B2_ADDRESS_MODEL: 32 77 | B2_CXXSTD: 11,14,1z 78 | B2_TOOLSET: gcc 79 | 80 | - FLAVOR: cygwin (64-bit) 81 | APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 82 | ADDPATH: C:\cygwin64\bin; 83 | B2_ADDRESS_MODEL: 64 84 | B2_CXXSTD: 11,14,1z 85 | B2_TOOLSET: gcc 86 | 87 | install: 88 | - git clone --depth 1 https://github.com/boostorg/boost-ci.git C:\boost-ci-cloned 89 | # Copy ci folder if not testing Boost.CI 90 | - if NOT "%APPVEYOR_PROJECT_NAME%" == "boost-ci" xcopy /s /e /q /i /y C:\boost-ci-cloned\ci .\ci 91 | - rmdir /s /q C:\boost-ci-cloned 92 | - ci\appveyor\install.bat 93 | 94 | build: off 95 | 96 | test_script: ci\build.bat 97 | 98 | -------------------------------------------------------------------------------- /.codecov.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2019 - 2021 Alexander Grund 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt) 4 | # 5 | # Sample codecov configuration file. Edit as required 6 | 7 | codecov: 8 | max_report_age: off 9 | require_ci_to_pass: yes 10 | notify: 11 | # Increase this if you have multiple coverage collection jobs 12 | after_n_builds: 2 13 | wait_for_ci: yes 14 | 15 | parsers: 16 | gcov: 17 | branch_detection: 18 | conditional: yes 19 | loop: yes 20 | method: no 21 | macro: no 22 | 23 | # Change how pull request comments look 24 | comment: 25 | layout: "reach,diff,flags,files,footer" 26 | 27 | # Ignore specific files or folders. Glob patterns are supported. 28 | # See https://docs.codecov.com/docs/ignoring-paths 29 | ignore: 30 | - libs/assign/test/ 31 | - test/ 32 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto !eol svneol=native#text/plain 2 | *.gitattributes text svneol=native#text/plain 3 | 4 | # Scriptish formats 5 | *.bat text svneol=native#text/plain 6 | *.bsh text svneol=native#text/x-beanshell 7 | *.cgi text svneol=native#text/plain 8 | *.cmd text svneol=native#text/plain 9 | *.js text svneol=native#text/javascript 10 | *.php text svneol=native#text/x-php 11 | *.pl text svneol=native#text/x-perl 12 | *.pm text svneol=native#text/x-perl 13 | *.py text svneol=native#text/x-python 14 | *.sh eol=lf svneol=LF#text/x-sh 15 | configure eol=lf svneol=LF#text/x-sh 16 | 17 | # Image formats 18 | *.bmp binary svneol=unset#image/bmp 19 | *.gif binary svneol=unset#image/gif 20 | *.ico binary svneol=unset#image/ico 21 | *.jpeg binary svneol=unset#image/jpeg 22 | *.jpg binary svneol=unset#image/jpeg 23 | *.png binary svneol=unset#image/png 24 | *.tif binary svneol=unset#image/tiff 25 | *.tiff binary svneol=unset#image/tiff 26 | *.svg text svneol=native#image/svg%2Bxml 27 | 28 | # Data formats 29 | *.pdf binary svneol=unset#application/pdf 30 | *.avi binary svneol=unset#video/avi 31 | *.doc binary svneol=unset#application/msword 32 | *.dsp text svneol=crlf#text/plain 33 | *.dsw text svneol=crlf#text/plain 34 | *.eps binary svneol=unset#application/postscript 35 | *.gz binary svneol=unset#application/gzip 36 | *.mov binary svneol=unset#video/quicktime 37 | *.mp3 binary svneol=unset#audio/mpeg 38 | *.ppt binary svneol=unset#application/vnd.ms-powerpoint 39 | *.ps binary svneol=unset#application/postscript 40 | *.psd binary svneol=unset#application/photoshop 41 | *.rdf binary svneol=unset#text/rdf 42 | *.rss text svneol=unset#text/xml 43 | *.rtf binary svneol=unset#text/rtf 44 | *.sln text svneol=native#text/plain 45 | *.swf binary svneol=unset#application/x-shockwave-flash 46 | *.tgz binary svneol=unset#application/gzip 47 | *.vcproj text svneol=native#text/xml 48 | *.vcxproj text svneol=native#text/xml 49 | *.vsprops text svneol=native#text/xml 50 | *.wav binary svneol=unset#audio/wav 51 | *.xls binary svneol=unset#application/vnd.ms-excel 52 | *.zip binary svneol=unset#application/zip 53 | 54 | # Text formats 55 | .htaccess text svneol=native#text/plain 56 | *.bbk text svneol=native#text/xml 57 | *.cmake text svneol=native#text/plain 58 | *.css text svneol=native#text/css 59 | *.dtd text svneol=native#text/xml 60 | *.htm text svneol=native#text/html 61 | *.html text svneol=native#text/html 62 | *.ini text svneol=native#text/plain 63 | *.log text svneol=native#text/plain 64 | *.mak text svneol=native#text/plain 65 | *.qbk text svneol=native#text/plain 66 | *.rst text svneol=native#text/plain 67 | *.sql text svneol=native#text/x-sql 68 | *.txt text svneol=native#text/plain 69 | *.xhtml text svneol=native#text/xhtml%2Bxml 70 | *.xml text svneol=native#text/xml 71 | *.xsd text svneol=native#text/xml 72 | *.xsl text svneol=native#text/xml 73 | *.xslt text svneol=native#text/xml 74 | *.xul text svneol=native#text/xul 75 | *.yml text svneol=native#text/plain 76 | boost-no-inspect text svneol=native#text/plain 77 | CHANGES text svneol=native#text/plain 78 | COPYING text svneol=native#text/plain 79 | INSTALL text svneol=native#text/plain 80 | Jamfile text svneol=native#text/plain 81 | Jamroot text svneol=native#text/plain 82 | Jamfile.v2 text svneol=native#text/plain 83 | Jamrules text svneol=native#text/plain 84 | Makefile* text svneol=native#text/plain 85 | README text svneol=native#text/plain 86 | TODO text svneol=native#text/plain 87 | 88 | # Code formats 89 | *.c text svneol=native#text/plain 90 | *.cpp text svneol=native#text/plain 91 | *.h text svneol=native#text/plain 92 | *.hpp text svneol=native#text/plain 93 | *.ipp text svneol=native#text/plain 94 | *.tpp text svneol=native#text/plain 95 | *.jam text svneol=native#text/plain 96 | *.java text svneol=native#text/plain 97 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2020-2021 Peter Dimov 2 | # Copyright 2021 Andrey Semashev 3 | # Copyright 2021 Alexander Grund 4 | # Copyright 2022-2024 James E. King III 5 | # 6 | # Distributed under the Boost Software License, Version 1.0. 7 | # (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt) 8 | --- 9 | name: CI 10 | 11 | on: 12 | pull_request: 13 | push: 14 | branches: 15 | - master 16 | - develop 17 | - bugfix/** 18 | - feature/** 19 | - fix/** 20 | - pr/** 21 | paths-ignore: 22 | - LICENSE 23 | - meta/** 24 | - README.md 25 | 26 | concurrency: 27 | group: ${{format('{0}:{1}', github.repository, github.ref)}} 28 | cancel-in-progress: true 29 | 30 | env: 31 | GIT_FETCH_JOBS: 8 32 | NET_RETRY_COUNT: 5 33 | B2_CI_VERSION: 1 34 | B2_VARIANT: debug,release 35 | B2_LINK: shared,static 36 | LCOV_BRANCH_COVERAGE: 0 37 | 38 | jobs: 39 | posix: 40 | defaults: 41 | run: 42 | shell: bash 43 | 44 | strategy: 45 | fail-fast: false 46 | matrix: 47 | include: 48 | # linux, gcc 49 | - { compiler: gcc-7, cxxstd: '11,14,17', os: ubuntu-20.04 } 50 | - { compiler: gcc-8, cxxstd: '11,14,17,2a', os: ubuntu-20.04 } 51 | - { compiler: gcc-9, cxxstd: '11,14,17,2a', os: ubuntu-20.04 } 52 | - { compiler: gcc-10, cxxstd: '11,14,17,20', os: ubuntu-20.04 } 53 | - { compiler: gcc-11, cxxstd: '11,14,17,20', os: ubuntu-20.04 } 54 | - { compiler: gcc-12, cxxstd: '11,14,17,20', os: ubuntu-22.04 } 55 | - { compiler: gcc-13, cxxstd: '11,14,17,20,2b', os: ubuntu-22.04 } 56 | - { compiler: gcc-14, cxxstd: '11,14,17,20,2b', os: ubuntu-24.04 } 57 | - { name: GCC w/ sanitizers, sanitize: yes, 58 | compiler: gcc-13, cxxstd: '11,14,17,20', os: ubuntu-22.04 } 59 | - { name: Collect coverage, coverage: yes, 60 | compiler: gcc-12, cxxstd: '11', os: ubuntu-22.04, install: 'g++-12-multilib', address-model: '32,64' } 61 | 62 | # linux, clang 63 | - { compiler: clang-9, cxxstd: '11,14,17,2a', os: ubuntu-20.04 } 64 | - { compiler: clang-10, cxxstd: '11,14,17,20', os: ubuntu-20.04 } 65 | - { compiler: clang-11, cxxstd: '11,14,17,20', os: ubuntu-20.04 } 66 | - { compiler: clang-12, cxxstd: '11,14,17,20', os: ubuntu-20.04 } 67 | # Clang isn't compatible with libstdc++-13, so use the slightly older one 68 | - { compiler: clang-13, cxxstd: '11,14,17,20', os: ubuntu-22.04, install: 'clang-13 g++-12', gcc_toolchain: 12 } 69 | - { compiler: clang-14, cxxstd: '11,14,17,20', os: ubuntu-22.04, install: 'clang-14 g++-12', gcc_toolchain: 12 } 70 | - { compiler: clang-15, cxxstd: '11,14,17,20', os: ubuntu-22.04, install: 'clang-15 g++-12', gcc_toolchain: 12 } 71 | - { compiler: clang-16, cxxstd: '11,14,17,20,2b', os: ubuntu-24.04 } 72 | # https://github.com/llvm/llvm-project/issues/59827: disabled 2b/23 for clang-17 with libstdc++13 in 24.04 73 | - { compiler: clang-17, cxxstd: '11,14,17,20', os: ubuntu-24.04 } 74 | - { compiler: clang-18, cxxstd: '11,17,20,23,2c', os: ubuntu-24.04 } 75 | 76 | # linux, libc++ 77 | - { name: Clang w/ sanitizers, sanitize: yes, 78 | compiler: clang-12, cxxstd: '11,14,17,20', os: ubuntu-20.04, stdlib: 'libc++', install: 'clang-12 libc++-12-dev libc++abi-12-dev' } 79 | 80 | - { name: MacOS w/ clang and sanitizers, 81 | compiler: clang, cxxstd: '11,14,17,20,2b', os: macos-13, sanitize: yes } 82 | - { compiler: clang, cxxstd: '11,14,17,20,2b', os: macos-14 } 83 | - { compiler: clang, cxxstd: '11,14,17,20,2b', os: macos-15 } 84 | 85 | # Coverity Scan 86 | # requires two github secrets in repo to activate; see ci/github/coverity.sh 87 | # does not run on pull requests, only on pushes into develop and master 88 | - { name: Coverity, coverity: yes, 89 | compiler: clang-12, cxxstd: '17', os: ubuntu-20.04, ccache: no } 90 | 91 | # multiarch (bigendian testing) - does not support coverage yet 92 | - { name: Big-endian, multiarch: yes, 93 | compiler: clang, cxxstd: '17', os: ubuntu-22.04, ccache: no, distro: fedora, edition: 34, arch: s390x } 94 | 95 | timeout-minutes: 120 96 | runs-on: ${{matrix.os}} 97 | env: {B2_USE_CCACHE: 1} 98 | 99 | steps: 100 | - name: Setup environment 101 | run: | 102 | if [ -f "/etc/debian_version" ]; then 103 | echo "DEBIAN_FRONTEND=noninteractive" >> $GITHUB_ENV 104 | export DEBIAN_FRONTEND=noninteractive 105 | fi 106 | if [ -n "${{matrix.container}}" ] && [ -f "/etc/debian_version" ]; then 107 | apt-get -o Acquire::Retries=$NET_RETRY_COUNT update 108 | apt-get -o Acquire::Retries=$NET_RETRY_COUNT install -y sudo software-properties-common curl 109 | # Need (newer) git, and the older Ubuntu container may require requesting the key manually using port 80 110 | curl -sSL --retry ${NET_RETRY_COUNT:-5} 'http://keyserver.ubuntu.com/pks/lookup?op=get&search=0xE1DD270288B4E6030699E45FA1715D88E1DF1F24' | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/git-core_ubuntu_ppa.gpg 111 | for i in {1..${NET_RETRY_COUNT:-3}}; do sudo -E add-apt-repository -y ppa:git-core/ppa && break || sleep 10; done 112 | apt-get -o Acquire::Retries=$NET_RETRY_COUNT update 113 | osver=$(lsb_release -sr | cut -f1 -d.) 114 | pkgs="g++ git xz-utils" 115 | # Ubuntu 22+ has only Python 3 in the repos 116 | if [ -n "$osver" ] && [ "$osver" -ge "22" ]; then 117 | pkgs+=" python-is-python3 libpython3-dev" 118 | else 119 | pkgs+=" python libpython-dev" 120 | fi 121 | apt-get -o Acquire::Retries=$NET_RETRY_COUNT install -y $pkgs 122 | fi 123 | # For jobs not compatible with ccache, use "ccache: no" in the matrix 124 | if [[ "${{ matrix.ccache }}" == "no" ]]; then 125 | echo "B2_USE_CCACHE=0" >> $GITHUB_ENV 126 | fi 127 | git config --global pack.threads 0 128 | if [[ "${{matrix.container}}" == "ubuntu:1"* ]]; then 129 | # Node 20 doesn't work with Ubuntu 16/18 glibc: https://github.com/actions/checkout/issues/1590 130 | curl -sL https://archives.boost.io/misc/node/node-v20.9.0-linux-x64-glibc-217.tar.xz | tar -xJ --strip-components 1 -C /node20217 131 | fi 132 | 133 | - uses: actions/checkout@v4 134 | with: 135 | # For coverage builds fetch the whole history, else only 1 commit using a 'fake ternary' 136 | fetch-depth: ${{ matrix.coverage && '0' || '1' }} 137 | 138 | - name: Cache ccache 139 | uses: actions/cache@v4 140 | if: env.B2_USE_CCACHE 141 | with: 142 | path: ~/.ccache 143 | key: ${{matrix.os}}-${{matrix.container}}-${{matrix.compiler}}-${{github.sha}} 144 | restore-keys: ${{matrix.os}}-${{matrix.container}}-${{matrix.compiler}}- 145 | 146 | - name: Fetch Boost.CI 147 | uses: actions/checkout@v4 148 | with: 149 | repository: boostorg/boost-ci 150 | ref: master 151 | path: boost-ci-cloned 152 | 153 | - name: Get CI scripts folder 154 | run: | 155 | # Copy ci folder if not testing Boost.CI 156 | [[ "$GITHUB_REPOSITORY" =~ "boost-ci" ]] || cp -r boost-ci-cloned/ci . 157 | rm -rf boost-ci-cloned 158 | 159 | - name: Install packages 160 | if: startsWith(matrix.os, 'ubuntu') 161 | run: | 162 | SOURCE_KEYS=("${{join(matrix.source_keys, '" "')}}") 163 | SOURCES=("${{join(matrix.sources, '" "')}}") 164 | # Add this by default 165 | SOURCE_KEYS+=('http://keyserver.ubuntu.com/pks/lookup?op=get&search=0x1E9377A2BA9EF27F') 166 | SOURCES+=(ppa:ubuntu-toolchain-r/test) 167 | 168 | ci/add-apt-keys.sh "${SOURCE_KEYS[@]}" 169 | # Initial update before adding sources required to get e.g. keys 170 | sudo apt-get -o Acquire::Retries=$NET_RETRY_COUNT update 171 | ci/add-apt-repositories.sh "${SOURCES[@]}" 172 | 173 | sudo apt-get -o Acquire::Retries=$NET_RETRY_COUNT update 174 | if [[ -z "${{matrix.install}}" ]]; then 175 | pkgs="${{matrix.compiler}}" 176 | pkgs="${pkgs/gcc-/g++-}" 177 | else 178 | pkgs="${{matrix.install}}" 179 | fi 180 | sudo apt-get -o Acquire::Retries=$NET_RETRY_COUNT install -y $pkgs 181 | 182 | - name: Setup GCC Toolchain 183 | if: matrix.gcc_toolchain 184 | run: | 185 | GCC_TOOLCHAIN_ROOT="$HOME/gcc-toolchain" 186 | echo "GCC_TOOLCHAIN_ROOT=$GCC_TOOLCHAIN_ROOT" >> $GITHUB_ENV 187 | if ! command -v dpkg-architecture; then 188 | apt-get install -y dpkg-dev 189 | fi 190 | MULTIARCH_TRIPLET="$(dpkg-architecture -qDEB_HOST_MULTIARCH)" 191 | mkdir -p "$GCC_TOOLCHAIN_ROOT" 192 | ln -s /usr/include "$GCC_TOOLCHAIN_ROOT/include" 193 | ln -s /usr/bin "$GCC_TOOLCHAIN_ROOT/bin" 194 | mkdir -p "$GCC_TOOLCHAIN_ROOT/lib/gcc/$MULTIARCH_TRIPLET" 195 | ln -s "/usr/lib/gcc/$MULTIARCH_TRIPLET/${{matrix.gcc_toolchain}}" "$GCC_TOOLCHAIN_ROOT/lib/gcc/$MULTIARCH_TRIPLET/${{matrix.gcc_toolchain}}" 196 | 197 | - name: Setup multiarch 198 | if: matrix.multiarch 199 | env: 200 | BDDE_DISTRO: ${{matrix.distro}} 201 | BDDE_EDITION: ${{matrix.edition}} 202 | BDDE_ARCH: ${{matrix.arch}} 203 | run: ci/github/setup_bdde.sh 204 | 205 | - name: Setup Boost 206 | env: 207 | B2_ADDRESS_MODEL: ${{matrix.address-model}} 208 | B2_COMPILER: ${{matrix.compiler}} 209 | B2_CXXSTD: ${{matrix.cxxstd}} 210 | B2_SANITIZE: ${{matrix.sanitize}} 211 | B2_STDLIB: ${{matrix.stdlib}} 212 | # More entries can be added in the same way, see the B2_ARGS assignment in ci/enforce.sh for the possible keys. 213 | # B2_DEFINES: ${{matrix.defines}} 214 | # Variables set here (to non-empty) will override the top-level environment variables, e.g. 215 | # B2_VARIANT: ${{matrix.variant}} 216 | # Set the (B2) target(s) to build, defaults to the test folder of the current library 217 | # Can alternatively be done like this in the build step or in the build command of the build step, e.g. `run: B2_TARGETS=libs/$SELF/doc ci/build.sh` 218 | # B2_TARGETS: libs/foo/test//bar 219 | run: source ci/github/install.sh 220 | 221 | - name: Setup coverage collection 222 | if: matrix.coverage 223 | run: ci/github/codecov.sh "setup" 224 | 225 | - name: Run tests 226 | if: '!matrix.coverity' 227 | run: ci/build.sh 228 | 229 | - name: Upload coverage 230 | if: matrix.coverage 231 | run: ci/codecov.sh "upload" 232 | env: 233 | CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} 234 | 235 | - name: Run coverity 236 | if: matrix.coverity && github.event_name == 'push' && (github.ref_name == 'develop' || github.ref_name == 'master') 237 | run: ci/github/coverity.sh 238 | env: 239 | COVERITY_SCAN_NOTIFICATION_EMAIL: ${{ secrets.COVERITY_SCAN_NOTIFICATION_EMAIL }} 240 | COVERITY_SCAN_TOKEN: ${{ secrets.COVERITY_SCAN_TOKEN }} 241 | 242 | windows: 243 | defaults: 244 | run: 245 | shell: cmd 246 | strategy: 247 | fail-fast: false 248 | matrix: 249 | include: 250 | - { toolset: msvc-14.0, cxxstd: '14,latest', addrmd: '32,64', os: windows-2019 } 251 | - { toolset: msvc-14.2, cxxstd: '14,17,20', addrmd: '32,64', os: windows-2019 } 252 | - { toolset: msvc-14.3, cxxstd: '14,17,20,latest',addrmd: '32,64', os: windows-2022 } 253 | - { name: Collect coverage, coverage: yes, 254 | toolset: msvc-14.3, cxxstd: 'latest', addrmd: '64', os: windows-2022 } 255 | - { toolset: clang-win, cxxstd: '14,17,latest', addrmd: '32,64', os: windows-2022 } 256 | - { toolset: gcc, cxxstd: '11,14,17,2a', addrmd: '64', os: windows-2019 } 257 | 258 | runs-on: ${{matrix.os}} 259 | 260 | steps: 261 | - uses: actions/checkout@v4 262 | 263 | - name: Fetch Boost.CI 264 | uses: actions/checkout@v4 265 | with: 266 | repository: boostorg/boost-ci 267 | ref: master 268 | path: boost-ci-cloned 269 | - name: Get CI scripts folder 270 | run: | 271 | REM Copy ci folder if not testing Boost.CI 272 | if "%GITHUB_REPOSITORY%" == "%GITHUB_REPOSITORY:boost-ci=%" xcopy /s /e /q /i /y boost-ci-cloned\ci .\ci 273 | rmdir /s /q boost-ci-cloned 274 | 275 | - name: Setup Boost 276 | run: ci\github\install.bat 277 | 278 | - name: Run tests 279 | if: '!matrix.coverage' 280 | run: ci\build.bat 281 | env: 282 | B2_TOOLSET: ${{matrix.toolset}} 283 | B2_CXXSTD: ${{matrix.cxxstd}} 284 | B2_ADDRESS_MODEL: ${{matrix.addrmd}} 285 | 286 | - name: Collect coverage 287 | shell: powershell 288 | if: matrix.coverage 289 | run: ci\opencppcoverage.ps1 290 | env: 291 | B2_TOOLSET: ${{matrix.toolset}} 292 | B2_CXXSTD: ${{matrix.cxxstd}} 293 | B2_ADDRESS_MODEL: ${{matrix.addrmd}} 294 | 295 | - name: Upload coverage 296 | if: matrix.coverage 297 | uses: codecov/codecov-action@v5 298 | with: 299 | disable_search: true 300 | fail_ci_if_error: true 301 | files: __out/cobertura.xml 302 | name: github-actions 303 | token: ${{secrets.CODECOV_TOKEN}} 304 | verbose: true 305 | 306 | MSYS2: 307 | defaults: 308 | run: 309 | shell: msys2 {0} 310 | strategy: 311 | fail-fast: false 312 | matrix: 313 | include: 314 | - { sys: MINGW32, compiler: gcc, cxxstd: '11,17,20' } 315 | - { sys: MINGW64, compiler: gcc, cxxstd: '11,17,20' } 316 | 317 | runs-on: windows-latest 318 | 319 | steps: 320 | - uses: actions/checkout@v4 321 | 322 | - name: Setup MSYS2 environment 323 | uses: msys2/setup-msys2@v2 324 | with: 325 | msystem: ${{matrix.sys}} 326 | update: true 327 | install: git python 328 | pacboy: gcc:p cmake:p ninja:p 329 | 330 | - name: Fetch Boost.CI 331 | uses: actions/checkout@v4 332 | with: 333 | repository: boostorg/boost-ci 334 | ref: master 335 | path: boost-ci-cloned 336 | - name: Get CI scripts folder 337 | run: | 338 | # Copy ci folder if not testing Boost.CI 339 | [[ "$GITHUB_REPOSITORY" =~ "boost-ci" ]] || cp -r boost-ci-cloned/ci . 340 | rm -rf boost-ci-cloned 341 | 342 | - name: Setup Boost 343 | env: 344 | B2_COMPILER: ${{matrix.compiler}} 345 | B2_CXXSTD: ${{matrix.cxxstd}} 346 | B2_SANITIZE: ${{matrix.sanitize}} 347 | B2_STDLIB: ${{matrix.stdlib}} 348 | run: ci/github/install.sh 349 | 350 | - name: Run tests 351 | run: ci/build.sh 352 | 353 | # Run also the CMake tests to avoid having to setup another matrix for CMake on MSYS 354 | - name: Run CMake tests 355 | run: | 356 | cd "$BOOST_ROOT" 357 | mkdir __build_cmake_test__ && cd __build_cmake_test__ 358 | cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DBOOST_INCLUDE_LIBRARIES=$SELF -DBUILD_SHARED_LIBS=ON -DBUILD_TESTING=ON -DBoost_VERBOSE=ON .. 359 | cmake --build . --target tests --config Debug -j$B2_JOBS 360 | ctest --output-on-failure --build-config Debug 361 | 362 | CMake: 363 | defaults: 364 | run: 365 | shell: bash 366 | 367 | strategy: 368 | fail-fast: false 369 | matrix: 370 | include: 371 | - { os: ubuntu-20.04, build_shared: ON, build_type: Debug, generator: 'Unix Makefiles' } 372 | - { os: ubuntu-20.04, build_shared: OFF, build_type: Debug, generator: 'Unix Makefiles' } 373 | - { os: windows-2019, build_shared: ON, build_type: Debug, generator: 'Visual Studio 16 2019' } 374 | - { os: windows-2019, build_shared: OFF, build_type: Debug, generator: 'Visual Studio 16 2019' } 375 | 376 | timeout-minutes: 120 377 | runs-on: ${{matrix.os}} 378 | 379 | steps: 380 | - uses: actions/checkout@v4 381 | - name: Fetch Boost.CI 382 | uses: actions/checkout@v4 383 | with: 384 | repository: boostorg/boost-ci 385 | ref: master 386 | path: boost-ci-cloned 387 | - name: Get CI scripts folder 388 | run: | 389 | # Copy ci folder if not testing Boost.CI 390 | [[ "$GITHUB_REPOSITORY" =~ "boost-ci" ]] || cp -r boost-ci-cloned/ci . 391 | rm -rf boost-ci-cloned 392 | - name: Setup Boost 393 | env: {B2_DONT_BOOTSTRAP: 1} 394 | run: source ci/github/install.sh 395 | 396 | - name: Run CMake tests 397 | run: | 398 | cd "$BOOST_ROOT" 399 | mkdir __build_cmake_test__ && cd __build_cmake_test__ 400 | cmake -G "${{matrix.generator}}" -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DBOOST_INCLUDE_LIBRARIES=$SELF -DBUILD_SHARED_LIBS=${{matrix.build_shared}} -DBUILD_TESTING=ON -DBoost_VERBOSE=ON .. 401 | cmake --build . --target tests --config ${{matrix.build_type}} -j$B2_JOBS 402 | ctest --output-on-failure --build-config ${{matrix.build_type}} 403 | 404 | - name: Run CMake subdir tests 405 | run: | 406 | cmake_test_folder="$BOOST_ROOT/libs/$SELF/test/cmake_test" # New unified folder 407 | [ -d "$cmake_test_folder" ] || cmake_test_folder="$BOOST_ROOT/libs/$SELF/test/cmake_subdir_test" 408 | cd "$cmake_test_folder" 409 | mkdir __build_cmake_subdir_test__ && cd __build_cmake_subdir_test__ 410 | cmake -G "${{matrix.generator}}" -DBOOST_CI_INSTALL_TEST=OFF -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DBUILD_SHARED_LIBS=${{matrix.build_shared}} .. 411 | cmake --build . --config ${{matrix.build_type}} -j$B2_JOBS 412 | ctest --output-on-failure --build-config ${{matrix.build_type}} 413 | 414 | - name: Install Library 415 | run: | 416 | cd "$BOOST_ROOT" 417 | mkdir __build_cmake_install_test__ && cd __build_cmake_install_test__ 418 | cmake -G "${{matrix.generator}}" -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DBOOST_INCLUDE_LIBRARIES=$SELF -DBUILD_SHARED_LIBS=${{matrix.build_shared}} -DCMAKE_INSTALL_PREFIX=~/.local -DBoost_VERBOSE=ON -DBoost_DEBUG=ON .. 419 | cmake --build . --target install --config ${{matrix.build_type}} -j$B2_JOBS 420 | - name: Run CMake install tests 421 | run: | 422 | cmake_test_folder="$BOOST_ROOT/libs/$SELF/test/cmake_test" # New unified folder 423 | [ -d "$cmake_test_folder" ] || cmake_test_folder="$BOOST_ROOT/libs/$SELF/test/cmake_install_test" 424 | cd "$cmake_test_folder" 425 | mkdir __build_cmake_install_test__ && cd __build_cmake_install_test__ 426 | cmake -G "${{matrix.generator}}" -DBOOST_CI_INSTALL_TEST=ON -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DBUILD_SHARED_LIBS=${{matrix.build_shared}} -DCMAKE_PREFIX_PATH=~/.local .. 427 | cmake --build . --config ${{matrix.build_type}} -j$B2_JOBS 428 | ctest --output-on-failure --build-config ${{matrix.build_type}} 429 | 430 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Generated by `boostdep --cmake assign` 2 | # Copyright 2020 Peter Dimov 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # https://www.boost.org/LICENSE_1_0.txt 5 | 6 | cmake_minimum_required(VERSION 3.5...3.16) 7 | 8 | project(boost_assign VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX) 9 | 10 | add_library(boost_assign INTERFACE) 11 | add_library(Boost::assign ALIAS boost_assign) 12 | 13 | target_include_directories(boost_assign INTERFACE include) 14 | 15 | target_link_libraries(boost_assign 16 | INTERFACE 17 | Boost::array 18 | Boost::config 19 | Boost::core 20 | Boost::move 21 | Boost::mpl 22 | Boost::preprocessor 23 | Boost::ptr_container 24 | Boost::range 25 | Boost::static_assert 26 | Boost::throw_exception 27 | Boost::tuple 28 | Boost::type_traits 29 | ) 30 | 31 | if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt") 32 | 33 | add_subdirectory(test) 34 | 35 | endif() 36 | 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Boost Software License - Version 1.0 - August 17th, 2003 2 | 3 | Permission is hereby granted, free of charge, to any person or organization 4 | obtaining a copy of the software and accompanying documentation covered by 5 | this license (the "Software") to use, reproduce, display, distribute, 6 | execute, and transmit the Software, and to prepare derivative works of the 7 | Software, and to permit third-parties to whom the Software is furnished to 8 | do so, all subject to the following: 9 | 10 | The copyright notices in the Software and this entire statement, including 11 | the above license grant, this restriction and the following disclaimer, 12 | must be included in all copies of the Software, in whole or in part, and 13 | all derivative works of the Software, unless such copies or derivative 14 | works are solely in the form of machine-executable object code generated by 15 | a source language processor. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 20 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 21 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Assign, part of collection of the [Boost C++ Libraries](https://github.com/boostorg), makes it easy to fill containers with data by overloading operator() and operator()(). 2 | 3 | ### License 4 | 5 | Distributed under the [Boost Software License, Version 1.0](https://www.boost.org/LICENSE_1_0.txt). 6 | 7 | ### Properties 8 | 9 | * C++11 10 | * Header Only 11 | 12 | ### Build Status 13 | 14 | 15 | | Branch | GHA CI | Appveyor | Coverity Scan | codecov.io | Deps | Docs | Tests | 16 | | :-------------: | ------ | -------- | ------------- | ---------- | ---- | ---- | ----- | 17 | | [`master`](https://github.com/boostorg/assign/tree/master) | [![Build Status](https://github.com/boostorg/assign/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/boostorg/assign/actions?query=branch:master) | [![Build status](https://ci.appveyor.com/api/projects/status/sjjn5t979ao2b845/branch/master?svg=true)](https://ci.appveyor.com/project/cppalliance/assign/branch/master) | [![Coverity Scan Build Status](https://scan.coverity.com/projects/16318/badge.svg)](https://scan.coverity.com/projects/boostorg-assign) | [![codecov](https://codecov.io/gh/boostorg/assign/branch/master/graph/badge.svg?token=SOGsyPqaS7)](https://codecov.io/gh/boostorg/assign/tree/master) | [![Deps](https://img.shields.io/badge/deps-master-brightgreen.svg)](https://pdimov.github.io/boostdep-report/master/assign.html) | [![Documentation](https://img.shields.io/badge/docs-master-brightgreen.svg)](https://www.boost.org/doc/libs/master/libs/assign) | [![Enter the Matrix](https://img.shields.io/badge/matrix-master-brightgreen.svg)](http://www.boost.org/development/tests/master/developer/assign.html) 18 | | [`develop`](https://github.com/boostorg/assign/tree/develop) | [![Build Status](https://github.com/boostorg/assign/actions/workflows/ci.yml/badge.svg?branch=develop)](https://github.com/boostorg/assign/actions?query=branch:develop) | [![Build status](https://ci.appveyor.com/api/projects/status/sjjn5t979ao2b845/branch/develop?svg=true)](https://ci.appveyor.com/project/cppalliance/assign/branch/develop) | [![Coverity Scan Build Status](https://scan.coverity.com/projects/16318/badge.svg)](https://scan.coverity.com/projects/boostorg-assign) | [![codecov](https://codecov.io/gh/boostorg/assign/branch/develop/graph/badge.svg?token=SOGsyPqaS7)](https://codecov.io/gh/boostorg/assign/tree/develop) | [![Deps](https://img.shields.io/badge/deps-develop-brightgreen.svg)](https://pdimov.github.io/boostdep-report/develop/assign.html) | [![Documentation](https://img.shields.io/badge/docs-develop-brightgreen.svg)](https://www.boost.org/doc/libs/develop/libs/assign) | [![Enter the Matrix](https://img.shields.io/badge/matrix-develop-brightgreen.svg)](http://www.boost.org/development/tests/develop/developer/assign.html) 19 | 20 | ### Directories 21 | 22 | | Name | Purpose | 23 | | ----------- | ------------------------------ | 24 | | `doc` | documentation | 25 | | `include` | headers | 26 | | `test` | unit tests | 27 | 28 | ### More information 29 | 30 | * [Ask questions](https://stackoverflow.com/questions/ask?tags=c%2B%2B,boost,boost-assign) 31 | * [Report bugs](https://github.com/boostorg/assign/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. 32 | * Submit your patches as pull requests against **develop** branch. Note that by submitting patches you agree to license your modifications under the [Boost Software License, Version 1.0](https://www.boost.org/LICENSE_1_0.txt). 33 | * Discussions about the library are held on the [Boost developers mailing list](https://www.boost.org/community/groups.html#main). Be sure to read the [discussion policy](https://www.boost.org/community/policy.html) before posting and add the `[assign]` tag at the beginning of the subject line. 34 | 35 | -------------------------------------------------------------------------------- /build.jam: -------------------------------------------------------------------------------- 1 | # Copyright René Ferdinand Rivera Morell 2023-2024 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at 4 | # http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | require-b2 5.2 ; 7 | 8 | constant boost_dependencies : 9 | /boost/array//boost_array 10 | /boost/config//boost_config 11 | /boost/core//boost_core 12 | /boost/move//boost_move 13 | /boost/preprocessor//boost_preprocessor 14 | /boost/ptr_container//boost_ptr_container 15 | /boost/range//boost_range 16 | /boost/static_assert//boost_static_assert 17 | /boost/throw_exception//boost_throw_exception 18 | /boost/tuple//boost_tuple 19 | /boost/type_traits//boost_type_traits ; 20 | 21 | project /boost/assign 22 | : common-requirements 23 | include 24 | ; 25 | 26 | explicit 27 | [ alias boost_assign : : : : $(boost_dependencies) ] 28 | [ alias all : boost_assign test ] 29 | ; 30 | 31 | call-if : boost-library assign 32 | ; 33 | 34 | -------------------------------------------------------------------------------- /doc/email_example.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Boost.Assignment Documentation 7 | 8 | 9 | 10 | 11 |
 12 | // Boost.Assign library
 13 | //
 14 | //  Copyright Thorsten Ottosen 2003-2004. Use, modification and
 15 | //  distribution is subject to the Boost Software License, Version
 16 | //  1.0. (See accompanying file LICENSE_1_0.txt or copy at
 17 | //  http://www.boost.org/LICENSE_1_0.txt)
 18 | //
 19 | // For more information, see http://www.boost.org/libs/assign/
 20 | //
 21 | 
 22 | 
 23 | #include <boost/detail/workaround.hpp>
 24 | 
 25 | #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
 26 | ###pragma warn -8091 // suppress warning in Boost.Test
 27 | ###pragma warn -8057 // unused argument argc/argv in Boost.Test
 28 | #endif
 29 | 
 30 | #include <boost/assign/list_inserter.hpp>
 31 | #include <boost/test/unit_test.hpp>
 32 | #include <boost/test/test_tools.hpp>
 33 | #include <boost/function.hpp>
 34 | #include <boost/bind.hpp>
 35 | #include <vector>
 36 | #include <map>
 37 | 
 38 | namespace ba = boost::assign;
 39 | 
 40 | class email
 41 | {
 42 | public:
 43 |     enum address_option
 44 |     {
 45 |         check_addr_book,
 46 |         dont_check_addr_book
 47 |     };
 48 |     
 49 |     typedef std::pair<std::string,address_option> bcc_type;
 50 |     typedef std::vector< bcc_type >               bcc_map;
 51 |     typedef std::map<std::string,address_option>  address_map;
 52 |     
 53 |     
 54 | private:
 55 | 
 56 |     mutable address_map      cc_list;
 57 |     mutable address_map      to_list;
 58 |     bcc_map                  bcc_list;
 59 |             
 60 |     struct add_to_map
 61 |     {
 62 |         address_map& m;
 63 |     
 64 |         add_to_map( address_map& m ) : m(m)        
 65 |         {}
 66 |     
 67 |         void operator()( const std::string& name, address_option ao )
 68 |         {
 69 |             m[ name ] = ao; 
 70 |         }
 71 |         
 72 |         void operator()( const std::string& name )
 73 |         {
 74 |             m[ name ] = check_addr_book;
 75 |         }
 76 |     };
 77 | 
 78 |     struct add_to_vector
 79 |     {
 80 |         bcc_map& m;
 81 |         
 82 |         add_to_vector( bcc_map& m ) : m(m)
 83 |         {}
 84 |         
 85 |         void operator()( const bcc_type& r )
 86 |         {
 87 |             m.push_back( r );
 88 |         }
 89 |     };
 90 | 
 91 | public:
 92 |     
 93 |     ba::list_inserter< add_to_map >
 94 |     add_cc( std::string name, address_option ao )
 95 |     {
 96 |         return ba::make_list_inserter( add_to_map( cc_list ) )( name, ao );
 97 |     }
 98 | 
 99 |     ba::list_inserter< add_to_map >
100 |     add_to( const std::string& name )
101 |     {
102 |         return ba::make_list_inserter( add_to_map( to_list ) )( name );
103 |     }
104 |     
105 |     ba::list_inserter< add_to_vector, bcc_type >
106 |     add_bcc( const bcc_type& bcc )
107 |     {
108 |         return ba::make_list_inserter( add_to_vector( bcc_list ) )( bcc );     
109 |     }
110 |     
111 |     address_option
112 |     cc_at( const std::string& name ) const
113 |     {
114 |         return cc_list[ name ];
115 |     }
116 |     
117 |     address_option 
118 |     to_at( const std::string& name ) const
119 |     {
120 |         return to_list[ name ];
121 |     }
122 |     
123 |     address_option
124 |     bcc_at( unsigned index ) const
125 |     {
126 |         return bcc_list.at( index ).second;
127 |     }
128 | };
129 | 
130 | 
131 | 
132 | void check_list_inserter()
133 | {
134 |     using namespace boost::assign;
135 | 
136 |     email e;
137 |     e.add_cc( "franz", email::dont_check_addr_book )
138 |             ( "hanz", email::check_addr_book )
139 |             ( "betty", email::dont_check_addr_book );
140 |     BOOST_CHECK_EQUAL( e.cc_at( "franz" ), email::dont_check_addr_book );
141 |     BOOST_CHECK_EQUAL( e.cc_at( "hanz" ), email::check_addr_book );
142 |     BOOST_CHECK_EQUAL( e.cc_at( "betty" ), email::dont_check_addr_book );
143 | 
144 |     e.add_to( "betsy" )( "peter" );
145 |     BOOST_CHECK_EQUAL( e.cc_at( "betsy" ), email::check_addr_book );
146 |     BOOST_CHECK_EQUAL( e.cc_at( "peter" ), email::check_addr_book );
147 |     
148 |     e.add_bcc( email::bcc_type( "Mr. Foo", email::check_addr_book ) )
149 |              ( "Mr. Bar", email::dont_check_addr_book );
150 |     BOOST_CHECK_EQUAL( e.bcc_at( 0 ), email::check_addr_book );
151 |     BOOST_CHECK_EQUAL( e.bcc_at( 1 ), email::dont_check_addr_book );
152 |     
153 | }
154 | 
155 | 
156 | 
157 | #include <boost/test/included/unit_test_framework.hpp> 
158 | 
159 | using boost::unit_test_framework::test_suite;
160 | 
161 | test_suite* init_unit_test_suite( int argc, char* argv[] )
162 | {
163 |     test_suite* test = BOOST_TEST_SUITE( "List Test Suite" );
164 | 
165 |     test->add( BOOST_TEST_CASE( &check_list_inserter ) );
166 | 
167 |     return test;
168 | }
169 | 
170 | 
171 | 
172 | 
173 | 174 | 175 | -------------------------------------------------------------------------------- /doc/index.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/assign/b452220f5de0f6205433c08cee63742102a424d2/doc/index.html -------------------------------------------------------------------------------- /doc/multi_index_container.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Boost.Assignment Documentation 7 | 8 | 9 | 10 | 11 |
 12 | // Boost.Assign library
 13 | //
 14 | //  Copyright Thorsten Ottosen 2003-2004. Use, modification and
 15 | //  distribution is subject to the Boost Software License, Version
 16 | //  1.0. (See accompanying file LICENSE_1_0.txt or copy at
 17 | //  http://www.boost.org/LICENSE_1_0.txt)
 18 | //
 19 | // For more information, see http://www.boost.org/libs/assign/
 20 | //
 21 | 
 22 | 
 23 | #include <boost/detail/workaround.hpp>
 24 | 
 25 | #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
 26 | ###pragma warn -8091 // suppress warning in Boost.Test
 27 | ###pragma warn -8057 // unused argument argc/argv in Boost.Test
 28 | #endif
 29 | 
 30 | #include <boost/assign/list_of.hpp>
 31 | #include <boost/assign/list_inserter.hpp>
 32 | #include <boost/multi_index_container.hpp>
 33 | #include <boost/multi_index/identity.hpp>
 34 | #include <boost/multi_index/member.hpp>
 35 | #include <boost/multi_index/ordered_index.hpp>
 36 | #include <boost/multi_index/sequenced_index.hpp>
 37 | #include <boost/test/unit_test.hpp>
 38 | #include <boost/test/test_tools.hpp>
 39 | #include <cstddef>
 40 | #include <ostream>
 41 | #include <string>
 42 | 
 43 | using namespace boost;
 44 | using namespace boost::multi_index;
 45 | namespace ba =  boost::assign;
 46 | 
 47 | //
 48 | // Define a classical multi_index_container for employees
 49 | //
 50 | struct employee
 51 | {
 52 |   int         id;
 53 |   std::string name;
 54 |   int         age;
 55 | 
 56 |   employee(int id_,std::string name_,int age_):id(id_),name(name_),age(age_){}
 57 | 
 58 |   bool operator==(const employee& x)const
 59 |   {
 60 |     return id==x.id&&name==x.name&&age==x.age;
 61 |   }
 62 | 
 63 |   bool operator<(const employee& x)const
 64 |   {
 65 |     return id<x.id;
 66 |   }
 67 | 
 68 |   bool operator!=(const employee& x)const{return !(*this==x);}
 69 |   bool operator> (const employee& x)const{return x<*this;}
 70 |   bool operator>=(const employee& x)const{return !(*this<x);}
 71 |   bool operator<=(const employee& x)const{return !(x<*this);}
 72 | 
 73 |   struct comp_id
 74 |   {
 75 |     bool operator()(int x,const employee& e2)const{return x<e2.id;}
 76 |     bool operator()(const employee& e1,int x)const{return e1.id<x;}
 77 |   };
 78 | 
 79 |   friend std::ostream& operator<<(std::ostream& os,const employee& e)
 80 |   {
 81 |     os<<e.id<<" "<<e.name<<" "<<e.age<<std::endl;
 82 |     return os;
 83 |   }
 84 | };
 85 | 
 86 | struct name{};
 87 | struct by_name{};
 88 | struct age{};
 89 | struct as_inserted{};
 90 | 
 91 | typedef
 92 |   multi_index_container<
 93 |     employee,
 94 |     indexed_by<
 95 |       ordered_unique<
 96 |         identity<employee> >,
 97 |       ordered_non_unique<
 98 |         tag<name,by_name>,
 99 |         BOOST_MULTI_INDEX_MEMBER(employee,std::string,name)>,
100 |       ordered_non_unique<
101 |         tag<age>,
102 |         BOOST_MULTI_INDEX_MEMBER(employee,int,age)>,
103 |       sequenced<
104 |         tag<as_inserted> > > >
105 |   employee_set;
106 | 
107 | #if defined(BOOST_NO_MEMBER_TEMPLATES)
108 | typedef nth_index<
109 |   employee_set,1>::type                       employee_set_by_name;
110 | #else
111 | typedef employee_set::nth_index<1>::type employee_set_by_name;
112 | #endif
113 | 
114 | typedef boost::multi_index::index<
115 |          employee_set,age>::type         employee_set_by_age;
116 | typedef boost::multi_index::index<
117 |          employee_set,as_inserted>::type employee_set_as_inserted;
118 | 
119 | //
120 | // Define a multi_index_container with a list-like index and an ordered index
121 | //
122 | typedef multi_index_container<
123 |   std::string,
124 |   indexed_by<
125 |     sequenced<>,                               // list-like index
126 |     ordered_non_unique<identity<std::string> > // words by alphabetical order
127 |   >
128 | > text_container;
129 | 
130 | 
131 | 
132 | void test_multi_index_container()
133 | {
134 |     employee_set eset = ba::list_of< employee >(1,"Franz",30)(2,"Hanz",40)(3,"Ilse",50);
135 |     BOOST_CHECK( eset.size() == 3u );
136 |     
137 |     //
138 |     // This container is associative, hence we can use 'insert()' 
139 |     // 
140 |     
141 |     ba::insert( eset )(4,"Kurt",55)(5,"Bjarne",77)(7,"Thorsten",24);
142 |     BOOST_CHECK( eset.size() == 6u );
143 |     
144 |     employee_set_by_name& name_index = boost::multi_index::get<name>(eset);
145 |     employee_set_by_name::iterator i = name_index.find("Ilse");
146 |     BOOST_CHECK( i->id == 3 );
147 |     BOOST_CHECK( i->age == 50 );
148 |     
149 |     text_container text = ba::list_of< std::string >("Have")("you")("ever")("wondered")("how")("much")("Boost")("rocks?!");
150 |     BOOST_CHECK_EQUAL( text.size(), 8u );
151 |     BOOST_CHECK_EQUAL( *text.begin(), "Have" );
152 |     
153 |     //
154 |     // This container is a sequence, hence we can use 'push_back()' and 'push_font()'
155 |     //
156 |     
157 |     ba::push_back( text )("Well")(",")("A")("LOT")(",")("obviously!");
158 |     BOOST_CHECK_EQUAL( text.size(), 14u );
159 |     BOOST_CHECK_EQUAL( *--text.end(), "obviously!" );
160 |     
161 |     ba::push_front( text ) = "question:", "simple", "A";
162 |     BOOST_CHECK_EQUAL( text.size(), 17u );
163 |     BOOST_CHECK_EQUAL( text.front(), "A" );
164 | }
165 | 
166 | 
167 | 
168 | #include <boost/test/included/unit_test_framework.hpp> 
169 | 
170 | using boost::unit_test_framework::test_suite;
171 | 
172 | test_suite* init_unit_test_suite( int argc, char* argv[] )
173 | {
174 |     test_suite* test = BOOST_TEST_SUITE( "List Test Suite" );
175 | 
176 |     test->add( BOOST_TEST_CASE( &test_multi_index_container ) );
177 | 
178 |     return test;
179 | }
180 | 
181 | 
182 | 
183 | 
184 | 185 | 186 | -------------------------------------------------------------------------------- /doc/my_vector_example.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Boost.Assignment Documentation 7 | 8 | 9 | 10 | 11 |
 12 | // Boost.Assign library
 13 | //
 14 | //  Copyright Thorsten Ottosen 2003-2004. Use, modification and
 15 | //  distribution is subject to the Boost Software License, Version
 16 | //  1.0. (See accompanying file LICENSE_1_0.txt or copy at
 17 | //  http://www.boost.org/LICENSE_1_0.txt)
 18 | //
 19 | // For more information, see http://www.boost.org/libs/assign/
 20 | //
 21 | 
 22 | 
 23 | #include <boost/detail/workaround.hpp>
 24 | 
 25 | #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
 26 | ###pragma warn -8091 // suppress warning in Boost.Test
 27 | ###pragma warn -8057 // unused argument argc/argv in Boost.Test
 28 | #endif
 29 | 
 30 | #include <boost/assign/list_inserter.hpp>
 31 | #include <boost/test/unit_test.hpp>
 32 | #include <boost/test/test_tools.hpp>
 33 | #include <boost/function.hpp>
 34 | #include <boost/bind.hpp>
 35 | #include <vector>
 36 | #include <stdexcept>
 37 | 
 38 | namespace ba = boost::assign;
 39 | 
 40 | 
 41 | 
 42 | template< class C >
 43 | class range_inserter
 44 | {
 45 |     typedef typename C::iterator iterator;
 46 |     iterator begin, end;
 47 | public:
 48 |     range_inserter( C& c )
 49 |     : begin( c.begin() ), end( c.end() )
 50 |     { }
 51 |     
 52 |     template< class T >
 53 |     void operator()( T r )
 54 |     {
 55 |         if( begin == end )
 56 |             throw std::range_error( "range error: <range_inserter>" );
 57 |         *begin = r;
 58 |         ++begin;
 59 |     }
 60 | };
 61 | 
 62 | 
 63 | 
 64 | template< class C >
 65 | inline range_inserter<C> make_range_inserter( C& c )
 66 | {
 67 |     return range_inserter<C>( c );
 68 | }
 69 | 
 70 | 
 71 | 
 72 | template< class T >
 73 | class my_vector
 74 | {
 75 |     typedef std::vector<T>                vector_t;
 76 |     typedef typename vector_t::size_type  size_type;
 77 |     vector_t data_;
 78 | 
 79 | public:
 80 |     my_vector() : data_( 10, 0 )
 81 |     { }
 82 |     
 83 |     ba::list_inserter< range_inserter< vector_t >, T >
 84 |     operator=( T r )
 85 |     {
 86 |         return ba::make_list_inserter( make_range_inserter( data_ ) )( r );
 87 |     }
 88 |     
 89 |     size_type size() const
 90 |     {
 91 |         return data_.size();
 92 |     }
 93 |     
 94 |     const T& operator[]( size_type index )
 95 |     {
 96 |         return data_.at( index );
 97 |     }
 98 | };
 99 | 
100 | 
101 | 
102 | void check_list_inserter()
103 | {
104 |     using namespace std;
105 |     using namespace boost::assign;
106 |     
107 |     my_vector<int> vec;
108 |     vec = 1,2,3,4,5,6,7,8,9,10;
109 |     BOOST_CHECK_EQUAL( vec.size(), 10u );
110 |     BOOST_CHECK_EQUAL( vec[0], 1 );
111 |     BOOST_CHECK_EQUAL( vec[9], 10 );
112 | }
113 | 
114 | 
115 | 
116 | #include <boost/test/included/unit_test_framework.hpp> 
117 | 
118 | using boost::unit_test_framework::test_suite;
119 | 
120 | test_suite* init_unit_test_suite( int argc, char* argv[] )
121 | {
122 |     test_suite* test = BOOST_TEST_SUITE( "List Test Suite" );
123 | 
124 |     test->add( BOOST_TEST_CASE( &check_list_inserter ) );
125 | 
126 |     return test;
127 | }
128 | 
129 | 
130 | 131 | 132 | -------------------------------------------------------------------------------- /doc/style.css: -------------------------------------------------------------------------------- 1 | /* 2 | #// Copyright Thorsten Ottosen 2003-2005. Use, modification and 3 | #// distribution is subject to the Boost Software License, Version 4 | #// 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5 | #// http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | 8 | pre{ 9 | BORDER-RIGHT: gray 1pt solid; 10 | PADDING-RIGHT: 2pt; 11 | BORDER-TOP: gray 1pt solid; 12 | DISPLAY: block; 13 | PADDING-LEFT: 2pt; 14 | PADDING-BOTTOM: 2pt; 15 | BORDER-LEFT: gray 1pt solid; 16 | MARGIN-RIGHT: 32pt; 17 | PADDING-TOP: 2pt; 18 | BORDER-BOTTOM: gray 1pt solid; 19 | FONT-FAMILY: "Courier New", Courier, mono; 20 | background-color: #EEEEEE; 21 | } 22 | 23 | 24 | .keyword{color: #0000FF;} 25 | .identifier{} 26 | .comment{font-style: italic; color: #008000;} 27 | .special{color: #800040;} 28 | .preprocessor{color: #3F007F;} 29 | .string{font-style: italic; color: #666666;} 30 | .literal{font-style: italic; color: #666666;} 31 | -------------------------------------------------------------------------------- /include/boost/assign.hpp: -------------------------------------------------------------------------------- 1 | // Boost.Assign library 2 | // 3 | // Copyright Thorsten Ottosen 2003-2004. Use, modification and 4 | // distribution is subject to the Boost Software License, Version 5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | // For more information, see http://www.boost.org/libs/assign/ 9 | // 10 | 11 | 12 | #ifndef BOOST_ASSIGN_HPP 13 | #define BOOST_ASSIGN_HPP 14 | 15 | #if defined(_MSC_VER) 16 | # pragma once 17 | #endif 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /include/boost/assign/assignment_exception.hpp: -------------------------------------------------------------------------------- 1 | // Boost.Assign library 2 | // 3 | // Copyright Thorsten Ottosen 2003-2004. Use, modification and 4 | // distribution is subject to the Boost Software License, Version 5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | // For more information, see http://www.boost.org/libs/assign/ 9 | // 10 | 11 | 12 | #ifndef BOOST_ASSIGN_ASSIGNMENT_EXCEPTION_HPP 13 | #define BOOST_ASSIGN_ASSIGNMENT_EXCEPTION_HPP 14 | 15 | #include 16 | #include 17 | 18 | #if defined(BOOST_HAS_PRAGMA_ONCE) 19 | # pragma once 20 | #endif 21 | 22 | namespace boost 23 | { 24 | namespace assign 25 | { 26 | class assignment_exception : public std::exception 27 | { 28 | public: 29 | assignment_exception( const char* _what ) 30 | : what_( _what ) 31 | { } 32 | 33 | virtual const char* what() const BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE 34 | { 35 | return what_; 36 | } 37 | 38 | private: 39 | const char* what_; 40 | }; 41 | } 42 | } 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /include/boost/assign/list_inserter.hpp: -------------------------------------------------------------------------------- 1 | // Boost.Assign library 2 | // 3 | // Copyright Thorsten Ottosen 2003-2004. Use, modification and 4 | // distribution is subject to the Boost Software License, Version 5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | // For more information, see http://www.boost.org/libs/assign/ 9 | // 10 | 11 | #ifndef BOOST_ASSIGN_LIST_INSERTER_HPP 12 | #define BOOST_ASSIGN_LIST_INSERTER_HPP 13 | 14 | #if defined(_MSC_VER) 15 | # pragma once 16 | #endif 17 | 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #endif 37 | 38 | namespace boost 39 | { 40 | namespace assign_detail 41 | { 42 | template< class T > 43 | struct repeater 44 | { 45 | std::size_t sz; 46 | T val; 47 | 48 | repeater( std::size_t sz_, T r ) : sz( sz_ ), val( r ) 49 | { } 50 | }; 51 | 52 | template< class Fun > 53 | struct fun_repeater 54 | { 55 | std::size_t sz; 56 | Fun val; 57 | 58 | fun_repeater( std::size_t sz_, Fun r ) : sz( sz_ ), val( r ) 59 | { } 60 | }; 61 | 62 | 63 | template< class T > 64 | struct is_repeater : boost::false_type {}; 65 | 66 | template< class T > 67 | struct is_repeater< boost::assign_detail::repeater > : boost::true_type{}; 68 | 69 | template< class Fun > 70 | struct is_repeater< boost::assign_detail::fun_repeater > : boost::true_type{}; 71 | 72 | 73 | template< class C > 74 | class call_push_back 75 | { 76 | C& c_; 77 | public: 78 | call_push_back( C& c ) : c_( c ) 79 | { } 80 | 81 | #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 82 | template< class T > 83 | void operator()( T r ) 84 | { 85 | c_.push_back( r ); 86 | } 87 | #else 88 | template< class T > 89 | void operator()(T&& r) 90 | { 91 | c_.push_back(boost::forward(r)); 92 | } 93 | #endif 94 | }; 95 | 96 | template< class C > 97 | class call_push_front 98 | { 99 | C& c_; 100 | public: 101 | call_push_front( C& c ) : c_( c ) 102 | { } 103 | 104 | #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 105 | template< class T > 106 | void operator()( T r ) 107 | { 108 | c_.push_front( r ); 109 | } 110 | #else 111 | template< class T > 112 | void operator()(T&& r) 113 | { 114 | c_.push_front(boost::forward(r)); 115 | } 116 | #endif 117 | }; 118 | 119 | template< class C > 120 | class call_push 121 | { 122 | C& c_; 123 | public: 124 | call_push( C& c ) : c_( c ) 125 | { } 126 | 127 | #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 128 | template< class T > 129 | void operator()( T r ) 130 | { 131 | c_.push( r ); 132 | } 133 | #else 134 | template< class T > 135 | void operator()(T&& r) 136 | { 137 | c_.push(boost::forward(r)); 138 | } 139 | #endif 140 | }; 141 | 142 | template< class C > 143 | class call_insert 144 | { 145 | C& c_; 146 | public: 147 | call_insert( C& c ) : c_( c ) 148 | { } 149 | 150 | #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 151 | template< class T > 152 | void operator()( T r ) 153 | { 154 | c_.insert( r ); 155 | } 156 | #else 157 | template< class T > 158 | void operator()(T&& r) 159 | { 160 | c_.insert(boost::forward(r)); 161 | } 162 | #endif 163 | }; 164 | 165 | template< class C > 166 | class call_add_edge 167 | { 168 | C& c_; 169 | public: 170 | call_add_edge( C& c ) : c_(c) 171 | { } 172 | 173 | template< class T > 174 | void operator()( T l, T r ) 175 | { 176 | add_edge( l, r, c_ ); 177 | } 178 | 179 | template< class T, class EP > 180 | void operator()( T l, T r, const EP& ep ) 181 | { 182 | add_edge( l, r, ep, c_ ); 183 | } 184 | 185 | }; 186 | 187 | struct forward_n_arguments {}; 188 | 189 | } // namespace 'assign_detail' 190 | 191 | namespace assign 192 | { 193 | 194 | template< class T > 195 | inline assign_detail::repeater 196 | repeat( std::size_t sz, T r ) 197 | { 198 | return assign_detail::repeater( sz, r ); 199 | } 200 | 201 | template< class Function > 202 | inline assign_detail::fun_repeater 203 | repeat_fun( std::size_t sz, Function r ) 204 | { 205 | return assign_detail::fun_repeater( sz, r ); 206 | } 207 | 208 | 209 | template< class Function, class Argument = assign_detail::forward_n_arguments > 210 | class list_inserter 211 | { 212 | struct single_arg_type {}; 213 | struct n_arg_type {}; 214 | struct repeater_arg_type {}; 215 | 216 | typedef BOOST_DEDUCED_TYPENAME ::boost::conditional< 217 | is_same::value, 218 | n_arg_type, 219 | single_arg_type >::type arg_type; 220 | 221 | public: 222 | 223 | list_inserter( Function fun ) : insert_( fun ) 224 | {} 225 | 226 | template< class Function2, class Arg > 227 | list_inserter( const list_inserter& r ) 228 | : insert_( r.fun_private() ) 229 | {} 230 | 231 | list_inserter( const list_inserter& r ) : insert_( r.insert_ ) 232 | {} 233 | 234 | list_inserter& operator()() 235 | { 236 | insert_( Argument() ); 237 | return *this; 238 | } 239 | 240 | #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 241 | template< class T > 242 | list_inserter& operator=( const T& r ) 243 | { 244 | insert_( r ); 245 | return *this; 246 | } 247 | 248 | template< class T > 249 | list_inserter& operator=( assign_detail::repeater r ) 250 | { 251 | return operator,( r ); 252 | } 253 | 254 | template< class Nullary_function > 255 | list_inserter& operator=( const assign_detail::fun_repeater& r ) 256 | { 257 | return operator,( r ); 258 | } 259 | 260 | template< class T > 261 | list_inserter& operator,( const T& r ) 262 | { 263 | insert_( r ); 264 | return *this; 265 | } 266 | 267 | #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205)) 268 | template< class T > 269 | list_inserter& operator,( const assign_detail::repeater & r ) 270 | { 271 | return repeat( r.sz, r.val ); 272 | } 273 | #else 274 | template< class T > 275 | list_inserter& operator,( assign_detail::repeater r ) 276 | { 277 | return repeat( r.sz, r.val ); 278 | } 279 | #endif 280 | 281 | template< class Nullary_function > 282 | list_inserter& operator,( const assign_detail::fun_repeater& r ) 283 | { 284 | return repeat_fun( r.sz, r.val ); 285 | } 286 | #else 287 | // BOOST_NO_CXX11_RVALUE_REFERENCES 288 | template< class T > 289 | list_inserter& operator=(T&& r) 290 | { 291 | return operator,(boost::forward(r)); 292 | } 293 | #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) 294 | template< class T > 295 | list_inserter& operator,(T&& r) 296 | { 297 | typedef BOOST_DEDUCED_TYPENAME ::boost::conditional< 298 | assign_detail::is_repeater< T >::value, 299 | repeater_arg_type, 300 | arg_type >::type tag; 301 | 302 | insert(boost::forward(r), tag()); 303 | return *this; 304 | } 305 | #else 306 | // we add the tag as the first argument when using variadic templates 307 | template< class T > 308 | list_inserter& operator,(T&& r) 309 | { 310 | typedef BOOST_DEDUCED_TYPENAME ::boost::conditional< 311 | assign_detail::is_repeater< T >::value, 312 | repeater_arg_type, 313 | arg_type >::type tag; 314 | 315 | insert(tag(), boost::forward(r)); 316 | return *this; 317 | } 318 | #endif 319 | #endif 320 | 321 | template< class T > 322 | list_inserter& repeat( std::size_t sz, T r ) 323 | { 324 | std::size_t i = 0; 325 | while( i++ != sz ) 326 | insert_( r ); 327 | return *this; 328 | } 329 | 330 | template< class Nullary_function > 331 | list_inserter& repeat_fun( std::size_t sz, Nullary_function fun ) 332 | { 333 | std::size_t i = 0; 334 | while( i++ != sz ) 335 | insert_( fun() ); 336 | return *this; 337 | } 338 | 339 | template< class SinglePassIterator > 340 | list_inserter& range( SinglePassIterator first, 341 | SinglePassIterator last ) 342 | { 343 | for( ; first != last; ++first ) 344 | insert_( *first ); 345 | return *this; 346 | } 347 | 348 | template< class SinglePassRange > 349 | list_inserter& range( const SinglePassRange& r ) 350 | { 351 | return range( boost::begin(r), boost::end(r) ); 352 | } 353 | 354 | #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 355 | template< class T > 356 | list_inserter& operator()( const T& t ) 357 | { 358 | insert_( t ); 359 | return *this; 360 | } 361 | 362 | #ifndef BOOST_ASSIGN_MAX_PARAMS // use user's value 363 | #define BOOST_ASSIGN_MAX_PARAMS 5 364 | #endif 365 | #define BOOST_ASSIGN_MAX_PARAMETERS (BOOST_ASSIGN_MAX_PARAMS - 1) 366 | #define BOOST_ASSIGN_PARAMS1(n) BOOST_PP_ENUM_PARAMS(n, class T) 367 | #define BOOST_ASSIGN_PARAMS2(n) BOOST_PP_ENUM_BINARY_PARAMS(n, T, const& t) 368 | #define BOOST_ASSIGN_PARAMS3(n) BOOST_PP_ENUM_PARAMS(n, t) 369 | 370 | #define BOOST_PP_LOCAL_LIMITS (1, BOOST_ASSIGN_MAX_PARAMETERS) 371 | #define BOOST_PP_LOCAL_MACRO(n) \ 372 | template< class T, BOOST_ASSIGN_PARAMS1(n) > \ 373 | list_inserter& operator()(T t, BOOST_ASSIGN_PARAMS2(n) ) \ 374 | { \ 375 | BOOST_PP_CAT(insert, BOOST_PP_INC(n))(t, BOOST_ASSIGN_PARAMS3(n), arg_type()); \ 376 | return *this; \ 377 | } \ 378 | /**/ 379 | 380 | #include BOOST_PP_LOCAL_ITERATE() 381 | 382 | 383 | #define BOOST_PP_LOCAL_LIMITS (1, BOOST_ASSIGN_MAX_PARAMETERS) 384 | #define BOOST_PP_LOCAL_MACRO(n) \ 385 | template< class T, BOOST_ASSIGN_PARAMS1(n) > \ 386 | void BOOST_PP_CAT(insert, BOOST_PP_INC(n))(T const& t, BOOST_ASSIGN_PARAMS2(n), single_arg_type) \ 387 | { \ 388 | insert_( Argument(t, BOOST_ASSIGN_PARAMS3(n) )); \ 389 | } \ 390 | /**/ 391 | 392 | #include BOOST_PP_LOCAL_ITERATE() 393 | 394 | #define BOOST_PP_LOCAL_LIMITS (1, BOOST_ASSIGN_MAX_PARAMETERS) 395 | #define BOOST_PP_LOCAL_MACRO(n) \ 396 | template< class T, BOOST_ASSIGN_PARAMS1(n) > \ 397 | void BOOST_PP_CAT(insert, BOOST_PP_INC(n))(T const& t, BOOST_ASSIGN_PARAMS2(n), n_arg_type) \ 398 | { \ 399 | insert_(t, BOOST_ASSIGN_PARAMS3(n) ); \ 400 | } \ 401 | /**/ 402 | 403 | #include BOOST_PP_LOCAL_ITERATE() 404 | 405 | #else 406 | template< class... Ts > 407 | list_inserter& operator()(Ts&&... ts) 408 | { 409 | insert(arg_type(), boost::forward(ts)...); 410 | return *this; 411 | } 412 | 413 | template< class T > 414 | void insert(single_arg_type, T&& t) 415 | { 416 | // Special implementation for single argument overload to prevent accidental casts (type-cast using functional notation) 417 | insert_(boost::forward(t)); 418 | } 419 | 420 | template< class T1, class T2, class... Ts > 421 | void insert(single_arg_type, T1&& t1, T2&& t2, Ts&&... ts) 422 | { 423 | insert_(Argument(boost::forward(t1), boost::forward(t2), boost::forward(ts)...)); 424 | } 425 | 426 | template< class... Ts > 427 | void insert(n_arg_type, Ts&&... ts) 428 | { 429 | insert_(boost::forward(ts)...); 430 | } 431 | 432 | #endif 433 | 434 | #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 435 | 436 | #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) 437 | 438 | template< class T > 439 | void insert( T&& r, arg_type) 440 | { 441 | insert_( boost::forward(r) ); 442 | } 443 | 444 | template< class T > 445 | void insert(assign_detail::repeater r, repeater_arg_type) 446 | { 447 | repeat(r.sz, r.val); 448 | } 449 | 450 | template< class Nullary_function > 451 | void insert(const assign_detail::fun_repeater& r, repeater_arg_type) 452 | { 453 | repeat_fun(r.sz, r.val); 454 | } 455 | #else 456 | template< class T > 457 | void insert(repeater_arg_type, assign_detail::repeater r) 458 | { 459 | repeat(r.sz, r.val); 460 | } 461 | 462 | template< class Nullary_function > 463 | void insert(repeater_arg_type, const assign_detail::fun_repeater& r) 464 | { 465 | repeat_fun(r.sz, r.val); 466 | } 467 | #endif 468 | #endif 469 | 470 | 471 | Function fun_private() const 472 | { 473 | return insert_; 474 | } 475 | 476 | private: 477 | 478 | list_inserter& operator=( const list_inserter& ); 479 | Function insert_; 480 | }; 481 | 482 | template< class Function > 483 | inline list_inserter< Function > 484 | make_list_inserter( Function fun ) 485 | { 486 | return list_inserter< Function >( fun ); 487 | } 488 | 489 | template< class Function, class Argument > 490 | inline list_inserter 491 | make_list_inserter( Function fun, Argument* ) 492 | { 493 | return list_inserter( fun ); 494 | } 495 | 496 | template< class C > 497 | inline list_inserter< assign_detail::call_push_back, 498 | BOOST_DEDUCED_TYPENAME C::value_type > 499 | push_back( C& c ) 500 | { 501 | static BOOST_DEDUCED_TYPENAME C::value_type* p = 0; 502 | return make_list_inserter( assign_detail::call_push_back( c ), 503 | p ); 504 | } 505 | 506 | template< class C > 507 | inline list_inserter< assign_detail::call_push_front, 508 | BOOST_DEDUCED_TYPENAME C::value_type > 509 | push_front( C& c ) 510 | { 511 | static BOOST_DEDUCED_TYPENAME C::value_type* p = 0; 512 | return make_list_inserter( assign_detail::call_push_front( c ), 513 | p ); 514 | } 515 | 516 | template< class C > 517 | inline list_inserter< assign_detail::call_insert, 518 | BOOST_DEDUCED_TYPENAME C::value_type > 519 | insert( C& c ) 520 | { 521 | static BOOST_DEDUCED_TYPENAME C::value_type* p = 0; 522 | return make_list_inserter( assign_detail::call_insert( c ), 523 | p ); 524 | } 525 | 526 | template< class C > 527 | inline list_inserter< assign_detail::call_push, 528 | BOOST_DEDUCED_TYPENAME C::value_type > 529 | push( C& c ) 530 | { 531 | static BOOST_DEDUCED_TYPENAME C::value_type* p = 0; 532 | return make_list_inserter( assign_detail::call_push( c ), 533 | p ); 534 | } 535 | 536 | template< class C > 537 | inline list_inserter< assign_detail::call_add_edge > 538 | add_edge( C& c ) 539 | { 540 | return make_list_inserter( assign_detail::call_add_edge( c ) ); 541 | } 542 | 543 | } // namespace 'assign' 544 | } // namespace 'boost' 545 | 546 | #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 547 | 548 | #undef BOOST_ASSIGN_PARAMS1 549 | #undef BOOST_ASSIGN_PARAMS2 550 | #undef BOOST_ASSIGN_PARAMS3 551 | #undef BOOST_ASSIGN_MAX_PARAMETERS 552 | 553 | #endif 554 | 555 | #endif 556 | -------------------------------------------------------------------------------- /include/boost/assign/ptr_list_inserter.hpp: -------------------------------------------------------------------------------- 1 | // Boost.Assign library 2 | // 3 | // Copyright Thorsten Ottosen 2003-2005. Use, modification and 4 | // distribution is subject to the Boost Software License, Version 5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | // For more information, see http://www.boost.org/libs/assign/ 9 | // 10 | 11 | #ifndef BOOST_ASSIGN_PTR_LIST_INSERTER_HPP 12 | #define BOOST_ASSIGN_PTR_LIST_INSERTER_HPP 13 | 14 | #if defined(_MSC_VER) 15 | # pragma once 16 | #endif 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #endif 30 | 31 | namespace boost 32 | { 33 | 34 | namespace assign 35 | { 36 | template< class Function, class Obj > 37 | class ptr_list_inserter 38 | { 39 | typedef BOOST_DEDUCED_TYPENAME 40 | remove_pointer< BOOST_DEDUCED_TYPENAME 41 | remove_reference::type >::type 42 | obj_type; 43 | public: 44 | 45 | ptr_list_inserter( Function fun ) : insert_( fun ) 46 | {} 47 | 48 | template< class Function2, class Obj2 > 49 | ptr_list_inserter( const ptr_list_inserter& r ) 50 | : insert_( r.fun_private() ) 51 | {} 52 | 53 | ptr_list_inserter( const ptr_list_inserter& r ) : insert_( r.insert_ ) 54 | {} 55 | 56 | 57 | #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 58 | ptr_list_inserter& operator()() 59 | { 60 | insert_( new obj_type() ); 61 | return *this; 62 | } 63 | 64 | template< class T > 65 | ptr_list_inserter& operator()( const T& t ) 66 | { 67 | insert_( new obj_type(t) ); 68 | return *this; 69 | } 70 | 71 | #ifndef BOOST_ASSIGN_MAX_PARAMS // use user's value 72 | #define BOOST_ASSIGN_MAX_PARAMS 5 73 | #endif 74 | #define BOOST_ASSIGN_MAX_PARAMETERS (BOOST_ASSIGN_MAX_PARAMS - 1) 75 | #define BOOST_ASSIGN_PARAMS1(n) BOOST_PP_ENUM_PARAMS(n, class T) 76 | #define BOOST_ASSIGN_PARAMS2(n) BOOST_PP_ENUM_BINARY_PARAMS(n, T, const& t) 77 | #define BOOST_ASSIGN_PARAMS3(n) BOOST_PP_ENUM_PARAMS(n, t) 78 | 79 | #define BOOST_PP_LOCAL_LIMITS (1, BOOST_ASSIGN_MAX_PARAMETERS) 80 | #define BOOST_PP_LOCAL_MACRO(n) \ 81 | template< class T, BOOST_ASSIGN_PARAMS1(n) > \ 82 | ptr_list_inserter& operator()( const T& t, BOOST_ASSIGN_PARAMS2(n) ) \ 83 | { \ 84 | insert_( new obj_type(t, BOOST_ASSIGN_PARAMS3(n) )); \ 85 | return *this; \ 86 | } \ 87 | /**/ 88 | 89 | #include BOOST_PP_LOCAL_ITERATE() 90 | 91 | #else 92 | 93 | template< class... Ts > 94 | ptr_list_inserter& operator()(Ts&&... ts) 95 | { 96 | insert_(new obj_type(boost::forward(ts)...)); 97 | return *this; 98 | } 99 | 100 | #endif 101 | 102 | private: 103 | 104 | ptr_list_inserter& operator=( const ptr_list_inserter& ); 105 | Function insert_; 106 | }; 107 | 108 | template< class Obj, class Function > 109 | inline ptr_list_inserter< Function, Obj > 110 | make_ptr_list_inserter( Function fun ) 111 | { 112 | return ptr_list_inserter< Function, Obj >( fun ); 113 | } 114 | 115 | template< class C > 116 | inline ptr_list_inserter< assign_detail::call_push_back, 117 | BOOST_DEDUCED_TYPENAME C::reference > 118 | ptr_push_back( C& c ) 119 | { 120 | return make_ptr_list_inserter 121 | ( assign_detail::call_push_back( c ) ); 122 | } 123 | 124 | #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING 125 | 126 | template< class T, class C > 127 | inline ptr_list_inserter< assign_detail::call_push_back, T > 128 | ptr_push_back( C& c ) 129 | { 130 | return make_ptr_list_inserter( 131 | assign_detail::call_push_back( c ) ); 132 | } 133 | 134 | #endif 135 | 136 | template< class C > 137 | inline ptr_list_inserter< assign_detail::call_push_front, 138 | BOOST_DEDUCED_TYPENAME C::reference > 139 | ptr_push_front( C& c ) 140 | { 141 | return make_ptr_list_inserter 142 | ( assign_detail::call_push_front( c ) ); 143 | } 144 | 145 | #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING 146 | 147 | template< class T, class C > 148 | inline ptr_list_inserter< assign_detail::call_push_front, T > 149 | ptr_push_front( C& c ) 150 | { 151 | return make_ptr_list_inserter( 152 | assign_detail::call_push_front( c ) ); 153 | } 154 | 155 | #endif 156 | 157 | template< class C > 158 | inline ptr_list_inserter< assign_detail::call_insert, 159 | BOOST_DEDUCED_TYPENAME C::reference> 160 | ptr_insert( C& c ) 161 | { 162 | return make_ptr_list_inserter 163 | ( assign_detail::call_insert( c ) ); 164 | } 165 | 166 | #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING 167 | 168 | template< class T, class C > 169 | inline ptr_list_inserter< assign_detail::call_insert, T > 170 | ptr_insert( C& c ) 171 | { 172 | return make_ptr_list_inserter( assign_detail::call_insert( c ) ); 173 | } 174 | 175 | #endif 176 | 177 | 178 | } // namespace 'assign' 179 | } // namespace 'boost' 180 | 181 | #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 182 | 183 | #undef BOOST_ASSIGN_PARAMS1 184 | #undef BOOST_ASSIGN_PARAMS2 185 | #undef BOOST_ASSIGN_PARAMS3 186 | #undef BOOST_ASSIGN_MAX_PARAMETERS 187 | 188 | #endif 189 | 190 | #endif 191 | -------------------------------------------------------------------------------- /include/boost/assign/ptr_list_of.hpp: -------------------------------------------------------------------------------- 1 | // Boost.Assign library 2 | // 3 | // Copyright Thorsten Ottosen 2003-2005. Use, modification and 4 | // distribution is subject to the Boost Software License, Version 5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | // For more information, see http://www.boost.org/libs/assign/ 9 | // 10 | 11 | 12 | #ifndef BOOST_ASSIGN_PTR_LIST_OF_HPP 13 | #define BOOST_ASSIGN_PTR_LIST_OF_HPP 14 | 15 | #if defined(_MSC_VER) 16 | # pragma once 17 | #endif 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #endif 37 | 38 | namespace boost 39 | { 40 | 41 | namespace assign_detail 42 | { 43 | ///////////////////////////////////////////////////////////////////////// 44 | // Part 1: flexible and efficient interface 45 | ///////////////////////////////////////////////////////////////////////// 46 | 47 | template< class T > 48 | class generic_ptr_list : 49 | public converter< generic_ptr_list, 50 | BOOST_DEDUCED_TYPENAME boost::ptr_vector::iterator > 51 | { 52 | protected: 53 | typedef boost::ptr_vector impl_type; 54 | #if defined(BOOST_NO_AUTO_PTR) 55 | typedef std::unique_ptr release_type; 56 | #else 57 | typedef std::auto_ptr release_type; 58 | #endif 59 | mutable impl_type values_; 60 | 61 | public: 62 | typedef BOOST_DEDUCED_TYPENAME impl_type::iterator iterator; 63 | typedef iterator const_iterator; 64 | typedef BOOST_DEDUCED_TYPENAME impl_type::value_type value_type; 65 | typedef BOOST_DEDUCED_TYPENAME impl_type::size_type size_type; 66 | typedef BOOST_DEDUCED_TYPENAME impl_type::difference_type difference_type; 67 | public: 68 | generic_ptr_list() : values_( 32u ) 69 | { } 70 | 71 | generic_ptr_list( release_type r ) : values_(r) 72 | { } 73 | 74 | release_type release() 75 | { 76 | return values_.release(); 77 | } 78 | 79 | public: 80 | iterator begin() const { return values_.begin(); } 81 | iterator end() const { return values_.end(); } 82 | bool empty() const { return values_.empty(); } 83 | size_type size() const { return values_.size(); } 84 | 85 | public: 86 | 87 | operator impl_type() const 88 | { 89 | return values_; 90 | } 91 | 92 | template< template class Seq, class U, 93 | class CA, class A > 94 | operator Seq() const 95 | { 96 | Seq result; 97 | result.transfer( result.end(), values_ ); 98 | BOOST_ASSERT( empty() ); 99 | return result; 100 | } 101 | 102 | template< class PtrContainer > 103 | #if defined(BOOST_NO_AUTO_PTR) 104 | std::unique_ptr 105 | #else 106 | std::auto_ptr 107 | #endif 108 | convert( const PtrContainer* c ) const 109 | { 110 | #if defined(BOOST_NO_AUTO_PTR) 111 | std::unique_ptr res( new PtrContainer() ); 112 | #else 113 | std::auto_ptr res( new PtrContainer() ); 114 | #endif 115 | while( !empty() ) 116 | res->insert( res->end(), 117 | values_.pop_back().release() ); 118 | return res; 119 | } 120 | 121 | template< class PtrContainer > 122 | #if defined(BOOST_NO_AUTO_PTR) 123 | std::unique_ptr 124 | #else 125 | std::auto_ptr 126 | #endif 127 | to_container( const PtrContainer& c ) const 128 | { 129 | return convert( &c ); 130 | } 131 | 132 | protected: 133 | void push_back( T* r ) { values_.push_back( r ); } 134 | 135 | public: 136 | #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 137 | 138 | generic_ptr_list& operator()() 139 | { 140 | this->push_back( new T() ); 141 | return *this; 142 | } 143 | 144 | template< class U > 145 | generic_ptr_list& operator()( const U& u ) 146 | { 147 | this->push_back( new T(u) ); 148 | return *this; 149 | } 150 | 151 | 152 | #ifndef BOOST_ASSIGN_MAX_PARAMS // use user's value 153 | #define BOOST_ASSIGN_MAX_PARAMS 5 154 | #endif 155 | #define BOOST_ASSIGN_MAX_PARAMETERS (BOOST_ASSIGN_MAX_PARAMS - 1) 156 | #define BOOST_ASSIGN_PARAMS1(n) BOOST_PP_ENUM_PARAMS(n, class U) 157 | #define BOOST_ASSIGN_PARAMS2(n) BOOST_PP_ENUM_BINARY_PARAMS(n, U, const& u) 158 | #define BOOST_ASSIGN_PARAMS3(n) BOOST_PP_ENUM_PARAMS(n, u) 159 | 160 | #define BOOST_PP_LOCAL_LIMITS (1, BOOST_ASSIGN_MAX_PARAMETERS) 161 | #define BOOST_PP_LOCAL_MACRO(n) \ 162 | template< class U, BOOST_ASSIGN_PARAMS1(n) > \ 163 | generic_ptr_list& operator()(U const& u, BOOST_ASSIGN_PARAMS2(n) ) \ 164 | { \ 165 | this->push_back( new T(u, BOOST_ASSIGN_PARAMS3(n))); \ 166 | return *this; \ 167 | } \ 168 | /**/ 169 | 170 | #include BOOST_PP_LOCAL_ITERATE() 171 | 172 | #else 173 | template< class... Us > 174 | generic_ptr_list& operator()(Us&&... us) 175 | { 176 | this->push_back(new T(boost::forward(us)...)); 177 | return *this; 178 | } 179 | #endif 180 | 181 | 182 | 183 | }; // class 'generic_ptr_list' 184 | 185 | } // namespace 'assign_detail' 186 | 187 | namespace assign 188 | { 189 | #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 190 | 191 | template< class T > 192 | inline assign_detail::generic_ptr_list 193 | ptr_list_of() 194 | { 195 | assign_detail::generic_ptr_list gpl; 196 | gpl(); 197 | return gpl; 198 | } 199 | 200 | template< class T, class U > 201 | inline assign_detail::generic_ptr_list 202 | ptr_list_of( const U& t ) 203 | { 204 | assign_detail::generic_ptr_list gpl; 205 | gpl( t ); 206 | return gpl; 207 | } 208 | 209 | 210 | #define BOOST_PP_LOCAL_LIMITS (1, BOOST_ASSIGN_MAX_PARAMETERS) 211 | #define BOOST_PP_LOCAL_MACRO(n) \ 212 | template< class T, class U, BOOST_ASSIGN_PARAMS1(n) > \ 213 | inline assign_detail::generic_ptr_list \ 214 | ptr_list_of(U const& u, BOOST_ASSIGN_PARAMS2(n) ) \ 215 | { \ 216 | return assign_detail::generic_ptr_list()(u, BOOST_ASSIGN_PARAMS3(n)); \ 217 | } \ 218 | /**/ 219 | 220 | #include BOOST_PP_LOCAL_ITERATE() 221 | 222 | #else 223 | template< class T, class... Us > 224 | inline assign_detail::generic_ptr_list 225 | ptr_list_of(Us&&... us) 226 | { 227 | assign_detail::generic_ptr_list gpl; 228 | gpl(boost::forward(us)...); 229 | return gpl; 230 | } 231 | 232 | #endif 233 | 234 | } // namespace 'assign' 235 | } // namespace 'boost' 236 | 237 | #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 238 | 239 | #undef BOOST_ASSIGN_PARAMS1 240 | #undef BOOST_ASSIGN_PARAMS2 241 | #undef BOOST_ASSIGN_PARAMS3 242 | #undef BOOST_ASSIGN_MAX_PARAMETERS 243 | 244 | #endif 245 | 246 | #endif 247 | -------------------------------------------------------------------------------- /include/boost/assign/ptr_map_inserter.hpp: -------------------------------------------------------------------------------- 1 | // Boost.Assign library 2 | // 3 | // Copyright Thorsten Ottosen 2006. Use, modification and 4 | // distribution is subject to the Boost Software License, Version 5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | // For more information, see http://www.boost.org/libs/assign/ 9 | // 10 | 11 | #ifndef BOOST_ASSIGN_PTR_CONTAINER_PTR_MAP_INSERTER_HPP 12 | #define BOOST_ASSIGN_PTR_CONTAINER_PTR_MAP_INSERTER_HPP 13 | 14 | #if defined(_MSC_VER) 15 | # pragma once 16 | #endif 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #endif 30 | 31 | namespace boost 32 | { 33 | 34 | namespace assign 35 | { 36 | template< class PtrMap, class Obj > 37 | class ptr_map_inserter 38 | { 39 | typedef BOOST_DEDUCED_TYPENAME 40 | remove_pointer< BOOST_DEDUCED_TYPENAME 41 | remove_reference::type >::type 42 | obj_type; 43 | typedef BOOST_DEDUCED_TYPENAME PtrMap::key_type 44 | key_type; 45 | 46 | public: 47 | 48 | ptr_map_inserter( PtrMap& m ) : m_( m ) 49 | {} 50 | 51 | #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 52 | 53 | template< class Key > 54 | ptr_map_inserter& operator()( const Key& t ) 55 | { 56 | key_type k(t); 57 | m_.insert( k, new obj_type ); 58 | return *this; 59 | } 60 | 61 | #ifndef BOOST_ASSIGN_MAX_PARAMS // use user's value 62 | #define BOOST_ASSIGN_MAX_PARAMS 6 63 | #endif 64 | #define BOOST_ASSIGN_MAX_PARAMETERS (BOOST_ASSIGN_MAX_PARAMS - 1) 65 | #define BOOST_ASSIGN_PARAMS1(n) BOOST_PP_ENUM_PARAMS(n, class T) 66 | #define BOOST_ASSIGN_PARAMS2(n) BOOST_PP_ENUM_BINARY_PARAMS(n, T, const& t) 67 | #define BOOST_ASSIGN_PARAMS3(n) BOOST_PP_ENUM_PARAMS(n, t) 68 | 69 | #define BOOST_PP_LOCAL_LIMITS (1, BOOST_ASSIGN_MAX_PARAMETERS) 70 | #define BOOST_PP_LOCAL_MACRO(n) \ 71 | template< class T, BOOST_ASSIGN_PARAMS1(n) > \ 72 | ptr_map_inserter& operator()( const T& t, BOOST_ASSIGN_PARAMS2(n) ) \ 73 | { \ 74 | key_type k(t); \ 75 | m_.insert( k, new obj_type( BOOST_ASSIGN_PARAMS3(n) ) ); \ 76 | return *this; \ 77 | } \ 78 | /**/ 79 | 80 | #include BOOST_PP_LOCAL_ITERATE() 81 | 82 | #else 83 | template< class Key, class... Ts > 84 | ptr_map_inserter& operator()(Key&& k, Ts&&... ts) 85 | { 86 | key_type key(boost::forward(k)); 87 | m_.insert(key, new obj_type(boost::forward(ts)...)); 88 | return *this; 89 | } 90 | 91 | #endif 92 | private: 93 | 94 | ptr_map_inserter& operator=( const ptr_map_inserter& ); 95 | PtrMap& m_; 96 | }; 97 | 98 | template< class PtrMap > 99 | inline ptr_map_inserter< PtrMap, typename PtrMap::mapped_reference > 100 | ptr_map_insert( PtrMap& m ) 101 | { 102 | return ptr_map_inserter< PtrMap, typename PtrMap::mapped_reference >( m ); 103 | } 104 | 105 | #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING 106 | 107 | template< class T, class PtrMap > 108 | inline ptr_map_inserter< PtrMap, T > 109 | ptr_map_insert( PtrMap& m ) 110 | { 111 | return ptr_map_inserter< PtrMap, T >( m ); 112 | } 113 | 114 | #endif 115 | 116 | } // namespace 'assign' 117 | } // namespace 'boost' 118 | 119 | #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 120 | 121 | #undef BOOST_ASSIGN_PARAMS1 122 | #undef BOOST_ASSIGN_PARAMS2 123 | #undef BOOST_ASSIGN_PARAMS3 124 | #undef BOOST_ASSIGN_MAX_PARAMETERS 125 | 126 | #endif 127 | 128 | #endif 129 | -------------------------------------------------------------------------------- /include/boost/assign/std.hpp: -------------------------------------------------------------------------------- 1 | // Boost.Assign library 2 | // 3 | // Copyright Thorsten Ottosen 2003-2004. Use, modification and 4 | // distribution is subject to the Boost Software License, Version 5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | // For more information, see http://www.boost.org/libs/assign/ 9 | // 10 | 11 | #ifndef BOOST_ASSIGN_STD_HPP 12 | #define BOOST_ASSIGN_STD_HPP 13 | 14 | #if defined(_MSC_VER) 15 | # pragma once 16 | #endif 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /include/boost/assign/std/deque.hpp: -------------------------------------------------------------------------------- 1 | // Boost.Assign library 2 | // 3 | // Copyright Thorsten Ottosen 2003-2004. Use, modification and 4 | // distribution is subject to the Boost Software License, Version 5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | // For more information, see http://www.boost.org/libs/assign/ 9 | // 10 | 11 | 12 | #ifndef BOOST_ASSIGN_STD_DEQUE_HPP 13 | #define BOOST_ASSIGN_STD_DEQUE_HPP 14 | 15 | #if defined(_MSC_VER) 16 | # pragma once 17 | #endif 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | namespace boost 25 | { 26 | namespace assign 27 | { 28 | #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 29 | 30 | template< class V, class A, class V2 > 31 | inline list_inserter< assign_detail::call_push_back< std::deque >, V > 32 | operator+=( std::deque& c, V2 v ) 33 | { 34 | return push_back( c )( v ); 35 | } 36 | 37 | #else 38 | 39 | template< class V, class A, class V2 > 40 | inline list_inserter< assign_detail::call_push_back< std::deque >, V > 41 | operator+=(std::deque& c, V2&& v) 42 | { 43 | return push_back(c)(boost::forward(v)); 44 | } 45 | 46 | #endif 47 | 48 | } 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /include/boost/assign/std/list.hpp: -------------------------------------------------------------------------------- 1 | // Boost.Assign library 2 | // 3 | // Copyright Thorsten Ottosen 2003-2004. Use, modification and 4 | // distribution is subject to the Boost Software License, Version 5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | // For more information, see http://www.boost.org/libs/assign/ 9 | // 10 | 11 | 12 | #ifndef BOOST_ASSIGN_STD_LIST_HPP 13 | #define BOOST_ASSIGN_STD_LIST_HPP 14 | 15 | #if defined(_MSC_VER) 16 | # pragma once 17 | #endif 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | namespace boost 25 | { 26 | namespace assign 27 | { 28 | #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 29 | 30 | template< class V, class A, class V2 > 31 | inline list_inserter< assign_detail::call_push_back< std::list >, V > 32 | operator+=( std::list& c, V2 v ) 33 | { 34 | return push_back( c )( v ); 35 | } 36 | 37 | #else 38 | 39 | template< class V, class A, class V2 > 40 | inline list_inserter< assign_detail::call_push_back< std::list >, V > 41 | operator+=(std::list& c, V2&& v) 42 | { 43 | return push_back(c)(boost::forward(v)); 44 | } 45 | 46 | #endif 47 | 48 | } 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /include/boost/assign/std/map.hpp: -------------------------------------------------------------------------------- 1 | // Boost.Assign library 2 | // 3 | // Copyright Thorsten Ottosen 2003-2004. Use, modification and 4 | // distribution is subject to the Boost Software License, Version 5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | // For more information, see http://www.boost.org/libs/assign/ 9 | // 10 | 11 | 12 | #ifndef BOOST_ASSIGN_STD_MAP_HPP 13 | #define BOOST_ASSIGN_STD_MAP_HPP 14 | 15 | #if defined(_MSC_VER) 16 | # pragma once 17 | #endif 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | namespace boost 24 | { 25 | namespace assign 26 | { 27 | 28 | template< class K, class V, class C, class A, class P > 29 | inline list_inserter< assign_detail::call_insert< std::map >, P > 30 | operator+=( std::map& m, const P& p ) 31 | { 32 | return insert( m )( p ); 33 | } 34 | 35 | template< class K, class V, class C, class A, class P > 36 | inline list_inserter< assign_detail::call_insert< std::multimap >, P > 37 | operator+=( std::multimap& m, const P& p ) 38 | { 39 | return insert( m )( p ); 40 | } 41 | 42 | } 43 | } 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /include/boost/assign/std/queue.hpp: -------------------------------------------------------------------------------- 1 | // Boost.Assign library 2 | // 3 | // Copyright Thorsten Ottosen 2003-2004. Use, modification and 4 | // distribution is subject to the Boost Software License, Version 5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | // For more information, see http://www.boost.org/libs/assign/ 9 | // 10 | 11 | 12 | #ifndef BOOST_ASSIGN_STD_QUEUE_HPP 13 | #define BOOST_ASSIGN_STD_QUEUE_HPP 14 | 15 | #if defined(_MSC_VER) 16 | # pragma once 17 | #endif 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | namespace boost 25 | { 26 | namespace assign 27 | { 28 | #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 29 | 30 | template< class V, class C, class V2 > 31 | inline list_inserter< assign_detail::call_push< std::queue >, V > 32 | operator+=( std::queue& c, V2 v ) 33 | { 34 | return push( c )( v ); 35 | } 36 | 37 | template< class V, class C, class V2 > 38 | inline list_inserter< assign_detail::call_push< std::priority_queue >, V > 39 | operator+=( std::priority_queue& c, V2 v ) 40 | { 41 | return push( c )( v ); 42 | } 43 | 44 | #else 45 | 46 | template< class V, class C, class V2 > 47 | inline list_inserter< assign_detail::call_push< std::queue >, V > 48 | operator+=(std::queue& c, V2&& v) 49 | { 50 | return push(c)(boost::forward(v)); 51 | } 52 | 53 | template< class V, class C, class V2 > 54 | inline list_inserter< assign_detail::call_push< std::priority_queue >, V > 55 | operator+=(std::priority_queue& c, V2&& v) 56 | { 57 | return push(c)(boost::forward(v)); 58 | } 59 | 60 | #endif 61 | } 62 | } 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /include/boost/assign/std/set.hpp: -------------------------------------------------------------------------------- 1 | // Boost.Assign library 2 | // 3 | // Copyright Thorsten Ottosen 2003-2004. Use, modification and 4 | // distribution is subject to the Boost Software License, Version 5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | // For more information, see http://www.boost.org/libs/assign/ 9 | // 10 | 11 | 12 | #ifndef BOOST_ASSIGN_STD_SET_HPP 13 | #define BOOST_ASSIGN_STD_SET_HPP 14 | 15 | #if defined(_MSC_VER) 16 | # pragma once 17 | #endif 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | namespace boost 25 | { 26 | namespace assign 27 | { 28 | 29 | #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 30 | 31 | template< class K, class C, class A, class K2 > 32 | inline list_inserter< assign_detail::call_insert< std::set >, K > 33 | operator+=( std::set& c, K2 k ) 34 | { 35 | return insert( c )( k ); 36 | } 37 | 38 | template< class K, class C, class A, class K2 > 39 | inline list_inserter< assign_detail::call_insert< std::multiset >, K > 40 | operator+=( std::multiset& c, K2 k ) 41 | { 42 | return insert( c )( k ); 43 | } 44 | 45 | #else 46 | 47 | template< class K, class C, class A, class K2 > 48 | inline list_inserter< assign_detail::call_insert< std::set >, K > 49 | operator+=(std::set& c, K2&& k) 50 | { 51 | return insert(c)(boost::forward(k)); 52 | } 53 | 54 | template< class K, class C, class A, class K2 > 55 | inline list_inserter< assign_detail::call_insert< std::multiset >, K > 56 | operator+=(std::multiset& c, K2&& k) 57 | { 58 | return insert(c)(boost::forward(k)); 59 | } 60 | 61 | #endif 62 | } 63 | } 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /include/boost/assign/std/slist.hpp: -------------------------------------------------------------------------------- 1 | // Boost.Assign library 2 | // 3 | // Copyright Thorsten Ottosen 2003-2004. Use, modification and 4 | // distribution is subject to the Boost Software License, Version 5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | // For more information, see http://www.boost.org/libs/assign/ 9 | // 10 | 11 | #ifndef BOOST_ASSIGN_STD_SLIST_HPP 12 | #define BOOST_ASSIGN_STD_SLIST_HPP 13 | 14 | #include 15 | #ifdef BOOST_HAS_SLIST 16 | 17 | #if defined(_MSC_VER) 18 | # pragma once 19 | #endif 20 | 21 | #include 22 | #include 23 | #ifdef BOOST_SLIST_HEADER 24 | # include BOOST_SLIST_HEADER 25 | #else 26 | # include 27 | #endif 28 | 29 | namespace boost 30 | { 31 | namespace assign 32 | { 33 | #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 34 | template< class V, class A, class V2 > 35 | inline list_inserter< assign_detail::call_push_back< BOOST_STD_EXTENSION_NAMESPACE::slist >, V > 36 | operator+=( BOOST_STD_EXTENSION_NAMESPACE::slist& c, V2 v ) 37 | { 38 | return push_back( c )( v ); 39 | } 40 | #else 41 | template< class V, class A, class V2 > 42 | inline list_inserter< assign_detail::call_push_back< BOOST_STD_EXTENSION_NAMESPACE::slist >, V > 43 | operator+=( BOOST_STD_EXTENSION_NAMESPACE::slist& c, V2&& v ) 44 | { 45 | return push_back( c )( boost::forward(v) ); 46 | } 47 | 48 | #endif 49 | } 50 | } 51 | 52 | #endif // BOOST_HAS_SLIST 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /include/boost/assign/std/stack.hpp: -------------------------------------------------------------------------------- 1 | // Boost.Assign library 2 | // 3 | // Copyright Thorsten Ottosen 2003-2004. Use, modification and 4 | // distribution is subject to the Boost Software License, Version 5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | // For more information, see http://www.boost.org/libs/assign/ 9 | // 10 | 11 | #ifndef BOOST_ASSIGN_STD_STACK_HPP 12 | #define BOOST_ASSIGN_STD_STACK_HPP 13 | 14 | #if defined(_MSC_VER) 15 | # pragma once 16 | #endif 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | namespace boost 24 | { 25 | namespace assign 26 | { 27 | #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 28 | 29 | template< class V, class C, class V2 > 30 | inline list_inserter< assign_detail::call_push< std::stack >, V > 31 | operator+=( std::stack& c, V2 v ) 32 | { 33 | return push( c )( v ); 34 | } 35 | 36 | #else 37 | 38 | template< class V, class C, class V2 > 39 | inline list_inserter< assign_detail::call_push< std::stack >, V > 40 | operator+=(std::stack& c, V2&& v) 41 | { 42 | return push(c)(boost::forward(v)); 43 | } 44 | 45 | #endif 46 | } 47 | } 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /include/boost/assign/std/vector.hpp: -------------------------------------------------------------------------------- 1 | // Boost.Assign library 2 | // 3 | // Copyright Thorsten Ottosen 2003-2004. Use, modification and 4 | // distribution is subject to the Boost Software License, Version 5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | // For more information, see http://www.boost.org/libs/assign/ 9 | // 10 | 11 | #ifndef BOOST_ASSIGN_STD_VECTOR_HPP 12 | #define BOOST_ASSIGN_STD_VECTOR_HPP 13 | 14 | #if defined(_MSC_VER) 15 | # pragma once 16 | #endif 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | namespace boost 24 | { 25 | namespace assign 26 | { 27 | #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) 28 | 29 | template< class V, class A, class V2 > 30 | inline list_inserter< assign_detail::call_push_back< std::vector >, V > 31 | operator+=( std::vector& c, V2 v ) 32 | { 33 | return push_back( c )( v ); 34 | } 35 | 36 | #else 37 | 38 | template< class V, class A, class V2 > 39 | inline list_inserter< assign_detail::call_push_back< std::vector >, V > 40 | operator+=( std::vector& c, V2&& v ) 41 | { 42 | return push_back( c )( std::forward(v) ); 43 | } 44 | 45 | #endif 46 | } 47 | } 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/assign/b452220f5de0f6205433c08cee63742102a424d2/index.html -------------------------------------------------------------------------------- /meta/libraries.json: -------------------------------------------------------------------------------- 1 | { 2 | "key": "assign", 3 | "name": "Assign", 4 | "authors": [ 5 | "Thorsten Ottosen" 6 | ], 7 | "description": "Filling containers with constant or generated data has never been easier.", 8 | "category": [ 9 | "IO" 10 | ], 11 | "maintainers": [ 12 | "Thorsten Ottosen " 13 | ], 14 | "cxxstd": "11" 15 | } 16 | -------------------------------------------------------------------------------- /test/Jamfile.v2: -------------------------------------------------------------------------------- 1 | # Boost.Assign library 2 | # 3 | # Copyright Thorsten Ottosen 2003-2005. Use, modification and 4 | # distribution is subject to the Boost Software License, Version 5 | # 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 | # http://www.boost.org/LICENSE_1_0.txt) 7 | # 8 | # For more information, see http://www.boost.org/libs/assign/ 9 | # 10 | 11 | import path ; 12 | import regex ; 13 | 14 | project : requirements /boost/assign//boost_assign ; 15 | 16 | rule assign-test ( name ) 17 | { 18 | return [ 19 | run $(name).cpp /boost/test//boost_unit_test_framework/static /boost/multi_index//boost_multi_index ] 20 | ; 21 | } 22 | 23 | # this rule enumerates through all the headers and ensures 24 | # that inclusion of the header by itself is sufficient to 25 | # compile successfully, proving the header does not depend 26 | # on any other headers to be included first - adapted from 27 | # logic in the winapi test bjam script 28 | rule test_headers 29 | { 30 | local all_rules = ; 31 | local file ; 32 | for file in [ glob-tree-ex ../include/boost/assign : *.hpp : assign ] 33 | { 34 | local rel_file = [ path.relative-to ../include/boost/assign $(file) ] ; 35 | # Note: The test name starts with '~' in order to group these tests in the test report table, preferably at the end. 36 | # All '/' are replaced with '-' because apparently test scripts have a problem with test names containing slashes. 37 | local test_name = [ regex.replace $(rel_file) "/" "-" ] ; 38 | local decl_test_name = ~hdr-decl-$(test_name) ; 39 | # ECHO $(rel_file) ; 40 | all_rules += [ compile compile/decl_header.cpp : "BOOST_ASSIGN_TEST_HEADER=$(rel_file)" $(file) : $(decl_test_name) ] ; 41 | } 42 | 43 | for file in [ glob-tree-ex compile-fail : *.cpp ] 44 | { 45 | local rel_file = [ path.relative-to compile-fail $(file) ] ; 46 | local test_name = [ regex.replace [ regex.replace $(rel_file) "/" "-" ] ".cpp" "" ] ; 47 | local decl_test_name = cf-$(test_name) ; 48 | # ECHO $(rel_file) ; 49 | all_rules += [ compile-fail $(file) : : $(decl_test_name) ] ; 50 | } 51 | 52 | # ECHO All rules: $(all_rules) ; 53 | return $(all_rules) ; 54 | } 55 | 56 | 57 | test-suite assign : 58 | [ test_headers ] 59 | [ assign-test basic ] 60 | [ assign-test std ] 61 | [ assign-test array ] 62 | [ assign-test list_of ] 63 | [ assign-test ptr_list_of ] 64 | [ assign-test static_list_of ] 65 | [ assign-test tuple_list_of ] 66 | [ assign-test list_inserter ] 67 | [ assign-test ptr_list_inserter ] 68 | [ assign-test ptr_map_inserter ] 69 | [ assign-test list_of_workaround ] 70 | [ assign-test email_example ] 71 | [ assign-test my_vector_example ] 72 | [ assign-test multi_index_container ] 73 | ; 74 | 75 | 76 | -------------------------------------------------------------------------------- /test/array.cpp: -------------------------------------------------------------------------------- 1 | // Boost.Assign library 2 | // 3 | // Copyright Thorsten Ottosen 2003-2004. Use, modification and 4 | // distribution is subject to the Boost Software License, Version 5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | // For more information, see http://www.boost.org/libs/assign/ 9 | // 10 | 11 | #include 12 | 13 | #if BOOST_WORKAROUND( BOOST_BORLANDC, BOOST_TESTED_AT(0x564) ) 14 | # pragma warn -8091 // suppress warning in Boost.Test 15 | # pragma warn -8057 // unused argument argc/argv in Boost.Test 16 | #endif 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #ifndef BOOST_NO_CXX11_HDR_ARRAY 26 | #include 27 | 28 | void check_std_array() 29 | { 30 | using namespace boost::assign; 31 | 32 | typedef std::array Array; 33 | 34 | Array a = list_of(1)(2)(3)(4)(5)(6); 35 | 36 | BOOST_CHECK_EQUAL( a[0], 1 ); 37 | BOOST_CHECK_EQUAL( a[5], 6 ); 38 | // last element is implicitly 0 39 | Array a2 = list_of(1)(2)(3)(4)(5); 40 | BOOST_CHECK_EQUAL( a2[5], 0 ); 41 | // two last elements are implicitly 42 | a2 = list_of(1)(2)(3)(4); 43 | BOOST_CHECK_EQUAL( a2[4], 0 ); 44 | BOOST_CHECK_EQUAL( a2[5], 0 ); 45 | // too many arguments 46 | BOOST_CHECK_THROW( a2 = list_of(1)(2)(3)(4)(5)(6)(7), assignment_exception ); 47 | } 48 | 49 | #endif 50 | 51 | void check_array() 52 | { 53 | using namespace boost::assign; 54 | 55 | typedef boost::array Array; 56 | 57 | 58 | #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) || BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564)) 59 | Array a = list_of(1)(2)(3)(4)(5)(6).to_array(a); 60 | #else 61 | Array a = list_of(1)(2)(3)(4)(5)(6); 62 | #endif 63 | 64 | BOOST_CHECK_EQUAL( a[0], 1 ); 65 | BOOST_CHECK_EQUAL( a[5], 6 ); 66 | // last element is implicitly 0 67 | #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) || BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564)) 68 | Array a2 = list_of(1)(2)(3)(4)(5).to_array(a2); 69 | #else 70 | Array a2 = list_of(1)(2)(3)(4)(5); 71 | #endif 72 | BOOST_CHECK_EQUAL( a2[5], 0 ); 73 | // two last elements are implicitly 74 | #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) || BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564)) 75 | a2 = list_of(1))(2)(3)(4).to_array(a2); 76 | #else 77 | a2 = list_of(1)(2)(3)(4); 78 | #endif 79 | BOOST_CHECK_EQUAL( a2[4], 0 ); 80 | BOOST_CHECK_EQUAL( a2[5], 0 ); 81 | // too many arguments 82 | #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) || BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564)) 83 | 84 | BOOST_CHECK_THROW( a2 = list_of(1)(2)(3)(4)(5)(6)(6).to_array(a2), 85 | assignment_exception ); 86 | #else 87 | BOOST_CHECK_THROW( a2 = list_of(1)(2)(3)(4)(5)(6)(7), assignment_exception ); 88 | #endif 89 | } 90 | 91 | 92 | #include 93 | using boost::unit_test::test_suite; 94 | 95 | 96 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 97 | { 98 | test_suite* test = BOOST_TEST_SUITE( "List Test Suite" ); 99 | 100 | test->add( BOOST_TEST_CASE( &check_array ) ); 101 | #ifndef BOOST_NO_CXX11_HDR_ARRAY 102 | test->add( BOOST_TEST_CASE( &check_std_array ) ); 103 | #endif 104 | 105 | return test; 106 | } 107 | 108 | -------------------------------------------------------------------------------- /test/basic.cpp: -------------------------------------------------------------------------------- 1 | // Boost.Assign library 2 | // 3 | // Copyright Thorsten Ottosen 2003-2004. Use, modification and 4 | // distribution is subject to the Boost Software License, Version 5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | // For more information, see http://www.boost.org/libs/assign/ 9 | // 10 | 11 | #include 12 | 13 | #if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564)) 14 | # pragma warn -8091 // suppress warning in Boost.Test 15 | # pragma warn -8057 // unused argument argc/argv in Boost.Test 16 | #endif 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | 23 | using namespace boost::assign; 24 | 25 | void check_basic_usage() 26 | { 27 | std::vector v; 28 | v += 1,2,3,4,5,6,7,8,9; 29 | push_back( v )(10)(11); 30 | std::map m; 31 | insert( m )( "foo", 1 )( "bar", 2 ); 32 | } 33 | 34 | 35 | 36 | #include 37 | using boost::unit_test::test_suite; 38 | 39 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 40 | { 41 | test_suite* test = BOOST_TEST_SUITE( "Assign Test Suite" ); 42 | 43 | test->add( BOOST_TEST_CASE( &check_basic_usage ) ); 44 | 45 | return test; 46 | } 47 | 48 | -------------------------------------------------------------------------------- /test/cmake_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2021-2024 Alexander Grund 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt 4 | 5 | cmake_minimum_required(VERSION 3.5...3.16) 6 | 7 | project(cmake_subdir_test LANGUAGES CXX) 8 | 9 | # Those 2 should work the same 10 | # while using find_package for the installed Boost avoids the need to manually specify dependencies 11 | if(BOOST_CI_INSTALL_TEST) 12 | find_package(boost_assign REQUIRED) 13 | else() 14 | set(BOOST_INCLUDE_LIBRARIES assign) 15 | add_subdirectory(../../../.. deps/boost EXCLUDE_FROM_ALL) 16 | endif() 17 | 18 | add_executable(main main.cpp) 19 | target_link_libraries(main Boost::assign) 20 | 21 | enable_testing() 22 | add_test(NAME main COMMAND main) 23 | -------------------------------------------------------------------------------- /test/cmake_test/main.cpp: -------------------------------------------------------------------------------- 1 | // This is the function operator+=() example from the documentation 2 | // 3 | #include // for 'operator+=()' 4 | #include 5 | 6 | using namespace std; 7 | using namespace boost::assign; // bring 'operator+=()' into scope 8 | 9 | int main() 10 | { 11 | vector values; 12 | values += 1,2,3,4,5,6,7,8,9; // insert values at the end of the container 13 | BOOST_ASSERT( values.size() == 9 ); 14 | BOOST_ASSERT( values[0] == 1 ); 15 | BOOST_ASSERT( values[8] == 9 ); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /test/compile/decl_header.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright Andrey Semashev 2015. 3 | * Distributed under the Boost Software License, Version 1.0. 4 | * (See accompanying file LICENSE_1_0.txt or copy at 5 | * http://www.boost.org/LICENSE_1_0.txt) 6 | */ 7 | /*! 8 | * \file decl_header.cpp 9 | * \author Andrey Semashev 10 | * \date 21.06.2015 11 | * 12 | * \brief This file contains a test boilerplate for checking that every 13 | * public header is self-contained and does not have any missing 14 | * #includes. 15 | */ 16 | 17 | #define BOOST_ASSIGN_TEST_INCLUDE_HEADER() 18 | 19 | #include BOOST_ASSIGN_TEST_INCLUDE_HEADER() 20 | 21 | int main(int, char*[]) 22 | { 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /test/email_example.cpp: -------------------------------------------------------------------------------- 1 | // Boost.Assign library 2 | // 3 | // Copyright Thorsten Ottosen 2003-2004. Use, modification and 4 | // distribution is subject to the Boost Software License, Version 5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | // For more information, see http://www.boost.org/libs/assign/ 9 | // 10 | 11 | 12 | #include 13 | 14 | #if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564)) 15 | # pragma warn -8091 // suppress warning in Boost.Test 16 | # pragma warn -8057 // unused argument argc/argv in Boost.Test 17 | #endif 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | namespace ba = boost::assign; 27 | 28 | class email 29 | { 30 | public: 31 | enum address_option 32 | { 33 | check_addr_book, 34 | dont_check_addr_book 35 | }; 36 | 37 | typedef std::pair bcc_type; 38 | typedef std::vector< bcc_type > bcc_map; 39 | typedef std::map address_map; 40 | 41 | 42 | private: 43 | 44 | mutable address_map cc_list; 45 | mutable address_map to_list; 46 | bcc_map bcc_list; 47 | 48 | struct add_to_map 49 | { 50 | address_map& m; 51 | 52 | add_to_map( address_map& m ) : m(m) 53 | {} 54 | 55 | void operator()( const std::string& name, address_option ao ) 56 | { 57 | m[ name ] = ao; 58 | } 59 | 60 | void operator()( const std::string& name ) 61 | { 62 | m[ name ] = check_addr_book; 63 | } 64 | }; 65 | 66 | struct add_to_vector 67 | { 68 | bcc_map& m; 69 | 70 | add_to_vector( bcc_map& m ) : m(m) 71 | {} 72 | 73 | void operator()( const bcc_type& r ) 74 | { 75 | m.push_back( r ); 76 | } 77 | }; 78 | 79 | public: 80 | 81 | ba::list_inserter< add_to_map > 82 | add_cc( std::string name, address_option ao ) 83 | { 84 | return ba::make_list_inserter( add_to_map( cc_list ) )( name, ao ); 85 | } 86 | 87 | ba::list_inserter< add_to_map > 88 | add_to( const std::string& name ) 89 | { 90 | return ba::make_list_inserter( add_to_map( to_list ) )( name ); 91 | } 92 | 93 | ba::list_inserter< add_to_vector, bcc_type > 94 | add_bcc( const bcc_type& bcc ) 95 | { 96 | return ba::make_list_inserter( add_to_vector( bcc_list ) )( bcc ); 97 | } 98 | 99 | address_option 100 | cc_at( const std::string& name ) const 101 | { 102 | return cc_list[ name ]; 103 | } 104 | 105 | address_option 106 | to_at( const std::string& name ) const 107 | { 108 | return to_list[ name ]; 109 | } 110 | 111 | address_option 112 | bcc_at( unsigned index ) const 113 | { 114 | return bcc_list.at( index ).second; 115 | } 116 | }; 117 | 118 | 119 | 120 | void check_list_inserter() 121 | { 122 | using namespace boost::assign; 123 | 124 | email e; 125 | e.add_cc( "franz", email::dont_check_addr_book ) 126 | ( "hanz", email::check_addr_book ) 127 | ( "betty", email::dont_check_addr_book ); 128 | BOOST_CHECK_EQUAL( e.cc_at( "franz" ), email::dont_check_addr_book ); 129 | BOOST_CHECK_EQUAL( e.cc_at( "hanz" ), email::check_addr_book ); 130 | BOOST_CHECK_EQUAL( e.cc_at( "betty" ), email::dont_check_addr_book ); 131 | 132 | e.add_to( "betsy" )( "peter" ); 133 | BOOST_CHECK_EQUAL( e.cc_at( "betsy" ), email::check_addr_book ); 134 | BOOST_CHECK_EQUAL( e.cc_at( "peter" ), email::check_addr_book ); 135 | 136 | e.add_bcc( email::bcc_type( "Mr. Foo", email::check_addr_book ) ) 137 | ( "Mr. Bar", email::dont_check_addr_book ); 138 | BOOST_CHECK_EQUAL( e.bcc_at( 0 ), email::check_addr_book ); 139 | BOOST_CHECK_EQUAL( e.bcc_at( 1 ), email::dont_check_addr_book ); 140 | 141 | } 142 | 143 | 144 | #include 145 | using boost::unit_test::test_suite; 146 | 147 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 148 | { 149 | test_suite* test = BOOST_TEST_SUITE( "List Test Suite" ); 150 | 151 | test->add( BOOST_TEST_CASE( &check_list_inserter ) ); 152 | 153 | return test; 154 | } 155 | 156 | -------------------------------------------------------------------------------- /test/list_inserter.cpp: -------------------------------------------------------------------------------- 1 | // Boost.Assign library 2 | // 3 | // Copyright Thorsten Ottosen 2003-2004. Use, modification and 4 | // distribution is subject to the Boost Software License, Version 5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | // For more information, see http://www.boost.org/libs/assign/ 9 | // 10 | 11 | #include 12 | 13 | #if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564)) 14 | # pragma warn -8091 // suppress warning in Boost.Test 15 | # pragma warn -8057 // unused argument argc/argv in Boost.Test 16 | #endif 17 | 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | 35 | namespace ba = boost::assign; 36 | 37 | void function_ptr( int ) 38 | { 39 | // do nothing 40 | } 41 | 42 | struct functor 43 | { 44 | template< class T > 45 | void operator()( T ) const 46 | { 47 | // do nothing 48 | } 49 | }; 50 | 51 | 52 | 53 | void check_list_inserter() 54 | { 55 | using namespace std; 56 | using namespace boost; 57 | using namespace boost::assign; 58 | vector v; 59 | 60 | // 61 | // @note: cast only necessary on CodeWarrior 62 | // 63 | make_list_inserter( (void (*)(int))&function_ptr )( 5 ),3; 64 | make_list_inserter( functor() )( 4 ),2; 65 | 66 | typedef void (vector::* push_back_t)(const int&); 67 | push_back_t push_back_func = &vector::push_back; 68 | make_list_inserter( boost::bind( push_back_func, &v, _1 ) )( 6 ),4; 69 | 70 | BOOST_CHECK_EQUAL( v.size(), 2u ); 71 | BOOST_CHECK_EQUAL( v[0], 6 ); 72 | BOOST_CHECK_EQUAL( v[1], 4 ); 73 | 74 | push_back( v ) = 1,2,3,4,5; 75 | BOOST_CHECK_EQUAL( v.size(), 7u ); 76 | BOOST_CHECK_EQUAL( v[6], 5 ); 77 | 78 | push_back( v )(6).repeat( 10, 7 )(8); 79 | BOOST_CHECK_EQUAL( v.size(), 19u ); 80 | BOOST_CHECK_EQUAL( v[18], 8 ); 81 | BOOST_CHECK_EQUAL( v[8], 7 ); 82 | BOOST_CHECK_EQUAL( v[16], 7 ); 83 | 84 | #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1200) 85 | push_back( v ) = repeat_fun( 10, &rand ); 86 | #else 87 | push_back( v ).repeat_fun( 10, &rand ); 88 | #endif 89 | 90 | BOOST_CHECK_EQUAL( v.size(), 29u ); 91 | 92 | #if BOOST_WORKAROUND(BOOST_MSVC, <= 1200) || BOOST_WORKAROUND(__SUNPRO_CC, <= 0x580 ) 93 | push_back( v )(1).repeat( 10, 2 )(3); 94 | #else 95 | push_back( v ) = 1,repeat( 10, 2 ),3; 96 | #endif 97 | BOOST_CHECK_EQUAL( v.size(), 41u ); 98 | 99 | #if BOOST_WORKAROUND(BOOST_MSVC, <= 1200) || BOOST_WORKAROUND(__SUNPRO_CC, <= 0x580 ) 100 | push_back( v )(1).repeat_fun( 10, &rand )(2); 101 | #else 102 | push_back( v ) = 1,repeat_fun( 10, &rand ),2; 103 | #endif 104 | 105 | BOOST_CHECK_EQUAL( v.size(), 53u ); 106 | 107 | typedef map map_t; 108 | typedef map_t::value_type V; 109 | map_t m; 110 | 111 | make_list_inserter( assign_detail::call_insert< map_t >( m ) ) 112 | ( V("bar",3) )( V("foo", 2) ); 113 | BOOST_CHECK_EQUAL( m.size(), 2u ); 114 | BOOST_CHECK_EQUAL( m["foo"], 2 ); 115 | 116 | 117 | #if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564)) \ 118 | || BOOST_WORKAROUND(BOOST_MSVC, <=1300) \ 119 | || BOOST_WORKAROUND(BOOST_MSVC, ==1700) \ 120 | || !defined( BOOST_NO_CXX11_HDR_INITIALIZER_LIST ) 121 | #else 122 | 123 | typedef vector score_type; 124 | typedef map team_score_map; 125 | typedef std::pair score_pair; 126 | team_score_map team_score; 127 | insert( team_score )( "Team Foo", list_of(1)(1)(0) ) 128 | ( "Team Bar", list_of(0)(0)(0) ) 129 | ( "Team FooBar", list_of(0)(0)(1) ); 130 | BOOST_CHECK_EQUAL( team_score.size(), 3u ); 131 | BOOST_CHECK_EQUAL( team_score[ "Team Foo" ][1], 1 ); 132 | BOOST_CHECK_EQUAL( team_score[ "Team Bar" ][0], 0 ); 133 | 134 | team_score = list_of< score_pair > 135 | ( "Team Foo", list_of(1)(1)(0) ) 136 | ( "Team Bar", list_of(0)(0)(0) ) 137 | ( "Team FooBar", list_of(0)(0)(1) ); 138 | BOOST_CHECK_EQUAL( team_score.size(), 3u ); 139 | BOOST_CHECK_EQUAL( team_score[ "Team Foo" ][1], 1 ); 140 | BOOST_CHECK_EQUAL( team_score[ "Team Bar" ][0], 0 ); 141 | #endif 142 | 143 | } 144 | 145 | 146 | 147 | #include 148 | using boost::unit_test::test_suite; 149 | 150 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 151 | { 152 | test_suite* test = BOOST_TEST_SUITE( "List Test Suite" ); 153 | 154 | test->add( BOOST_TEST_CASE( &check_list_inserter ) ); 155 | 156 | return test; 157 | } 158 | 159 | -------------------------------------------------------------------------------- /test/list_of.cpp: -------------------------------------------------------------------------------- 1 | // Boost.Assign library 2 | // 3 | // Copyright Thorsten Ottosen 2003-2004. Use, modification and 4 | // distribution is subject to the Boost Software License, Version 5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | // For more information, see http://www.boost.org/libs/assign/ 9 | // 10 | 11 | 12 | #include 13 | 14 | #if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564)) 15 | # pragma warn -8091 // suppress warning in Boost.Test 16 | # pragma warn -8057 // unused argument argc/argv in Boost.Test 17 | #endif 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | struct nothing 34 | { 35 | template< class T > 36 | void operator()( T ) 37 | { } 38 | 39 | }; 40 | 41 | template< class Range > 42 | void for_each( const Range& r ) 43 | { 44 | std::for_each( r.begin(), r.end(), nothing() ); 45 | } 46 | 47 | namespace ba = boost::assign; 48 | 49 | template< class C > 50 | void test_sequence_list_of_string() 51 | { 52 | #if BOOST_WORKAROUND(BOOST_MSVC, <=1300) 53 | const C c = ba::list_of( "foo" )( "bar" ).to_container( c ); 54 | #else 55 | const C c = ba::list_of( "foo" )( "bar" ); 56 | #endif 57 | BOOST_CHECK_EQUAL( c.size(), 2u ); 58 | } 59 | 60 | struct parameter_list 61 | { 62 | int val; 63 | 64 | template< class T > 65 | parameter_list( T ) 66 | : val(0) 67 | { } 68 | 69 | template< class T > 70 | parameter_list( const T&, int ) 71 | : val(1) 72 | { } 73 | }; 74 | 75 | template< class C > 76 | void test_sequence_list_of_int() 77 | { 78 | using namespace std; 79 | #if BOOST_WORKAROUND(BOOST_MSVC, <=1300) 80 | 81 | const C c = ba::list_of(1)(2)(3)(4).to_container( c ); 82 | const C c2 = ba::list_of(1)(2)(3)(4).to_container( c2 ); 83 | BOOST_CHECK_EQUAL( c.size(), 4u ); 84 | BOOST_CHECK_EQUAL( c2.size(), 4u ); 85 | C c3 = ba::list_of(1).repeat( 1, 2 )(3).to_container( c3 ); 86 | BOOST_CHECK_EQUAL( c3.size(), 3u ); 87 | 88 | c3 = ba::list_of(1).repeat_fun( 10, &rand )(2)(3).to_container( c3 ); 89 | BOOST_CHECK_EQUAL( c3.size(), 13u ); 90 | 91 | #else 92 | 93 | const C c = ba::list_of(1)(2)(3)(4); 94 | const C c2 = ba::list_of(1)(2)(3)(4); 95 | BOOST_CHECK_EQUAL( c.size(), 4u ); 96 | BOOST_CHECK_EQUAL( c2.size(), 4u ); 97 | C c3 = ba::list_of(1).repeat( 1, 2 )(3); 98 | BOOST_CHECK_EQUAL( c3.size(), 3u ); 99 | 100 | #if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564)) 101 | // BCB fails to use operator=() directly, 102 | // it must be worked around using e.g. auxiliary variable 103 | C aux = ba::list_of(1).repeat_fun( 10, &rand )(2)(3); 104 | BOOST_CHECK_EQUAL( aux.size(), 13u ); 105 | c3 = aux; 106 | BOOST_CHECK_EQUAL( c3.size(), 13u ); 107 | #elif defined( BOOST_NO_CXX11_HDR_INITIALIZER_LIST ) 108 | c3 = ba::list_of(1).repeat_fun( 10, &rand )(2)(3); 109 | BOOST_CHECK_EQUAL( c3.size(), 13u ); 110 | #endif 111 | 112 | #if !defined( BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS ) 113 | C c4; 114 | c4 = ba::list_of(1)(2)(3)(4); 115 | BOOST_CHECK_EQUAL( c4.size(), 4u ); 116 | C c5(ba::list_of(1)(2)(3)(4)(5)); 117 | BOOST_CHECK_EQUAL( c5.size(), 5u ); 118 | #endif 119 | 120 | #endif 121 | 122 | parameter_list p( ba::list_of(1)(2), 3u ); 123 | BOOST_CHECK_EQUAL( p.val, 1 ); 124 | 125 | } 126 | 127 | template< class C > 128 | void test_map_list_of() 129 | { 130 | const C c = ba::list_of< std::pair >( "foo", 1 )( "bar", 2 )( "buh", 3 )( "bah", 4 ); 131 | BOOST_CHECK_EQUAL( c.size(), 4u ); 132 | const C c2 = ba::map_list_of( "foo", 1 )( "bar", 2 )( "buh", 3 )( "bah", 4 ); 133 | BOOST_CHECK_EQUAL( c2.size(), 4u ); 134 | } 135 | 136 | void test_vector_matrix() 137 | { 138 | using namespace boost; 139 | using namespace boost::assign; 140 | using namespace std; 141 | using boost::array; 142 | 143 | #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) || BOOST_WORKAROUND(BOOST_MSVC, <=1300) 144 | #else 145 | 146 | const int sz = 3; 147 | typedef array row3; 148 | typedef array matrix3x3; 149 | 150 | 151 | matrix3x3 m = list_of( list_of(1)(2)(3) ) 152 | ( list_of(4)(5)(6) ) 153 | ( list_of(7)(8)(9) ); 154 | 155 | for( int i = 0; i != sz; ++i ) 156 | for( int j = 0; j != sz; ++j ) 157 | BOOST_CHECK_EQUAL( m[i][j], i*sz + j + 1 ); 158 | 159 | typedef vector row; 160 | typedef vector matrix; 161 | 162 | // 163 | // note: some libraries need a little help 164 | // with the conversion, hence the 'row' template parameter. 165 | // 166 | matrix m2 = list_of< row >( list_of(1)(2)(3) ) 167 | ( list_of(4)(5) ) 168 | ( list_of(6) ); 169 | 170 | for( int i = 0; i != sz; ++i ) 171 | for( int j = 0; j != sz - i; ++j ) 172 | BOOST_CHECK_EQUAL( m[i][j], i*sz + j + 1 ); 173 | 174 | #endif 175 | 176 | } 177 | 178 | void test_map_list_of() 179 | { 180 | /* 181 | maybe in the future... 182 | 183 | using namespace std; 184 | using namespace boost::assign; 185 | 186 | typedef vector score_type; 187 | typedef map team_score_map; 188 | 189 | team_score_map team_score = map_list_of 190 | ( "Team Foo", list_of(1)(1)(0) ) 191 | ( "Team Bar", list_of(0)(0)(0) ) 192 | ( "Team FooBar", list_of(0)(0)(1) ); 193 | BOOST_CHECK_EQUAL( team_score.size(), 3 ); 194 | BOOST_CHECK_EQUAL( team_score[ "Team Foo" ][1], 1 ); 195 | BOOST_CHECK_EQUAL( team_score[ "Team Bar" ][0], 0 ); 196 | */ 197 | 198 | } 199 | 200 | /* 201 | void test_complex_list_of() 202 | { 203 | typedef std::complex complex_t; 204 | std::vector v; 205 | v = ba::list_of(1,2)(2,3)(4,5)(0). 206 | repeat_from_to( complex_t(0,0), complex_t(10,10), complex_t(1,1) ); 207 | } 208 | */ 209 | 210 | struct five 211 | { 212 | five( int, int, int, int, int ) 213 | { 214 | } 215 | }; 216 | 217 | void test_list_of() 218 | { 219 | ba::list_of< five >(1,2,3,4,5)(6,7,8,9,10); 220 | 221 | /* Maybe this could be useful in a later version? 222 | 223 | // an anonymous lists, fulfills Range concept 224 | for_each( ba::list_of( T() )( T() )( T() ) ); 225 | 226 | // non-anonymous lists 227 | ba::generic_list list_1 = ba::list_of( T() ); 228 | BOOST_CHECK_EQUAL( list_1.size(), 1 ); 229 | ba::generic_list list_2 = list_1 + ba::list_of( T() )( T() ) + list_1; 230 | BOOST_CHECK_EQUAL( list_2.size(), 4 ); 231 | list_1 += list_2; 232 | BOOST_CHECK_EQUAL( list_1.size(), 5 ); 233 | */ 234 | } 235 | 236 | // 237 | // @remark: ADL is required here, but it is a bit weird to 238 | // open up namespace std. Perhaps Boost.Test needs a 239 | // better configuration option. 240 | // 241 | namespace std 242 | { 243 | template< class T, class Elem, class Traits > 244 | inline std::basic_ostream& 245 | operator<<( std::basic_ostream& Os, 246 | const std::vector& r ) 247 | { 248 | return Os << ::boost::make_iterator_range( r.begin(), r.end() ); 249 | } 250 | } 251 | 252 | template 253 | inline std::vector as_seq( const Seq& s ) 254 | { 255 | std::vector c; 256 | return s.to_container( c ); 257 | } 258 | 259 | void test_comparison_operations() 260 | { 261 | BOOST_CHECK_EQUAL( ba::list_of(0)(1)(2), as_seq(ba::list_of(0)(1)(2)) ); 262 | BOOST_CHECK_NE( ba::list_of(0)(1)(2), as_seq(ba::list_of(-1)(1)(2)) ); 263 | BOOST_CHECK_LT( ba::list_of(0)(1)(2), as_seq(ba::list_of(0)(1)(3)) ); 264 | BOOST_CHECK_LE( ba::list_of(0)(1)(2), as_seq(ba::list_of(0)(1)(2)) ); 265 | BOOST_CHECK_GT( ba::list_of(0)(1)(3), as_seq(ba::list_of(0)(1)(2)) ); 266 | BOOST_CHECK_GE( ba::list_of(0)(1)(2), as_seq(ba::list_of(0)(1)(2)) ); 267 | BOOST_CHECK_EQUAL( as_seq(ba::list_of(0)(1)(2)), ba::list_of(0)(1)(2) ); 268 | BOOST_CHECK_NE( as_seq(ba::list_of(0)(1)(2)), ba::list_of(-1)(1)(2) ); 269 | BOOST_CHECK_LT( as_seq(ba::list_of(0)(1)(2)), ba::list_of(0)(1)(3) ); 270 | BOOST_CHECK_LE( as_seq(ba::list_of(0)(1)(2)), ba::list_of(0)(1)(2) ); 271 | BOOST_CHECK_GT( as_seq(ba::list_of(0)(1)(3)), ba::list_of(0)(1)(2) ); 272 | BOOST_CHECK_GE( as_seq(ba::list_of(0)(1)(2)), ba::list_of(0)(1)(2) ); 273 | } 274 | 275 | void check_list_of() 276 | { 277 | test_sequence_list_of_int< std::vector >(); 278 | test_sequence_list_of_int< std::list >(); 279 | test_sequence_list_of_int< std::deque >(); 280 | test_sequence_list_of_int< std::set >(); 281 | test_sequence_list_of_int< std::multiset >(); 282 | test_sequence_list_of_int< std::vector >(); 283 | 284 | test_sequence_list_of_string< std::vector >(); 285 | 286 | test_map_list_of< std::map >(); 287 | test_map_list_of< std::multimap >(); 288 | 289 | std::stack s = ba::list_of( "Foo" )( "Bar" )( "FooBar" ).to_adapter( s ); 290 | test_list_of(); 291 | test_vector_matrix(); 292 | test_comparison_operations(); 293 | } 294 | 295 | 296 | 297 | #include 298 | using boost::unit_test::test_suite; 299 | 300 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 301 | { 302 | test_suite* test = BOOST_TEST_SUITE( "List Test Suite" ); 303 | 304 | test->add( BOOST_TEST_CASE( &check_list_of ) ); 305 | 306 | return test; 307 | } 308 | 309 | 310 | -------------------------------------------------------------------------------- /test/list_of_workaround.cpp: -------------------------------------------------------------------------------- 1 | // Boost.Assign library 2 | // 3 | // Copyright Thorsten Ottosen 2003-2004. Use, modification and 4 | // distribution is subject to the Boost Software License, Version 5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | // For more information, see http://www.boost.org/libs/assign/ 9 | // 10 | 11 | 12 | #include 13 | 14 | #if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564)) 15 | # pragma warn -8091 // suppress warning in Boost.Test 16 | # pragma warn -8057 // unused argument argc/argv in Boost.Test 17 | #endif 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | void check_list_of() 29 | { 30 | using namespace std; 31 | using namespace boost; 32 | using namespace boost::assign; 33 | using boost::array; 34 | 35 | vector v = list_of(1)(2)(3)(4).to_container( v ); 36 | set s = list_of(1)(2)(3)(4).to_container( s ); 37 | map m = map_list_of(1,2)(2,3).to_container( m ); 38 | stack st = list_of(1)(2)(3)(4).to_adapter( st ); 39 | queue q = list_of(1)(2)(3)(4).to_adapter( q ); 40 | array a = list_of(1)(2)(3)(4).to_array( a ); 41 | const vector v2 = list_of(1).to_container( v2 ); 42 | const array a2 = list_of(1).to_array( a2 ); 43 | } 44 | 45 | 46 | 47 | #include 48 | using boost::unit_test::test_suite; 49 | 50 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 51 | { 52 | test_suite* test = BOOST_TEST_SUITE( "List Test Suite" ); 53 | 54 | test->add( BOOST_TEST_CASE( &check_list_of ) ); 55 | 56 | return test; 57 | } 58 | 59 | 60 | -------------------------------------------------------------------------------- /test/multi_index_container.cpp: -------------------------------------------------------------------------------- 1 | // Boost.Assign library 2 | // 3 | // Copyright Thorsten Ottosen 2003-2004. Use, modification and 4 | // distribution is subject to the Boost Software License, Version 5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | // For more information, see http://www.boost.org/libs/assign/ 9 | // 10 | 11 | 12 | #include 13 | 14 | #if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564)) 15 | # pragma warn -8091 // suppress warning in Boost.Test 16 | # pragma warn -8057 // unused argument argc/argv in Boost.Test 17 | #endif 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | using namespace boost; 33 | using namespace boost::multi_index; 34 | namespace ba = boost::assign; 35 | 36 | // 37 | // Define a classical multi_index_container for employees 38 | // 39 | struct employee 40 | { 41 | int id; 42 | std::string name; 43 | int age; 44 | 45 | employee(int id_,std::string name_,int age_):id(id_),name(name_),age(age_){} 46 | 47 | bool operator==(const employee& x)const 48 | { 49 | return id==x.id&&name==x.name&&age==x.age; 50 | } 51 | 52 | bool operator<(const employee& x)const 53 | { 54 | return id (const employee& x)const{return x<*this;} 59 | bool operator>=(const employee& x)const{return !(*this >, 86 | ordered_non_unique< 87 | tag, 88 | BOOST_MULTI_INDEX_MEMBER(employee,std::string,name)>, 89 | ordered_non_unique< 90 | tag, 91 | BOOST_MULTI_INDEX_MEMBER(employee,int,age)>, 92 | sequenced< 93 | tag > > > 94 | employee_set; 95 | 96 | #if defined(BOOST_NO_MEMBER_TEMPLATES) 97 | typedef nth_index< 98 | employee_set,1>::type employee_set_by_name; 99 | #else 100 | typedef employee_set::nth_index<1>::type employee_set_by_name; 101 | #endif 102 | 103 | typedef boost::multi_index::index< 104 | employee_set,age>::type employee_set_by_age; 105 | typedef boost::multi_index::index< 106 | employee_set,as_inserted>::type employee_set_as_inserted; 107 | 108 | // 109 | // Define a multi_index_container with a list-like index and an ordered index 110 | // 111 | typedef multi_index_container< 112 | std::string, 113 | indexed_by< 114 | sequenced<>, // list-like index 115 | ordered_non_unique > // words by alphabetical order 116 | > 117 | > text_container; 118 | 119 | 120 | 121 | void test_multi_index_container() 122 | { 123 | employee_set eset = ba::list_of< employee >(1,"Franz",30)(2,"Hanz",40)(3,"Ilse",50); 124 | BOOST_CHECK( eset.size() == 3u ); 125 | 126 | // 127 | // This container is associative, hence we can use 'insert()' 128 | // 129 | 130 | ba::insert( eset )(4,"Kurt",55)(5,"Bjarne",77)(7,"Thorsten",24); 131 | BOOST_CHECK( eset.size() == 6u ); 132 | 133 | employee_set_by_name& name_index = boost::multi_index::get(eset); 134 | employee_set_by_name::iterator i = name_index.find("Ilse"); 135 | BOOST_CHECK( i->id == 3 ); 136 | BOOST_CHECK( i->age == 50 ); 137 | 138 | text_container text = ba::list_of< std::string >("Have")("you")("ever")("wondered")("how")("much")("Boost")("rocks?!"); 139 | BOOST_CHECK_EQUAL( text.size(), 8u ); 140 | BOOST_CHECK_EQUAL( *text.begin(), "Have" ); 141 | 142 | // 143 | // This container is a sequence, hence we can use 'push_back()' and 'push_font()' 144 | // 145 | 146 | ba::push_back( text )("Well")(",")("A")("LOT")(",")("obviously!"); 147 | BOOST_CHECK_EQUAL( text.size(), 14u ); 148 | BOOST_CHECK_EQUAL( *--text.end(), "obviously!" ); 149 | 150 | ba::push_front( text ) = "question:", "simple", "A"; 151 | BOOST_CHECK_EQUAL( text.size(), 17u ); 152 | BOOST_CHECK_EQUAL( text.front(), "A" ); 153 | } 154 | 155 | 156 | 157 | using boost::unit_test::test_suite; 158 | 159 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 160 | { 161 | test_suite* test = BOOST_TEST_SUITE( "List Test Suite" ); 162 | 163 | test->add( BOOST_TEST_CASE( &test_multi_index_container ) ); 164 | 165 | return test; 166 | } 167 | 168 | 169 | -------------------------------------------------------------------------------- /test/my_vector_example.cpp: -------------------------------------------------------------------------------- 1 | // Boost.Assign library 2 | // 3 | // Copyright Thorsten Ottosen 2003-2004. Use, modification and 4 | // distribution is subject to the Boost Software License, Version 5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | // For more information, see http://www.boost.org/libs/assign/ 9 | // 10 | 11 | 12 | #include 13 | 14 | #if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564)) 15 | # pragma warn -8091 // suppress warning in Boost.Test 16 | # pragma warn -8057 // unused argument argc/argv in Boost.Test 17 | #endif 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | namespace ba = boost::assign; 27 | 28 | 29 | 30 | template< class C > 31 | class range_inserter 32 | { 33 | typedef typename C::iterator iterator; 34 | iterator begin, end; 35 | public: 36 | range_inserter( C& c ) 37 | : begin( c.begin() ), end( c.end() ) 38 | { } 39 | 40 | template< class T > 41 | void operator()( T r ) 42 | { 43 | if( begin == end ) 44 | throw std::range_error( "range error: " ); 45 | *begin = r; 46 | ++begin; 47 | } 48 | }; 49 | 50 | 51 | 52 | template< class C > 53 | inline range_inserter make_range_inserter( C& c ) 54 | { 55 | return range_inserter( c ); 56 | } 57 | 58 | 59 | 60 | template< class T > 61 | class my_vector 62 | { 63 | typedef std::vector vector_t; 64 | typedef typename vector_t::size_type size_type; 65 | vector_t data_; 66 | 67 | public: 68 | my_vector() : data_( 10, 0 ) 69 | { } 70 | 71 | ba::list_inserter< range_inserter< vector_t >, T > 72 | operator=( T r ) 73 | { 74 | return ba::make_list_inserter( make_range_inserter( data_ ) )( r ); 75 | } 76 | 77 | size_type size() const 78 | { 79 | return data_.size(); 80 | } 81 | 82 | const T& operator[]( size_type index ) 83 | { 84 | return data_.at( index ); 85 | } 86 | }; 87 | 88 | 89 | 90 | void check_list_inserter() 91 | { 92 | using namespace std; 93 | using namespace boost::assign; 94 | 95 | my_vector vec; 96 | vec = 1,2,3,4,5,6,7,8,9,10; 97 | BOOST_CHECK_EQUAL( vec.size(), 10u ); 98 | BOOST_CHECK_EQUAL( vec[0], 1 ); 99 | BOOST_CHECK_EQUAL( vec[9], 10 ); 100 | } 101 | 102 | 103 | 104 | #include 105 | using boost::unit_test::test_suite; 106 | 107 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 108 | { 109 | test_suite* test = BOOST_TEST_SUITE( "List Test Suite" ); 110 | 111 | test->add( BOOST_TEST_CASE( &check_list_inserter ) ); 112 | 113 | return test; 114 | } 115 | 116 | -------------------------------------------------------------------------------- /test/ptr_list_inserter.cpp: -------------------------------------------------------------------------------- 1 | // Boost.Assign library 2 | // 3 | // Copyright Thorsten Ottosen 2003-2006. Use, modification and 4 | // distribution is subject to the Boost Software License, Version 5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | // For more information, see http://www.boost.org/libs/assign/ 9 | // 10 | 11 | #include 12 | 13 | #if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564)) 14 | # pragma warn -8091 // suppress warning in Boost.Test 15 | # pragma warn -8057 // unused argument argc/argv in Boost.Test 16 | #endif 17 | 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | struct Foo 26 | { 27 | int i; 28 | 29 | Foo() : i(0) 30 | { } 31 | Foo( int i ) : i(i) 32 | { } 33 | Foo( int i, int ) : i(i) 34 | { } 35 | Foo( const char*, int i, int ) : i(i) 36 | { } 37 | 38 | virtual ~Foo() 39 | { } 40 | }; 41 | 42 | struct FooBar : Foo 43 | { 44 | FooBar( int i ) : Foo(i) 45 | { } 46 | 47 | FooBar( int i, const char* ) 48 | { } 49 | }; 50 | 51 | inline bool operator<( const Foo& l, const Foo& r ) 52 | { 53 | return l.i < r.i; 54 | } 55 | 56 | void check_ptr_list_inserter() 57 | { 58 | using namespace std; 59 | using namespace boost; 60 | using namespace boost::assign; 61 | 62 | ptr_deque deq; 63 | ptr_push_back( deq )()(); 64 | BOOST_CHECK( deq.size() == 2u ); 65 | 66 | ptr_push_front( deq )( 3 )( 42, 42 )( "foo", 42, 42 ); 67 | BOOST_CHECK( deq.size() == 5u ); 68 | 69 | ptr_set a_set; 70 | ptr_insert( a_set )()( 1 )( 2, 2 )( "foo", 3, 3 ); 71 | BOOST_CHECK( a_set.size() == 4u ); 72 | ptr_insert( a_set )()()()(); 73 | BOOST_CHECK( a_set.size() == 4u ); // duplicates not inserted 74 | 75 | #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING 76 | 77 | ptr_push_back( deq )( 42, "42" ); 78 | BOOST_CHECK_EQUAL( deq.size(), 6u ); 79 | BOOST_CHECK( typeid(deq[5u]) == typeid(FooBar) ); 80 | 81 | ptr_push_front( deq )( 42, "42" ); 82 | BOOST_CHECK_EQUAL( deq.size(), 7u ); 83 | BOOST_CHECK( typeid(deq[0]) == typeid(FooBar) ); 84 | 85 | ptr_insert( a_set )( 4 ); 86 | BOOST_CHECK( a_set.size() == 5u ); 87 | BOOST_CHECK( typeid(*--a_set.end()) == typeid(FooBar) ); 88 | 89 | #endif 90 | 91 | } 92 | 93 | 94 | 95 | #include 96 | using boost::unit_test::test_suite; 97 | 98 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 99 | { 100 | test_suite* test = BOOST_TEST_SUITE( "List Test Suite" ); 101 | 102 | test->add( BOOST_TEST_CASE( &check_ptr_list_inserter ) ); 103 | 104 | return test; 105 | } 106 | 107 | -------------------------------------------------------------------------------- /test/ptr_list_of.cpp: -------------------------------------------------------------------------------- 1 | // Boost.Assign library 2 | // 3 | // Copyright Thorsten Ottosen 2003-2004. Use, modification and 4 | // distribution is subject to the Boost Software License, Version 5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | // For more information, see http://www.boost.org/libs/assign/ 9 | // 10 | 11 | 12 | #include 13 | 14 | #if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564)) 15 | # pragma warn -8091 // suppress warning in Boost.Test 16 | # pragma warn -8057 // unused argument argc/argv in Boost.Test 17 | #endif 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | struct Foo 24 | { 25 | int i; 26 | 27 | Foo() : i(0) 28 | { } 29 | Foo( int i ) : i(i) 30 | { } 31 | Foo( int i, int ) : i(i) 32 | { } 33 | Foo( const char*, int i, int ) : i(i) 34 | { } 35 | }; 36 | 37 | inline bool operator<( Foo l, Foo r ) 38 | { 39 | return l.i < r.i; 40 | } 41 | 42 | template< class PtrCont > 43 | void check_ptr_list_of_impl() 44 | { 45 | using namespace std; 46 | using namespace boost; 47 | using namespace boost::assign; 48 | 49 | PtrCont deq; 50 | deq = ptr_list_of( 42 )()()( 3, 3 )( "foo", 2, 1 ); 51 | BOOST_CHECK( deq.size() == 5 ); 52 | 53 | } 54 | 55 | void check_ptr_list_of() 56 | { 57 | check_ptr_list_of_impl< boost::ptr_deque >(); 58 | check_ptr_list_of_impl< boost::ptr_list >(); 59 | check_ptr_list_of_impl< boost::ptr_vector >(); 60 | } 61 | 62 | 63 | #include 64 | using boost::unit_test::test_suite; 65 | 66 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 67 | { 68 | test_suite* test = BOOST_TEST_SUITE( "List Test Suite" ); 69 | 70 | test->add( BOOST_TEST_CASE( &check_ptr_list_of ) ); 71 | 72 | return test; 73 | } 74 | 75 | 76 | -------------------------------------------------------------------------------- /test/ptr_map_inserter.cpp: -------------------------------------------------------------------------------- 1 | // Boost.Assign library 2 | // 3 | // Copyright Thorsten Ottosen 2003-2004. Use, modification and 4 | // distribution is subject to the Boost Software License, Version 5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | // For more information, see http://www.boost.org/libs/assign/ 9 | // 10 | 11 | #include 12 | 13 | #if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564)) 14 | # pragma warn -8091 // suppress warning in Boost.Test 15 | # pragma warn -8057 // unused argument argc/argv in Boost.Test 16 | #endif 17 | 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | // 26 | // abstract base class definition 27 | // 28 | struct abstract_base 29 | { 30 | virtual ~abstract_base() {} 31 | virtual void foo() = 0; 32 | virtual abstract_base* clone() const = 0; 33 | }; 34 | 35 | struct implementation : abstract_base 36 | { 37 | implementation() 38 | { } 39 | 40 | implementation( const implementation& ) 41 | { } 42 | 43 | implementation( int ) 44 | { } 45 | 46 | implementation( int, int ) 47 | { } 48 | 49 | implementation( int, std::string, int, std::string ) 50 | { } 51 | 52 | virtual void foo() {} 53 | virtual abstract_base* clone() const 54 | { 55 | return new implementation( *this ); 56 | } 57 | }; 58 | 59 | 60 | void check_ptr_map_inserter() 61 | { 62 | 63 | #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING 64 | 65 | boost::ptr_map m; 66 | boost::assign::ptr_map_insert( m ) 67 | ( "foo", 1, "two", 3, "four" ) 68 | ( "bar", 41, "42", 43, "44" ); 69 | BOOST_CHECK_EQUAL( m.size(), 2u ); 70 | BOOST_CHECK( typeid(m.at("foo")) == typeid(implementation) ); 71 | 72 | #endif 73 | 74 | boost::ptr_map m2; 75 | boost::assign::ptr_map_insert( m2 ) 76 | ( "foobar", 1, "two", 3, "four" ) 77 | ( "key1" )( "key2" )( "key3" )( "key4" ) 78 | ( "key5", 42 )( "key6", 42, 42 ); 79 | 80 | BOOST_CHECK_EQUAL( m2.size(), 7u ); 81 | boost::assign::ptr_map_insert( m2 )( "key1" ); 82 | BOOST_CHECK_EQUAL( m2.size(), 7u ); // duplicates not inserted 83 | 84 | } 85 | 86 | 87 | 88 | #include 89 | using boost::unit_test::test_suite; 90 | 91 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 92 | { 93 | test_suite* test = BOOST_TEST_SUITE( "List Test Suite" ); 94 | 95 | test->add( BOOST_TEST_CASE( &check_ptr_map_inserter ) ); 96 | 97 | return test; 98 | } 99 | 100 | -------------------------------------------------------------------------------- /test/static_list_of.cpp: -------------------------------------------------------------------------------- 1 | // Boost.Assign library 2 | // 3 | // Copyright Thorsten Ottosen 2003-2004. Use, modification and 4 | // distribution is subject to the Boost Software License, Version 5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | // For more information, see http://www.boost.org/libs/assign/ 9 | // 10 | 11 | 12 | #include 13 | 14 | #if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564)) 15 | # pragma warn -8091 // suppress warning in Boost.Test 16 | # pragma warn -8057 // unused argument argc/argv in Boost.Test 17 | #endif 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | template< class Range > 26 | void print( const Range& r ) 27 | { 28 | std::cout << "\n printing " << typeid(r).name() << " \n"; 29 | std::cout << "\n"; 30 | for( typename Range::iterator i = r.begin(), e = r.end(); 31 | i !=e; ++i ) 32 | std::cout << " " << *i; 33 | } 34 | 35 | template< class Range > 36 | void sort( const Range& r ) 37 | { 38 | std::cout << "\n sorting " << typeid(r).name() << " \n"; 39 | std::sort( r.begin(), r.end() ); 40 | print( r ); 41 | } 42 | 43 | template< class Range, class Pred > 44 | void sort( const Range& r, Pred pred ) 45 | { 46 | std::cout << "\n sorting " << typeid(r).name() << " \n"; 47 | std::sort( r.begin(), r.end(), pred ); 48 | print( r ); 49 | } 50 | 51 | template< class Range > 52 | typename Range::const_iterator max_element( const Range& r ) 53 | { 54 | return std::max_element( r.begin(), r.end() ); 55 | } 56 | 57 | 58 | 59 | void check_static_list_of() 60 | { 61 | using namespace boost::assign; 62 | 63 | BOOST_CHECK( cref_list_of<5>( 1 )( 2 )( 3 )( 4 ).size() == 4 ); 64 | 65 | int a=1,b=5,c=3,d=4,e=2,f=9,g=0,h=7; 66 | 67 | int& max = *max_element( ref_list_of<8>(a)(b)(c)(d)(e)(f)(g)(h) ); 68 | BOOST_CHECK_EQUAL( max, f ); 69 | max = 8; 70 | BOOST_CHECK_EQUAL( f, 8 ); 71 | const int& const_max = *max_element( cref_list_of<8>(a)(b)(c)(d)(e)(f)(g)(h) ); 72 | BOOST_CHECK_EQUAL( max, const_max ); 73 | 74 | print( ref_list_of<8>(a)(b)(c)(d)(e)(f)(g)(h) ); 75 | print( cref_list_of<8>(a)(b)(c)(d)(e)(f)(g)(h) ); 76 | 77 | boost::array array = cref_list_of<4>(1)(2)(3)(4); 78 | 79 | BOOST_CHECK_EQUAL( array[0], 1 ); 80 | BOOST_CHECK_EQUAL( array[3], 4 ); 81 | // 82 | //print( cref_list_of<5>( "foo" )( "bar" )( "foobar" ) ); 83 | // 84 | } 85 | 86 | #include 87 | using boost::unit_test::test_suite; 88 | 89 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 90 | { 91 | test_suite* test = BOOST_TEST_SUITE( "List Test Suite" ); 92 | 93 | test->add( BOOST_TEST_CASE( &check_static_list_of ) ); 94 | 95 | return test; 96 | } 97 | 98 | 99 | -------------------------------------------------------------------------------- /test/std.cpp: -------------------------------------------------------------------------------- 1 | // Boost.Assign library 2 | // 3 | // Copyright Thorsten Ottosen 2003-2004. Use, modification and 4 | // distribution is subject to the Boost Software License, Version 5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | // For more information, see http://www.boost.org/libs/assign/ 9 | // 10 | 11 | 12 | #include 13 | 14 | #if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564)) 15 | # pragma warn -8091 // suppress warning in Boost.Test 16 | # pragma warn -8057 // unused argument argc/argv in Boost.Test 17 | #endif 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | using std::deque; 25 | using std::list; 26 | using std::vector; 27 | using std::set; 28 | using std::multiset; 29 | using std::map; 30 | using std::multimap; 31 | using std::stack; 32 | using std::queue; 33 | using std::priority_queue; 34 | using std::string; 35 | using std::pair; 36 | using std::make_pair; 37 | using namespace boost::assign; 38 | 39 | template< typename K, typename V > 40 | inline pair P( K k, V v ) 41 | { 42 | return make_pair( k, v ); 43 | } 44 | 45 | struct three 46 | { 47 | three( int, int, int ) { } 48 | three( const string&, const string&, const string& ) { } 49 | }; 50 | 51 | struct four 52 | { 53 | four( int, int, int, int ) { } 54 | four( const string&, const string&, const string&, const string& ) { } 55 | }; 56 | 57 | struct five 58 | { 59 | five( int, int, int, int, int ) { } 60 | five( const string&, const string&, const string&, 61 | const string&, const string& ) { } 62 | }; 63 | 64 | 65 | 66 | template< class C > 67 | void test_int_sequence() 68 | { 69 | C c; 70 | 71 | BOOST_CHECK_EQUAL( c.size(), 0u ); 72 | c +=1,2,3,4,5,6,7,8,9,10; 73 | BOOST_CHECK_EQUAL( c.size(), 10u ); 74 | } 75 | 76 | 77 | 78 | template< class C > 79 | void test_string_sequence() 80 | { 81 | C c; 82 | 83 | BOOST_CHECK_EQUAL( c.size(), 0u ); 84 | c += "1","2","3","4","5","6","7","8","9","10"; 85 | BOOST_CHECK_EQUAL( c.size(), 10u ); 86 | } 87 | 88 | 89 | 90 | typedef pair two_tuple; 91 | 92 | template< class C > 93 | void test_tuple_sequence() 94 | { 95 | C c; 96 | 97 | BOOST_CHECK_EQUAL( c.size(), 0u ); 98 | c += P("1",1), P("2",2), P("3",3), P("4",4), P("5",5), P("6",6), 99 | P("7",7), P("8",8), P("9",9), P("10",10); 100 | BOOST_CHECK_EQUAL( c.size(), 10u ); 101 | } 102 | 103 | 104 | 105 | template< class M > 106 | void test_map() 107 | { 108 | M m; 109 | m += P( "january", 31 ), P( "february", 28 ), 110 | P( "march", 31 ), P( "april", 30 ), 111 | P( "may", 31 ), P( "june", 30 ), 112 | P( "july", 31 ), P( "august", 31 ), 113 | P( "september", 30 ), P( "october", 31 ), 114 | P( "november", 30 ), P( "december", 31 ); 115 | BOOST_CHECK_EQUAL( m.size(), 12u ); 116 | m.clear(); 117 | insert( m ) 118 | ( "january", 31 )( "february", 28 ) 119 | ( "march", 31 )( "april", 30 ) 120 | ( "may", 31 )( "june", 30 ) 121 | ( "july", 31 )( "august", 31 ) 122 | ( "september", 30 )( "october", 31 ) 123 | ( "november", 30 )( "december", 31 ); 124 | BOOST_CHECK_EQUAL( m.size(), 12u ); 125 | } 126 | 127 | 128 | 129 | void test_tuple() 130 | { 131 | vector v_three; 132 | vector v_four; 133 | vector v_five; 134 | 135 | push_back( v_three ) (1,2,3) ("1","2","3"); 136 | push_back( v_four ) (1,2,3,4) ("1","2","3","4"); 137 | push_back( v_five ) (1,2,3,4,5) ("1","2","3","4","5"); 138 | BOOST_CHECK_EQUAL( v_three.size(), 2u ); 139 | BOOST_CHECK_EQUAL( v_four.size(), 2u ); 140 | BOOST_CHECK_EQUAL( v_five.size(), 2u ); 141 | 142 | } 143 | 144 | 145 | 146 | void check_std() 147 | { 148 | test_int_sequence< deque >(); 149 | test_int_sequence< list >(); 150 | test_int_sequence< vector >(); 151 | test_int_sequence< set >(); 152 | test_int_sequence< multiset >(); 153 | test_int_sequence< stack >(); 154 | test_int_sequence< queue >(); 155 | test_int_sequence< priority_queue >(); 156 | 157 | test_string_sequence< deque >(); 158 | test_string_sequence< list >(); 159 | test_string_sequence< vector >(); 160 | test_string_sequence< set >(); 161 | test_string_sequence< multiset >(); 162 | test_string_sequence< stack >(); 163 | test_string_sequence< queue >(); 164 | test_string_sequence< priority_queue >(); 165 | 166 | test_tuple_sequence< deque >(); 167 | test_tuple_sequence< list >(); 168 | test_tuple_sequence< vector >(); 169 | test_tuple_sequence< set >(); 170 | test_tuple_sequence< multiset >(); 171 | test_tuple_sequence< stack >(); 172 | test_tuple_sequence< queue >(); 173 | test_tuple_sequence< priority_queue >(); 174 | test_tuple(); 175 | 176 | deque di; 177 | push_back( di )( 1 ); 178 | push_front( di )( 2 ); 179 | BOOST_CHECK_EQUAL( di[0], 2 ); 180 | BOOST_CHECK_EQUAL( di[1], 1 ); 181 | 182 | list li; 183 | push_back( li )( 2 ); 184 | push_front( li )( 1 ); 185 | BOOST_CHECK_EQUAL( li.front(), 1 ); 186 | BOOST_CHECK_EQUAL( li.back(), 2 ); 187 | 188 | vector vi; 189 | push_back( vi ) = 2,3; 190 | BOOST_CHECK_EQUAL( vi[0], 2 ); 191 | BOOST_CHECK_EQUAL( vi[1], 3 ); 192 | 193 | set si; 194 | insert( si )( 4 ); 195 | BOOST_CHECK_EQUAL( *si.find( 4 ), 4 ); 196 | 197 | multiset msi; 198 | insert( msi )( 5 ); 199 | BOOST_CHECK_EQUAL( *msi.find( 5 ), 5 ); 200 | 201 | stack sti; 202 | push( sti )( 6 ); 203 | BOOST_CHECK_EQUAL( sti.top(), 6 ); 204 | 205 | queue qi; 206 | push( qi )( 7 ); 207 | BOOST_CHECK_EQUAL( qi.back(), 7 ); 208 | 209 | priority_queue pqi; 210 | push( pqi )( 8 ); 211 | BOOST_CHECK_EQUAL( pqi.top(), 8 ); 212 | 213 | test_map< map >(); 214 | test_map< multimap >(); 215 | 216 | } 217 | 218 | 219 | 220 | #include 221 | using boost::unit_test::test_suite; 222 | 223 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 224 | { 225 | test_suite* test = BOOST_TEST_SUITE( "List Test Suite" ); 226 | 227 | test->add( BOOST_TEST_CASE( &check_std ) ); 228 | 229 | return test; 230 | } 231 | 232 | -------------------------------------------------------------------------------- /test/tuple_list_of.cpp: -------------------------------------------------------------------------------- 1 | // Boost.Assign library 2 | // 3 | // Copyright Thorsten Ottosen 2003-2004. Use, modification and 4 | // distribution is subject to the Boost Software License, Version 5 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | // For more information, see http://www.boost.org/libs/assign/ 9 | // 10 | 11 | 12 | #include 13 | 14 | #if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564)) 15 | # pragma warn -8091 // suppress warning in Boost.Test 16 | # pragma warn -8057 // unused argument argc/argv in Boost.Test 17 | #endif 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | void check_tuple_list_of() 28 | { 29 | using namespace boost::assign; 30 | 31 | typedef boost::tuple tuple; 32 | 33 | std::vector v = tuple_list_of( 1, "foo", 2 )( 3, "bar", 4 ); 34 | BOOST_CHECK( v.size() == 2 ); 35 | BOOST_CHECK( boost::get<0>( v[1] ) == 3 ); 36 | 37 | std::map m = pair_list_of( "foo", 3 )( "bar", 5 ); 38 | BOOST_CHECK( m.size() == 2 ); 39 | BOOST_CHECK( m["foo"] == 3 ); 40 | } 41 | 42 | #include 43 | using boost::unit_test::test_suite; 44 | 45 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 46 | { 47 | test_suite* test = BOOST_TEST_SUITE( "List Test Suite" ); 48 | 49 | test->add( BOOST_TEST_CASE( &check_tuple_list_of ) ); 50 | 51 | return test; 52 | } 53 | 54 | 55 | --------------------------------------------------------------------------------