mirror of
https://github.com/boostorg/array.git
synced 2025-06-26 20:41:36 +02:00
Compare commits
1 Commits
boost-1.82
...
svn-branch
Author | SHA1 | Date | |
---|---|---|---|
96469dc8fe |
37
.drone.star
37
.drone.star
@ -1,37 +0,0 @@
|
|||||||
# Use, modification, and distribution are
|
|
||||||
# subject to the Boost Software License, Version 1.0. (See accompanying
|
|
||||||
# file LICENSE.txt)
|
|
||||||
#
|
|
||||||
# Copyright Rene Rivera 2020.
|
|
||||||
|
|
||||||
# For Drone CI we use the Starlark scripting language to reduce duplication.
|
|
||||||
# As the yaml syntax for Drone CI is rather limited.
|
|
||||||
#
|
|
||||||
#
|
|
||||||
globalenv={}
|
|
||||||
linuxglobalimage="cppalliance/droneubuntu1604:1"
|
|
||||||
windowsglobalimage="cppalliance/dronevs2019"
|
|
||||||
|
|
||||||
def main(ctx):
|
|
||||||
return [
|
|
||||||
linux_cxx("TEST_CMAKE=TRUE Job 0", "g++", packages="", buildtype="96ad197d74-2319b6d45f", image=linuxglobalimage, environment={'TEST_CMAKE': 'TRUE', 'DRONE_JOB_UUID': 'b6589fc6ab'}, globalenv=globalenv),
|
|
||||||
linux_cxx("TOOLSET=gcc COMPILER=g++ CXXSTD=03,11 Job 1", "g++", packages="", buildtype="boost", image=linuxglobalimage, environment={'TOOLSET': 'gcc', 'COMPILER': 'g++', 'CXXSTD': '03,11', 'DRONE_JOB_UUID': '356a192b79'}, globalenv=globalenv),
|
|
||||||
linux_cxx("TOOLSET=gcc COMPILER=g++-4.7 CXXSTD=03,11 Job 2", "g++-4.7", packages="g++-4.7", buildtype="boost", image=linuxglobalimage, environment={'TOOLSET': 'gcc', 'COMPILER': 'g++-4.7', 'CXXSTD': '03,11', 'DRONE_JOB_UUID': 'da4b9237ba'}, globalenv=globalenv),
|
|
||||||
linux_cxx("TOOLSET=gcc COMPILER=g++-4.8 CXXSTD=03,11 Job 3", "g++-4.8", packages="g++-4.8", buildtype="boost", image=linuxglobalimage, environment={'TOOLSET': 'gcc', 'COMPILER': 'g++-4.8', 'CXXSTD': '03,11', 'DRONE_JOB_UUID': '77de68daec'}, globalenv=globalenv),
|
|
||||||
linux_cxx("TOOLSET=gcc COMPILER=g++-4.9 CXXSTD=03,11 Job 4", "g++-4.9", packages="g++-4.9", buildtype="boost", image=linuxglobalimage, environment={'TOOLSET': 'gcc', 'COMPILER': 'g++-4.9', 'CXXSTD': '03,11', 'DRONE_JOB_UUID': '1b64538924'}, globalenv=globalenv),
|
|
||||||
linux_cxx("TOOLSET=gcc COMPILER=g++-5 CXXSTD=03,11,14,1z Job 5", "g++-5", packages="g++-5", buildtype="boost", image=linuxglobalimage, environment={'TOOLSET': 'gcc', 'COMPILER': 'g++-5', 'CXXSTD': '03,11,14,1z', 'DRONE_JOB_UUID': 'ac3478d69a'}, globalenv=globalenv),
|
|
||||||
linux_cxx("TOOLSET=gcc COMPILER=g++-6 CXXSTD=03,11,14,1z Job 6", "g++-6", packages="g++-6", buildtype="boost", image=linuxglobalimage, environment={'TOOLSET': 'gcc', 'COMPILER': 'g++-6', 'CXXSTD': '03,11,14,1z', 'DRONE_JOB_UUID': 'c1dfd96eea'}, globalenv=globalenv),
|
|
||||||
linux_cxx("TOOLSET=gcc COMPILER=g++-7 CXXSTD=03,11,14,17 Job 7", "g++-7", packages="g++-7", buildtype="boost", image="cppalliance/droneubuntu1404:1", environment={'TOOLSET': 'gcc', 'COMPILER': 'g++-7', 'CXXSTD': '03,11,14,17', 'DRONE_JOB_UUID': '902ba3cda1'}, globalenv=globalenv),
|
|
||||||
linux_cxx("TOOLSET=clang COMPILER=clang++ CXXSTD=03,11 Job 8", "clang++", packages="", buildtype="boost", image=linuxglobalimage, environment={'TOOLSET': 'clang', 'COMPILER': 'clang++', 'CXXSTD': '03,11', 'DRONE_JOB_UUID': 'fe5dbbcea5'}, globalenv=globalenv),
|
|
||||||
linux_cxx("TOOLSET=clang COMPILER=clang++-3.5 CXXSTD=03, Job 9", "clang++", packages="clang-3.5 libstdc++-4.9-dev", llvm_os="precise", llvm_ver="3.5", buildtype="boost", image=linuxglobalimage, environment={'TOOLSET': 'clang', 'COMPILER': 'clang++-3.5', 'CXXSTD': '03,11,14,1z', 'DRONE_JOB_UUID': '0ade7c2cf9'}, globalenv=globalenv),
|
|
||||||
linux_cxx("TOOLSET=clang COMPILER=clang++-3.6 CXXSTD=03, Job 10", "clang++", packages="clang-3.6", llvm_os="precise", llvm_ver="3.6", buildtype="boost", image=linuxglobalimage, environment={'TOOLSET': 'clang', 'COMPILER': 'clang++-3.6', 'CXXSTD': '03,11,14,1z', 'DRONE_JOB_UUID': 'b1d5781111'}, globalenv=globalenv),
|
|
||||||
linux_cxx("TOOLSET=clang COMPILER=clang++-3.7 CXXSTD=03, Job 11", "clang++", packages="clang-3.7", llvm_os="precise", llvm_ver="3.7", buildtype="boost", image=linuxglobalimage, environment={'TOOLSET': 'clang', 'COMPILER': 'clang++-3.7', 'CXXSTD': '03,11,14,1z', 'DRONE_JOB_UUID': '17ba079149'}, globalenv=globalenv),
|
|
||||||
linux_cxx("TOOLSET=clang COMPILER=clang++-3.8 CXXSTD=03, Job 12", "clang++-3.8", packages="clang-3.8 libstdc++-4.9-dev", llvm_os="precise", llvm_ver="3.8", buildtype="boost", image=linuxglobalimage, environment={'TOOLSET': 'clang', 'COMPILER': 'clang++-3.8', 'CXXSTD': '03,11,14,1z', 'DRONE_JOB_UUID': '7b52009b64'}, globalenv=globalenv),
|
|
||||||
linux_cxx("TOOLSET=clang COMPILER=clang++-3.9 CXXSTD=03, Job 13", "clang++-3.9", packages="clang-3.9 libstdc++-4.9-dev", llvm_os="precise", llvm_ver="3.9", buildtype="boost", image=linuxglobalimage, environment={'TOOLSET': 'clang', 'COMPILER': 'clang++-3.9', 'CXXSTD': '03,11,14,1z', 'DRONE_JOB_UUID': 'bd307a3ec3'}, globalenv=globalenv),
|
|
||||||
linux_cxx("TOOLSET=clang COMPILER=clang++-4.0 CXXSTD=03, Job 14", "clang++-4.0", packages="clang-4.0", llvm_os="xenial", llvm_ver="4.0", buildtype="boost", image=linuxglobalimage, environment={'TOOLSET': 'clang', 'COMPILER': 'clang++-4.0', 'CXXSTD': '03,11,14,1z', 'DRONE_JOB_UUID': 'fa35e19212'}, globalenv=globalenv),
|
|
||||||
linux_cxx("TOOLSET=clang COMPILER=clang++-5.0 CXXSTD=03, Job 15", "clang++-5.0", packages="clang-5.0", llvm_os="xenial", llvm_ver="5.0", buildtype="boost", image=linuxglobalimage, environment={'TOOLSET': 'clang', 'COMPILER': 'clang++-5.0', 'CXXSTD': '03,11,14,1z', 'DRONE_JOB_UUID': 'f1abd67035'}, globalenv=globalenv),
|
|
||||||
osx_cxx("TOOLSET=clang COMPILER=clang++ CXXSTD=03,11,1 Job 16", "clang++", packages="", buildtype="boost", environment={'TOOLSET': 'clang', 'COMPILER': 'clang++', 'CXXSTD': '03,11,14,1z', 'DRONE_JOB_UUID': '1574bddb75'}, globalenv=globalenv),
|
|
||||||
]
|
|
||||||
|
|
||||||
# from https://github.com/boostorg/boost-ci
|
|
||||||
load("@boost_ci//ci/drone/:functions.star", "linux_cxx","windows_cxx","osx_cxx","freebsd_cxx")
|
|
@ -1,37 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -ex
|
|
||||||
export TRAVIS_BUILD_DIR=$(pwd)
|
|
||||||
export DRONE_BUILD_DIR=$(pwd)
|
|
||||||
export TRAVIS_BRANCH=$DRONE_BRANCH
|
|
||||||
export VCS_COMMIT_ID=$DRONE_COMMIT
|
|
||||||
export GIT_COMMIT=$DRONE_COMMIT
|
|
||||||
export REPO_NAME=$DRONE_REPO
|
|
||||||
export PATH=~/.local/bin:/usr/local/bin:$PATH
|
|
||||||
|
|
||||||
echo '==================================> BEFORE_INSTALL'
|
|
||||||
|
|
||||||
. .drone/before-install.sh
|
|
||||||
|
|
||||||
echo '==================================> INSTALL'
|
|
||||||
|
|
||||||
BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true
|
|
||||||
git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/assert.git ../assert
|
|
||||||
git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/config.git ../config
|
|
||||||
git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/core.git ../core
|
|
||||||
git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/static_assert.git ../static_assert
|
|
||||||
git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/throw_exception.git ../throw_exception
|
|
||||||
|
|
||||||
echo '==================================> BEFORE_SCRIPT'
|
|
||||||
|
|
||||||
. $DRONE_BUILD_DIR/.drone/before-script.sh
|
|
||||||
|
|
||||||
echo '==================================> SCRIPT'
|
|
||||||
|
|
||||||
mkdir __build__ && cd __build__
|
|
||||||
cmake ../test/test_cmake
|
|
||||||
cmake --build .
|
|
||||||
|
|
||||||
echo '==================================> AFTER_SUCCESS'
|
|
||||||
|
|
||||||
. $DRONE_BUILD_DIR/.drone/after-success.sh
|
|
@ -1,3 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -ex
|
|
||||||
export TRAVIS_BUILD_DIR=$(pwd)
|
|
||||||
export DRONE_BUILD_DIR=$(pwd)
|
|
||||||
export TRAVIS_BRANCH=$DRONE_BRANCH
|
|
||||||
export VCS_COMMIT_ID=$DRONE_COMMIT
|
|
||||||
export GIT_COMMIT=$DRONE_COMMIT
|
|
||||||
export REPO_NAME=$DRONE_REPO
|
|
||||||
export PATH=~/.local/bin:/usr/local/bin:$PATH
|
|
||||||
|
|
||||||
echo '==================================> BEFORE_INSTALL'
|
|
||||||
|
|
||||||
. .drone/before-install.sh
|
|
||||||
|
|
||||||
echo '==================================> INSTALL'
|
|
||||||
|
|
||||||
BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true
|
|
||||||
cd ..
|
|
||||||
git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
|
|
||||||
cd boost-root
|
|
||||||
git submodule update --init tools/build
|
|
||||||
git submodule update --init libs/config
|
|
||||||
git submodule update --init tools/boostdep
|
|
||||||
cp -r $TRAVIS_BUILD_DIR/* libs/array
|
|
||||||
python tools/boostdep/depinst/depinst.py array
|
|
||||||
./bootstrap.sh
|
|
||||||
./b2 headers
|
|
||||||
|
|
||||||
echo '==================================> BEFORE_SCRIPT'
|
|
||||||
|
|
||||||
. $DRONE_BUILD_DIR/.drone/before-script.sh
|
|
||||||
|
|
||||||
echo '==================================> SCRIPT'
|
|
||||||
|
|
||||||
echo "using $TOOLSET : : $COMPILER ;" > ~/user-config.jam
|
|
||||||
./b2 -j 3 libs/array/test toolset=$TOOLSET cxxstd=$CXXSTD
|
|
||||||
|
|
||||||
echo '==================================> AFTER_SUCCESS'
|
|
||||||
|
|
||||||
. $DRONE_BUILD_DIR/.drone/after-success.sh
|
|
421
.github/workflows/ci.yml
vendored
421
.github/workflows/ci.yml
vendored
@ -1,421 +0,0 @@
|
|||||||
name: GitHub Actions CI
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
- develop
|
|
||||||
- githubactions*
|
|
||||||
- feature/**
|
|
||||||
- fix/**
|
|
||||||
- pr/**
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
posix:
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
include:
|
|
||||||
- name: "TEST_CMAKE=TRUE Job 0"
|
|
||||||
buildtype: "96ad197d74-2319b6d45f"
|
|
||||||
packages: ""
|
|
||||||
packages_to_remove: ""
|
|
||||||
os: "ubuntu-20.04"
|
|
||||||
container: "ubuntu:16.04"
|
|
||||||
cxx: "g++"
|
|
||||||
sources: ""
|
|
||||||
llvm_os: ""
|
|
||||||
llvm_ver: ""
|
|
||||||
test_cmake: "TRUE"
|
|
||||||
- name: "TOOLSET=gcc COMPILER=g++ CXXSTD=03,11 Job 1"
|
|
||||||
buildtype: "boost"
|
|
||||||
packages: ""
|
|
||||||
packages_to_remove: ""
|
|
||||||
os: "ubuntu-20.04"
|
|
||||||
container: "ubuntu:16.04"
|
|
||||||
cxx: "g++"
|
|
||||||
sources: ""
|
|
||||||
llvm_os: ""
|
|
||||||
llvm_ver: ""
|
|
||||||
toolset: "gcc"
|
|
||||||
compiler: "g++"
|
|
||||||
cxxstd: "03,11"
|
|
||||||
- name: "TOOLSET=gcc COMPILER=g++-4.7 CXXSTD=03,11 Job 2"
|
|
||||||
buildtype: "boost"
|
|
||||||
packages: "g++-4.7"
|
|
||||||
packages_to_remove: ""
|
|
||||||
os: "ubuntu-20.04"
|
|
||||||
container: "ubuntu:16.04"
|
|
||||||
cxx: "g++-4.7"
|
|
||||||
sources: ""
|
|
||||||
llvm_os: ""
|
|
||||||
llvm_ver: ""
|
|
||||||
toolset: "gcc"
|
|
||||||
compiler: "g++-4.7"
|
|
||||||
cxxstd: "03,11"
|
|
||||||
- name: "TOOLSET=gcc COMPILER=g++-4.8 CXXSTD=03,11 Job 3"
|
|
||||||
buildtype: "boost"
|
|
||||||
packages: "g++-4.8"
|
|
||||||
packages_to_remove: ""
|
|
||||||
os: "ubuntu-20.04"
|
|
||||||
container: "ubuntu:16.04"
|
|
||||||
cxx: "g++-4.8"
|
|
||||||
sources: ""
|
|
||||||
llvm_os: ""
|
|
||||||
llvm_ver: ""
|
|
||||||
toolset: "gcc"
|
|
||||||
compiler: "g++-4.8"
|
|
||||||
cxxstd: "03,11"
|
|
||||||
- name: "TOOLSET=gcc COMPILER=g++-4.9 CXXSTD=03,11 Job 4"
|
|
||||||
buildtype: "boost"
|
|
||||||
packages: "g++-4.9"
|
|
||||||
packages_to_remove: ""
|
|
||||||
os: "ubuntu-20.04"
|
|
||||||
container: "ubuntu:16.04"
|
|
||||||
cxx: "g++-4.9"
|
|
||||||
sources: ""
|
|
||||||
llvm_os: ""
|
|
||||||
llvm_ver: ""
|
|
||||||
toolset: "gcc"
|
|
||||||
compiler: "g++-4.9"
|
|
||||||
cxxstd: "03,11"
|
|
||||||
- name: "TOOLSET=gcc COMPILER=g++-5 CXXSTD=03,11,14,1z Job 5"
|
|
||||||
buildtype: "boost"
|
|
||||||
packages: "g++-5"
|
|
||||||
packages_to_remove: ""
|
|
||||||
os: "ubuntu-20.04"
|
|
||||||
container: "ubuntu:16.04"
|
|
||||||
cxx: "g++-5"
|
|
||||||
sources: ""
|
|
||||||
llvm_os: ""
|
|
||||||
llvm_ver: ""
|
|
||||||
toolset: "gcc"
|
|
||||||
compiler: "g++-5"
|
|
||||||
cxxstd: "03,11,14,1z"
|
|
||||||
- name: "TOOLSET=gcc COMPILER=g++-6 CXXSTD=03,11,14,1z Job 6"
|
|
||||||
buildtype: "boost"
|
|
||||||
packages: "g++-6"
|
|
||||||
packages_to_remove: ""
|
|
||||||
os: "ubuntu-20.04"
|
|
||||||
container: "ubuntu:16.04"
|
|
||||||
cxx: "g++-6"
|
|
||||||
sources: ""
|
|
||||||
llvm_os: ""
|
|
||||||
llvm_ver: ""
|
|
||||||
toolset: "gcc"
|
|
||||||
compiler: "g++-6"
|
|
||||||
cxxstd: "03,11,14,1z"
|
|
||||||
- name: "TOOLSET=gcc COMPILER=g++-7 CXXSTD=03,11,14,17 Job 7"
|
|
||||||
buildtype: "boost"
|
|
||||||
packages: "g++-7"
|
|
||||||
packages_to_remove: ""
|
|
||||||
os: "ubuntu-20.04"
|
|
||||||
container: "ubuntu:16.04"
|
|
||||||
cxx: "g++-7"
|
|
||||||
sources: ""
|
|
||||||
llvm_os: ""
|
|
||||||
llvm_ver: ""
|
|
||||||
toolset: "gcc"
|
|
||||||
compiler: "g++-7"
|
|
||||||
cxxstd: "03,11,14,17"
|
|
||||||
- name: "TOOLSET=clang COMPILER=clang++ CXXSTD=03,11 Job 8"
|
|
||||||
buildtype: "boost"
|
|
||||||
packages: ""
|
|
||||||
packages_to_remove: ""
|
|
||||||
os: "ubuntu-18.04"
|
|
||||||
cxx: "clang++"
|
|
||||||
sources: ""
|
|
||||||
llvm_os: ""
|
|
||||||
llvm_ver: ""
|
|
||||||
toolset: "clang"
|
|
||||||
compiler: "clang++"
|
|
||||||
cxxstd: "03,11"
|
|
||||||
- name: "TOOLSET=clang COMPILER=clang++-3.5 CXXSTD=03, Job 9"
|
|
||||||
buildtype: "boost"
|
|
||||||
packages: "clang-3.5 libstdc++-4.9-dev"
|
|
||||||
packages_to_remove: ""
|
|
||||||
os: "ubuntu-20.04"
|
|
||||||
container: "ubuntu:16.04"
|
|
||||||
cxx: "clang++-3.5"
|
|
||||||
sources: ""
|
|
||||||
llvm_os: "precise"
|
|
||||||
llvm_ver: "3.5"
|
|
||||||
toolset: "clang"
|
|
||||||
compiler: "clang++-3.5"
|
|
||||||
cxxstd: "03,11,14"
|
|
||||||
- name: "TOOLSET=clang COMPILER=clang++-3.6 CXXSTD=03, Job 10"
|
|
||||||
buildtype: "boost"
|
|
||||||
packages: "clang-3.6"
|
|
||||||
packages_to_remove: ""
|
|
||||||
os: "ubuntu-20.04"
|
|
||||||
container: "ubuntu:16.04"
|
|
||||||
cxx: "clang++-3.6"
|
|
||||||
sources: ""
|
|
||||||
llvm_os: "precise"
|
|
||||||
llvm_ver: "3.6"
|
|
||||||
toolset: "clang"
|
|
||||||
compiler: "clang++-3.6"
|
|
||||||
cxxstd: "03,11,14"
|
|
||||||
- name: "TOOLSET=clang COMPILER=clang++-3.7 CXXSTD=03, Job 11"
|
|
||||||
buildtype: "boost"
|
|
||||||
packages: "clang-3.7"
|
|
||||||
packages_to_remove: ""
|
|
||||||
os: "ubuntu-20.04"
|
|
||||||
container: "ubuntu:16.04"
|
|
||||||
cxx: "clang++-3.7"
|
|
||||||
sources: ""
|
|
||||||
llvm_os: "precise"
|
|
||||||
llvm_ver: "3.7"
|
|
||||||
toolset: "clang"
|
|
||||||
compiler: "clang++-3.7"
|
|
||||||
cxxstd: "03,11,14"
|
|
||||||
- name: "TOOLSET=clang COMPILER=clang++-3.8 CXXSTD=03, Job 12"
|
|
||||||
buildtype: "boost"
|
|
||||||
packages: "clang-3.8 libstdc++-4.9-dev"
|
|
||||||
packages_to_remove: ""
|
|
||||||
os: "ubuntu-20.04"
|
|
||||||
container: "ubuntu:16.04"
|
|
||||||
cxx: "clang++-3.8"
|
|
||||||
sources: ""
|
|
||||||
llvm_os: "precise"
|
|
||||||
llvm_ver: "3.8"
|
|
||||||
toolset: "clang"
|
|
||||||
compiler: "clang++-3.8"
|
|
||||||
cxxstd: "03,11,14"
|
|
||||||
- name: "TOOLSET=clang COMPILER=clang++-3.9 CXXSTD=03, Job 13"
|
|
||||||
buildtype: "boost"
|
|
||||||
packages: "clang-3.9 libstdc++-4.9-dev"
|
|
||||||
packages_to_remove: ""
|
|
||||||
os: "ubuntu-20.04"
|
|
||||||
container: "ubuntu:16.04"
|
|
||||||
cxx: "clang++-3.9"
|
|
||||||
sources: ""
|
|
||||||
llvm_os: "precise"
|
|
||||||
llvm_ver: "3.9"
|
|
||||||
toolset: "clang"
|
|
||||||
compiler: "clang++-3.9"
|
|
||||||
cxxstd: "03,11,14"
|
|
||||||
- name: "TOOLSET=clang COMPILER=clang++-4.0 CXXSTD=03, Job 14"
|
|
||||||
buildtype: "boost"
|
|
||||||
packages: "clang-4.0"
|
|
||||||
packages_to_remove: ""
|
|
||||||
os: "ubuntu-20.04"
|
|
||||||
container: "ubuntu:16.04"
|
|
||||||
cxx: "clang++-4.0"
|
|
||||||
sources: ""
|
|
||||||
llvm_os: "xenial"
|
|
||||||
llvm_ver: "4.0"
|
|
||||||
toolset: "clang"
|
|
||||||
compiler: "clang++-4.0"
|
|
||||||
cxxstd: "03,11,14"
|
|
||||||
- name: "TOOLSET=clang COMPILER=clang++-5.0 CXXSTD=03, Job 15"
|
|
||||||
buildtype: "boost"
|
|
||||||
packages: "clang-5.0"
|
|
||||||
packages_to_remove: ""
|
|
||||||
os: "ubuntu-20.04"
|
|
||||||
container: "ubuntu:16.04"
|
|
||||||
cxx: "clang++-5.0"
|
|
||||||
sources: ""
|
|
||||||
llvm_os: "xenial"
|
|
||||||
llvm_ver: "5.0"
|
|
||||||
toolset: "clang"
|
|
||||||
compiler: "clang++-5.0"
|
|
||||||
cxxstd: "03,11,14,1z"
|
|
||||||
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
container: ${{ matrix.container }}
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Check if running in container
|
|
||||||
if: matrix.container != ''
|
|
||||||
run: echo "GHA_CONTAINER=${{ matrix.container }}" >> $GITHUB_ENV
|
|
||||||
- name: If running in container, upgrade packages
|
|
||||||
if: matrix.container != ''
|
|
||||||
run: |
|
|
||||||
apt-get -o Acquire::Retries=3 update && DEBIAN_FRONTEND=noninteractive apt-get -y install tzdata && apt-get -o Acquire::Retries=3 install -y sudo software-properties-common wget curl apt-transport-https make apt-file sudo unzip libssl-dev build-essential autotools-dev autoconf automake g++ libc++-helpers python ruby cpio gcc-multilib g++-multilib pkgconf python3 ccache libpython-dev
|
|
||||||
sudo apt-add-repository ppa:git-core/ppa
|
|
||||||
sudo apt-get -o Acquire::Retries=3 update && apt-get -o Acquire::Retries=3 -y install git
|
|
||||||
python_version=$(python3 -c 'import sys; print("{0.major}.{0.minor}".format(sys.version_info))')
|
|
||||||
sudo wget https://bootstrap.pypa.io/pip/$python_version/get-pip.py
|
|
||||||
sudo python3 get-pip.py
|
|
||||||
sudo /usr/local/bin/pip install cmake
|
|
||||||
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- name: linux
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
CXX: ${{ matrix.cxx }}
|
|
||||||
SOURCES: ${{ matrix.sources }}
|
|
||||||
LLVM_OS: ${{ matrix.llvm_os }}
|
|
||||||
LLVM_VER: ${{ matrix.llvm_ver }}
|
|
||||||
PACKAGES: ${{ matrix.packages }}
|
|
||||||
PACKAGES_TO_REMOVE: ${{ matrix.packages_to_remove }}
|
|
||||||
JOB_BUILDTYPE: ${{ matrix.buildtype }}
|
|
||||||
TEST_CMAKE: ${{ matrix.test_cmake }}
|
|
||||||
TOOLSET: ${{ matrix.toolset }}
|
|
||||||
COMPILER: ${{ matrix.compiler }}
|
|
||||||
CXXSTD: ${{ matrix.cxxstd }}
|
|
||||||
TRAVIS_BRANCH: ${{ github.base_ref }}
|
|
||||||
TRAVIS_OS_NAME: "linux"
|
|
||||||
run: |
|
|
||||||
echo '==================================> SETUP'
|
|
||||||
echo '==================================> PACKAGES'
|
|
||||||
set -e
|
|
||||||
if [ -n "$PACKAGES_TO_REMOVE" ]; then sudo apt-get purge -y $PACKAGES_TO_REMOVE; fi
|
|
||||||
echo ">>>>> APT: REPO.."
|
|
||||||
for i in {1..3}; do sudo -E apt-add-repository -y "ppa:ubuntu-toolchain-r/test" && break || sleep 2; done
|
|
||||||
|
|
||||||
if test -n "${LLVM_OS}" ; then
|
|
||||||
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
|
|
||||||
if test -n "${LLVM_VER}" ; then
|
|
||||||
sudo -E apt-add-repository "deb http://apt.llvm.org/${LLVM_OS}/ llvm-toolchain-${LLVM_OS}-${LLVM_VER} main"
|
|
||||||
else
|
|
||||||
# Snapshot (i.e. trunk) build of clang
|
|
||||||
sudo -E apt-add-repository "deb http://apt.llvm.org/${LLVM_OS}/ llvm-toolchain-${LLVM_OS} main"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
echo ">>>>> APT: UPDATE.."
|
|
||||||
sudo -E apt-get -o Acquire::Retries=3 update
|
|
||||||
if test -n "${SOURCES}" ; then
|
|
||||||
echo ">>>>> APT: INSTALL SOURCES.."
|
|
||||||
for SOURCE in $SOURCES; do
|
|
||||||
sudo -E apt-add-repository ppa:$SOURCE
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
echo ">>>>> APT: INSTALL ${PACKAGES}.."
|
|
||||||
sudo -E DEBIAN_FRONTEND=noninteractive apt-get -o Acquire::Retries=3 -y --no-install-suggests --no-install-recommends install ${PACKAGES}
|
|
||||||
|
|
||||||
echo '==================================> INSTALL AND COMPILE'
|
|
||||||
set -e
|
|
||||||
export TRAVIS_BUILD_DIR=$(pwd)
|
|
||||||
export TRAVIS_BRANCH=${TRAVIS_BRANCH:-$(echo $GITHUB_REF | awk 'BEGIN { FS = "/" } ; { print $3 }')}
|
|
||||||
export VCS_COMMIT_ID=$GITHUB_SHA
|
|
||||||
export GIT_COMMIT=$GITHUB_SHA
|
|
||||||
export REPO_NAME=$(basename $GITHUB_REPOSITORY)
|
|
||||||
export USER=$(whoami)
|
|
||||||
export CC=${CC:-gcc}
|
|
||||||
export PATH=~/.local/bin:/usr/local/bin:$PATH
|
|
||||||
|
|
||||||
if [ "$JOB_BUILDTYPE" == "96ad197d74-2319b6d45f" ]; then
|
|
||||||
|
|
||||||
echo '==================================> INSTALL'
|
|
||||||
|
|
||||||
BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true
|
|
||||||
git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/assert.git ../assert
|
|
||||||
git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/config.git ../config
|
|
||||||
git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/core.git ../core
|
|
||||||
git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/static_assert.git ../static_assert
|
|
||||||
git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/throw_exception.git ../throw_exception
|
|
||||||
|
|
||||||
echo '==================================> SCRIPT'
|
|
||||||
|
|
||||||
mkdir __build__ && cd __build__
|
|
||||||
cmake ../test/test_cmake
|
|
||||||
cmake --build .
|
|
||||||
|
|
||||||
elif [ "$JOB_BUILDTYPE" == "boost" ]; then
|
|
||||||
|
|
||||||
echo '==================================> INSTALL'
|
|
||||||
|
|
||||||
BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true
|
|
||||||
cd ..
|
|
||||||
git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
|
|
||||||
cd boost-root
|
|
||||||
git submodule update --init tools/build
|
|
||||||
git submodule update --init libs/config
|
|
||||||
git submodule update --init tools/boostdep
|
|
||||||
cp -r $TRAVIS_BUILD_DIR/* libs/array
|
|
||||||
python tools/boostdep/depinst/depinst.py array
|
|
||||||
./bootstrap.sh
|
|
||||||
./b2 headers
|
|
||||||
|
|
||||||
echo '==================================> SCRIPT'
|
|
||||||
|
|
||||||
echo "using $TOOLSET : : $COMPILER ;" > ~/user-config.jam
|
|
||||||
./b2 -j 3 libs/array/test toolset=$TOOLSET cxxstd=$CXXSTD
|
|
||||||
|
|
||||||
fi
|
|
||||||
osx:
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
include:
|
|
||||||
- name: "TOOLSET=clang COMPILER=clang++ CXXSTD=03,11,1 Job 16"
|
|
||||||
buildtype: "boost"
|
|
||||||
packages: ""
|
|
||||||
os: "macos-11"
|
|
||||||
cxx: "clang++"
|
|
||||||
sources: ""
|
|
||||||
llvm_os: ""
|
|
||||||
llvm_ver: ""
|
|
||||||
xcode_version: 11.7
|
|
||||||
toolset: "clang"
|
|
||||||
compiler: "clang++"
|
|
||||||
cxxstd: "03,11,14,1z"
|
|
||||||
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- name: Set DEVELOPER_DIR
|
|
||||||
if: matrix.xcode_version != ''
|
|
||||||
run: echo "DEVELOPER_DIR=/Applications/Xcode_${{ matrix.xcode_version }}.app/Contents/Developer" >> $GITHUB_ENV
|
|
||||||
- name: Test DEVELOPER_DIR
|
|
||||||
run: echo $DEVELOPER_DIR
|
|
||||||
|
|
||||||
- name: "osx"
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
CXX: ${{ matrix.cxx }}
|
|
||||||
SOURCES: ${{ matrix.sources }}
|
|
||||||
LLVM_OS: ${{ matrix.llvm_os }}
|
|
||||||
LLVM_VER: ${{ matrix.llvm_ver }}
|
|
||||||
PACKAGES: ${{ matrix.packages }}
|
|
||||||
JOB_BUILDTYPE: ${{ matrix.buildtype }}
|
|
||||||
TEST_CMAKE: ${{ matrix.test_cmake }}
|
|
||||||
TOOLSET: ${{ matrix.toolset }}
|
|
||||||
COMPILER: ${{ matrix.compiler }}
|
|
||||||
CXXSTD: ${{ matrix.cxxstd }}
|
|
||||||
TRAVIS_BRANCH: ${{ github.base_ref }}
|
|
||||||
TRAVIS_OS_NAME: "osx"
|
|
||||||
run: |
|
|
||||||
echo '==================================> SETUP'
|
|
||||||
set -e
|
|
||||||
sudo mv /Library/Developer/CommandLineTools /Library/Developer/CommandLineTools.bck
|
|
||||||
echo '==================================> PACKAGES'
|
|
||||||
echo '==================================> INSTALL AND COMPILE'
|
|
||||||
set -e
|
|
||||||
export TRAVIS_BUILD_DIR=$(pwd)
|
|
||||||
export TRAVIS_BRANCH=${TRAVIS_BRANCH:-$(echo $GITHUB_REF | awk 'BEGIN { FS = "/" } ; { print $3 }')}
|
|
||||||
export VCS_COMMIT_ID=$GITHUB_SHA
|
|
||||||
export GIT_COMMIT=$GITHUB_SHA
|
|
||||||
export REPO_NAME=$(basename $GITHUB_REPOSITORY)
|
|
||||||
export USER=$(whoami)
|
|
||||||
export CC=${CC:-gcc}
|
|
||||||
export PATH=~/.local/bin:/usr/local/bin:$PATH
|
|
||||||
|
|
||||||
if [ "$JOB_BUILDTYPE" == "boost" ]; then
|
|
||||||
|
|
||||||
echo '==================================> INSTALL'
|
|
||||||
|
|
||||||
BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true
|
|
||||||
cd ..
|
|
||||||
git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
|
|
||||||
cd boost-root
|
|
||||||
git submodule update --init tools/build
|
|
||||||
git submodule update --init libs/config
|
|
||||||
git submodule update --init tools/boostdep
|
|
||||||
cp -r $TRAVIS_BUILD_DIR/* libs/array
|
|
||||||
python tools/boostdep/depinst/depinst.py array
|
|
||||||
./bootstrap.sh
|
|
||||||
./b2 headers
|
|
||||||
|
|
||||||
echo '==================================> SCRIPT'
|
|
||||||
|
|
||||||
echo "using $TOOLSET : : $COMPILER ;" > ~/user-config.jam
|
|
||||||
./b2 -j 3 libs/array/test toolset=$TOOLSET cxxstd=$CXXSTD
|
|
||||||
|
|
||||||
fi
|
|
217
.travis.yml
217
.travis.yml
@ -1,217 +0,0 @@
|
|||||||
# Copyright 2016, 2017 Peter Dimov
|
|
||||||
# Copyright 2018, Mike-Dev
|
|
||||||
# Distributed under the Boost Software License, Version 1.0.
|
|
||||||
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
|
|
||||||
|
|
||||||
language: cpp
|
|
||||||
|
|
||||||
sudo: false
|
|
||||||
|
|
||||||
python: "2.7"
|
|
||||||
|
|
||||||
branches:
|
|
||||||
only:
|
|
||||||
- master
|
|
||||||
- develop
|
|
||||||
- /feature\/.*/
|
|
||||||
|
|
||||||
env:
|
|
||||||
matrix:
|
|
||||||
- BOGUS_JOB=true
|
|
||||||
|
|
||||||
matrix:
|
|
||||||
|
|
||||||
exclude:
|
|
||||||
- env: BOGUS_JOB=true
|
|
||||||
|
|
||||||
include:
|
|
||||||
|
|
||||||
# cmake self-test
|
|
||||||
- os: linux
|
|
||||||
env: TEST_CMAKE=TRUE #Only for easier identification in travis web gui
|
|
||||||
install:
|
|
||||||
- BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true
|
|
||||||
- git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/assert.git ../assert
|
|
||||||
- git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/config.git ../config
|
|
||||||
- git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/core.git ../core
|
|
||||||
- git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/static_assert.git ../static_assert
|
|
||||||
- git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/throw_exception.git ../throw_exception
|
|
||||||
|
|
||||||
script:
|
|
||||||
- mkdir __build__ && cd __build__
|
|
||||||
- cmake ../test/test_cmake
|
|
||||||
- cmake --build .
|
|
||||||
|
|
||||||
- os: linux
|
|
||||||
compiler: g++
|
|
||||||
env: TOOLSET=gcc COMPILER=g++ CXXSTD=03,11
|
|
||||||
|
|
||||||
- os: linux
|
|
||||||
compiler: g++-4.7
|
|
||||||
env: TOOLSET=gcc COMPILER=g++-4.7 CXXSTD=03,11
|
|
||||||
addons:
|
|
||||||
apt:
|
|
||||||
packages:
|
|
||||||
- g++-4.7
|
|
||||||
sources:
|
|
||||||
- ubuntu-toolchain-r-test
|
|
||||||
|
|
||||||
- os: linux
|
|
||||||
compiler: g++-4.8
|
|
||||||
env: TOOLSET=gcc COMPILER=g++-4.8 CXXSTD=03,11
|
|
||||||
addons:
|
|
||||||
apt:
|
|
||||||
packages:
|
|
||||||
- g++-4.8
|
|
||||||
sources:
|
|
||||||
- ubuntu-toolchain-r-test
|
|
||||||
- os: linux
|
|
||||||
compiler: g++-4.9
|
|
||||||
env: TOOLSET=gcc COMPILER=g++-4.9 CXXSTD=03,11
|
|
||||||
addons:
|
|
||||||
apt:
|
|
||||||
packages:
|
|
||||||
- g++-4.9
|
|
||||||
sources:
|
|
||||||
- ubuntu-toolchain-r-test
|
|
||||||
|
|
||||||
- os: linux
|
|
||||||
compiler: g++-5
|
|
||||||
env: TOOLSET=gcc COMPILER=g++-5 CXXSTD=03,11,14,1z
|
|
||||||
addons:
|
|
||||||
apt:
|
|
||||||
packages:
|
|
||||||
- g++-5
|
|
||||||
sources:
|
|
||||||
- ubuntu-toolchain-r-test
|
|
||||||
|
|
||||||
- os: linux
|
|
||||||
compiler: g++-6
|
|
||||||
env: TOOLSET=gcc COMPILER=g++-6 CXXSTD=03,11,14,1z
|
|
||||||
addons:
|
|
||||||
apt:
|
|
||||||
packages:
|
|
||||||
- g++-6
|
|
||||||
sources:
|
|
||||||
- ubuntu-toolchain-r-test
|
|
||||||
|
|
||||||
- os: linux
|
|
||||||
dist: trusty
|
|
||||||
compiler: g++-7
|
|
||||||
env: TOOLSET=gcc COMPILER=g++-7 CXXSTD=03,11,14,17
|
|
||||||
addons:
|
|
||||||
apt:
|
|
||||||
packages:
|
|
||||||
- g++-7
|
|
||||||
sources:
|
|
||||||
- ubuntu-toolchain-r-test
|
|
||||||
|
|
||||||
- os: linux
|
|
||||||
compiler: clang++
|
|
||||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=03,11
|
|
||||||
|
|
||||||
- os: linux
|
|
||||||
compiler: clang++-3.5
|
|
||||||
env: TOOLSET=clang COMPILER=clang++-3.5 CXXSTD=03,11,14,1z
|
|
||||||
addons:
|
|
||||||
apt:
|
|
||||||
packages:
|
|
||||||
- clang-3.5
|
|
||||||
- libstdc++-4.9-dev
|
|
||||||
sources:
|
|
||||||
- ubuntu-toolchain-r-test
|
|
||||||
- llvm-toolchain-precise-3.5
|
|
||||||
|
|
||||||
- os: linux
|
|
||||||
compiler: clang++-3.6
|
|
||||||
env: TOOLSET=clang COMPILER=clang++-3.6 CXXSTD=03,11,14,1z
|
|
||||||
addons:
|
|
||||||
apt:
|
|
||||||
packages:
|
|
||||||
- clang-3.6
|
|
||||||
sources:
|
|
||||||
- ubuntu-toolchain-r-test
|
|
||||||
- llvm-toolchain-precise-3.6
|
|
||||||
|
|
||||||
- os: linux
|
|
||||||
compiler: clang++-3.7
|
|
||||||
env: TOOLSET=clang COMPILER=clang++-3.7 CXXSTD=03,11,14,1z
|
|
||||||
addons:
|
|
||||||
apt:
|
|
||||||
packages:
|
|
||||||
- clang-3.7
|
|
||||||
sources:
|
|
||||||
- ubuntu-toolchain-r-test
|
|
||||||
- llvm-toolchain-precise-3.7
|
|
||||||
|
|
||||||
- os: linux
|
|
||||||
compiler: clang++-3.8
|
|
||||||
env: TOOLSET=clang COMPILER=clang++-3.8 CXXSTD=03,11,14,1z
|
|
||||||
addons:
|
|
||||||
apt:
|
|
||||||
packages:
|
|
||||||
- clang-3.8
|
|
||||||
- libstdc++-4.9-dev
|
|
||||||
sources:
|
|
||||||
- ubuntu-toolchain-r-test
|
|
||||||
- llvm-toolchain-precise-3.8
|
|
||||||
|
|
||||||
- os: linux
|
|
||||||
compiler: clang++-3.9
|
|
||||||
env: TOOLSET=clang COMPILER=clang++-3.9 CXXSTD=03,11,14,1z
|
|
||||||
addons:
|
|
||||||
apt:
|
|
||||||
packages:
|
|
||||||
- clang-3.9
|
|
||||||
- libstdc++-4.9-dev
|
|
||||||
sources:
|
|
||||||
- ubuntu-toolchain-r-test
|
|
||||||
- llvm-toolchain-precise-3.9
|
|
||||||
|
|
||||||
- os: linux
|
|
||||||
compiler: clang++-4.0
|
|
||||||
env: TOOLSET=clang COMPILER=clang++-4.0 CXXSTD=03,11,14,1z
|
|
||||||
addons:
|
|
||||||
apt:
|
|
||||||
packages:
|
|
||||||
- clang-4.0
|
|
||||||
sources:
|
|
||||||
- ubuntu-toolchain-r-test
|
|
||||||
- llvm-toolchain-trusty-4.0
|
|
||||||
|
|
||||||
- os: linux
|
|
||||||
compiler: clang++-5.0
|
|
||||||
env: TOOLSET=clang COMPILER=clang++-5.0 CXXSTD=03,11,14,1z
|
|
||||||
addons:
|
|
||||||
apt:
|
|
||||||
packages:
|
|
||||||
- clang-5.0
|
|
||||||
sources:
|
|
||||||
- ubuntu-toolchain-r-test
|
|
||||||
- llvm-toolchain-trusty-5.0
|
|
||||||
|
|
||||||
- os: osx
|
|
||||||
compiler: clang++
|
|
||||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=03,11,14,1z
|
|
||||||
|
|
||||||
install:
|
|
||||||
- BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true
|
|
||||||
- cd ..
|
|
||||||
- git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
|
|
||||||
- cd boost-root
|
|
||||||
- git submodule update --init tools/build
|
|
||||||
- git submodule update --init libs/config
|
|
||||||
- git submodule update --init tools/boostdep
|
|
||||||
- cp -r $TRAVIS_BUILD_DIR/* libs/array
|
|
||||||
- python tools/boostdep/depinst/depinst.py array
|
|
||||||
- ./bootstrap.sh
|
|
||||||
- ./b2 headers
|
|
||||||
|
|
||||||
script:
|
|
||||||
- |-
|
|
||||||
echo "using $TOOLSET : : $COMPILER ;" > ~/user-config.jam
|
|
||||||
- ./b2 -j 3 libs/array/test toolset=$TOOLSET cxxstd=$CXXSTD
|
|
||||||
|
|
||||||
notifications:
|
|
||||||
email:
|
|
||||||
on_success: always
|
|
@ -1,20 +0,0 @@
|
|||||||
# Copyright 2018 Mike Dev
|
|
||||||
# Distributed under the Boost Software License, Version 1.0.
|
|
||||||
# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt
|
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 3.5...3.20)
|
|
||||||
project(boost_array VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)
|
|
||||||
|
|
||||||
add_library(boost_array INTERFACE)
|
|
||||||
add_library(Boost::array ALIAS boost_array)
|
|
||||||
|
|
||||||
target_include_directories(boost_array INTERFACE include)
|
|
||||||
|
|
||||||
target_link_libraries(boost_array
|
|
||||||
INTERFACE
|
|
||||||
Boost::assert
|
|
||||||
Boost::config
|
|
||||||
Boost::core
|
|
||||||
Boost::static_assert
|
|
||||||
Boost::throw_exception
|
|
||||||
)
|
|
169
array.hpp.html
Normal file
169
array.hpp.html
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
<HTML>
|
||||||
|
<HEAD>
|
||||||
|
<TITLE>array.hpp</TITLE>
|
||||||
|
</HEAD>
|
||||||
|
|
||||||
|
<BODY TEXT="#000000" BGCOLOR="#FFFFFF">
|
||||||
|
|
||||||
|
<TABLE HEIGHT=40 WIDTH="100%">
|
||||||
|
<TR> <TD ALIGN=LEFT WIDTH="100%" BGCOLOR="#DDDDDD">
|
||||||
|
<FONT face="Arial,Helvetica" size=+2><B>
|
||||||
|
array.hpp
|
||||||
|
</B></FONT>
|
||||||
|
</TD></TR></TABLE><BR>
|
||||||
|
|
||||||
|
<BR><BR>
|
||||||
|
<TT>
|
||||||
|
<SPAN class="Source">
|
||||||
|
<Font color="0000FF" >/</FONT><I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* The following code declares class array,</FONT></I><BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* an STL container (as wrapper) for arrays of constant size.</FONT></I><BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*</FONT></I><BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* See</FONT></I><BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* http://www.josuttis.com/cppcode</FONT></I><BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* for details and the latest version.</FONT></I><BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*</FONT></I><BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* (C) Copyright Nicolai M. Josuttis 1999.</FONT></I><BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* Permission to copy, use, modify, sell and distribute this software</FONT></I><BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* is granted provided this copyright notice appears in all copies.</FONT></I><BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* This software is provided "as is" without express or implied</FONT></I><BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* warranty, and with no claim as to its suitability for any purpose.</FONT></I><BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*</FONT></I><BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* Jul 31, 2000</FONT></I><BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*/</FONT></I><BR>
|
||||||
|
#ifndef BOOST_ARRAY_HPP<BR>
|
||||||
|
#define BOOST_ARRAY_HPP<BR>
|
||||||
|
<BR>
|
||||||
|
#include <cstddef><BR>
|
||||||
|
#include <stdexcept><BR>
|
||||||
|
#include <iterator><BR>
|
||||||
|
#include <algorithm><BR>
|
||||||
|
<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// BUG-FIX for compilers that don't support</FONT></I><BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// std::size_t and std::ptrdiff_t yet</FONT></I><BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// (such as gcc)</FONT></I><BR>
|
||||||
|
#include <<A href="./config.hpp.html">boost/config.hpp</A>><BR>
|
||||||
|
<BR>
|
||||||
|
namespace boost {<BR>
|
||||||
|
<BR>
|
||||||
|
template<class T, std::size_t N><BR>
|
||||||
|
class array {<BR>
|
||||||
|
public:<BR>
|
||||||
|
T elems[N]; <I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// fixed-size array of elements of type T</FONT></I><BR>
|
||||||
|
<BR>
|
||||||
|
public:<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// type definitions</FONT></I><BR>
|
||||||
|
typedef T value_type;<BR>
|
||||||
|
typedef T* iterator;<BR>
|
||||||
|
typedef const T* const_iterator;<BR>
|
||||||
|
typedef T& reference;<BR>
|
||||||
|
typedef const T& const_reference;<BR>
|
||||||
|
typedef std::size_t size_type;<BR>
|
||||||
|
typedef std::ptrdiff_t difference_type;<BR>
|
||||||
|
<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// iterator support</FONT></I><BR>
|
||||||
|
iterator begin() { return elems; }<BR>
|
||||||
|
const_iterator begin() const { return elems; }<BR>
|
||||||
|
iterator end() { return elems+N; }<BR>
|
||||||
|
const_iterator end() const { return elems+N; }<BR>
|
||||||
|
<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// reverse iterator support</FONT></I><BR>
|
||||||
|
typedef std::reverse_iterator<iterator> reverse_iterator;<BR>
|
||||||
|
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;<BR>
|
||||||
|
reverse_iterator rbegin() { return reverse_iterator(end()); }<BR>
|
||||||
|
const_reverse_iterator rbegin() const {<BR>
|
||||||
|
return const_reverse_iterator(end());<BR>
|
||||||
|
}<BR>
|
||||||
|
reverse_iterator rend() { return reverse_iterator(begin()); }<BR>
|
||||||
|
const_reverse_iterator rend() const {<BR>
|
||||||
|
return const_reverse_iterator(begin());<BR>
|
||||||
|
}<BR>
|
||||||
|
<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// operator[]</FONT></I><BR>
|
||||||
|
reference operator[](size_type i) { return elems[i]; }<BR>
|
||||||
|
const_reference operator[](size_type i) const { return elems[i]; }<BR>
|
||||||
|
<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// at() with range check</FONT></I><BR>
|
||||||
|
reference at(size_type i) { rangecheck(i); return elems[i]; }<BR>
|
||||||
|
const_reference at(size_type i) const { rangecheck(i); return elems[i]; }<BR>
|
||||||
|
<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// front() and back()</FONT></I><BR>
|
||||||
|
reference front() { return elems[0]; }<BR>
|
||||||
|
const_reference front() const { return elems[0]; }<BR>
|
||||||
|
reference back() { return elems[N-1]; }<BR>
|
||||||
|
const_reference back() const { return elems[N-1]; }<BR>
|
||||||
|
<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// size is constant</FONT></I><BR>
|
||||||
|
static size_type size() { return N; }<BR>
|
||||||
|
static bool empty() { return false; }<BR>
|
||||||
|
static size_type max_size() { return N; }<BR>
|
||||||
|
enum { static_size = N };<BR>
|
||||||
|
<BR>
|
||||||
|
public:<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// swap (note: linear complexity)</FONT></I><BR>
|
||||||
|
void swap (array<T,N>& y) {<BR>
|
||||||
|
std::swap_ranges(begin(),end(),y.begin());<BR>
|
||||||
|
}<BR>
|
||||||
|
<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// direct access to data</FONT></I><BR>
|
||||||
|
const T* data() const { return elems; }<BR>
|
||||||
|
<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// assignment with type conversion</FONT></I><BR>
|
||||||
|
template <typename T2><BR>
|
||||||
|
array<T,N>& operator= (const array<T2,N>& rhs) {<BR>
|
||||||
|
std::copy(rhs.begin(),rhs.end(), begin());<BR>
|
||||||
|
return *this;<BR>
|
||||||
|
}<BR>
|
||||||
|
<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// assign one value to all elements</FONT></I><BR>
|
||||||
|
void assign (const T& value)<BR>
|
||||||
|
{<BR>
|
||||||
|
std::fill_n(begin(),size(),value);<BR>
|
||||||
|
}<BR>
|
||||||
|
<BR>
|
||||||
|
private:<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// check range (may be private because it is static)</FONT></I><BR>
|
||||||
|
static void rangecheck (size_type i) {<BR>
|
||||||
|
if (i >= size()) { throw std::range_error("array"); }<BR>
|
||||||
|
}<BR>
|
||||||
|
<BR>
|
||||||
|
};<BR>
|
||||||
|
<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// comparisons</FONT></I><BR>
|
||||||
|
template<class T, std::size_t N><BR>
|
||||||
|
bool operator== (const array<T,N>& x, const array<T,N>& y) {<BR>
|
||||||
|
return std::equal(x.begin(), x.end(), y.begin());<BR>
|
||||||
|
}<BR>
|
||||||
|
template<class T, std::size_t N><BR>
|
||||||
|
bool operator< (const array<T,N>& x, const array<T,N>& y) {<BR>
|
||||||
|
return std::lexicographical_compare(x.begin(),x.end(),y.begin(),y.end());<BR>
|
||||||
|
}<BR>
|
||||||
|
template<class T, std::size_t N><BR>
|
||||||
|
bool operator!= (const array<T,N>& x, const array<T,N>& y) {<BR>
|
||||||
|
return !(x==y);<BR>
|
||||||
|
}<BR>
|
||||||
|
template<class T, std::size_t N><BR>
|
||||||
|
bool operator> (const array<T,N>& x, const array<T,N>& y) {<BR>
|
||||||
|
return y<x;<BR>
|
||||||
|
}<BR>
|
||||||
|
template<class T, std::size_t N><BR>
|
||||||
|
bool operator<= (const array<T,N>& x, const array<T,N>& y) {<BR>
|
||||||
|
return !(y<x);<BR>
|
||||||
|
}<BR>
|
||||||
|
template<class T, std::size_t N><BR>
|
||||||
|
bool operator>= (const array<T,N>& x, const array<T,N>& y) {<BR>
|
||||||
|
return !(x<y);<BR>
|
||||||
|
}<BR>
|
||||||
|
<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// global swap()</FONT></I><BR>
|
||||||
|
template<class T, std::size_t N><BR>
|
||||||
|
inline void swap (array<T,N>& x, array<T,N>& y) {<BR>
|
||||||
|
x.swap(y);<BR>
|
||||||
|
}<BR>
|
||||||
|
<BR>
|
||||||
|
} <I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >/* namespace boost */</FONT></I><BR>
|
||||||
|
<BR>
|
||||||
|
#endif <I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >/*BOOST_ARRAY_HPP*/</FONT></I><BR>
|
||||||
|
</SPAN>
|
||||||
|
</TT>
|
||||||
|
</BODY>
|
||||||
|
</HTML>
|
320
array.html
Normal file
320
array.html
Normal file
@ -0,0 +1,320 @@
|
|||||||
|
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||||
|
<meta name="Keywords" content="array, block, carray, c_array, array wrapper, adapter, adaptor, STL, C++ Standard Library, array.hpp">
|
||||||
|
|
||||||
|
<title>array.hpp, an STL Array Wrapper</title>
|
||||||
|
</head>
|
||||||
|
<body text="#000000" bgcolor="#FFFFFF" link="#186ABF">
|
||||||
|
<font face="Arial, Helvetica, sans-serif"> </font>
|
||||||
|
<table width="100%" height="40">
|
||||||
|
<tr>
|
||||||
|
<td BGCOLOR="#DDDDDD"><b><font face="Arial,helvetica" color="#000000" size="+1">Class
|
||||||
|
<font face="Courier New, Courier, mono">array</font>, an STL Container (as
|
||||||
|
Wrapper) for Arrays of Constant Size</font></b></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<p><font face="Arial, Helvetica, sans-serif" size="-1">The C++ Standard Template
|
||||||
|
Library STL as part of the C++ Standard Library provides a framework for processing
|
||||||
|
algorithms on different kind of containers. However, ordinary arrays don't provide
|
||||||
|
the interface of STL containers (although, they provide the iterator interface
|
||||||
|
of STL containers).</font>
|
||||||
|
<p><font face="Arial, Helvetica, sans-serif" size="-1">As replacement for ordinary
|
||||||
|
arrays, the STL provides class <font face="Courier New, Courier, mono">vector<></font>.
|
||||||
|
However, <font face="Courier New, Courier, mono">vector<></font> provides
|
||||||
|
the semantics of dynamic arrays. Thus, it manages data to be able to change
|
||||||
|
the number of elements. This results in some overhead in case only arrays with
|
||||||
|
static size are needed.</font>
|
||||||
|
<p><font face="Arial, Helvetica, sans-serif" size="-1">In his book, <i>Generic
|
||||||
|
Programming and the STL</i>, Matthew H. Austern introduces a useful wrapper
|
||||||
|
class for ordinary arrays with static size, called <font face="Courier New, Courier, mono"><b>block</b></font>.
|
||||||
|
It is safer and has no worse performance than ordinary arrays. In <i>The C++
|
||||||
|
Programming Language</i>, 3rd edition, Bjarne Stroustrup introduces a similar
|
||||||
|
class, called <font face="Courier New, Courier, mono"><b>c_array</b></font>,
|
||||||
|
which I (<a href="http://www.josuttis.com">Nicolai Josuttis</a>) present slightly
|
||||||
|
modified in my book <i>The C++ Standard Library - A Tutorial and Reference</i>,
|
||||||
|
called <font face="Courier New, Courier, mono"><b>carray</b></font>. This is
|
||||||
|
the essence of these approaches spiced with many feedback from <a href="http://www.boost.org">boost</a>.</font>
|
||||||
|
<p><font face="Arial, Helvetica, sans-serif" size="-1">After considering different
|
||||||
|
names, we decided to name this class simply <font face="Courier New, Courier, mono"><b>array</b></font>.</font>
|
||||||
|
<p><font face="Arial, Helvetica, sans-serif" size="-1">The class provides the
|
||||||
|
following interface:</font>
|
||||||
|
<table border="0">
|
||||||
|
<tr>
|
||||||
|
<td><font face="Arial, Helvetica, sans-serif" size="-1"><b>Types:</b></font></td>
|
||||||
|
<td><font size="-1"></font></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><font face="Courier New, Courier, mono" size="-1">value_type</font></td>
|
||||||
|
<td><font face="Arial, Helvetica, sans-serif" size="-1">type of the elements</font></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><font face="Courier New, Courier, mono" size="-1">iterator</font></td>
|
||||||
|
<td><font face="Arial, Helvetica, sans-serif" size="-1">type of the iterator
|
||||||
|
(random-access iterator)</font></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><font face="Courier New, Courier, mono" size="-1">const_iterator</font></td>
|
||||||
|
<td><font face="Arial, Helvetica, sans-serif" size="-1">type of iterator that
|
||||||
|
considers elements as being constant</font></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><font face="Courier New, Courier, mono" size="-1">reference</font></td>
|
||||||
|
<td><font face="Arial, Helvetica, sans-serif" size="-1">type of element reference</font></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><font face="Courier New, Courier, mono" size="-1">const_reference</font></td>
|
||||||
|
<td><font face="Arial, Helvetica, sans-serif" size="-1">type of element reference
|
||||||
|
that considers elements as being constant</font></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><font face="Courier New, Courier, mono" size="-1">size_type</font></td>
|
||||||
|
<td><font face="Arial, Helvetica, sans-serif" size="-1">type for signed size
|
||||||
|
values</font></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><font face="Courier New, Courier, mono" size="-1">difference_type</font></td>
|
||||||
|
<td><font face="Arial, Helvetica, sans-serif" size="-1">type for unsigned
|
||||||
|
difference values</font></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><font face="Arial, Helvetica, sans-serif" size="-1"><b>Operations:</b></font></td>
|
||||||
|
<td><font size="-1"></font></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<p><font face="Courier New, Courier, mono" size="-1">array<<i>type</i>,<i>num</i>></font></p>
|
||||||
|
</td>
|
||||||
|
<td><font face="Arial, Helvetica, sans-serif" size="-1">default constructor,
|
||||||
|
creates array of <i><font face="Courier New, Courier, mono">num</font></i>
|
||||||
|
element of <i><font face="Courier New, Courier, mono">type</font></i>, see
|
||||||
|
comment below</font></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><font face="Courier New, Courier, mono" size="-1">array<<i>type</i>,<i>num</i>>(<i>a</i>)</font></td>
|
||||||
|
<td><font face="Arial, Helvetica, sans-serif" size="-1">copy constructor,
|
||||||
|
copies all elements of <i><font face="Courier New, Courier, mono">a</font></i>
|
||||||
|
(<i><font face="Courier New, Courier, mono">a</font></i> must have same
|
||||||
|
<i> <font face="Courier New, Courier, mono">type</font></i><font face="Courier New, Courier, mono"><font face="Arial, Helvetica, sans-serif">
|
||||||
|
and </font></font><i><font face="Courier New, Courier, mono">num</font></i>)</font></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><font face="Courier New, Courier, mono" size="-1">operator=</font></td>
|
||||||
|
<td><font face="Arial, Helvetica, sans-serif" size="-1">assignment, assigns
|
||||||
|
all elements</font></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><font face="Courier New, Courier, mono" size="-1">assign(<i>val</i>)</font></td>
|
||||||
|
<td><font face="Arial, Helvetica, sans-serif" size="-1">assigns <i>val</i>
|
||||||
|
to all elements</font></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><font face="Courier New, Courier, mono" size="-1">begin()</font></td>
|
||||||
|
<td><font face="Arial, Helvetica, sans-serif" size="-1">returns iterator for
|
||||||
|
the first element</font></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><font face="Courier New, Courier, mono" size="-1">end()</font></td>
|
||||||
|
<td><font face="Arial, Helvetica, sans-serif" size="-1">returns iterator for
|
||||||
|
position after the last element</font></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><font face="Courier New, Courier, mono" size="-1">rbegin()</font></td>
|
||||||
|
<td><font face="Arial, Helvetica, sans-serif" size="-1">returns reverse iterator
|
||||||
|
for position of first element of reverse iteration</font></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><font face="Courier New, Courier, mono" size="-1">rend()</font></td>
|
||||||
|
<td><font face="Arial, Helvetica, sans-serif" size="-1">returns reverse iterator
|
||||||
|
for posistion behind last element of reverese iteration </font></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><font face="Courier New, Courier, mono" size="-1">operator[<i>i</i>]</font></td>
|
||||||
|
<td><font face="Arial, Helvetica, sans-serif" size="-1">returns element with
|
||||||
|
index <i><font face="Courier New, Courier, mono">i</font></i> (no range
|
||||||
|
checking)</font></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><font face="Courier New, Courier, mono" size="-1">at(<i>i</i>)</font></td>
|
||||||
|
<td><font face="Arial, Helvetica, sans-serif" size="-1">returns element with
|
||||||
|
index <font face="Courier New, Courier, mono"><i>i</i></font> (throw std::range_error
|
||||||
|
if <i><font face="Courier New, Courier, mono">i</font></i> is not valid)</font></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><font face="Courier New, Courier, mono" size="-1">front()</font></td>
|
||||||
|
<td><font face="Arial, Helvetica, sans-serif" size="-1">returns first element
|
||||||
|
(caller has to ensure that it exists)</font></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><font face="Courier New, Courier, mono" size="-1">back()</font></td>
|
||||||
|
<td><font face="Arial, Helvetica, sans-serif" size="-1">returns last element
|
||||||
|
(caller has to ensure that it exists)</font></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><font face="Courier New, Courier, mono" size="-1">data()</font></td>
|
||||||
|
<td><font face="Arial, Helvetica, sans-serif" size="-1">returns raw element
|
||||||
|
array for read-only element access</font></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><font face="Courier New, Courier, mono" size="-1">size()</font></td>
|
||||||
|
<td><font face="Arial, Helvetica, sans-serif" size="-1">returns number of
|
||||||
|
elements</font></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><font face="Courier New, Courier, mono" size="-1">empty()</font></td>
|
||||||
|
<td><font face="Arial, Helvetica, sans-serif" size="-1">returns whether array
|
||||||
|
is empty</font></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><font face="Courier New, Courier, mono" size="-1">max_size()</font></td>
|
||||||
|
<td><font face="Arial, Helvetica, sans-serif" size="-1">returns maximum possible
|
||||||
|
number of elements (same as size())</font></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><font face="Courier New, Courier, mono" size="-1">swap(a)</font></td>
|
||||||
|
<td><font face="Arial, Helvetica, sans-serif" size="-1">swap elements with
|
||||||
|
array a</font></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><font face="Courier New, Courier, mono" size="-1">==<font face="Arial, Helvetica, sans-serif">,
|
||||||
|
</font>!=</font></td>
|
||||||
|
<td><font face="Arial, Helvetica, sans-serif" size="-1">checks for equality</font></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><font face="Courier New, Courier, mono" size="-1"><<font face="Arial, Helvetica, sans-serif">,
|
||||||
|
</font><=<font face="Arial, Helvetica, sans-serif">, </font>><font face="Arial, Helvetica, sans-serif">,
|
||||||
|
</font>>=</font></td>
|
||||||
|
<td><font face="Arial, Helvetica, sans-serif" size="-1">compares array</font></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><font face="Arial, Helvetica, sans-serif" size="-1"><b>Values:</b></font></td>
|
||||||
|
<td> </td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><font face="Courier New, Courier, mono" size="-1">static_size</font></td>
|
||||||
|
<td><font size="-1" face="Arial, Helvetica, sans-serif">yields size at compile
|
||||||
|
time</font></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<p><font face="Arial, Helvetica, sans-serif" size="-1">Class array fulfills most
|
||||||
|
but not all of the requirements of "reversible containers" (see Section
|
||||||
|
23.1, [lib.container.requirements] of the C++ Standard). The reasons array is
|
||||||
|
not an reversible STL container is because: </font> <font face="Arial, Helvetica, sans-serif" size="-1"><br>
|
||||||
|
- No constructors are provided<br>
|
||||||
|
- Elements may have an indetermined initial value (see below)<br>
|
||||||
|
- swap() has no constant complexity<br>
|
||||||
|
- size() is always constant, based on the second template argument of the type<br>
|
||||||
|
- The container provides no allocator support</font>
|
||||||
|
<p><font face="Arial, Helvetica, sans-serif" size="-1">It doesn't fulfill the
|
||||||
|
requirements of a "sequence" (see Section 23.1.1, [lib.sequence.reqmts]
|
||||||
|
of the C++ Standard), except that</font> <font face="Arial, Helvetica, sans-serif" size="-1"><br>
|
||||||
|
- front() and back() are provided<br>
|
||||||
|
- operator[] and at() are provided</font>
|
||||||
|
<p><font face="Arial, Helvetica, sans-serif" size="-1">Regarding the constructors
|
||||||
|
there was an important design tradeoff: We could implement array as an "<b>aggregate</b>"
|
||||||
|
(see Section 8.5.1, [dcl.init.aggr], of the C++ Standard). This would mean:</font></p>
|
||||||
|
<ul>
|
||||||
|
<li><font face="Arial, Helvetica, sans-serif" size="-1">An array can be initialized
|
||||||
|
with a brace-enclosing, comma-separated list of initializers for the elements
|
||||||
|
of the container, written in increasing subscript order:</font>
|
||||||
|
<blockquote>
|
||||||
|
<p><font face="Arial, Helvetica, sans-serif" size="-1">boost::array<int,4>
|
||||||
|
a = { { 1, 2, 3 } };</font></p>
|
||||||
|
</blockquote>
|
||||||
|
<p><font face="Arial, Helvetica, sans-serif" size="-1">Note that if there
|
||||||
|
are fewer elements in the initializer list, then each remaining element
|
||||||
|
gets default-initialized (thus, it has a defined value).</font></p>
|
||||||
|
</li>
|
||||||
|
<li><font face="Arial, Helvetica, sans-serif" size="-1">However, <b>passing
|
||||||
|
no initializer list means that the elements have an indetermined initial value</b>.</font></li>
|
||||||
|
<li><font face="Arial, Helvetica, sans-serif" size="-1">It has no user-declared
|
||||||
|
constructors.</font></li>
|
||||||
|
<li><font face="Arial, Helvetica, sans-serif" size="-1">It has no private or
|
||||||
|
protected non-static data members.</font></li>
|
||||||
|
<li><font face="Arial, Helvetica, sans-serif" size="-1">It has no base classes.</font></li>
|
||||||
|
<li><font face="Arial, Helvetica, sans-serif" size="-1">It has no virtual functions.</font></li>
|
||||||
|
</ul>
|
||||||
|
<p><font face="Arial, Helvetica, sans-serif" size="-1">The current implementation
|
||||||
|
useus this approach. However, being able to have indetermined initial values
|
||||||
|
is a big drawback. So, please give me some feedback, how useful you consider
|
||||||
|
this feature to be. This leads to the list of <b>Open issues:</b></font>
|
||||||
|
<ul>
|
||||||
|
<li><font face="Arial, Helvetica, sans-serif">Do we want initializer list support
|
||||||
|
or would the following be OK?:</font>
|
||||||
|
<blockquote>
|
||||||
|
<p><font face="Courier New, Courier, mono">int data[] = { 1, 2, 3, 4 }</font></p>
|
||||||
|
<p><font face="Courier New, Courier, mono">array<int,5> x(data); <font face="Arial, Helvetica, sans-serif">or
|
||||||
|
</font> array<int,data> x;</font></p>
|
||||||
|
</blockquote>
|
||||||
|
</li>
|
||||||
|
<li><font face="Arial, Helvetica, sans-serif">Could "<font face="Courier New, Courier, mono">{
|
||||||
|
</font>...<font face="Courier New, Courier, mono"> }</font>" be used
|
||||||
|
portably instead of "<font face="Courier New, Courier, mono">{ { </font>...<font face="Courier New, Courier, mono">
|
||||||
|
} }</font>" to initialize values?</font> </li>
|
||||||
|
<blockquote>
|
||||||
|
<p><font face="Arial, Helvetica, sans-serif">8.5.1 (11) of the Standard seem
|
||||||
|
to allow it; however, gcc 2.95.2 printa warning message.</font></p>
|
||||||
|
</blockquote>
|
||||||
|
<li><font face="Arial, Helvetica, sans-serif">Any way to have determined initial
|
||||||
|
values and initializer list support?</font></li>
|
||||||
|
<li><font face="Arial, Helvetica, sans-serif">Static_casts for reverse iterator
|
||||||
|
stuff</font><font face="Arial, Helvetica, sans-serif">?</font></li>
|
||||||
|
</ul>
|
||||||
|
<p><font face="Arial, Helvetica, sans-serif">I'd appreciate any constructive <a href="mailto:solutions@josuttis.com">feedback</a>.
|
||||||
|
<b>Please note: I don't have time to read all boost mails. Thus, to make sure
|
||||||
|
that feedback arrives me, please send me a copy of each mail regarding this
|
||||||
|
class.</b></font>
|
||||||
|
<p><font face="Arial, Helvetica, sans-serif">The code is provided "as is" without
|
||||||
|
expressed or implied warranty.</font>
|
||||||
|
<p><font face="Arial, Helvetica, sans-serif"><b>array.hpp</b>, the implementation
|
||||||
|
of <font face="Courier New, Courier, mono">array<></font><b>:</b> </font>
|
||||||
|
<li><font face="Arial, Helvetica, sans-serif">
|
||||||
|
<a href="array.hpp.html">as HTML file</a></font></li>
|
||||||
|
<li><font face="Arial, Helvetica, sans-serif">
|
||||||
|
<a href="array.hpp">as plain file</a></font></li>
|
||||||
|
<p> <font face="Arial, Helvetica, sans-serif">Simple Example for using <font face="Courier New, Courier, mono">array<><font face="Arial, Helvetica, sans-serif">:</font></font></font>
|
||||||
|
<li><font face="Arial, Helvetica, sans-serif">
|
||||||
|
<a href="array1.cpp.html">as HTML file</a></font> </li>
|
||||||
|
<li><font face="Arial, Helvetica, sans-serif">
|
||||||
|
<a href="array1.cpp">as plain file</a></font></li>
|
||||||
|
<p> <font face="Arial, Helvetica, sans-serif">Another Example for using <font face="Courier New, Courier, mono">array<><font face="Arial, Helvetica, sans-serif">:</font></font></font>
|
||||||
|
<li><font face="Arial, Helvetica, sans-serif">
|
||||||
|
<a href="array2.cpp.html">as HTML file</a></font></li>
|
||||||
|
<li><font face="Arial, Helvetica, sans-serif">
|
||||||
|
<a href="array2.cpp">as plain file</a></font></li>
|
||||||
|
<p> <font face="Arial, Helvetica, sans-serif">A third Example for using <font face="Courier New, Courier, mono">array<><font face="Arial, Helvetica, sans-serif">:</font></font></font>
|
||||||
|
<li><font face="Arial, Helvetica, sans-serif">
|
||||||
|
<a href="array3.cpp.html">as HTML file</a></font></li>
|
||||||
|
<li><font face="Arial, Helvetica, sans-serif">
|
||||||
|
<a href="array3.cpp">as plain file</a></font></li>
|
||||||
|
<p> <font face="Arial, Helvetica, sans-serif">An Example for using <font face="Courier New, Courier, mono">array</font>s
|
||||||
|
of <font face="Courier New, Courier, mono">array</font>s<font face="Courier New, Courier, mono"><font face="Arial, Helvetica, sans-serif">:</font></font></font>
|
||||||
|
<li><font face="Arial, Helvetica, sans-serif"> <a href="array4.cpp.html">as HTML
|
||||||
|
file</a></font></li>
|
||||||
|
<li><font face="Arial, Helvetica, sans-serif"> <a href="array4.cpp">as plain file</a></font></li>
|
||||||
|
<p><font face="Arial, Helvetica, sans-serif">An Example for testing other operations
|
||||||
|
of <font face="Courier New, Courier, mono">array<></font><font face="Courier New, Courier, mono"><font face="Arial, Helvetica, sans-serif">:</font></font></font>
|
||||||
|
<li><font face="Arial, Helvetica, sans-serif"> <a href="array5.cpp.html">as HTML
|
||||||
|
file</a></font></li>
|
||||||
|
<li><font face="Arial, Helvetica, sans-serif"> <a href="array5.cpp">as plain file</a></font></li>
|
||||||
|
<p><b><font face="Arial, Helvetica, sans-serif">All files</font></b>
|
||||||
|
<li><font face="Arial, Helvetica, sans-serif"> <a href="array.zip">as ZIP file
|
||||||
|
(24KB)</a></font></li>
|
||||||
|
<li><font face="Arial, Helvetica, sans-serif"> <a href="array.tgz">as TGZ file
|
||||||
|
(13KB)</a><br>
|
||||||
|
<br>
|
||||||
|
To find more details about using ordinary arrays in C++ and the framework of
|
||||||
|
the STL, see e.g.</font> <font face="Arial, Helvetica, sans-serif"><br>
|
||||||
|
<i> <a href="http://www.josuttis.com/libbook/">The C++
|
||||||
|
Standard Library - A Tutorial and Reference</a></i> <br>
|
||||||
|
by <a href="http://www.josuttis.com" target="_top">Nicolai
|
||||||
|
M. Josuttis</a></font> <font face="Arial, Helvetica, sans-serif"><br>
|
||||||
|
Addison Wesley Longman, 1999</font> <font face="Arial, Helvetica, sans-serif"><br>
|
||||||
|
ISBN 0-201-37926-0</font> <font face="Arial, Helvetica, sans-serif"><br>
|
||||||
|
</font></li>
|
||||||
|
<p><font face="Arial, Helvetica, sans-serif"><a href="http://www.josuttis.com/" TARGET="_top">Home
|
||||||
|
Page of Nicolai Josuttis</a></font> <font face="Arial, Helvetica, sans-serif"><br>
|
||||||
|
</font>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -1,15 +1,5 @@
|
|||||||
/* simple example for using class array<>
|
/* simple example for using class array<>
|
||||||
*
|
|
||||||
* (C) Copyright Nicolai M. Josuttis 2001.
|
|
||||||
* Distributed under the Boost Software License, Version 1.0. (See
|
|
||||||
* accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
* http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
*
|
|
||||||
* Changelog:
|
|
||||||
* 20 Jan 2001 - Removed boolalpha use since stock GCC doesn't support it
|
|
||||||
* (David Abrahams)
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <boost/array.hpp>
|
#include <boost/array.hpp>
|
||||||
|
|
||||||
@ -28,7 +18,7 @@ int main()
|
|||||||
|
|
||||||
// use some common STL container operations
|
// use some common STL container operations
|
||||||
std::cout << "size: " << a.size() << std::endl;
|
std::cout << "size: " << a.size() << std::endl;
|
||||||
std::cout << "empty: " << (a.empty() ? "true" : "false") << std::endl;
|
std::cout << "empty: " << std::boolalpha << a.empty() << std::endl;
|
||||||
std::cout << "max_size: " << a.max_size() << std::endl;
|
std::cout << "max_size: " << a.max_size() << std::endl;
|
||||||
std::cout << "front: " << a.front() << std::endl;
|
std::cout << "front: " << a.front() << std::endl;
|
||||||
std::cout << "back: " << a.back() << std::endl;
|
std::cout << "back: " << a.back() << std::endl;
|
||||||
@ -49,10 +39,8 @@ int main()
|
|||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
std::cout << "copy construction and copy assignment FAILED"
|
std::cout << "copy construction and copy assignment are OK"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0; // makes Visual-C++ compiler happy
|
|
||||||
}
|
}
|
||||||
|
|
67
array1.cpp.html
Normal file
67
array1.cpp.html
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
<HTML>
|
||||||
|
<HEAD>
|
||||||
|
<TITLE>array1.cpp</TITLE>
|
||||||
|
</HEAD>
|
||||||
|
|
||||||
|
<BODY TEXT="#000000" BGCOLOR="#FFFFFF">
|
||||||
|
|
||||||
|
<TABLE HEIGHT=40 WIDTH="100%">
|
||||||
|
<TR> <TD ALIGN=LEFT WIDTH="100%" BGCOLOR="#DDDDDD">
|
||||||
|
<FONT face="Arial,Helvetica" size=+2><B>
|
||||||
|
array1.cpp
|
||||||
|
</B></FONT>
|
||||||
|
</TD></TR></TABLE><BR>
|
||||||
|
|
||||||
|
<BR><BR>
|
||||||
|
<TT>
|
||||||
|
<SPAN class="Source">
|
||||||
|
<Font color="0000FF" >/</FONT><I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* simple example for using class array<></FONT></I><BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*/</FONT></I><BR>
|
||||||
|
#include <iostream><BR>
|
||||||
|
#include <<A href="./array.hpp.html">boost/array.hpp</A>><BR>
|
||||||
|
<BR>
|
||||||
|
int main()<BR>
|
||||||
|
{<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// define special type name</FONT></I><BR>
|
||||||
|
typedef boost::array<float,6> Array;<BR>
|
||||||
|
<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// create and initialize an array</FONT></I><BR>
|
||||||
|
Array a = { { 42 } };<BR>
|
||||||
|
<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// access elements</FONT></I><BR>
|
||||||
|
for (unsigned i=1; i<a.size(); ++i) {<BR>
|
||||||
|
a[i] = a[i-1]+1;<BR>
|
||||||
|
}<BR>
|
||||||
|
<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// use some common STL container operations</FONT></I><BR>
|
||||||
|
std::cout << "size: " << a.size() << std::endl;<BR>
|
||||||
|
std::cout << "empty: " << std::boolalpha << a.empty() << std::endl;<BR>
|
||||||
|
std::cout << "max_size: " << a.max_size() << std::endl;<BR>
|
||||||
|
std::cout << "front: " << a.front() << std::endl;<BR>
|
||||||
|
std::cout << "back: " << a.back() << std::endl;<BR>
|
||||||
|
std::cout << "elems: ";<BR>
|
||||||
|
<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// iterate through all elements</FONT></I><BR>
|
||||||
|
for (Array::const_iterator pos=a.begin(); pos<a.end(); ++pos) {<BR>
|
||||||
|
std::cout << *pos << ' ';<BR>
|
||||||
|
}<BR>
|
||||||
|
std::cout << std::endl;<BR>
|
||||||
|
<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// check copy constructor and assignment operator</FONT></I><BR>
|
||||||
|
Array b(a);<BR>
|
||||||
|
Array c;<BR>
|
||||||
|
c = a;<BR>
|
||||||
|
if (a==b && a==c) {<BR>
|
||||||
|
std::cout << "copy construction and copy assignment are OK"<BR>
|
||||||
|
<< std::endl;<BR>
|
||||||
|
}<BR>
|
||||||
|
else {<BR>
|
||||||
|
std::cout << "copy construction and copy assignment are OK"<BR>
|
||||||
|
<< std::endl;<BR>
|
||||||
|
}<BR>
|
||||||
|
}<BR>
|
||||||
|
<BR>
|
||||||
|
</SPAN>
|
||||||
|
</TT>
|
||||||
|
</BODY>
|
||||||
|
</HTML>
|
@ -1,44 +1,33 @@
|
|||||||
/* example for using class array<>
|
/* example for using class array<>
|
||||||
* (C) Copyright Nicolai M. Josuttis 2001.
|
|
||||||
* Distributed under the Boost Software License, Version 1.0. (See
|
|
||||||
* accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
* http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _SCL_SECURE_NO_WARNINGS
|
|
||||||
// Suppress warnings from the std lib:
|
|
||||||
# define _SCL_SECURE_NO_WARNINGS
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <boost/array.hpp>
|
#include <boost/array.hpp>
|
||||||
#include "print.hpp"
|
#include "print.hpp"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using namespace boost;
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// create and initialize array
|
// create and initialize array
|
||||||
boost::array<int,10> a = { { 1, 2, 3, 4, 5 } };
|
array<int,10> a = { { 1, 2, 3, 4, 5 } };
|
||||||
|
|
||||||
print_elements(a);
|
PRINT_ELEMENTS(a);
|
||||||
|
|
||||||
// modify elements directly
|
// modify elements directly
|
||||||
for (unsigned i=0; i<a.size(); ++i) {
|
for (unsigned i=0; i<a.size(); ++i) {
|
||||||
++a[i];
|
++a[i];
|
||||||
}
|
}
|
||||||
print_elements(a);
|
PRINT_ELEMENTS(a);
|
||||||
|
|
||||||
// change order using an STL algorithm
|
// change order using an STL algorithm
|
||||||
reverse(a.begin(),a.end());
|
reverse(a.begin(),a.end());
|
||||||
print_elements(a);
|
PRINT_ELEMENTS(a);
|
||||||
|
|
||||||
// negate elements using STL framework
|
// negate elements using STL framework
|
||||||
transform(a.begin(),a.end(), // source
|
transform(a.begin(),a.end(), // source
|
||||||
a.begin(), // destination
|
a.begin(), // destination
|
||||||
negate<int>()); // operation
|
negate<int>()); // operation
|
||||||
print_elements(a);
|
PRINT_ELEMENTS(a);
|
||||||
|
|
||||||
return 0; // makes Visual-C++ compiler happy
|
|
||||||
}
|
}
|
||||||
|
|
54
array2.cpp.html
Normal file
54
array2.cpp.html
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
<HTML>
|
||||||
|
<HEAD>
|
||||||
|
<TITLE>array2.cpp</TITLE>
|
||||||
|
</HEAD>
|
||||||
|
|
||||||
|
<BODY TEXT="#000000" BGCOLOR="#FFFFFF">
|
||||||
|
|
||||||
|
<TABLE HEIGHT=40 WIDTH="100%">
|
||||||
|
<TR> <TD ALIGN=LEFT WIDTH="100%" BGCOLOR="#DDDDDD">
|
||||||
|
<FONT face="Arial,Helvetica" size=+2><B>
|
||||||
|
array2.cpp
|
||||||
|
</B></FONT>
|
||||||
|
</TD></TR></TABLE><BR>
|
||||||
|
|
||||||
|
<BR><BR>
|
||||||
|
<TT>
|
||||||
|
<SPAN class="Source">
|
||||||
|
<Font color="0000FF" >/</FONT><I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* example for using class array<></FONT></I><BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*/</FONT></I><BR>
|
||||||
|
#include <algorithm><BR>
|
||||||
|
#include <functional><BR>
|
||||||
|
#include <<A href="./array.hpp.html">boost/array.hpp</A>><BR>
|
||||||
|
#include "<A href="print.hpp.html">print.hpp</A>"<BR>
|
||||||
|
using namespace std;<BR>
|
||||||
|
using namespace boost;<BR>
|
||||||
|
<BR>
|
||||||
|
int main()<BR>
|
||||||
|
{<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// create and initialize array</FONT></I><BR>
|
||||||
|
array<int,10> a = { { 1, 2, 3, 4, 5 } };<BR>
|
||||||
|
<BR>
|
||||||
|
PRINT_ELEMENTS(a);<BR>
|
||||||
|
<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// modify elements directly</FONT></I><BR>
|
||||||
|
for (unsigned i=0; i<a.size(); ++i) {<BR>
|
||||||
|
++a[i];<BR>
|
||||||
|
}<BR>
|
||||||
|
PRINT_ELEMENTS(a);<BR>
|
||||||
|
<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// change order using an STL algorithm</FONT></I><BR>
|
||||||
|
reverse(a.begin(),a.end());<BR>
|
||||||
|
PRINT_ELEMENTS(a);<BR>
|
||||||
|
<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// negate elements using STL framework</FONT></I><BR>
|
||||||
|
transform(a.begin(),a.end(), <I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// source</FONT></I><BR>
|
||||||
|
a.begin(), <I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// destination</FONT></I><BR>
|
||||||
|
negate<int>()); <I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// operation</FONT></I><BR>
|
||||||
|
PRINT_ELEMENTS(a);<BR>
|
||||||
|
}<BR>
|
||||||
|
<BR>
|
||||||
|
</SPAN>
|
||||||
|
</TT>
|
||||||
|
</BODY>
|
||||||
|
</HTML>
|
@ -1,10 +1,5 @@
|
|||||||
/* example for using class array<>
|
/* example for using class array<>
|
||||||
* (C) Copyright Nicolai M. Josuttis 2001.
|
|
||||||
* Distributed under the Boost Software License, Version 1.0. (See
|
|
||||||
* accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
* http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <boost/array.hpp>
|
#include <boost/array.hpp>
|
||||||
@ -21,8 +16,8 @@ int main()
|
|||||||
|
|
||||||
// copy and change order
|
// copy and change order
|
||||||
boost::array<std::string,4> seasons_orig = seasons;
|
boost::array<std::string,4> seasons_orig = seasons;
|
||||||
for (std::size_t i=seasons.size()-1; i>0; --i) {
|
for (unsigned i=seasons.size()-1; i>0; --i) {
|
||||||
std::swap(seasons.at(i),seasons.at((i+1)%seasons.size()));
|
swap(seasons.at(i),seasons.at((i+1)%seasons.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "one way: ";
|
std::cout << "one way: ";
|
||||||
@ -30,7 +25,7 @@ int main()
|
|||||||
|
|
||||||
// try swap()
|
// try swap()
|
||||||
std::cout << "other way: ";
|
std::cout << "other way: ";
|
||||||
std::swap(seasons,seasons_orig);
|
swap(seasons,seasons_orig);
|
||||||
print_elements(seasons);
|
print_elements(seasons);
|
||||||
|
|
||||||
// try reverse iterators
|
// try reverse iterators
|
||||||
@ -39,16 +34,7 @@ int main()
|
|||||||
=seasons.rbegin(); pos<seasons.rend(); ++pos) {
|
=seasons.rbegin(); pos<seasons.rend(); ++pos) {
|
||||||
std::cout << " " << *pos;
|
std::cout << " " << *pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
// try constant reverse iterators
|
|
||||||
std::cout << "reverse: ";
|
|
||||||
for (boost::array<std::string,4>::const_reverse_iterator pos
|
|
||||||
=seasons.crbegin(); pos<seasons.crend(); ++pos) {
|
|
||||||
std::cout << " " << *pos;
|
|
||||||
}
|
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
||||||
return 0; // makes Visual-C++ compiler happy
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
69
array3.cpp.html
Normal file
69
array3.cpp.html
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
<HTML>
|
||||||
|
<HEAD>
|
||||||
|
<TITLE>array3.cpp</TITLE>
|
||||||
|
</HEAD>
|
||||||
|
|
||||||
|
<BODY TEXT="#000000" BGCOLOR="#FFFFFF">
|
||||||
|
|
||||||
|
<TABLE HEIGHT=40 WIDTH="100%">
|
||||||
|
<TR> <TD ALIGN=LEFT WIDTH="100%" BGCOLOR="#DDDDDD">
|
||||||
|
<FONT face="Arial,Helvetica" size=+2><B>
|
||||||
|
array3.cpp
|
||||||
|
</B></FONT>
|
||||||
|
</TD></TR></TABLE><BR>
|
||||||
|
|
||||||
|
<BR><BR>
|
||||||
|
<TT>
|
||||||
|
<SPAN class="Source">
|
||||||
|
<Font color="0000FF" >/</FONT><I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* example for using class array<></FONT></I><BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*/</FONT></I><BR>
|
||||||
|
#include <string><BR>
|
||||||
|
#include <iostream><BR>
|
||||||
|
#include <<A href="./array.hpp.html">boost/array.hpp</A>><BR>
|
||||||
|
<BR>
|
||||||
|
template <class T><BR>
|
||||||
|
void print_elements (const T& x);<BR>
|
||||||
|
<BR>
|
||||||
|
int main()<BR>
|
||||||
|
{<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// create array of four seasons</FONT></I><BR>
|
||||||
|
boost::array<std::string,4> seasons = {<BR>
|
||||||
|
{ "spring", "summer", "autumn", "winter" }<BR>
|
||||||
|
};<BR>
|
||||||
|
<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// copy and change order</FONT></I><BR>
|
||||||
|
boost::array<std::string,4> seasons_orig = seasons;<BR>
|
||||||
|
for (unsigned i=seasons.size()-1; i>0; --i) {<BR>
|
||||||
|
swap(seasons.at(i),seasons.at((i+1)%seasons.size()));<BR>
|
||||||
|
}<BR>
|
||||||
|
<BR>
|
||||||
|
std::cout << "one way: ";<BR>
|
||||||
|
print_elements(seasons);<BR>
|
||||||
|
<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// try swap()</FONT></I><BR>
|
||||||
|
std::cout << "other way: ";<BR>
|
||||||
|
swap(seasons,seasons_orig);<BR>
|
||||||
|
print_elements(seasons);<BR>
|
||||||
|
<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// try reverse iterators</FONT></I><BR>
|
||||||
|
std::cout << "reverse: ";<BR>
|
||||||
|
for (boost::array<std::string,4>::reverse_iterator pos<BR>
|
||||||
|
=seasons.rbegin(); pos<seasons.rend(); ++pos) {<BR>
|
||||||
|
std::cout << " " << *pos;<BR>
|
||||||
|
}<BR>
|
||||||
|
std::cout << std::endl;<BR>
|
||||||
|
}<BR>
|
||||||
|
<BR>
|
||||||
|
template <class T><BR>
|
||||||
|
void print_elements (const T& x)<BR>
|
||||||
|
{<BR>
|
||||||
|
for (unsigned i=0; i<x.size(); ++i) {<BR>
|
||||||
|
std::cout << " " << x[i];<BR>
|
||||||
|
}<BR>
|
||||||
|
std::cout << std::endl;<BR>
|
||||||
|
}<BR>
|
||||||
|
<BR>
|
||||||
|
</SPAN>
|
||||||
|
</TT>
|
||||||
|
</BODY>
|
||||||
|
</HTML>
|
@ -1,10 +1,5 @@
|
|||||||
/* example for using class array<>
|
/* example for using class array<>
|
||||||
* (C) Copyright Nicolai M. Josuttis 2001.
|
|
||||||
* Distributed under the Boost Software License, Version 1.0. (See
|
|
||||||
* accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
* http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -37,7 +32,5 @@ int main()
|
|||||||
std::cout << "last element of last array: "
|
std::cout << "last element of last array: "
|
||||||
<< seasons_i18n[seasons_i18n.size()-1][seasons_i18n[0].size()-1]
|
<< seasons_i18n[seasons_i18n.size()-1][seasons_i18n[0].size()-1]
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
|
||||||
return 0; // makes Visual-C++ compiler happy
|
|
||||||
}
|
}
|
||||||
|
|
57
array4.cpp.html
Normal file
57
array4.cpp.html
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
<HTML>
|
||||||
|
<HEAD>
|
||||||
|
<TITLE>array4.cpp</TITLE>
|
||||||
|
</HEAD>
|
||||||
|
|
||||||
|
<BODY TEXT="#000000" BGCOLOR="#FFFFFF">
|
||||||
|
|
||||||
|
<TABLE HEIGHT=40 WIDTH="100%">
|
||||||
|
<TR> <TD ALIGN=LEFT WIDTH="100%" BGCOLOR="#DDDDDD">
|
||||||
|
<FONT face="Arial,Helvetica" size=+2><B>
|
||||||
|
array4.cpp
|
||||||
|
</B></FONT>
|
||||||
|
</TD></TR></TABLE><BR>
|
||||||
|
|
||||||
|
<BR><BR>
|
||||||
|
<TT>
|
||||||
|
<SPAN class="Source">
|
||||||
|
<Font color="0000FF" >/</FONT><I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* example for using class array<></FONT></I><BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*/</FONT></I><BR>
|
||||||
|
#include <algorithm><BR>
|
||||||
|
#include <functional><BR>
|
||||||
|
#include <string><BR>
|
||||||
|
#include <iostream><BR>
|
||||||
|
#include <<A href="./array.hpp.html">boost/array.hpp</A>><BR>
|
||||||
|
<BR>
|
||||||
|
int main()<BR>
|
||||||
|
{<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// array of arrays of seasons</FONT></I><BR>
|
||||||
|
boost::array<boost::array<std::string,4>,2> seasons_i18n = {<BR>
|
||||||
|
{ { { "spring", "summer", "autumn", "winter", } },<BR>
|
||||||
|
{ { "Fruehling", "Sommer", "Herbst", "Winter" } }<BR>
|
||||||
|
}<BR>
|
||||||
|
};<BR>
|
||||||
|
<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// for any array of seasons print seasons</FONT></I><BR>
|
||||||
|
for (unsigned i=0; i<seasons_i18n.size(); ++i) {<BR>
|
||||||
|
boost::array<std::string,4> seasons = seasons_i18n[i];<BR>
|
||||||
|
for (unsigned j=0; j<seasons.size(); ++j) {<BR>
|
||||||
|
std::cout << seasons[j] << " ";<BR>
|
||||||
|
}<BR>
|
||||||
|
std::cout << std::endl;<BR>
|
||||||
|
}<BR>
|
||||||
|
<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// print first element of first array</FONT></I><BR>
|
||||||
|
std::cout << "first element of first array: "<BR>
|
||||||
|
<< seasons_i18n[0][0] << std::endl;<BR>
|
||||||
|
<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// print last element of last array</FONT></I><BR>
|
||||||
|
std::cout << "last element of last array: "<BR>
|
||||||
|
<< seasons_i18n[seasons_i18n.size()-1][seasons_i18n[0].size()-1]<BR>
|
||||||
|
<< std::endl;<BR>
|
||||||
|
}<BR>
|
||||||
|
<BR>
|
||||||
|
</SPAN>
|
||||||
|
</TT>
|
||||||
|
</BODY>
|
||||||
|
</HTML>
|
@ -1,10 +1,5 @@
|
|||||||
/* simple example for using class array<>
|
/* simple example for using class array<>
|
||||||
* (C) Copyright Nicolai M. Josuttis 2001.
|
|
||||||
* Distributed under the Boost Software License, Version 1.0. (See
|
|
||||||
* accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
* http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <boost/array.hpp>
|
#include <boost/array.hpp>
|
||||||
|
|
||||||
@ -15,8 +10,8 @@ void test_static_size (const T& cont)
|
|||||||
for (unsigned i=0; i<T::static_size; ++i) {
|
for (unsigned i=0; i<T::static_size; ++i) {
|
||||||
tmp[i] = int(cont[i]);
|
tmp[i] = int(cont[i]);
|
||||||
}
|
}
|
||||||
for (unsigned j=0; j<T::static_size; ++j) {
|
for (unsigned i=0; i<T::static_size; ++i) {
|
||||||
std::cout << tmp[j] << ' ';
|
std::cout << tmp[i] << ' ';
|
||||||
}
|
}
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
@ -27,13 +22,12 @@ int main()
|
|||||||
typedef boost::array<float,6> Array;
|
typedef boost::array<float,6> Array;
|
||||||
|
|
||||||
// create and initialize an array
|
// create and initialize an array
|
||||||
const Array a = { { 42.42f } };
|
const Array a = { { 42.42 } };
|
||||||
|
|
||||||
// use some common STL container operations
|
// use some common STL container operations
|
||||||
std::cout << "static_size: " << a.size() << std::endl;
|
std::cout << "static_size: " << a.size() << std::endl;
|
||||||
std::cout << "size: " << a.size() << std::endl;
|
std::cout << "size: " << a.size() << std::endl;
|
||||||
// Can't use std::boolalpha because it isn't portable
|
std::cout << "empty: " << std::boolalpha << a.empty() << std::endl;
|
||||||
std::cout << "empty: " << (a.empty()? "true" : "false") << std::endl;
|
|
||||||
std::cout << "max_size: " << a.max_size() << std::endl;
|
std::cout << "max_size: " << a.max_size() << std::endl;
|
||||||
std::cout << "front: " << a.front() << std::endl;
|
std::cout << "front: " << a.front() << std::endl;
|
||||||
std::cout << "back: " << a.back() << std::endl;
|
std::cout << "back: " << a.back() << std::endl;
|
||||||
@ -56,17 +50,15 @@ int main()
|
|||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
std::cout << "copy construction and copy assignment are BROKEN"
|
std::cout << "copy construction and copy assignment are OK"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef boost::array<double,6> DArray;
|
typedef boost::array<double,6> DArray;
|
||||||
typedef boost::array<int,6> IArray;
|
typedef boost::array<int,6> IArray;
|
||||||
IArray ia = { { 1, 2, 3, 4, 5, 6 } } ; // extra braces silence GCC warning
|
IArray ia = { 1, 2, 3, 4, 5, 6 };
|
||||||
DArray da;
|
DArray da;
|
||||||
da = ia;
|
da = ia;
|
||||||
da.assign(42);
|
da.assign(42);
|
||||||
|
|
||||||
return 0; // makes Visual-C++ compiler happy
|
|
||||||
}
|
}
|
||||||
|
|
85
array5.cpp.html
Normal file
85
array5.cpp.html
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
<HTML>
|
||||||
|
<HEAD>
|
||||||
|
<TITLE>array5.cpp</TITLE>
|
||||||
|
</HEAD>
|
||||||
|
|
||||||
|
<BODY TEXT="#000000" BGCOLOR="#FFFFFF">
|
||||||
|
|
||||||
|
<TABLE HEIGHT=40 WIDTH="100%">
|
||||||
|
<TR> <TD ALIGN=LEFT WIDTH="100%" BGCOLOR="#DDDDDD">
|
||||||
|
<FONT face="Arial,Helvetica" size=+2><B>
|
||||||
|
array5.cpp
|
||||||
|
</B></FONT>
|
||||||
|
</TD></TR></TABLE><BR>
|
||||||
|
|
||||||
|
<BR><BR>
|
||||||
|
<TT>
|
||||||
|
<SPAN class="Source">
|
||||||
|
<Font color="0000FF" >/</FONT><I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* simple example for using class array<></FONT></I><BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*/</FONT></I><BR>
|
||||||
|
#include <iostream><BR>
|
||||||
|
#include <<A href="./array.hpp.html">boost/array.hpp</A>><BR>
|
||||||
|
<BR>
|
||||||
|
template <typename T><BR>
|
||||||
|
void test_static_size (const T& cont)<BR>
|
||||||
|
{<BR>
|
||||||
|
int tmp[T::static_size];<BR>
|
||||||
|
for (unsigned i=0; i<T::static_size; ++i) {<BR>
|
||||||
|
tmp[i] = int(cont[i]);<BR>
|
||||||
|
}<BR>
|
||||||
|
for (unsigned i=0; i<T::static_size; ++i) {<BR>
|
||||||
|
std::cout << tmp[i] << ' ';<BR>
|
||||||
|
}<BR>
|
||||||
|
std::cout << std::endl;<BR>
|
||||||
|
}<BR>
|
||||||
|
<BR>
|
||||||
|
int main()<BR>
|
||||||
|
{<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// define special type name</FONT></I><BR>
|
||||||
|
typedef boost::array<float,6> Array;<BR>
|
||||||
|
<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// create and initialize an array</FONT></I><BR>
|
||||||
|
const Array a = { { 42.42 } };<BR>
|
||||||
|
<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// use some common STL container operations</FONT></I><BR>
|
||||||
|
std::cout << "static_size: " << a.size() << std::endl;<BR>
|
||||||
|
std::cout << "size: " << a.size() << std::endl;<BR>
|
||||||
|
std::cout << "empty: " << std::boolalpha << a.empty() << std::endl;<BR>
|
||||||
|
std::cout << "max_size: " << a.max_size() << std::endl;<BR>
|
||||||
|
std::cout << "front: " << a.front() << std::endl;<BR>
|
||||||
|
std::cout << "back: " << a.back() << std::endl;<BR>
|
||||||
|
std::cout << "[0]: " << a[0] << std::endl;<BR>
|
||||||
|
std::cout << "elems: ";<BR>
|
||||||
|
<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// iterate through all elements</FONT></I><BR>
|
||||||
|
for (Array::const_iterator pos=a.begin(); pos<a.end(); ++pos) {<BR>
|
||||||
|
std::cout << *pos << ' ';<BR>
|
||||||
|
}<BR>
|
||||||
|
std::cout << std::endl;<BR>
|
||||||
|
test_static_size(a);<BR>
|
||||||
|
<BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >// check copy constructor and assignment operator</FONT></I><BR>
|
||||||
|
Array b(a);<BR>
|
||||||
|
Array c;<BR>
|
||||||
|
c = a;<BR>
|
||||||
|
if (a==b && a==c) {<BR>
|
||||||
|
std::cout << "copy construction and copy assignment are OK"<BR>
|
||||||
|
<< std::endl;<BR>
|
||||||
|
}<BR>
|
||||||
|
else {<BR>
|
||||||
|
std::cout << "copy construction and copy assignment are OK"<BR>
|
||||||
|
<< std::endl;<BR>
|
||||||
|
}<BR>
|
||||||
|
<BR>
|
||||||
|
typedef boost::array<double,6> DArray;<BR>
|
||||||
|
typedef boost::array<int,6> IArray;<BR>
|
||||||
|
IArray ia = { 1, 2, 3, 4, 5, 6 };<BR>
|
||||||
|
DArray da;<BR>
|
||||||
|
da = ia;<BR>
|
||||||
|
da.assign(42);<BR>
|
||||||
|
}<BR>
|
||||||
|
<BR>
|
||||||
|
</SPAN>
|
||||||
|
</TT>
|
||||||
|
</BODY>
|
||||||
|
</HTML>
|
@ -1,19 +0,0 @@
|
|||||||
#~ Copyright Marshall Clow 2013
|
|
||||||
#~ Distributed under the Boost Software License, Version 1.0.
|
|
||||||
#~ (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
|
|
||||||
using boostbook ;
|
|
||||||
|
|
||||||
boostbook standalone
|
|
||||||
: array.xml
|
|
||||||
: <xsl:param>boost.root=../../../.. ;
|
|
||||||
|
|
||||||
###############################################################################
|
|
||||||
alias boostdoc
|
|
||||||
: array.xml
|
|
||||||
:
|
|
||||||
:
|
|
||||||
: ;
|
|
||||||
explicit boostdoc ;
|
|
||||||
alias boostrelease ;
|
|
||||||
explicit boostrelease ;
|
|
639
doc/array.xml
639
doc/array.xml
@ -1,639 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
|
|
||||||
"http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
|
|
||||||
<library name="Array" dirname="array" id="array" last-revision="$Date$">
|
|
||||||
<libraryinfo>
|
|
||||||
<author>
|
|
||||||
<firstname>Nicolai</firstname>
|
|
||||||
<surname>Josuttis</surname>
|
|
||||||
</author>
|
|
||||||
<maintainer>
|
|
||||||
<firstname>Marshall</firstname>
|
|
||||||
<surname>Clow</surname>
|
|
||||||
</maintainer>
|
|
||||||
|
|
||||||
<copyright>
|
|
||||||
<year>2001</year>
|
|
||||||
<year>2002</year>
|
|
||||||
<year>2003</year>
|
|
||||||
<year>2004</year>
|
|
||||||
<holder>Nicolai M. Josuttis</holder>
|
|
||||||
</copyright>
|
|
||||||
|
|
||||||
<copyright>
|
|
||||||
<year>2012</year>
|
|
||||||
<holder>Marshall Clow</holder>
|
|
||||||
</copyright>
|
|
||||||
|
|
||||||
<legalnotice>
|
|
||||||
<para>Distributed under the Boost Software License, Version 1.0.
|
|
||||||
(See accompanying file <filename>LICENSE_1_0.txt</filename> or copy at
|
|
||||||
<ulink
|
|
||||||
url="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</ulink>)
|
|
||||||
</para>
|
|
||||||
</legalnotice>
|
|
||||||
|
|
||||||
<librarypurpose>STL compliant container wrapper for arrays of constant size</librarypurpose>
|
|
||||||
<librarycategory name="category:containers"/>
|
|
||||||
</libraryinfo>
|
|
||||||
|
|
||||||
<title>Boost.Array</title>
|
|
||||||
|
|
||||||
<section id="array.intro">
|
|
||||||
<title>Introduction</title>
|
|
||||||
|
|
||||||
<using-namespace name="boost"/>
|
|
||||||
<using-class name="array"/>
|
|
||||||
|
|
||||||
<para>The C++ Standard Template Library STL as part of the C++
|
|
||||||
Standard Library provides a framework for processing algorithms on
|
|
||||||
different kind of containers. However, ordinary arrays don't
|
|
||||||
provide the interface of STL containers (although, they provide
|
|
||||||
the iterator interface of STL containers).</para>
|
|
||||||
|
|
||||||
<para>As replacement for ordinary arrays, the STL provides class
|
|
||||||
<code><classname>std::vector</classname></code>. However,
|
|
||||||
<code><classname>std::vector<></classname></code> provides
|
|
||||||
the semantics of dynamic arrays. Thus, it manages data to be able
|
|
||||||
to change the number of elements. This results in some overhead in
|
|
||||||
case only arrays with static size are needed.</para>
|
|
||||||
|
|
||||||
<para>In his book, <emphasis>Generic Programming and the
|
|
||||||
STL</emphasis>, Matthew H. Austern introduces a useful wrapper
|
|
||||||
class for ordinary arrays with static size, called
|
|
||||||
<code>block</code>. It is safer and has no worse performance than
|
|
||||||
ordinary arrays. In <emphasis>The C++ Programming
|
|
||||||
Language</emphasis>, 3rd edition, Bjarne Stroustrup introduces a
|
|
||||||
similar class, called <code>c_array</code>, which I (<ulink
|
|
||||||
url="http://www.josuttis.com">Nicolai Josuttis</ulink>) present
|
|
||||||
slightly modified in my book <emphasis>The C++ Standard Library -
|
|
||||||
A Tutorial and Reference</emphasis>, called
|
|
||||||
<code>carray</code>. This is the essence of these approaches
|
|
||||||
spiced with many feedback from <ulink
|
|
||||||
url="http://www.boost.org">boost</ulink>.</para>
|
|
||||||
|
|
||||||
<para>After considering different names, we decided to name this
|
|
||||||
class simply <code><classname>array</classname></code>.</para>
|
|
||||||
|
|
||||||
<para>Note that this class is suggested to be part of the next
|
|
||||||
Technical Report, which will extend the C++ Standard (see
|
|
||||||
<ulink url="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1548.htm">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1548.htm</ulink>).</para>
|
|
||||||
|
|
||||||
<para>Update: <code>std::array</code> is (as of C++11) part of the C++ standard.
|
|
||||||
The differences between <code>boost::array</code> and <code>std::array</code> are minimal.
|
|
||||||
If you are using C++11, you should consider using <code>std::array</code> instead of <code>boost::array</code>.
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>Class <code><classname>array</classname></code> fulfills most
|
|
||||||
but not all of the requirements of "reversible containers" (see
|
|
||||||
Section 23.1, [lib.container.requirements] of the C++
|
|
||||||
Standard). The reasons array is not an reversible STL container is
|
|
||||||
because:
|
|
||||||
<itemizedlist spacing="compact">
|
|
||||||
<listitem><simpara>No constructors are provided.</simpara></listitem>
|
|
||||||
<listitem><simpara>Elements may have an undetermined initial value (see <xref linkend="array.rationale"/>).</simpara></listitem>
|
|
||||||
<listitem><simpara><functionname>swap</functionname>() has no constant complexity.</simpara></listitem>
|
|
||||||
<listitem><simpara><methodname>size</methodname>() is always constant, based on the second template argument of the type.</simpara></listitem>
|
|
||||||
<listitem><simpara>The container provides no allocator support.</simpara></listitem>
|
|
||||||
</itemizedlist>
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>It doesn't fulfill the requirements of a "sequence" (see Section 23.1.1, [lib.sequence.reqmts] of the C++ Standard), except that:
|
|
||||||
<itemizedlist spacing="compact">
|
|
||||||
<listitem><simpara><methodname>front</methodname>() and <methodname>back</methodname>() are provided.</simpara></listitem>
|
|
||||||
<listitem><simpara><methodname>operator[]</methodname> and <methodname>at</methodname>() are provided.</simpara></listitem>
|
|
||||||
</itemizedlist>
|
|
||||||
</para>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<library-reference>
|
|
||||||
<header name="boost/array.hpp">
|
|
||||||
<namespace name="boost">
|
|
||||||
<class name="array">
|
|
||||||
<template>
|
|
||||||
<template-type-parameter name="T"/>
|
|
||||||
<template-nontype-parameter name="N">
|
|
||||||
<type>std::size_t</type>
|
|
||||||
</template-nontype-parameter>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<purpose><para>STL compliant container wrapper for arrays of constant size</para></purpose>
|
|
||||||
<typedef name="value_type">
|
|
||||||
<type>T</type>
|
|
||||||
</typedef>
|
|
||||||
<typedef name="iterator">
|
|
||||||
<type>T*</type>
|
|
||||||
</typedef>
|
|
||||||
<typedef name="const_iterator">
|
|
||||||
<type>const T*</type>
|
|
||||||
</typedef>
|
|
||||||
<typedef name="reverse_iterator">
|
|
||||||
<type><classname>std::reverse_iterator</classname><iterator></type>
|
|
||||||
</typedef>
|
|
||||||
<typedef name="const_reverse_iterator">
|
|
||||||
<type><classname>std::reverse_iterator</classname><const_iterator></type>
|
|
||||||
</typedef>
|
|
||||||
<typedef name="reference">
|
|
||||||
<type>T&</type>
|
|
||||||
</typedef>
|
|
||||||
<typedef name="const_reference">
|
|
||||||
<type>const T&</type>
|
|
||||||
</typedef>
|
|
||||||
<typedef name="size_type">
|
|
||||||
<type>std::size_t</type>
|
|
||||||
</typedef>
|
|
||||||
<typedef name="difference_type">
|
|
||||||
<type>std::ptrdiff_t</type>
|
|
||||||
</typedef>
|
|
||||||
|
|
||||||
<static-constant name="static_size">
|
|
||||||
<type>size_type</type>
|
|
||||||
<default>N</default>
|
|
||||||
</static-constant>
|
|
||||||
|
|
||||||
<copy-assignment>
|
|
||||||
<template>
|
|
||||||
<template-type-parameter name="U"/>
|
|
||||||
</template>
|
|
||||||
<parameter name="other">
|
|
||||||
<paramtype>const <classname>array</classname><U, N>&</paramtype>
|
|
||||||
</parameter>
|
|
||||||
<effects><simpara><code>std::copy(rhs.<methodname>begin</methodname>(),rhs.<methodname>end</methodname>(), <methodname>begin</methodname>())</code></simpara></effects>
|
|
||||||
</copy-assignment>
|
|
||||||
|
|
||||||
<method-group name="iterator support">
|
|
||||||
<overloaded-method name="begin">
|
|
||||||
<signature>
|
|
||||||
<type>iterator</type>
|
|
||||||
</signature>
|
|
||||||
<signature cv="const">
|
|
||||||
<type>const_iterator</type>
|
|
||||||
</signature>
|
|
||||||
|
|
||||||
<returns><simpara>iterator for the first element</simpara></returns>
|
|
||||||
<throws><simpara>will not throw</simpara></throws>
|
|
||||||
</overloaded-method>
|
|
||||||
|
|
||||||
<overloaded-method name="end">
|
|
||||||
<signature>
|
|
||||||
<type>iterator</type>
|
|
||||||
</signature>
|
|
||||||
<signature cv="const">
|
|
||||||
<type>const_iterator</type>
|
|
||||||
</signature>
|
|
||||||
|
|
||||||
<returns><simpara>iterator for position after the last element</simpara></returns>
|
|
||||||
<throws><simpara>will not throw</simpara></throws>
|
|
||||||
</overloaded-method>
|
|
||||||
|
|
||||||
<overloaded-method name="cbegin" cv="const">
|
|
||||||
<signature>
|
|
||||||
<type>const_iterator</type>
|
|
||||||
</signature>
|
|
||||||
|
|
||||||
<returns><simpara>constant iterator for the first element</simpara></returns>
|
|
||||||
<throws><simpara>will not throw</simpara></throws>
|
|
||||||
</overloaded-method>
|
|
||||||
|
|
||||||
<overloaded-method name="cend" cv="const">
|
|
||||||
<signature>
|
|
||||||
<type>const_iterator</type>
|
|
||||||
</signature>
|
|
||||||
|
|
||||||
<returns><simpara>constant iterator for position after the last element</simpara></returns>
|
|
||||||
<throws><simpara>will not throw</simpara></throws>
|
|
||||||
</overloaded-method>
|
|
||||||
</method-group>
|
|
||||||
|
|
||||||
<method-group name="reverse iterator support">
|
|
||||||
<overloaded-method name="rbegin">
|
|
||||||
<signature>
|
|
||||||
<type>reverse_iterator</type>
|
|
||||||
</signature>
|
|
||||||
<signature cv="const">
|
|
||||||
<type>const_reverse_iterator</type>
|
|
||||||
</signature>
|
|
||||||
|
|
||||||
<returns><simpara>reverse iterator for the first element of reverse iteration</simpara></returns>
|
|
||||||
</overloaded-method>
|
|
||||||
|
|
||||||
<overloaded-method name="rend">
|
|
||||||
<signature>
|
|
||||||
<type>reverse_iterator</type>
|
|
||||||
</signature>
|
|
||||||
<signature cv="const">
|
|
||||||
<type>const_reverse_iterator</type>
|
|
||||||
</signature>
|
|
||||||
|
|
||||||
<returns><simpara>reverse iterator for position after the last element in reverse iteration</simpara></returns>
|
|
||||||
</overloaded-method>
|
|
||||||
|
|
||||||
<overloaded-method name="crbegin" cv="const">
|
|
||||||
<signature>
|
|
||||||
<type>const_reverse_iterator</type>
|
|
||||||
</signature>
|
|
||||||
|
|
||||||
<returns><simpara>constant reverse iterator for the first element of reverse iteration</simpara></returns>
|
|
||||||
<throws><simpara>will not throw</simpara></throws>
|
|
||||||
</overloaded-method>
|
|
||||||
|
|
||||||
<overloaded-method name="crend" cv="const">
|
|
||||||
<signature>
|
|
||||||
<type>const_reverse_iterator</type>
|
|
||||||
</signature>
|
|
||||||
|
|
||||||
<returns><simpara>constant reverse iterator for position after the last element in reverse iteration</simpara></returns>
|
|
||||||
<throws><simpara>will not throw</simpara></throws>
|
|
||||||
</overloaded-method>
|
|
||||||
</method-group>
|
|
||||||
|
|
||||||
<method-group name="capacity">
|
|
||||||
<method name="size">
|
|
||||||
<type>size_type</type>
|
|
||||||
<returns><simpara><code>N</code></simpara></returns>
|
|
||||||
</method>
|
|
||||||
<method name="empty">
|
|
||||||
<type>bool</type>
|
|
||||||
<returns><simpara><code>N==0</code></simpara></returns>
|
|
||||||
<throws><simpara>will not throw</simpara></throws>
|
|
||||||
</method>
|
|
||||||
<method name="max_size">
|
|
||||||
<type>size_type</type>
|
|
||||||
<returns><simpara><code>N</code></simpara></returns>
|
|
||||||
<throws><simpara>will not throw</simpara></throws>
|
|
||||||
</method>
|
|
||||||
</method-group>
|
|
||||||
|
|
||||||
<method-group name="element access">
|
|
||||||
<overloaded-method name="operator[]">
|
|
||||||
<signature>
|
|
||||||
<type>reference</type>
|
|
||||||
<parameter name="i">
|
|
||||||
<paramtype>size_type</paramtype>
|
|
||||||
</parameter>
|
|
||||||
</signature>
|
|
||||||
|
|
||||||
<signature cv="const">
|
|
||||||
<type>const_reference</type>
|
|
||||||
<parameter name="i">
|
|
||||||
<paramtype>size_type</paramtype>
|
|
||||||
</parameter>
|
|
||||||
</signature>
|
|
||||||
|
|
||||||
<requires><simpara><code>i < N</code></simpara></requires>
|
|
||||||
<returns><simpara>element with index <code>i</code></simpara></returns>
|
|
||||||
<throws><simpara>will not throw.</simpara></throws>
|
|
||||||
</overloaded-method>
|
|
||||||
|
|
||||||
<overloaded-method name="at">
|
|
||||||
<signature>
|
|
||||||
<type>reference</type>
|
|
||||||
<parameter name="i">
|
|
||||||
<paramtype>size_type</paramtype>
|
|
||||||
</parameter>
|
|
||||||
</signature>
|
|
||||||
|
|
||||||
<signature cv="const">
|
|
||||||
<type>const_reference</type>
|
|
||||||
<parameter name="i">
|
|
||||||
<paramtype>size_type</paramtype>
|
|
||||||
</parameter>
|
|
||||||
</signature>
|
|
||||||
|
|
||||||
<returns><simpara>element with index <code>i</code></simpara></returns>
|
|
||||||
<throws><simpara><code><classname>std::range_error</classname></code> if <code>i >= N</code></simpara></throws>
|
|
||||||
</overloaded-method>
|
|
||||||
|
|
||||||
<overloaded-method name="front">
|
|
||||||
<signature>
|
|
||||||
<type>reference</type>
|
|
||||||
</signature>
|
|
||||||
<signature cv="const">
|
|
||||||
<type>const_reference</type>
|
|
||||||
</signature>
|
|
||||||
<requires><simpara><code>N > 0</code></simpara></requires>
|
|
||||||
<returns><simpara>the first element</simpara></returns>
|
|
||||||
<throws><simpara>will not throw</simpara></throws>
|
|
||||||
</overloaded-method>
|
|
||||||
|
|
||||||
<overloaded-method name="back">
|
|
||||||
<signature>
|
|
||||||
<type>reference</type>
|
|
||||||
</signature>
|
|
||||||
<signature cv="const">
|
|
||||||
<type>const_reference</type>
|
|
||||||
</signature>
|
|
||||||
<requires><simpara><code>N > 0</code></simpara></requires>
|
|
||||||
<returns><simpara>the last element</simpara></returns>
|
|
||||||
<throws><simpara>will not throw</simpara></throws>
|
|
||||||
</overloaded-method>
|
|
||||||
|
|
||||||
<method name="data" cv="const">
|
|
||||||
<type>const T*</type>
|
|
||||||
<returns><simpara><code>elems</code></simpara></returns>
|
|
||||||
<throws><simpara>will not throw</simpara></throws>
|
|
||||||
</method>
|
|
||||||
|
|
||||||
<method name="c_array">
|
|
||||||
<type>T*</type>
|
|
||||||
<returns><simpara><code>elems</code></simpara></returns>
|
|
||||||
<throws><simpara>will not throw</simpara></throws>
|
|
||||||
</method>
|
|
||||||
</method-group>
|
|
||||||
|
|
||||||
<method-group name="modifiers">
|
|
||||||
<method name="swap">
|
|
||||||
<type>void</type>
|
|
||||||
<parameter name="other">
|
|
||||||
<paramtype><classname>array</classname><T, N>&</paramtype>
|
|
||||||
</parameter>
|
|
||||||
<effects><simpara><code>std::swap_ranges(<methodname>begin</methodname>(), <methodname>end</methodname>(), other.<methodname>begin</methodname>())</code></simpara></effects>
|
|
||||||
<complexity><simpara>linear in <code>N</code></simpara></complexity>
|
|
||||||
</method>
|
|
||||||
<method name="assign">
|
|
||||||
<type>void</type>
|
|
||||||
<parameter name="value">
|
|
||||||
<paramtype>const T&</paramtype>
|
|
||||||
</parameter>
|
|
||||||
<effects><simpara><code>std::fill_n(<methodname>begin</methodname>(), N, value)</code></simpara></effects>
|
|
||||||
</method>
|
|
||||||
</method-group>
|
|
||||||
|
|
||||||
<data-member name="elems[N]"> <!-- HACK -->
|
|
||||||
<type>T</type>
|
|
||||||
</data-member>
|
|
||||||
|
|
||||||
<free-function-group name="specialized algorithms">
|
|
||||||
<function name="swap">
|
|
||||||
<template>
|
|
||||||
<template-type-parameter name="T"/>
|
|
||||||
<template-nontype-parameter name="N">
|
|
||||||
<type>std::size_t</type>
|
|
||||||
</template-nontype-parameter>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<type>void</type>
|
|
||||||
|
|
||||||
<parameter name="x">
|
|
||||||
<paramtype><classname>array</classname><T, N>&</paramtype>
|
|
||||||
</parameter>
|
|
||||||
<parameter name="y">
|
|
||||||
<paramtype><classname>array</classname><T, N>&</paramtype>
|
|
||||||
</parameter>
|
|
||||||
|
|
||||||
<effects><simpara><code>x.<methodname>swap</methodname>(y)</code></simpara></effects>
|
|
||||||
<throws><simpara>will not throw.</simpara></throws>
|
|
||||||
</function>
|
|
||||||
</free-function-group>
|
|
||||||
|
|
||||||
<free-function-group name="comparisons">
|
|
||||||
<function name="operator==">
|
|
||||||
<template>
|
|
||||||
<template-type-parameter name="T"/>
|
|
||||||
<template-nontype-parameter name="N">
|
|
||||||
<type>std::size_t</type>
|
|
||||||
</template-nontype-parameter>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<type>bool</type>
|
|
||||||
|
|
||||||
<parameter name="x">
|
|
||||||
<paramtype>const <classname>array</classname><T, N>&</paramtype>
|
|
||||||
</parameter>
|
|
||||||
<parameter name="y">
|
|
||||||
<paramtype>const <classname>array</classname><T, N>&</paramtype>
|
|
||||||
</parameter>
|
|
||||||
|
|
||||||
<returns><simpara><code>std::equal(x.<methodname>begin</methodname>(), x.<methodname>end</methodname>(), y.<methodname>begin</methodname>())</code></simpara>
|
|
||||||
</returns>
|
|
||||||
</function>
|
|
||||||
|
|
||||||
<function name="operator!=">
|
|
||||||
<template>
|
|
||||||
<template-type-parameter name="T"/>
|
|
||||||
<template-nontype-parameter name="N">
|
|
||||||
<type>std::size_t</type>
|
|
||||||
</template-nontype-parameter>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<type>bool</type>
|
|
||||||
|
|
||||||
<parameter name="x">
|
|
||||||
<paramtype>const <classname>array</classname><T, N>&</paramtype>
|
|
||||||
</parameter>
|
|
||||||
<parameter name="y">
|
|
||||||
<paramtype>const <classname>array</classname><T, N>&</paramtype>
|
|
||||||
</parameter>
|
|
||||||
|
|
||||||
<returns><simpara><code>!(x == y)</code></simpara>
|
|
||||||
</returns>
|
|
||||||
</function>
|
|
||||||
|
|
||||||
<function name="operator<">
|
|
||||||
<template>
|
|
||||||
<template-type-parameter name="T"/>
|
|
||||||
<template-nontype-parameter name="N">
|
|
||||||
<type>std::size_t</type>
|
|
||||||
</template-nontype-parameter>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<type>bool</type>
|
|
||||||
|
|
||||||
<parameter name="x">
|
|
||||||
<paramtype>const <classname>array</classname><T, N>&</paramtype>
|
|
||||||
</parameter>
|
|
||||||
<parameter name="y">
|
|
||||||
<paramtype>const <classname>array</classname><T, N>&</paramtype>
|
|
||||||
</parameter>
|
|
||||||
|
|
||||||
<returns><simpara><code>std::lexicographical_compare(x.<methodname>begin</methodname>(), x.<methodname>end</methodname>(), y.<methodname>begin</methodname>(), y.<methodname>end</methodname>())</code></simpara>
|
|
||||||
</returns>
|
|
||||||
</function>
|
|
||||||
|
|
||||||
<function name="operator>">
|
|
||||||
<template>
|
|
||||||
<template-type-parameter name="T"/>
|
|
||||||
<template-nontype-parameter name="N">
|
|
||||||
<type>std::size_t</type>
|
|
||||||
</template-nontype-parameter>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<type>bool</type>
|
|
||||||
|
|
||||||
<parameter name="x">
|
|
||||||
<paramtype>const <classname>array</classname><T, N>&</paramtype>
|
|
||||||
</parameter>
|
|
||||||
<parameter name="y">
|
|
||||||
<paramtype>const <classname>array</classname><T, N>&</paramtype>
|
|
||||||
</parameter>
|
|
||||||
|
|
||||||
<returns><simpara><code>y < x</code></simpara></returns>
|
|
||||||
</function>
|
|
||||||
|
|
||||||
<function name="operator<=">
|
|
||||||
<template>
|
|
||||||
<template-type-parameter name="T"/>
|
|
||||||
<template-nontype-parameter name="N">
|
|
||||||
<type>std::size_t</type>
|
|
||||||
</template-nontype-parameter>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<type>bool</type>
|
|
||||||
|
|
||||||
<parameter name="x">
|
|
||||||
<paramtype>const <classname>array</classname><T, N>&</paramtype>
|
|
||||||
</parameter>
|
|
||||||
<parameter name="y">
|
|
||||||
<paramtype>const <classname>array</classname><T, N>&</paramtype>
|
|
||||||
</parameter>
|
|
||||||
|
|
||||||
<returns><simpara><code>!(y < x)</code></simpara></returns>
|
|
||||||
</function>
|
|
||||||
|
|
||||||
<function name="operator>=">
|
|
||||||
<template>
|
|
||||||
<template-type-parameter name="T"/>
|
|
||||||
<template-nontype-parameter name="N">
|
|
||||||
<type>std::size_t</type>
|
|
||||||
</template-nontype-parameter>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<type>bool</type>
|
|
||||||
|
|
||||||
<parameter name="x">
|
|
||||||
<paramtype>const <classname>array</classname><T, N>&</paramtype>
|
|
||||||
</parameter>
|
|
||||||
<parameter name="y">
|
|
||||||
<paramtype>const <classname>array</classname><T, N>&</paramtype>
|
|
||||||
</parameter>
|
|
||||||
|
|
||||||
<returns><simpara><code>!(x < y)</code></simpara></returns>
|
|
||||||
</function>
|
|
||||||
</free-function-group>
|
|
||||||
|
|
||||||
<free-function-group name="specializations">
|
|
||||||
<function name="boost::get">
|
|
||||||
<template>
|
|
||||||
<template-type-parameter name="T"/>
|
|
||||||
<template-nontype-parameter name="N">
|
|
||||||
<type>std::size_t</type>
|
|
||||||
</template-nontype-parameter>
|
|
||||||
<template-nontype-parameter name="Idx">
|
|
||||||
<type>std::size_t</type>
|
|
||||||
</template-nontype-parameter>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<type>T</type>
|
|
||||||
|
|
||||||
<parameter name="arr">
|
|
||||||
<paramtype><classname>array</classname><T, N>&</paramtype>
|
|
||||||
</parameter>
|
|
||||||
<returns><simpara>element of array with index <code>Idx</code></simpara></returns>
|
|
||||||
<effects><simpara>Will <code>static_assert</code> if <code>Idx >= N</code></simpara></effects>
|
|
||||||
</function>
|
|
||||||
|
|
||||||
<function name="boost::get">
|
|
||||||
<template>
|
|
||||||
<template-type-parameter name="T"/>
|
|
||||||
<template-nontype-parameter name="N">
|
|
||||||
<type>std::size_t</type>
|
|
||||||
</template-nontype-parameter>
|
|
||||||
<template-nontype-parameter name="Idx">
|
|
||||||
<type>std::size_t</type>
|
|
||||||
</template-nontype-parameter>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<type>T</type>
|
|
||||||
|
|
||||||
<parameter name="arr">
|
|
||||||
<paramtype>const <classname>array</classname><T, N>&</paramtype>
|
|
||||||
</parameter>
|
|
||||||
<returns><simpara>const element of array with index <code>Idx</code></simpara></returns>
|
|
||||||
<effects><simpara>Will <code>static_assert</code> if <code>Idx >= N</code></simpara></effects>
|
|
||||||
</function>
|
|
||||||
</free-function-group>
|
|
||||||
|
|
||||||
</class>
|
|
||||||
</namespace>
|
|
||||||
</header>
|
|
||||||
</library-reference>
|
|
||||||
|
|
||||||
<section id="array.rationale">
|
|
||||||
<title>Design Rationale</title>
|
|
||||||
|
|
||||||
<para>There was an important design tradeoff regarding the
|
|
||||||
constructors: We could implement array as an "aggregate" (see
|
|
||||||
Section 8.5.1, [dcl.init.aggr], of the C++ Standard). This would
|
|
||||||
mean:
|
|
||||||
<itemizedlist>
|
|
||||||
<listitem><simpara>An array can be initialized with a
|
|
||||||
brace-enclosing, comma-separated list of initializers for the
|
|
||||||
elements of the container, written in increasing subscript
|
|
||||||
order:</simpara>
|
|
||||||
|
|
||||||
<programlisting><classname>boost::array</classname><int,4> a = { { 1, 2, 3 } };</programlisting>
|
|
||||||
|
|
||||||
<simpara>Note that if there are fewer elements in the
|
|
||||||
initializer list, then each remaining element gets
|
|
||||||
default-initialized (thus, it has a defined value).</simpara>
|
|
||||||
</listitem></itemizedlist></para>
|
|
||||||
|
|
||||||
<para>However, this approach has its drawbacks: <emphasis
|
|
||||||
role="bold"> passing no initializer list means that the elements
|
|
||||||
have an indetermined initial value</emphasis>, because the rule says
|
|
||||||
that aggregates may have:
|
|
||||||
<itemizedlist>
|
|
||||||
<listitem><simpara>No user-declared constructors.</simpara></listitem>
|
|
||||||
<listitem><simpara>No private or protected non-static data members.</simpara></listitem>
|
|
||||||
<listitem><simpara>No base classes.</simpara></listitem>
|
|
||||||
<listitem><simpara>No virtual functions.</simpara></listitem>
|
|
||||||
</itemizedlist>
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>Nevertheless, The current implementation uses this approach.</para>
|
|
||||||
|
|
||||||
<para>Note that for standard conforming compilers it is possible to
|
|
||||||
use fewer braces (according to 8.5.1 (11) of the Standard). That is,
|
|
||||||
you can initialize an array as follows:</para>
|
|
||||||
|
|
||||||
<programlisting>
|
|
||||||
<classname>boost::array</classname><int,4> a = { 1, 2, 3 };
|
|
||||||
</programlisting>
|
|
||||||
|
|
||||||
<para>I'd appreciate any constructive feedback. <emphasis
|
|
||||||
role="bold">Please note: I don't have time to read all boost
|
|
||||||
mails. Thus, to make sure that feedback arrives to me, please send
|
|
||||||
me a copy of each mail regarding this class.</emphasis></para>
|
|
||||||
|
|
||||||
<para>The code is provided "as is" without expressed or implied
|
|
||||||
warranty.</para>
|
|
||||||
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section id="array.more.info">
|
|
||||||
<title>For more information...</title>
|
|
||||||
<para>To find more details about using ordinary arrays in C++ and
|
|
||||||
the framework of the STL, see e.g.
|
|
||||||
|
|
||||||
<literallayout>The C++ Standard Library - A Tutorial and Reference
|
|
||||||
by Nicolai M. Josuttis
|
|
||||||
Addison Wesley Longman, 1999
|
|
||||||
ISBN 0-201-37926-0</literallayout>
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para><ulink url="http://www.josuttis.com/">Home Page of Nicolai
|
|
||||||
Josuttis</ulink></para>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section id="array.ack">
|
|
||||||
<title>Acknowledgements</title>
|
|
||||||
|
|
||||||
<para>Doug Gregor ported the documentation to the BoostBook format.</para>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<!-- Notes:
|
|
||||||
empty() should return N != 0
|
|
||||||
size(), empty(), max_size() should be const
|
|
||||||
-->
|
|
||||||
|
|
||||||
</library>
|
|
@ -2,58 +2,30 @@
|
|||||||
* an STL container (as wrapper) for arrays of constant size.
|
* an STL container (as wrapper) for arrays of constant size.
|
||||||
*
|
*
|
||||||
* See
|
* See
|
||||||
* http://www.boost.org/libs/array/
|
* http://www.josuttis.com/cppcode
|
||||||
* for documentation.
|
* for details and the latest version.
|
||||||
*
|
*
|
||||||
* The original author site is at: http://www.josuttis.com/
|
* (C) Copyright Nicolai M. Josuttis 1999.
|
||||||
|
* Permission to copy, use, modify, sell and distribute this software
|
||||||
|
* is granted provided this copyright notice appears in all copies.
|
||||||
|
* This software is provided "as is" without express or implied
|
||||||
|
* warranty, and with no claim as to its suitability for any purpose.
|
||||||
*
|
*
|
||||||
* (C) Copyright Nicolai M. Josuttis 2001.
|
* Jul 31, 2000
|
||||||
*
|
|
||||||
* Distributed under the Boost Software License, Version 1.0. (See
|
|
||||||
* accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
* http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
*
|
|
||||||
* 9 Jan 2013 - (mtc) Added constexpr
|
|
||||||
* 14 Apr 2012 - (mtc) Added support for boost::hash
|
|
||||||
* 28 Dec 2010 - (mtc) Added cbegin and cend (and crbegin and crend) for C++Ox compatibility.
|
|
||||||
* 10 Mar 2010 - (mtc) fill method added, matching resolution of the standard library working group.
|
|
||||||
* See <http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#776> or Trac issue #3168
|
|
||||||
* Eventually, we should remove "assign" which is now a synonym for "fill" (Marshall Clow)
|
|
||||||
* 10 Mar 2010 - added workaround for SUNCC and !STLPort [trac #3893] (Marshall Clow)
|
|
||||||
* 29 Jan 2004 - c_array() added, BOOST_NO_PRIVATE_IN_AGGREGATE removed (Nico Josuttis)
|
|
||||||
* 23 Aug 2002 - fix for Non-MSVC compilers combined with MSVC libraries.
|
|
||||||
* 05 Aug 2001 - minor update (Nico Josuttis)
|
|
||||||
* 20 Jan 2001 - STLport fix (Beman Dawes)
|
|
||||||
* 29 Sep 2000 - Initial Revision (Nico Josuttis)
|
|
||||||
*
|
|
||||||
* Jan 29, 2004
|
|
||||||
*/
|
*/
|
||||||
#ifndef BOOST_ARRAY_HPP
|
#ifndef BOOST_ARRAY_HPP
|
||||||
#define BOOST_ARRAY_HPP
|
#define BOOST_ARRAY_HPP
|
||||||
|
|
||||||
#include <boost/detail/workaround.hpp>
|
|
||||||
|
|
||||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
|
||||||
# pragma warning(push)
|
|
||||||
# pragma warning(disable:4996) // 'std::equal': Function call with parameters that may be unsafe
|
|
||||||
# pragma warning(disable:4510) // boost::array<T,N>' : default constructor could not be generated
|
|
||||||
# pragma warning(disable:4610) // warning C4610: class 'boost::array<T,N>' can never be instantiated - user defined constructor required
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <iterator>
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <boost/assert.hpp>
|
#include <iterator>
|
||||||
#include <boost/core/swap.hpp>
|
|
||||||
#include <boost/static_assert.hpp>
|
|
||||||
|
|
||||||
#include <boost/throw_exception.hpp>
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
// FIXES for broken compilers
|
// BUG-FIX for compilers that don't support
|
||||||
|
// std::size_t and std::ptrdiff_t yet
|
||||||
|
// (such as gcc)
|
||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
|
|
||||||
template<class T, std::size_t N>
|
template<class T, std::size_t N>
|
||||||
@ -74,23 +46,15 @@ namespace boost {
|
|||||||
// iterator support
|
// iterator support
|
||||||
iterator begin() { return elems; }
|
iterator begin() { return elems; }
|
||||||
const_iterator begin() const { return elems; }
|
const_iterator begin() const { return elems; }
|
||||||
const_iterator cbegin() const { return elems; }
|
|
||||||
|
|
||||||
iterator end() { return elems+N; }
|
iterator end() { return elems+N; }
|
||||||
const_iterator end() const { return elems+N; }
|
const_iterator end() const { return elems+N; }
|
||||||
const_iterator cend() const { return elems+N; }
|
|
||||||
|
|
||||||
// reverse iterator support
|
// reverse iterator support
|
||||||
#if !defined(BOOST_MSVC_STD_ITERATOR) && !defined(BOOST_NO_STD_ITERATOR_TRAITS)
|
# if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
||||||
typedef std::reverse_iterator<iterator> reverse_iterator;
|
typedef std::reverse_iterator<iterator> reverse_iterator;
|
||||||
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
||||||
#elif defined(_RWSTD_NO_CLASS_PARTIAL_SPEC)
|
|
||||||
typedef std::reverse_iterator<iterator, std::random_access_iterator_tag,
|
|
||||||
value_type, reference, iterator, difference_type> reverse_iterator;
|
|
||||||
typedef std::reverse_iterator<const_iterator, std::random_access_iterator_tag,
|
|
||||||
value_type, const_reference, const_iterator, difference_type> const_reverse_iterator;
|
|
||||||
# else
|
# else
|
||||||
// workaround for broken reverse_iterator implementations
|
// workaround for broken reverse_iterator implementations due to no partial specialization
|
||||||
typedef std::reverse_iterator<iterator,T> reverse_iterator;
|
typedef std::reverse_iterator<iterator,T> reverse_iterator;
|
||||||
typedef std::reverse_iterator<const_iterator,T> const_reverse_iterator;
|
typedef std::reverse_iterator<const_iterator,T> const_reverse_iterator;
|
||||||
# endif
|
# endif
|
||||||
@ -99,72 +63,39 @@ namespace boost {
|
|||||||
const_reverse_iterator rbegin() const {
|
const_reverse_iterator rbegin() const {
|
||||||
return const_reverse_iterator(end());
|
return const_reverse_iterator(end());
|
||||||
}
|
}
|
||||||
const_reverse_iterator crbegin() const {
|
|
||||||
return const_reverse_iterator(end());
|
|
||||||
}
|
|
||||||
|
|
||||||
reverse_iterator rend() { return reverse_iterator(begin()); }
|
reverse_iterator rend() { return reverse_iterator(begin()); }
|
||||||
const_reverse_iterator rend() const {
|
const_reverse_iterator rend() const {
|
||||||
return const_reverse_iterator(begin());
|
return const_reverse_iterator(begin());
|
||||||
}
|
}
|
||||||
const_reverse_iterator crend() const {
|
|
||||||
return const_reverse_iterator(begin());
|
|
||||||
}
|
|
||||||
|
|
||||||
// operator[]
|
// operator[]
|
||||||
reference operator[](size_type i)
|
reference operator[](size_type i) { return elems[i]; }
|
||||||
{
|
const_reference operator[](size_type i) const { return elems[i]; }
|
||||||
return BOOST_ASSERT_MSG( i < N, "out of range" ), elems[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
/*BOOST_CONSTEXPR*/ const_reference operator[](size_type i) const
|
|
||||||
{
|
|
||||||
return BOOST_ASSERT_MSG( i < N, "out of range" ), elems[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
// at() with range check
|
// at() with range check
|
||||||
reference at(size_type i) { return rangecheck(i), elems[i]; }
|
reference at(size_type i) { rangecheck(i); return elems[i]; }
|
||||||
/*BOOST_CONSTEXPR*/ const_reference at(size_type i) const { return rangecheck(i), elems[i]; }
|
const_reference at(size_type i) const { rangecheck(i); return elems[i]; }
|
||||||
|
|
||||||
// front() and back()
|
// front() and back()
|
||||||
reference front()
|
reference front() { return elems[0]; }
|
||||||
{
|
const_reference front() const { return elems[0]; }
|
||||||
return elems[0];
|
reference back() { return elems[N-1]; }
|
||||||
}
|
const_reference back() const { return elems[N-1]; }
|
||||||
|
|
||||||
BOOST_CONSTEXPR const_reference front() const
|
|
||||||
{
|
|
||||||
return elems[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
reference back()
|
|
||||||
{
|
|
||||||
return elems[N-1];
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_CONSTEXPR const_reference back() const
|
|
||||||
{
|
|
||||||
return elems[N-1];
|
|
||||||
}
|
|
||||||
|
|
||||||
// size is constant
|
// size is constant
|
||||||
static BOOST_CONSTEXPR size_type size() { return N; }
|
static size_type size() { return N; }
|
||||||
static BOOST_CONSTEXPR bool empty() { return false; }
|
static bool empty() { return false; }
|
||||||
static BOOST_CONSTEXPR size_type max_size() { return N; }
|
static size_type max_size() { return N; }
|
||||||
enum { static_size = N };
|
enum { static_size = N };
|
||||||
|
|
||||||
|
public:
|
||||||
// swap (note: linear complexity)
|
// swap (note: linear complexity)
|
||||||
void swap (array<T,N>& y) {
|
void swap (array<T,N>& y) {
|
||||||
for (size_type i = 0; i < N; ++i)
|
std::swap_ranges(begin(),end(),y.begin());
|
||||||
boost::swap(elems[i],y.elems[i]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// direct access to data (read-only)
|
// direct access to data
|
||||||
const T* data() const { return elems; }
|
const T* data() const { return elems; }
|
||||||
T* data() { return elems; }
|
|
||||||
|
|
||||||
// use array as C array (direct read/write access to data)
|
|
||||||
T* c_array() { return elems; }
|
|
||||||
|
|
||||||
// assignment with type conversion
|
// assignment with type conversion
|
||||||
template <typename T2>
|
template <typename T2>
|
||||||
@ -174,148 +105,19 @@ namespace boost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// assign one value to all elements
|
// assign one value to all elements
|
||||||
void assign (const T& value) { fill ( value ); } // A synonym for fill
|
void assign (const T& value)
|
||||||
void fill (const T& value)
|
|
||||||
{
|
{
|
||||||
std::fill_n(begin(),size(),value);
|
std::fill_n(begin(),size(),value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check range (may be private because it is static)
|
# ifndef BOOST_NO_PRIVATE_IN_AGGREGATE
|
||||||
static BOOST_CONSTEXPR bool rangecheck (size_type i) {
|
private:
|
||||||
return i >= size() ? boost::throw_exception(std::out_of_range ("array<>: index out of range")), true : true;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
template< class T >
|
|
||||||
class array< T, 0 > {
|
|
||||||
|
|
||||||
public:
|
|
||||||
// type definitions
|
|
||||||
typedef T value_type;
|
|
||||||
typedef T* iterator;
|
|
||||||
typedef const T* const_iterator;
|
|
||||||
typedef T& reference;
|
|
||||||
typedef const T& const_reference;
|
|
||||||
typedef std::size_t size_type;
|
|
||||||
typedef std::ptrdiff_t difference_type;
|
|
||||||
|
|
||||||
// iterator support
|
|
||||||
iterator begin() { return iterator( reinterpret_cast< T * >( this ) ); }
|
|
||||||
const_iterator begin() const { return const_iterator( reinterpret_cast< const T * >( this ) ); }
|
|
||||||
const_iterator cbegin() const { return const_iterator( reinterpret_cast< const T * >( this ) ); }
|
|
||||||
|
|
||||||
iterator end() { return begin(); }
|
|
||||||
const_iterator end() const { return begin(); }
|
|
||||||
const_iterator cend() const { return cbegin(); }
|
|
||||||
|
|
||||||
// reverse iterator support
|
|
||||||
#if !defined(BOOST_MSVC_STD_ITERATOR) && !defined(BOOST_NO_STD_ITERATOR_TRAITS)
|
|
||||||
typedef std::reverse_iterator<iterator> reverse_iterator;
|
|
||||||
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
|
||||||
#elif defined(_RWSTD_NO_CLASS_PARTIAL_SPEC)
|
|
||||||
typedef std::reverse_iterator<iterator, std::random_access_iterator_tag,
|
|
||||||
value_type, reference, iterator, difference_type> reverse_iterator;
|
|
||||||
typedef std::reverse_iterator<const_iterator, std::random_access_iterator_tag,
|
|
||||||
value_type, const_reference, const_iterator, difference_type> const_reverse_iterator;
|
|
||||||
#else
|
|
||||||
// workaround for broken reverse_iterator implementations
|
|
||||||
typedef std::reverse_iterator<iterator,T> reverse_iterator;
|
|
||||||
typedef std::reverse_iterator<const_iterator,T> const_reverse_iterator;
|
|
||||||
# endif
|
# endif
|
||||||
|
// private member functions are allowed in aggregates [ISO 8.5.1]
|
||||||
reverse_iterator rbegin() { return reverse_iterator(end()); }
|
static void rangecheck (size_type i) {
|
||||||
const_reverse_iterator rbegin() const {
|
if (i >= size()) { throw std::range_error("array"); }
|
||||||
return const_reverse_iterator(end());
|
|
||||||
}
|
|
||||||
const_reverse_iterator crbegin() const {
|
|
||||||
return const_reverse_iterator(end());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
reverse_iterator rend() { return reverse_iterator(begin()); }
|
|
||||||
const_reverse_iterator rend() const {
|
|
||||||
return const_reverse_iterator(begin());
|
|
||||||
}
|
|
||||||
const_reverse_iterator crend() const {
|
|
||||||
return const_reverse_iterator(begin());
|
|
||||||
}
|
|
||||||
|
|
||||||
// operator[]
|
|
||||||
reference operator[](size_type /*i*/)
|
|
||||||
{
|
|
||||||
return failed_rangecheck();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*BOOST_CONSTEXPR*/ const_reference operator[](size_type /*i*/) const
|
|
||||||
{
|
|
||||||
return failed_rangecheck();
|
|
||||||
}
|
|
||||||
|
|
||||||
// at() with range check
|
|
||||||
reference at(size_type /*i*/) { return failed_rangecheck(); }
|
|
||||||
/*BOOST_CONSTEXPR*/ const_reference at(size_type /*i*/) const { return failed_rangecheck(); }
|
|
||||||
|
|
||||||
// front() and back()
|
|
||||||
reference front()
|
|
||||||
{
|
|
||||||
return failed_rangecheck();
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_CONSTEXPR const_reference front() const
|
|
||||||
{
|
|
||||||
return failed_rangecheck();
|
|
||||||
}
|
|
||||||
|
|
||||||
reference back()
|
|
||||||
{
|
|
||||||
return failed_rangecheck();
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_CONSTEXPR const_reference back() const
|
|
||||||
{
|
|
||||||
return failed_rangecheck();
|
|
||||||
}
|
|
||||||
|
|
||||||
// size is constant
|
|
||||||
static BOOST_CONSTEXPR size_type size() { return 0; }
|
|
||||||
static BOOST_CONSTEXPR bool empty() { return true; }
|
|
||||||
static BOOST_CONSTEXPR size_type max_size() { return 0; }
|
|
||||||
enum { static_size = 0 };
|
|
||||||
|
|
||||||
void swap (array<T,0>& /*y*/) {
|
|
||||||
}
|
|
||||||
|
|
||||||
// direct access to data (read-only)
|
|
||||||
const T* data() const { return 0; }
|
|
||||||
T* data() { return 0; }
|
|
||||||
|
|
||||||
// use array as C array (direct read/write access to data)
|
|
||||||
T* c_array() { return 0; }
|
|
||||||
|
|
||||||
// assignment with type conversion
|
|
||||||
template <typename T2>
|
|
||||||
array<T,0>& operator= (const array<T2,0>& ) {
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
// assign one value to all elements
|
|
||||||
void assign (const T& value) { fill ( value ); }
|
|
||||||
void fill (const T& ) {}
|
|
||||||
|
|
||||||
// check range (may be private because it is static)
|
|
||||||
static reference failed_rangecheck () {
|
|
||||||
std::out_of_range e("attempt to access element of an empty array");
|
|
||||||
boost::throw_exception(e);
|
|
||||||
#if defined(BOOST_NO_EXCEPTIONS) || (!defined(BOOST_MSVC) && !defined(__PATHSCALE__))
|
|
||||||
//
|
|
||||||
// We need to return something here to keep
|
|
||||||
// some compilers happy: however we will never
|
|
||||||
// actually get here....
|
|
||||||
//
|
|
||||||
static T placeholder;
|
|
||||||
return placeholder;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// comparisons
|
// comparisons
|
||||||
@ -350,107 +152,6 @@ namespace boost {
|
|||||||
x.swap(y);
|
x.swap(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(__SUNPRO_CC)
|
|
||||||
// Trac ticket #4757; the Sun Solaris compiler can't handle
|
|
||||||
// syntax like 'T(&get_c_array(boost::array<T,N>& arg))[N]'
|
|
||||||
//
|
|
||||||
// We can't just use this for all compilers, because the
|
|
||||||
// borland compilers can't handle this form.
|
|
||||||
namespace detail {
|
|
||||||
template <typename T, std::size_t N> struct c_array
|
|
||||||
{
|
|
||||||
typedef T type[N];
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Specific for boost::array: simply returns its elems data member.
|
|
||||||
template <typename T, std::size_t N>
|
|
||||||
typename detail::c_array<T,N>::type& get_c_array(boost::array<T,N>& arg)
|
|
||||||
{
|
|
||||||
return arg.elems;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Specific for boost::array: simply returns its elems data member.
|
|
||||||
template <typename T, std::size_t N>
|
|
||||||
typename detail::c_array<T,N>::type const& get_c_array(const boost::array<T,N>& arg)
|
|
||||||
{
|
|
||||||
return arg.elems;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
// Specific for boost::array: simply returns its elems data member.
|
|
||||||
template <typename T, std::size_t N>
|
|
||||||
T(&get_c_array(boost::array<T,N>& arg))[N]
|
|
||||||
{
|
|
||||||
return arg.elems;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Const version.
|
|
||||||
template <typename T, std::size_t N>
|
|
||||||
const T(&get_c_array(const boost::array<T,N>& arg))[N]
|
|
||||||
{
|
|
||||||
return arg.elems;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
// Overload for std::array, assuming that std::array will have
|
|
||||||
// explicit conversion functions as discussed at the WG21 meeting
|
|
||||||
// in Summit, March 2009.
|
|
||||||
template <typename T, std::size_t N>
|
|
||||||
T(&get_c_array(std::array<T,N>& arg))[N]
|
|
||||||
{
|
|
||||||
return static_cast<T(&)[N]>(arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Const version.
|
|
||||||
template <typename T, std::size_t N>
|
|
||||||
const T(&get_c_array(const std::array<T,N>& arg))[N]
|
|
||||||
{
|
|
||||||
return static_cast<T(&)[N]>(arg);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
template <class It> std::size_t hash_range(It, It);
|
|
||||||
|
|
||||||
template<class T, std::size_t N>
|
|
||||||
std::size_t hash_value(const array<T,N>& arr)
|
|
||||||
{
|
|
||||||
return boost::hash_range(arr.begin(), arr.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t Idx, typename T, size_t N>
|
|
||||||
T &get(boost::array<T,N> &arr) BOOST_NOEXCEPT {
|
|
||||||
BOOST_STATIC_ASSERT_MSG ( Idx < N, "boost::get<>(boost::array &) index out of range" );
|
|
||||||
return arr[Idx];
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t Idx, typename T, size_t N>
|
|
||||||
const T &get(const boost::array<T,N> &arr) BOOST_NOEXCEPT {
|
|
||||||
BOOST_STATIC_ASSERT_MSG ( Idx < N, "boost::get<>(const boost::array &) index out of range" );
|
|
||||||
return arr[Idx];
|
|
||||||
}
|
|
||||||
|
|
||||||
} /* namespace boost */
|
} /* namespace boost */
|
||||||
|
|
||||||
#ifndef BOOST_NO_CXX11_HDR_ARRAY
|
|
||||||
// If we don't have std::array, I'm assuming that we don't have std::get
|
|
||||||
namespace std {
|
|
||||||
template <size_t Idx, typename T, size_t N>
|
|
||||||
T &get(boost::array<T,N> &arr) BOOST_NOEXCEPT {
|
|
||||||
BOOST_STATIC_ASSERT_MSG ( Idx < N, "std::get<>(boost::array &) index out of range" );
|
|
||||||
return arr[Idx];
|
|
||||||
}
|
|
||||||
|
|
||||||
template <size_t Idx, typename T, size_t N>
|
|
||||||
const T &get(const boost::array<T,N> &arr) BOOST_NOEXCEPT {
|
|
||||||
BOOST_STATIC_ASSERT_MSG ( Idx < N, "std::get<>(const boost::array &) index out of range" );
|
|
||||||
return arr[Idx];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
|
||||||
# pragma warning(pop)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /*BOOST_ARRAY_HPP*/
|
#endif /*BOOST_ARRAY_HPP*/
|
||||||
|
36
index.htm
Normal file
36
index.htm
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
|
||||||
|
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
|
||||||
|
<meta name="ProgId" content="FrontPage.Editor.Document">
|
||||||
|
<title>Array Wrapper Libary</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body bgcolor="#FFFFFF" text="#000000">
|
||||||
|
|
||||||
|
<table border="1" bgcolor="#007F7F" cellpadding="2">
|
||||||
|
<tr>
|
||||||
|
<td bgcolor="#FFFFFF"><img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)" width="277" height="86"></td>
|
||||||
|
<td><a href="../../index.htm"><font face="Arial" color="#FFFFFF"><big>Home</big></font></a></td>
|
||||||
|
<td><a href="../../libraries.htm"><font face="Arial" color="#FFFFFF"><big>Libraries</big></font></a></td>
|
||||||
|
<td><a href="../../people.htm"><font face="Arial" color="#FFFFFF"><big>People</big></font></a></td>
|
||||||
|
<td><a href="../../more/faq.htm"><font face="Arial" color="#FFFFFF"><big>FAQ</big></font></a></td>
|
||||||
|
<td><a href="../../more/index.htm"><font face="Arial" color="#FFFFFF"><big>More</big></font></a></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<h1>Array wrapper library</h1>
|
||||||
|
<p>The header array.hpp provides an STL compliant container wrapper for arrays
|
||||||
|
of constant size.
|
||||||
|
<ul>
|
||||||
|
<li><a href="array.htm">Documentation</a> (HTML).</li>
|
||||||
|
<li>Header <a href="../../boost/array.hpp">array.hpp</a></li>
|
||||||
|
<li>See docs for links to example programs.</li>
|
||||||
|
<li>Download <a href="../../boost_all.zip">all of Boost</a> (ZIP format).</li>
|
||||||
|
<li>Submitted by <a href="http://www.josuttis.com">Nicolai M. Josuttis</a>.</li>
|
||||||
|
</ul>
|
||||||
|
<p>Revised <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %b %Y" startspan -->02 Aug 2000<!--webbot bot="Timestamp" endspan i-checksum="14748" --></p>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
13
index.html
13
index.html
@ -1,13 +0,0 @@
|
|||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta http-equiv="refresh" content="0; URL=../../doc/html/array.html">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
Automatic redirection failed, please go to
|
|
||||||
<a href="../../doc/html/array.html">../../doc/html/array.html</a> <hr>
|
|
||||||
<p><EFBFBD> Copyright Beman Dawes, 2001</p>
|
|
||||||
<p>Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
||||||
file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy
|
|
||||||
at <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</p>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,18 +0,0 @@
|
|||||||
{
|
|
||||||
"key": "array",
|
|
||||||
"name": "Array",
|
|
||||||
"authors": [
|
|
||||||
"Nicolai Josuttis"
|
|
||||||
],
|
|
||||||
"description": "STL compliant container wrapper for arrays of constant size.",
|
|
||||||
"std": [
|
|
||||||
"tr1"
|
|
||||||
],
|
|
||||||
"category": [
|
|
||||||
"Containers"
|
|
||||||
],
|
|
||||||
"maintainers": [
|
|
||||||
"Marshall Clow <marshall -at- idio.com>"
|
|
||||||
],
|
|
||||||
"cxxstd": "03"
|
|
||||||
}
|
|
@ -3,19 +3,20 @@
|
|||||||
* by Nicolai M. Josuttis, Addison-Wesley, 1999
|
* by Nicolai M. Josuttis, Addison-Wesley, 1999
|
||||||
*
|
*
|
||||||
* (C) Copyright Nicolai M. Josuttis 1999.
|
* (C) Copyright Nicolai M. Josuttis 1999.
|
||||||
* Distributed under the Boost Software License, Version 1.0. (See
|
* Permission to copy, use, modify, sell and distribute this software
|
||||||
* accompanying file LICENSE_1_0.txt or copy at
|
* is granted provided this copyright notice appears in all copies.
|
||||||
* http://www.boost.org/LICENSE_1_0.txt)
|
* This software is provided "as is" without express or implied
|
||||||
|
* warranty, and with no claim as to its suitability for any purpose.
|
||||||
*/
|
*/
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
/* print_elements()
|
/* PRINT_ELEMENTS()
|
||||||
* - prints optional C-string optcstr followed by
|
* - prints optional C-string optcstr followed by
|
||||||
* - all elements of the collection coll
|
* - all elements of the collection coll
|
||||||
* - separated by spaces
|
* - separated by spaces
|
||||||
*/
|
*/
|
||||||
template <class T>
|
template <class T>
|
||||||
inline void print_elements (const T& coll, const char* optcstr="")
|
inline void PRINT_ELEMENTS (const T& coll, const char* optcstr="")
|
||||||
{
|
{
|
||||||
typename T::const_iterator pos;
|
typename T::const_iterator pos;
|
||||||
|
|
48
print.hpp.html
Normal file
48
print.hpp.html
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
<HTML>
|
||||||
|
<HEAD>
|
||||||
|
<TITLE>PRINT_ELEMENTS()</TITLE>
|
||||||
|
</HEAD>
|
||||||
|
|
||||||
|
<BODY TEXT="#000000" BGCOLOR="#FFFFFF">
|
||||||
|
|
||||||
|
<TABLE HEIGHT=40 WIDTH="100%">
|
||||||
|
<TR> <TD ALIGN=LEFT WIDTH="100%" BGCOLOR="#DDDDDD">
|
||||||
|
<FONT face="Arial,Helvetica" size=+2><B>
|
||||||
|
PRINT_ELEMENTS()
|
||||||
|
</B></FONT>
|
||||||
|
</TD></TR></TABLE><BR>
|
||||||
|
|
||||||
|
<FONT face="Arial,Helvetica"><B>
|
||||||
|
The following code example is taken from the book<BR>
|
||||||
|
<A HREF="http://www.josuttis.com/libbook/" TARGET="_top">
|
||||||
|
The C++ Standard Library - A Tutorial and Reference</A><BR>
|
||||||
|
by Nicolai M. Josuttis, Addison-Wesley, 1999<BR>
|
||||||
|
<A HREF="http://www.josuttis.com/libbook/copyright.html">
|
||||||
|
© Copyright</A> Nicolai M. Josuttis 1999<BR>
|
||||||
|
</B></FONT>
|
||||||
|
|
||||||
|
<BR><BR>
|
||||||
|
<TT>
|
||||||
|
<SPAN class="Source">
|
||||||
|
#include <iostream><BR>
|
||||||
|
<BR>
|
||||||
|
<Font color="0000FF" >/</FONT><I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* PRINT_ELEMENTS()</FONT></I><BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* - prints optional C-string optcstr followed by</FONT></I><BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* - all elements of the collection coll</FONT></I><BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >* - separated by spaces</FONT></I><BR>
|
||||||
|
<I><FONT face="Arial,Helvetica,sans-serif" color="0000FF" >*/</FONT></I><BR>
|
||||||
|
template <class T><BR>
|
||||||
|
inline void PRINT_ELEMENTS (const T& coll, const char* optcstr="")<BR>
|
||||||
|
{<BR>
|
||||||
|
typename T::const_iterator pos;<BR>
|
||||||
|
<BR>
|
||||||
|
std::cout << optcstr;<BR>
|
||||||
|
for (pos=coll.begin(); pos!=coll.end(); ++pos) {<BR>
|
||||||
|
std::cout << *pos << ' ';<BR>
|
||||||
|
}<BR>
|
||||||
|
std::cout << std::endl;<BR>
|
||||||
|
}<BR>
|
||||||
|
</SPAN>
|
||||||
|
</TT>
|
||||||
|
</BODY>
|
||||||
|
</HTML>
|
@ -1,18 +0,0 @@
|
|||||||
#~ Copyright Rene Rivera 2008
|
|
||||||
#~ Distributed under the Boost Software License, Version 1.0.
|
|
||||||
#~ (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
|
|
||||||
test-suite array :
|
|
||||||
[ run array0.cpp ]
|
|
||||||
[ run array1.cpp ]
|
|
||||||
[ run array2.cpp ]
|
|
||||||
[ run array3.cpp ]
|
|
||||||
[ run array4.cpp ]
|
|
||||||
[ run array5.cpp ]
|
|
||||||
[ run array6.cpp ]
|
|
||||||
[ run array7.cpp ]
|
|
||||||
# [ run array_constexpr.cpp ]
|
|
||||||
[ compile-fail array_getfail1.cpp ]
|
|
||||||
[ compile-fail array_getfail2.cpp ]
|
|
||||||
[ run array_hash.cpp ]
|
|
||||||
;
|
|
@ -1,89 +0,0 @@
|
|||||||
/* tests for using class array<> specialization for size 0
|
|
||||||
* (C) Copyright Alisdair Meredith 2006.
|
|
||||||
* Distributed under the Boost Software License, Version 1.0. (See
|
|
||||||
* accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
* http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <iostream>
|
|
||||||
#include <boost/array.hpp>
|
|
||||||
|
|
||||||
#include <boost/core/lightweight_test_trait.hpp>
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
template< class T >
|
|
||||||
void BadValue( const T & )
|
|
||||||
{
|
|
||||||
BOOST_TEST ( false );
|
|
||||||
}
|
|
||||||
|
|
||||||
template< class T >
|
|
||||||
void RunTests()
|
|
||||||
{
|
|
||||||
typedef boost::array< T, 0 > test_type;
|
|
||||||
|
|
||||||
// Test value and aggegrate initialization
|
|
||||||
test_type test_case = {};
|
|
||||||
const boost::array< T, 0 > const_test_case = test_type();
|
|
||||||
|
|
||||||
test_case.fill ( T() );
|
|
||||||
|
|
||||||
// front/back and operator[] must compile, but calling them is undefined
|
|
||||||
// Likewise, all tests below should evaluate to false, avoiding undefined behaviour
|
|
||||||
BOOST_TEST ( test_case.empty());
|
|
||||||
BOOST_TEST ( const_test_case.empty());
|
|
||||||
|
|
||||||
BOOST_TEST ( test_case.size() == 0 );
|
|
||||||
BOOST_TEST ( const_test_case.size() == 0 );
|
|
||||||
|
|
||||||
// Assert requirements of TR1 6.2.2.4
|
|
||||||
BOOST_TEST ( test_case.begin() == test_case.end());
|
|
||||||
BOOST_TEST ( test_case.cbegin() == test_case.cend());
|
|
||||||
BOOST_TEST ( const_test_case.begin() == const_test_case.end());
|
|
||||||
BOOST_TEST ( const_test_case.cbegin() == const_test_case.cend());
|
|
||||||
|
|
||||||
BOOST_TEST ( test_case.begin() != const_test_case.begin() );
|
|
||||||
if( test_case.data() == const_test_case.data() ) {
|
|
||||||
// Value of data is unspecified in TR1, so no requirement this test pass or fail
|
|
||||||
// However, it must compile!
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check can safely use all iterator types with std algorithms
|
|
||||||
std::for_each( test_case.begin(), test_case.end(), BadValue< T > );
|
|
||||||
std::for_each( test_case.rbegin(), test_case.rend(), BadValue< T > );
|
|
||||||
std::for_each( test_case.cbegin(), test_case.cend(), BadValue< T > );
|
|
||||||
std::for_each( const_test_case.begin(), const_test_case.end(), BadValue< T > );
|
|
||||||
std::for_each( const_test_case.rbegin(), const_test_case.rend(), BadValue< T > );
|
|
||||||
std::for_each( const_test_case.cbegin(), const_test_case.cend(), BadValue< T > );
|
|
||||||
|
|
||||||
// Check swap is well formed
|
|
||||||
std::swap( test_case, test_case );
|
|
||||||
|
|
||||||
// Check assignment operator and overloads are well formed
|
|
||||||
test_case = const_test_case;
|
|
||||||
|
|
||||||
// Confirm at() throws the std lib defined exception
|
|
||||||
try {
|
|
||||||
BadValue( test_case.at( 0 ));
|
|
||||||
} catch ( const std::out_of_range & ) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
BadValue( const_test_case.at( 0 ) );
|
|
||||||
} catch ( const std::out_of_range & ) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
RunTests< bool >();
|
|
||||||
RunTests< void * >();
|
|
||||||
RunTests< long double >();
|
|
||||||
RunTests< std::string >();
|
|
||||||
|
|
||||||
return boost::report_errors();
|
|
||||||
}
|
|
@ -1,60 +0,0 @@
|
|||||||
/* tests for using class array<> specialization for size 0
|
|
||||||
* (C) Copyright Alisdair Meredith 2006.
|
|
||||||
* Distributed under the Boost Software License, Version 1.0. (See
|
|
||||||
* accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
* http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <iostream>
|
|
||||||
#include <boost/array.hpp>
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
#include <boost/core/lightweight_test_trait.hpp>
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
template< class T >
|
|
||||||
void RunTests()
|
|
||||||
{
|
|
||||||
typedef boost::array< T, 5 > test_type;
|
|
||||||
typedef T arr[5];
|
|
||||||
test_type test_case; // = { 1, 1, 2, 3, 5 };
|
|
||||||
|
|
||||||
arr &aRef = get_c_array ( test_case );
|
|
||||||
BOOST_TEST ( &*test_case.begin () == &aRef[0] );
|
|
||||||
|
|
||||||
const arr &caRef = get_c_array ( test_case );
|
|
||||||
typename test_type::const_iterator iter = test_case.begin ();
|
|
||||||
BOOST_TEST ( &*iter == &caRef[0] );
|
|
||||||
|
|
||||||
// Confirm at() throws the std lib defined exception
|
|
||||||
try {
|
|
||||||
test_case.at( test_case.size());
|
|
||||||
BOOST_TEST(false);
|
|
||||||
}
|
|
||||||
catch ( const std::out_of_range & ) {}
|
|
||||||
|
|
||||||
try {
|
|
||||||
test_case.at( test_case.size() + 1);
|
|
||||||
BOOST_TEST(false);
|
|
||||||
}
|
|
||||||
catch ( const std::out_of_range & ) {}
|
|
||||||
|
|
||||||
try {
|
|
||||||
test_case.at( test_case.size() + 100);
|
|
||||||
BOOST_TEST(false);
|
|
||||||
}
|
|
||||||
catch ( const std::out_of_range & ) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main ()
|
|
||||||
{
|
|
||||||
RunTests< bool >();
|
|
||||||
RunTests< void * >();
|
|
||||||
RunTests< long double >();
|
|
||||||
RunTests< std::string >();
|
|
||||||
|
|
||||||
return boost::report_errors();
|
|
||||||
}
|
|
||||||
|
|
@ -1,66 +0,0 @@
|
|||||||
/* tests using std::get on boost:array
|
|
||||||
* (C) Copyright Marshall Clow 2012
|
|
||||||
* Distributed under the Boost Software License, Version 1.0. (See
|
|
||||||
* accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
* http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <iostream>
|
|
||||||
#include <boost/array.hpp>
|
|
||||||
#include <algorithm>
|
|
||||||
#ifndef BOOST_NO_CXX11_HDR_ARRAY
|
|
||||||
#include <array>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <boost/core/lightweight_test_trait.hpp>
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
#ifndef BOOST_NO_CXX11_HDR_ARRAY
|
|
||||||
template< class T >
|
|
||||||
void RunStdTests()
|
|
||||||
{
|
|
||||||
typedef boost::array< T, 5 > test_type;
|
|
||||||
test_type test_case; // = { 1, 1, 2, 3, 5 };
|
|
||||||
|
|
||||||
T &aRef = std::get<0> ( test_case );
|
|
||||||
BOOST_TEST ( &*test_case.begin () == &aRef );
|
|
||||||
|
|
||||||
const T &caRef = std::get<0> ( test_case );
|
|
||||||
BOOST_TEST ( &*test_case.cbegin () == &caRef );
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
template< class T >
|
|
||||||
void RunBoostTests()
|
|
||||||
{
|
|
||||||
typedef boost::array< T, 5 > test_type;
|
|
||||||
test_type test_case; // = { 1, 1, 2, 3, 5 };
|
|
||||||
|
|
||||||
T &aRef = boost::get<0> ( test_case );
|
|
||||||
BOOST_TEST ( &*test_case.begin () == &aRef );
|
|
||||||
|
|
||||||
const T &caRef = boost::get<0> ( test_case );
|
|
||||||
BOOST_TEST ( &*test_case.cbegin () == &caRef );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
RunBoostTests< bool >();
|
|
||||||
RunBoostTests< void * >();
|
|
||||||
RunBoostTests< long double >();
|
|
||||||
RunBoostTests< std::string >();
|
|
||||||
|
|
||||||
#ifndef BOOST_NO_CXX11_HDR_ARRAY
|
|
||||||
RunStdTests< bool >();
|
|
||||||
RunStdTests< void * >();
|
|
||||||
RunStdTests< long double >();
|
|
||||||
RunStdTests< std::string >();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return boost::report_errors();
|
|
||||||
}
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
|||||||
/* tests using constexpr on boost:array
|
|
||||||
* (C) Copyright Marshall Clow 2012
|
|
||||||
* Distributed under the Boost Software License, Version 1.0. (See
|
|
||||||
* accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
* http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <iostream>
|
|
||||||
#include <boost/array.hpp>
|
|
||||||
#include <algorithm>
|
|
||||||
#ifndef BOOST_NO_CXX11_HDR_ARRAY
|
|
||||||
#include <array>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef BOOST_NO_CXX11_CONSTEXPR
|
|
||||||
constexpr boost::array<int, 10> arr {{ 0,1,2,3,4,5,6,7,8,9 }};
|
|
||||||
constexpr std::array<int, 10> arr_std {{ 0,1,2,3,4,5,6,7,8,9 }};
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
void sink ( T t ) {}
|
|
||||||
|
|
||||||
template <typename T, size_t N>
|
|
||||||
void sink ( boost::array<T,N> &arr ) {}
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
// constexpr int two = arr_std.at (2);
|
|
||||||
constexpr int three = arr.at (3);
|
|
||||||
int whatever [ arr.at(4) ];
|
|
||||||
(void)three;
|
|
||||||
(void) whatever;
|
|
||||||
}
|
|
||||||
|
|
||||||
#else // no constexpr means no constexpr tests!
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
#endif
|
|
@ -1,50 +0,0 @@
|
|||||||
/* tests using std::get on boost:array
|
|
||||||
* (C) Copyright Marshall Clow 2012
|
|
||||||
* Distributed under the Boost Software License, Version 1.0. (See
|
|
||||||
* accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
* http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <boost/array.hpp>
|
|
||||||
#include <boost/static_assert.hpp>
|
|
||||||
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <iostream>
|
|
||||||
#include <algorithm>
|
|
||||||
#ifndef BOOST_NO_CXX11_HDR_ARRAY
|
|
||||||
#include <array>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <boost/core/lightweight_test_trait.hpp>
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
#ifndef BOOST_NO_CXX11_HDR_ARRAY
|
|
||||||
template< class T >
|
|
||||||
void RunStdTests()
|
|
||||||
{
|
|
||||||
typedef boost::array< T, 5 > test_type;
|
|
||||||
typedef T arr[5];
|
|
||||||
test_type test_case; // = { 1, 1, 2, 3, 5 };
|
|
||||||
|
|
||||||
T &aRef = std::get<5> ( test_case ); // should fail to compile
|
|
||||||
BOOST_TEST ( &*test_case.begin () == &aRef );
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
#ifndef BOOST_NO_CXX11_HDR_ARRAY
|
|
||||||
RunStdTests< bool >();
|
|
||||||
RunStdTests< void * >();
|
|
||||||
RunStdTests< long double >();
|
|
||||||
RunStdTests< std::string >();
|
|
||||||
#else
|
|
||||||
BOOST_STATIC_ASSERT ( false ); // fail on C++03 systems.
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return boost::report_errors();
|
|
||||||
}
|
|
@ -1,65 +0,0 @@
|
|||||||
/* tests using std::get on boost:array
|
|
||||||
* (C) Copyright Marshall Clow 2012
|
|
||||||
* Distributed under the Boost Software License, Version 1.0. (See
|
|
||||||
* accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
* http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <iostream>
|
|
||||||
#include <boost/array.hpp>
|
|
||||||
#include <algorithm>
|
|
||||||
#ifndef BOOST_NO_CXX11_HDR_ARRAY
|
|
||||||
#include <array>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <boost/core/lightweight_test_trait.hpp>
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
#ifndef BOOST_NO_CXX11_HDR_ARRAY
|
|
||||||
template< class T >
|
|
||||||
void RunStdTests()
|
|
||||||
{
|
|
||||||
typedef boost::array< T, 5 > test_type;
|
|
||||||
typedef T arr[5];
|
|
||||||
test_type test_case; // = { 1, 1, 2, 3, 5 };
|
|
||||||
|
|
||||||
T &aRef = std::get<0> ( test_case );
|
|
||||||
BOOST_TEST ( &*test_case.begin () == &aRef );
|
|
||||||
|
|
||||||
const T &caRef = std::get<0> ( test_case );
|
|
||||||
BOOST_TEST ( &*test_case.cbegin () == &caRef );
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
template< class T >
|
|
||||||
void RunBoostTests()
|
|
||||||
{
|
|
||||||
typedef boost::array< T, 5 > test_type;
|
|
||||||
typedef T arr[5];
|
|
||||||
test_type test_case; // = { 1, 1, 2, 3, 5 };
|
|
||||||
|
|
||||||
T &aRef = boost::get<5> ( test_case );
|
|
||||||
BOOST_TEST ( &*test_case.begin () == &aRef );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
RunBoostTests< bool >();
|
|
||||||
RunBoostTests< void * >();
|
|
||||||
RunBoostTests< long double >();
|
|
||||||
RunBoostTests< std::string >();
|
|
||||||
|
|
||||||
#ifndef BOOST_NO_CXX11_HDR_ARRAY
|
|
||||||
RunStdTests< bool >();
|
|
||||||
RunStdTests< void * >();
|
|
||||||
RunStdTests< long double >();
|
|
||||||
RunStdTests< std::string >();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return boost::report_errors();
|
|
||||||
}
|
|
||||||
|
|
@ -1,44 +0,0 @@
|
|||||||
/* tests for using boost::hash with boost::array
|
|
||||||
* (C) Copyright Marshall Clow 2012
|
|
||||||
* Distributed under the Boost Software License, Version 1.0. (See
|
|
||||||
* accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
* http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <iostream>
|
|
||||||
#include <boost/array.hpp>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <boost/functional/hash.hpp>
|
|
||||||
|
|
||||||
#include <boost/core/lightweight_test_trait.hpp>
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
template< class T >
|
|
||||||
void RunTests()
|
|
||||||
{
|
|
||||||
// std::size_t hash0 = boost::hash<boost::array<T,0> > () ( boost::array<T, 0> ());
|
|
||||||
// std::size_t hash1 = boost::hash<boost::array<T,1> > () ( boost::array<T, 1> ());
|
|
||||||
|
|
||||||
typedef boost::array< T, 5 > barr;
|
|
||||||
typedef T arr[5];
|
|
||||||
barr test_barr = {{ 1, 1, 2, 3, 5 }};
|
|
||||||
arr test_arr = { 1, 1, 2, 3, 5 };
|
|
||||||
|
|
||||||
std::size_t bhash = boost::hash<barr> () ( test_barr );
|
|
||||||
std::size_t ahash = boost::hash<arr> () ( test_arr );
|
|
||||||
BOOST_TEST ( ahash == bhash );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
RunTests< int >();
|
|
||||||
RunTests< long >();
|
|
||||||
RunTests< long double >();
|
|
||||||
|
|
||||||
return boost::report_errors();
|
|
||||||
}
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
|||||||
# Copyright 2018 Mike Dev
|
|
||||||
# Distributed under the Boost Software License, Version 1.0.
|
|
||||||
# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt
|
|
||||||
#
|
|
||||||
# NOTE: This does NOT run the unit tests for Boost.Array.
|
|
||||||
# It only tests, if the CMakeLists.txt file in it's root works as expected
|
|
||||||
|
|
||||||
cmake_minimum_required( VERSION 3.5 )
|
|
||||||
|
|
||||||
project( BoostBindCMakeSelfTest )
|
|
||||||
|
|
||||||
add_subdirectory( ../../../assert ${CMAKE_CURRENT_BINARY_DIR}/libs/assert )
|
|
||||||
add_subdirectory( ../../../config ${CMAKE_CURRENT_BINARY_DIR}/libs/config )
|
|
||||||
add_subdirectory( ../../../core ${CMAKE_CURRENT_BINARY_DIR}/libs/core )
|
|
||||||
add_subdirectory( ../../../static_assert ${CMAKE_CURRENT_BINARY_DIR}/libs/static_assert )
|
|
||||||
add_subdirectory( ../../../throw_exception ${CMAKE_CURRENT_BINARY_DIR}/libs/thorw_exception )
|
|
||||||
|
|
||||||
add_subdirectory( ../.. ${CMAKE_CURRENT_BINARY_DIR}/libs/boost_array )
|
|
||||||
|
|
||||||
add_executable( boost_array_cmake_self_test main.cpp )
|
|
||||||
target_link_libraries( boost_array_cmake_self_test Boost::array )
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
|||||||
#include <boost/array.hpp>
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
boost::array<int,5> a{};
|
|
||||||
}
|
|
Reference in New Issue
Block a user