forked from boostorg/integer
Compare commits
72 Commits
boost-1.65
...
boost-1.73
Author | SHA1 | Date | |
---|---|---|---|
bee5818e18 | |||
1067b2d170 | |||
8cfbb2a222 | |||
00154b31a5 | |||
63f14838a0 | |||
33c165552c | |||
5195d682ec | |||
49dd6f5645 | |||
96f430b7e2 | |||
39082b1bc5 | |||
51d1b16bfd | |||
131107704f | |||
eaf2561e95 | |||
29e3ae824c | |||
0af165bf6d | |||
080f2bdfdc | |||
289939a640 | |||
51b259da19 | |||
4bc1a5eb75 | |||
682d4ac66b | |||
2f634ca78b | |||
2b08ca9368 | |||
aa68e17f2e | |||
cad4623876 | |||
9a7f24e8ca | |||
3599683975 | |||
b3680b77fd | |||
099cf261b0 | |||
ab509ca840 | |||
37204ea892 | |||
5df4961448 | |||
95a19b6364 | |||
8674c6724f | |||
a7da90a79e | |||
9312962a68 | |||
df7adb52ca | |||
6c58aa9a48 | |||
cd60c4c9f9 | |||
7c5def9d39 | |||
791a139a51 | |||
835ac98a23 | |||
f76d776698 | |||
c4c3373708 | |||
bbb1da275b | |||
b5d5c56e68 | |||
3961dc2f1e | |||
645edc971d | |||
e00ffe97ae | |||
6340dec871 | |||
de0d24733b | |||
0c6ec8088d | |||
f21a8e301a | |||
cdefe039ee | |||
f6525ae186 | |||
e0646cb7ec | |||
3632ae43b2 | |||
2d463f3ee7 | |||
3f1603938c | |||
54d0e4c63e | |||
87e5b365d8 | |||
ada03a59d7 | |||
9167594533 | |||
1c586d6dd0 | |||
6a97e49614 | |||
661986dd3d | |||
faa61cd911 | |||
4f4f3eda37 | |||
b3966428c4 | |||
8c415f77b1 | |||
fc4d657201 | |||
919c5277c1 | |||
bc2349f71b |
429
.travis.yml
429
.travis.yml
@ -1,4 +1,5 @@
|
||||
# Copyright 2016, 2017 Peter Dimov
|
||||
# Copyright 2019 Andrey Semashev
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
|
||||
@ -6,32 +7,51 @@ language: cpp
|
||||
|
||||
sudo: false
|
||||
|
||||
python: "2.7"
|
||||
|
||||
os:
|
||||
- linux
|
||||
- osx
|
||||
dist: trusty
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- develop
|
||||
- /feature\/.*/
|
||||
|
||||
env:
|
||||
matrix:
|
||||
- BOGUS_JOB=true
|
||||
- EMPTY=true
|
||||
|
||||
matrix:
|
||||
|
||||
exclude:
|
||||
- env: BOGUS_JOB=true
|
||||
- env: EMPTY=true
|
||||
|
||||
include:
|
||||
# gcc, Linux
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++ CXXSTD=c++03
|
||||
dist: trusty
|
||||
compiler: gcc-4.4
|
||||
env: TOOLSET=gcc COMPILER=g++-4.4 CXXSTD=98,0x
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-4.4
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-4.7 CXXSTD=c++03
|
||||
dist: trusty
|
||||
compiler: gcc-4.6
|
||||
env: TOOLSET=gcc COMPILER=g++-4.6 CXXSTD=03,0x
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-4.6
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
dist: trusty
|
||||
compiler: gcc-4.7
|
||||
env: TOOLSET=gcc COMPILER=g++-4.7 CXXSTD=03,11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
@ -40,16 +60,9 @@ matrix:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-4.7 CXXSTD=c++11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-4.7
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-4.8 CXXSTD=c++03
|
||||
dist: xenial
|
||||
compiler: gcc-4.8
|
||||
env: TOOLSET=gcc COMPILER=g++-4.8 CXXSTD=03,11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
@ -58,16 +71,9 @@ matrix:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-4.8 CXXSTD=c++11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-4.8
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-4.9 CXXSTD=c++03
|
||||
dist: xenial
|
||||
compiler: gcc-4.9
|
||||
env: TOOLSET=gcc COMPILER=g++-4.9 CXXSTD=03,11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
@ -76,16 +82,9 @@ matrix:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-4.9 CXXSTD=c++11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-4.9
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-5 CXXSTD=c++03
|
||||
dist: xenial
|
||||
compiler: gcc-5
|
||||
env: TOOLSET=gcc COMPILER=g++-5 CXXSTD=03,11,14,1z
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
@ -94,25 +93,9 @@ matrix:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-5 CXXSTD=c++11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-5
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-5 CXXSTD=c++14
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-5
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-6 CXXSTD=c++03
|
||||
dist: xenial
|
||||
compiler: gcc-6
|
||||
env: TOOLSET=gcc COMPILER=g++-6 CXXSTD=03,11,14,1z
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
@ -121,227 +104,299 @@ matrix:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-6 CXXSTD=c++11
|
||||
dist: xenial
|
||||
compiler: gcc-7
|
||||
env: TOOLSET=gcc COMPILER=g++-7 CXXSTD=03,11,14,17
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-6
|
||||
- g++-7
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-6 CXXSTD=c++14
|
||||
dist: xenial
|
||||
compiler: gcc-8
|
||||
env: TOOLSET=gcc COMPILER=g++-8 CXXSTD=03,11,14,17,2a
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-6
|
||||
- g++-8
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-6 CXXSTD=c++1z
|
||||
dist: bionic
|
||||
compiler: gcc-9
|
||||
env: TOOLSET=gcc COMPILER=g++-9 CXXSTD=03,11,14,17,2a
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-6
|
||||
- g++-9
|
||||
sources:
|
||||
- sourceline: "ppa:ubuntu-toolchain-r/test"
|
||||
|
||||
- os: linux
|
||||
dist: bionic
|
||||
compiler: gcc-UBSAN
|
||||
env: UBSAN=1 TOOLSET=gcc COMPILER=g++-9 CXXSTD=03,11,14,17,2a UBSAN_OPTIONS=print_stacktrace=1 LINKFLAGS=-fuse-ld=gold
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-9
|
||||
sources:
|
||||
- sourceline: "ppa:ubuntu-toolchain-r/test"
|
||||
|
||||
# clang, Linux
|
||||
- os: linux
|
||||
dist: trusty
|
||||
compiler: clang-3.4
|
||||
env: TOOLSET=clang COMPILER=clang++-3.4 CXXSTD=03,11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.4
|
||||
- libstdc++-4.9-dev
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- sourceline: "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-3.4 main"
|
||||
key_url: "https://apt.llvm.org/llvm-snapshot.gpg.key"
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++03
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++11
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++-3.5 CXXSTD=c++03
|
||||
dist: trusty
|
||||
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
|
||||
- sourceline: "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-3.5 main"
|
||||
key_url: "https://apt.llvm.org/llvm-snapshot.gpg.key"
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++-3.5 CXXSTD=c++11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.5
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.5
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++-3.6 CXXSTD=c++03
|
||||
dist: trusty
|
||||
compiler: clang-3.6
|
||||
env: TOOLSET=clang COMPILER=clang++-3.6 CXXSTD=03,11,14,1z
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.6
|
||||
- libstdc++-5-dev
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.6
|
||||
- sourceline: "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-3.6 main"
|
||||
key_url: "https://apt.llvm.org/llvm-snapshot.gpg.key"
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++-3.6 CXXSTD=c++11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.6
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.6
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++-3.7 CXXSTD=c++03
|
||||
dist: trusty
|
||||
compiler: clang-3.7
|
||||
env: TOOLSET=clang COMPILER=clang++-3.7 CXXSTD=03,11,14,1z
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.7
|
||||
- libstdc++-5-dev
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.7
|
||||
- sourceline: "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-3.7 main"
|
||||
key_url: "https://apt.llvm.org/llvm-snapshot.gpg.key"
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++-3.7 CXXSTD=c++11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.7
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.7
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++-3.8 CXXSTD=c++03
|
||||
dist: xenial
|
||||
compiler: clang-3.8
|
||||
env: TOOLSET=clang COMPILER=clang++-3.8 CXXSTD=03,11,14,1z
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.8
|
||||
- libstdc++-6-dev
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.8
|
||||
- sourceline: "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-3.8 main"
|
||||
key_url: "https://apt.llvm.org/llvm-snapshot.gpg.key"
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++-3.8 CXXSTD=c++11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.8
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.8
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++-3.8 CXXSTD=c++14
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.8
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.8
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++-3.8 CXXSTD=c++1z
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.8
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.8
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++-3.9 CXXSTD=c++03
|
||||
dist: xenial
|
||||
compiler: clang-3.9
|
||||
env: TOOLSET=clang COMPILER=clang++-3.9 CXXSTD=03,11,14,1z
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.9
|
||||
- libstdc++-6-dev
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.9
|
||||
- sourceline: "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-3.9 main"
|
||||
key_url: "https://apt.llvm.org/llvm-snapshot.gpg.key"
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++-3.9 CXXSTD=c++11
|
||||
dist: xenial
|
||||
compiler: clang-4
|
||||
env: TOOLSET=clang COMPILER=clang++-4.0 CXXSTD=03,11,14,1z
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.9
|
||||
- clang-4.0
|
||||
- libstdc++-6-dev
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.9
|
||||
- sourceline: "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-4.0 main"
|
||||
key_url: "https://apt.llvm.org/llvm-snapshot.gpg.key"
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++-3.9 CXXSTD=c++14
|
||||
dist: xenial
|
||||
compiler: clang-5
|
||||
env: TOOLSET=clang COMPILER=clang++-5.0 CXXSTD=03,11,14,1z
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.9
|
||||
- clang-5.0
|
||||
- libstdc++-7-dev
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.9
|
||||
- sourceline: "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-5.0 main"
|
||||
key_url: "https://apt.llvm.org/llvm-snapshot.gpg.key"
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++-3.9 CXXSTD=c++1z
|
||||
dist: xenial
|
||||
compiler: clang-6
|
||||
env: TOOLSET=clang COMPILER=clang++-6.0 CXXSTD=03,11,14,17,2a
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.9
|
||||
- clang-6.0
|
||||
- libstdc++-8-dev
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.9
|
||||
- sourceline: "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-6.0 main"
|
||||
key_url: "https://apt.llvm.org/llvm-snapshot.gpg.key"
|
||||
|
||||
- os: linux
|
||||
dist: xenial
|
||||
compiler: clang-7
|
||||
env: TOOLSET=clang COMPILER=clang++-7 CXXSTD=03,11,14,17,2a
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-7
|
||||
- libstdc++-8-dev
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- sourceline: "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-7 main"
|
||||
key_url: "https://apt.llvm.org/llvm-snapshot.gpg.key"
|
||||
|
||||
- os: linux
|
||||
dist: xenial
|
||||
compiler: clang-8
|
||||
env: TOOLSET=clang COMPILER=clang++-8 CXXSTD=03,11,14,17,2a
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-8
|
||||
- libstdc++-8-dev
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- sourceline: "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-8 main"
|
||||
key_url: "https://apt.llvm.org/llvm-snapshot.gpg.key"
|
||||
|
||||
- os: linux
|
||||
dist: xenial
|
||||
compiler: clang-9
|
||||
env: TOOLSET=clang COMPILER=clang++-9 CXXSTD=03,11,14,17,2a
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-9
|
||||
- libstdc++-9-dev
|
||||
sources:
|
||||
- sourceline: "ppa:ubuntu-toolchain-r/test"
|
||||
- sourceline: "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-9 main"
|
||||
key_url: "https://apt.llvm.org/llvm-snapshot.gpg.key"
|
||||
|
||||
- os: linux
|
||||
dist: xenial
|
||||
compiler: clang-UBSAN
|
||||
env: UBSAN=1 TOOLSET=clang COMPILER=clang++-9 CXXSTD=03,11,14,17,2a UBSAN_OPTIONS=print_stacktrace=1
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-9
|
||||
- libstdc++-9-dev
|
||||
sources:
|
||||
- sourceline: "ppa:ubuntu-toolchain-r/test"
|
||||
- sourceline: "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-9 main"
|
||||
key_url: "https://apt.llvm.org/llvm-snapshot.gpg.key"
|
||||
|
||||
- os: linux
|
||||
dist: xenial
|
||||
compiler: clang-libc++
|
||||
env: TOOLSET=clang COMPILER=clang++-9 CXXSTD=03,11,14,17,2a CXXFLAGS="-stdlib=libc++" LINKFLAGS="-stdlib=libc++"
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-9
|
||||
- libc++-9-dev
|
||||
- libc++abi-9-dev
|
||||
sources:
|
||||
- sourceline: "ppa:ubuntu-toolchain-r/test"
|
||||
- sourceline: "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-9 main"
|
||||
key_url: "https://apt.llvm.org/llvm-snapshot.gpg.key"
|
||||
|
||||
- os: linux
|
||||
dist: xenial
|
||||
compiler: clang-libc++-UBSAN
|
||||
env: UBSAN=1 TOOLSET=clang COMPILER=clang++-9 CXXSTD=03,11,14,17,2a UBSAN_OPTIONS=print_stacktrace=1 CXXFLAGS="-stdlib=libc++" LINKFLAGS="-stdlib=libc++"
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-9
|
||||
- libc++-9-dev
|
||||
- libc++abi-9-dev
|
||||
sources:
|
||||
- sourceline: "ppa:ubuntu-toolchain-r/test"
|
||||
- sourceline: "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-9 main"
|
||||
key_url: "https://apt.llvm.org/llvm-snapshot.gpg.key"
|
||||
|
||||
# clang, OS X
|
||||
# OS X builds are slow on Travis CI
|
||||
# - os: osx
|
||||
# env: TOOLSET=clang COMPILER=clang++ CXXSTD=03,11,14,1z
|
||||
# osx_image: xcode9.4
|
||||
#
|
||||
# - os: osx
|
||||
# env: TOOLSET=clang COMPILER=clang++ CXXSTD=03,11,14,1z
|
||||
# osx_image: xcode10.3
|
||||
|
||||
- os: osx
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++03
|
||||
|
||||
- os: osx
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++11
|
||||
|
||||
- os: osx
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++14
|
||||
|
||||
- os: osx
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++1z
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=03,11,14,17
|
||||
osx_image: xcode11.2
|
||||
|
||||
install:
|
||||
- GIT_FETCH_JOBS=8
|
||||
- BOOST_BRANCH=develop
|
||||
- if [ "$TRAVIS_BRANCH" = "master" ]; then BOOST_BRANCH=master; fi
|
||||
- cd ..
|
||||
- git clone -b $TRAVIS_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
|
||||
- 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 libs/core
|
||||
- git submodule update --init libs/detail
|
||||
- git submodule update --init libs/assert
|
||||
- git submodule update --init libs/static_assert
|
||||
- git submodule update --init libs/type_traits
|
||||
- git submodule update --init libs/mpl
|
||||
- git submodule update --init libs/preprocessor
|
||||
- git submodule update --init libs/multiprecision
|
||||
- git submodule update --init libs/math
|
||||
- git submodule update --init libs/rational
|
||||
- git submodule update --init libs/throw_exception
|
||||
- git submodule update --init libs/predef
|
||||
- git submodule update --init libs/lexical_cast
|
||||
- git submodule update --init libs/range
|
||||
- git submodule update --init libs/iterator
|
||||
- git submodule update --init libs/concept_check
|
||||
- git submodule update --init libs/numeric
|
||||
- git submodule update --init libs/array
|
||||
- git submodule update --init libs/container
|
||||
- git submodule update --init libs/move
|
||||
- git submodule update --init libs/functional
|
||||
- git submodule update --init libs/random
|
||||
- git submodule update --init libs/utility
|
||||
- git submodule init tools/boostdep
|
||||
- git submodule init tools/build
|
||||
- git submodule init tools/boost_install
|
||||
- git submodule init libs/headers
|
||||
- git submodule init libs/config
|
||||
- git submodule update --jobs $GIT_FETCH_JOBS
|
||||
- cp -r $TRAVIS_BUILD_DIR/* libs/integer
|
||||
- python tools/boostdep/depinst/depinst.py --git_args "--jobs $GIT_FETCH_JOBS" integer
|
||||
- ./bootstrap.sh
|
||||
- ./b2 headers
|
||||
|
||||
script:
|
||||
- |-
|
||||
echo "using $TOOLSET : : $COMPILER : <cxxflags>-std=$CXXSTD ;" > ~/user-config.jam
|
||||
- ./b2 libs/integer/test toolset=$TOOLSET
|
||||
echo "using $TOOLSET : : $COMPILER ;" > ~/user-config.jam
|
||||
- BUILD_JOBS=`(nproc || sysctl -n hw.ncpu) 2> /dev/null`
|
||||
- ./b2 -j $BUILD_JOBS libs/integer/test toolset=$TOOLSET cxxstd=$CXXSTD ${UBSAN:+cxxflags=-fsanitize=undefined cxxflags=-fno-sanitize-recover=undefined linkflags=-fsanitize=undefined define=UBSAN=1 debug-symbols=on visibility=global} ${CXXFLAGS:+cxxflags="$CXXFLAGS"} ${LINKFLAGS:+linkflags="$LINKFLAGS"}
|
||||
|
||||
notifications:
|
||||
email:
|
||||
|
25
CMakeLists.txt
Normal file
25
CMakeLists.txt
Normal file
@ -0,0 +1,25 @@
|
||||
# Copyright 2018 Peter Dimov
|
||||
# Copyright 2018 Andrey Semashev
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
# Partial (add_subdirectory only) and experimental CMake support
|
||||
# Subject to change; please do not rely on the contents of this file yet.
|
||||
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
project(BoostInteger LANGUAGES CXX)
|
||||
|
||||
add_library(boost_integer INTERFACE)
|
||||
add_library(Boost::integer ALIAS boost_integer)
|
||||
|
||||
target_include_directories(boost_integer INTERFACE include)
|
||||
|
||||
target_link_libraries(boost_integer
|
||||
INTERFACE
|
||||
Boost::assert
|
||||
Boost::config
|
||||
Boost::core
|
||||
Boost::static_assert
|
||||
Boost::throw_exception
|
||||
)
|
30
README.md
Normal file
30
README.md
Normal file
@ -0,0 +1,30 @@
|
||||
# Boost.Integer
|
||||
|
||||
Boost.Integer, part of collection of the [Boost C++ Libraries](https://github.com/boostorg), provides
|
||||
integer type support, particularly helpful in generic programming. It provides the means to select
|
||||
an integer type based upon its properties, like the number of bits or the maximum supported value,
|
||||
as well as compile-time bit mask selection. There is a derivative of `std::numeric_limits` that provides
|
||||
integral constant expressions for `min` and `max`...
|
||||
Finally, it provides two compile-time algorithms: determining the highest power of two in a
|
||||
compile-time value; and computing min and max of constant expressions.
|
||||
|
||||
### Directories
|
||||
|
||||
* **doc** - QuickBook documentation sources
|
||||
* **include** - Interface headers of Boost.Integer
|
||||
* **test** - Boost.Integer unit tests
|
||||
|
||||
### More information
|
||||
|
||||
* [Documentation](https://boost.org/libs/integer)
|
||||
* [Report bugs](https://github.com/boostorg/integer/issues/new). Be sure to mention Boost version, platform and compiler you're using. A small compilable code sample to reproduce the problem is always good as well.
|
||||
* Submit your patches as pull requests against **develop** branch. Note that by submitting patches you agree to license your modifications under the [Boost Software License, Version 1.0](https://www.boost.org/LICENSE_1_0.txt).
|
||||
|
||||
### Build status
|
||||
|
||||
Master: [](https://ci.appveyor.com/project/Lastique/integer/branch/master) [](https://travis-ci.org/boostorg/integer)
|
||||
Develop: [](https://ci.appveyor.com/project/Lastique/integer/branch/develop) [](https://travis-ci.org/boostorg/integer)
|
||||
|
||||
### License
|
||||
|
||||
Distributed under the [Boost Software License, Version 1.0](https://www.boost.org/LICENSE_1_0.txt).
|
116
appveyor.yml
116
appveyor.yml
@ -1,4 +1,4 @@
|
||||
# Copyright 2016 Peter Dimov
|
||||
# Copyright 2019 Andrey Semashev
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
|
||||
@ -10,74 +10,70 @@ branches:
|
||||
only:
|
||||
- master
|
||||
- develop
|
||||
|
||||
platform:
|
||||
- x64
|
||||
- /feature\/.*/
|
||||
|
||||
environment:
|
||||
matrix:
|
||||
- ARGS: --toolset=msvc-9.0 address-model=32
|
||||
- ARGS: --toolset=msvc-10.0 address-model=32
|
||||
- ARGS: --toolset=msvc-11.0 address-model=32
|
||||
- ARGS: --toolset=msvc-12.0 address-model=32
|
||||
- ARGS: --toolset=msvc-14.0 address-model=32
|
||||
- ARGS: --toolset=msvc-12.0 address-model=64
|
||||
- ARGS: --toolset=msvc-14.0 address-model=64
|
||||
- ARGS: --toolset=msvc-14.0 address-model=64 cxxflags=-std:c++latest
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
ARGS: --toolset=msvc-14.1 address-model=64
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
ARGS: --toolset=msvc-14.1 address-model=32
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
ARGS: --toolset=msvc-14.1 address-model=64 cxxflags=-std:c++latest
|
||||
- ARGS: --toolset=gcc address-model=64
|
||||
PATH: C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin;%PATH%
|
||||
- ARGS: --toolset=gcc address-model=64 cxxflags=-std=gnu++1z
|
||||
PATH: C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin;%PATH%
|
||||
- ARGS: --toolset=gcc address-model=32
|
||||
PATH: C:\mingw-w64\i686-5.3.0-posix-dwarf-rt_v4-rev0\mingw32\bin;%PATH%
|
||||
- ARGS: --toolset=gcc address-model=32 linkflags=-Wl,-allow-multiple-definition
|
||||
PATH: C:\MinGW\bin;%PATH%
|
||||
|
||||
- TOOLSET: msvc-9.0,msvc-10.0,msvc-11.0,msvc-12.0
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
- TOOLSET: msvc-14.0
|
||||
ADDRMD: 32,64
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
- TOOLSET: msvc-14.1
|
||||
CXXSTD: 14,17
|
||||
ADDRMD: 32,64
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
- TOOLSET: msvc-14.2
|
||||
ADDRMD: 32,64
|
||||
CXXSTD: 14,17
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
||||
- TOOLSET: clang-win
|
||||
ADDRMD: 32,64
|
||||
CXXSTD: 14,17
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
- TOOLSET: gcc
|
||||
CXXSTD: 03,11,14,1z
|
||||
ADDPATH: C:\cygwin\bin;
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
- TOOLSET: gcc
|
||||
CXXSTD: 03,11,14,1z
|
||||
ADDPATH: C:\cygwin64\bin;
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
- TOOLSET: gcc
|
||||
CXXSTD: 03,11,14,1z
|
||||
ADDPATH: C:\mingw\bin;
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
- TOOLSET: gcc
|
||||
CXXSTD: 03,11,14,1z
|
||||
ADDPATH: C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin;
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
- TOOLSET: gcc
|
||||
CXXSTD: 03,11,14,1z
|
||||
ADDPATH: C:\mingw-w64\x86_64-7.3.0-posix-seh-rt_v5-rev0\mingw64\bin;
|
||||
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||
|
||||
install:
|
||||
- set GIT_FETCH_JOBS=8
|
||||
- set BOOST_BRANCH=develop
|
||||
- if "%APPVEYOR_REPO_BRANCH%" == "master" set BOOST_BRANCH=master
|
||||
- cd ..
|
||||
- git clone -b %APPVEYOR_REPO_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root
|
||||
- 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 libs/core
|
||||
- git submodule update --init libs/detail
|
||||
- git submodule update --init libs/assert
|
||||
- git submodule update --init libs/static_assert
|
||||
- git submodule update --init libs/type_traits
|
||||
- git submodule update --init libs/mpl
|
||||
- git submodule update --init libs/preprocessor
|
||||
- git submodule update --init libs/multiprecision
|
||||
- git submodule update --init libs/math
|
||||
- git submodule update --init libs/rational
|
||||
- git submodule update --init libs/throw_exception
|
||||
- git submodule update --init libs/predef
|
||||
- git submodule update --init libs/lexical_cast
|
||||
- git submodule update --init libs/range
|
||||
- git submodule update --init libs/iterator
|
||||
- git submodule update --init libs/concept_check
|
||||
- git submodule update --init libs/numeric
|
||||
- git submodule update --init libs/array
|
||||
- git submodule update --init libs/container
|
||||
- git submodule update --init libs/move
|
||||
- git submodule update --init libs/functional
|
||||
- git submodule update --init libs/random
|
||||
- git submodule update --init libs/utility
|
||||
- git submodule init tools/build
|
||||
- git submodule init tools/boostdep
|
||||
- git submodule init tools/boost_install
|
||||
- git submodule init libs/headers
|
||||
- git submodule init libs/config
|
||||
- git submodule update --jobs %GIT_FETCH_JOBS%
|
||||
- xcopy /s /e /q %APPVEYOR_BUILD_FOLDER% libs\integer
|
||||
- bootstrap
|
||||
- b2 headers
|
||||
- python tools/boostdep/depinst/depinst.py --git_args "--jobs %GIT_FETCH_JOBS%" integer
|
||||
- cmd /c bootstrap
|
||||
- b2 -d0 headers
|
||||
|
||||
build: off
|
||||
|
||||
test_script:
|
||||
- cd libs\config\test
|
||||
- ..\..\..\b2 config_info_travis_install %ARGS%
|
||||
- config_info_travis
|
||||
- cd ..\..\integer\test
|
||||
- ..\..\..\b2 -j3 %ARGS% define=CI_SUPPRESS_KNOWN_ISSUES
|
||||
- PATH=%ADDPATH%%PATH%
|
||||
- if not "%CXXSTD%" == "" set CXXSTD=cxxstd=%CXXSTD%
|
||||
- if not "%ADDRMD%" == "" set ADDRMD=address-model=%ADDRMD%
|
||||
- b2 -j %NUMBER_OF_PROCESSORS% libs/integer/test toolset=%TOOLSET% %CXXSTD% %ADDRMD%
|
||||
|
@ -15,7 +15,7 @@ programming problems.
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace math
|
||||
namespace integer
|
||||
{
|
||||
|
||||
template < typename IntegerType >
|
||||
@ -53,10 +53,10 @@ programming problems.
|
||||
|
||||
[section GCD Function Object]
|
||||
|
||||
[*Header: ] [@../../../../boost/math/common_factor_rt.hpp <boost/math/common_factor_rt.hpp>]
|
||||
[*Header: ] [@../../../../boost/integer/common_factor_rt.hpp <boost/integer/common_factor_rt.hpp>]
|
||||
|
||||
template < typename IntegerType >
|
||||
class boost::math::gcd_evaluator
|
||||
class boost::integer::gcd_evaluator
|
||||
{
|
||||
public:
|
||||
// Types
|
||||
@ -65,12 +65,12 @@ programming problems.
|
||||
typedef IntegerType second_argument_type;
|
||||
|
||||
// Function object interface
|
||||
constexpr result_type operator ()(
|
||||
constexpr result_type operator ()(
|
||||
first_argument_type const &a,
|
||||
second_argument_type const &b ) const;
|
||||
};
|
||||
|
||||
The boost::math::gcd_evaluator class template defines a function object
|
||||
The boost::integer::gcd_evaluator class template defines a function object
|
||||
class to return the greatest common divisor of two integers.
|
||||
The template is parameterized by a single type, called IntegerType here.
|
||||
This type should be a numeric type that represents integers.
|
||||
@ -82,17 +82,17 @@ the GCD function template. If a numeric type wants to customize evaluations
|
||||
of its greatest common divisors, then the type should specialize on the
|
||||
gcd_evaluator class template.
|
||||
|
||||
Note that these function objects are `constexpr` in C++14 and later only.
|
||||
Note that these function objects are `constexpr` in C++14 and later only.
|
||||
They are also declared `noexcept` when appropriate.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section LCM Function Object]
|
||||
|
||||
[*Header: ] [@../../../../boost/math/common_factor_rt.hpp <boost/math/common_factor_rt.hpp>]
|
||||
[*Header: ] [@../../../../boost/integer/common_factor_rt.hpp <boost/integer/common_factor_rt.hpp>]
|
||||
|
||||
template < typename IntegerType >
|
||||
class boost::math::lcm_evaluator
|
||||
class boost::integer::lcm_evaluator
|
||||
{
|
||||
public:
|
||||
// Types
|
||||
@ -101,12 +101,12 @@ They are also declared `noexcept` when appropriate.
|
||||
typedef IntegerType second_argument_type;
|
||||
|
||||
// Function object interface
|
||||
constexpr result_type operator ()(
|
||||
constexpr result_type operator ()(
|
||||
first_argument_type const &a,
|
||||
second_argument_type const &b ) const;
|
||||
};
|
||||
|
||||
The boost::math::lcm_evaluator class template defines a function object
|
||||
The boost::integer::lcm_evaluator class template defines a function object
|
||||
class to return the least common multiple of two integers. The template
|
||||
is parameterized by a single type, called IntegerType here. This type
|
||||
should be a numeric type that represents integers. The result of the
|
||||
@ -126,13 +126,13 @@ They are also declared `noexcept` when appropriate.
|
||||
|
||||
[section:run_time Run-time GCD & LCM Determination]
|
||||
|
||||
[*Header: ] [@../../../../boost/math/common_factor_rt.hpp <boost/math/common_factor_rt.hpp>]
|
||||
[*Header: ] [@../../../../boost/integer/common_factor_rt.hpp <boost/integer/common_factor_rt.hpp>]
|
||||
|
||||
template < typename IntegerType >
|
||||
constexpr IntegerType boost::math::gcd( IntegerType const &a, IntegerType const &b );
|
||||
constexpr IntegerType boost::integer::gcd( IntegerType const &a, IntegerType const &b );
|
||||
|
||||
template < typename IntegerType >
|
||||
constexpr IntegerType boost::math::lcm( IntegerType const &a, IntegerType const &b );
|
||||
constexpr IntegerType boost::integer::lcm( IntegerType const &a, IntegerType const &b );
|
||||
|
||||
template < typename IntegerType, typename... Args >
|
||||
constexpr IntegerType gcd( IntegerType const &a, IntegerType const &b, Args const&... );
|
||||
@ -148,18 +148,18 @@ They are also declared `noexcept` when appropriate.
|
||||
std::pair<typename std::iterator_traits<I>::value_type, I>
|
||||
lcm_range(I first, I last);
|
||||
|
||||
The boost::math::gcd function template returns the greatest common
|
||||
The boost::integer::gcd function template returns the greatest common
|
||||
(nonnegative) divisor of the two integers passed to it.
|
||||
`boost::math::gcd_range` is the iteration of the above gcd algorithm over a
|
||||
range, returning the greatest common divisor of all the elements. The algorithm
|
||||
terminates when the gcd reaches unity or the end of the range. Thus it also
|
||||
returns the iterator after the last element inspected because this may not be
|
||||
`boost::integer::gcd_range` is the iteration of the above gcd algorithm over a
|
||||
range, returning the greatest common divisor of all the elements. The algorithm
|
||||
terminates when the gcd reaches unity or the end of the range. Thus it also
|
||||
returns the iterator after the last element inspected because this may not be
|
||||
equal to the end of the range. The variadic version of `gcd` behaves similarly
|
||||
but does not indicate which input value caused the gcd to reach unity.
|
||||
|
||||
The boost::math::lcm function template returns the least common
|
||||
The boost::integer::lcm function template returns the least common
|
||||
(nonnegative) multiple of the two integers passed to it.
|
||||
As with gcd, there are range and variadic versions of the function for
|
||||
As with gcd, there are range and variadic versions of the function for
|
||||
more than 2 arguments.
|
||||
|
||||
Note that these functions are constexpr in C++14 and later only.
|
||||
@ -171,17 +171,17 @@ They are also declared `noexcept` when appropriate.
|
||||
|
||||
[note These functions are deprecated in favor of constexpr `gcd` and `lcm` on C++14 capable compilers.]
|
||||
|
||||
[*Header: ] [@../../../../boost/math/common_factor_ct.hpp <boost/math/common_factor_ct.hpp>]
|
||||
[*Header: ] [@../../../../boost/integer/common_factor_ct.hpp <boost/integer/common_factor_ct.hpp>]
|
||||
|
||||
typedef ``['unspecified]`` static_gcd_type;
|
||||
|
||||
template < static_gcd_type Value1, static_gcd_type Value2 >
|
||||
struct boost::math::static_gcd : public mpl::integral_c<static_gcd_type, implementation_defined>
|
||||
struct boost::integer::static_gcd : public mpl::integral_c<static_gcd_type, implementation_defined>
|
||||
{
|
||||
};
|
||||
|
||||
template < static_gcd_type Value1, static_gcd_type Value2 >
|
||||
struct boost::math::static_lcm : public mpl::integral_c<static_gcd_type, implementation_defined>
|
||||
struct boost::integer::static_lcm : public mpl::integral_c<static_gcd_type, implementation_defined>
|
||||
{
|
||||
};
|
||||
|
||||
@ -190,7 +190,7 @@ for use in integral-constant-expressions by the compiler. Usually this
|
||||
the same type as `boost::uintmax_t`, but may fall back to being `unsigned long`
|
||||
for some older compilers.
|
||||
|
||||
The boost::math::static_gcd and boost::math::static_lcm class templates
|
||||
The boost::integer::static_gcd and boost::integer::static_lcm class templates
|
||||
take two value-based template parameters of the ['static_gcd_type] type
|
||||
and inherit from the type `boost::mpl::integral_c`.
|
||||
Inherited from the base class, they have a member /value/
|
||||
@ -201,7 +201,7 @@ is beyond the range of `static_gcd_type`.
|
||||
|
||||
[h3 Example]
|
||||
|
||||
#include <boost/math/common_factor.hpp>
|
||||
#include <boost/integer/common_factor.hpp>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <iostream>
|
||||
@ -212,28 +212,28 @@ is beyond the range of `static_gcd_type`.
|
||||
using std::endl;
|
||||
|
||||
cout << "The GCD and LCM of 6 and 15 are "
|
||||
<< boost::math::gcd(6, 15) << " and "
|
||||
<< boost::math::lcm(6, 15) << ", respectively."
|
||||
<< boost::integer::gcd(6, 15) << " and "
|
||||
<< boost::integer::lcm(6, 15) << ", respectively."
|
||||
<< endl;
|
||||
|
||||
cout << "The GCD and LCM of 8 and 9 are "
|
||||
<< boost::math::static_gcd<8, 9>::value
|
||||
<< boost::integer::static_gcd<8, 9>::value
|
||||
<< " and "
|
||||
<< boost::math::static_lcm<8, 9>::value
|
||||
<< boost::integer::static_lcm<8, 9>::value
|
||||
<< ", respectively." << endl;
|
||||
|
||||
int a[] = { 4, 5, 6 }, b[] = { 7, 8, 9 }, c[3];
|
||||
std::transform( a, a + 3, b, c, boost::math::gcd_evaluator<int>() );
|
||||
std::transform( a, a + 3, b, c, boost::integer::gcd_evaluator<int>() );
|
||||
std::copy( c, c + 3, std::ostream_iterator<int>(cout, " ") );
|
||||
}
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:gcd_header Header <boost/math/common_factor.hpp>]
|
||||
[section:gcd_header Header <boost/integer/common_factor.hpp>]
|
||||
|
||||
This header simply includes the headers
|
||||
[@../../../../boost/math/common_factor_ct.hpp <boost/math/common_factor_ct.hpp>]
|
||||
and [@../../../../boost/math/common_factor_rt.hpp <boost/math/common_factor_rt.hpp>].
|
||||
[@../../../../boost/integer/common_factor_ct.hpp <boost/integer/common_factor_ct.hpp>]
|
||||
and [@../../../../boost/integer/common_factor_rt.hpp <boost/integer/common_factor_rt.hpp>].
|
||||
|
||||
Note this is a legacy header: it used to contain the actual implementation,
|
||||
but the compile-time and run-time facilities
|
||||
@ -243,7 +243,7 @@ were moved to separate headers (since they were independent of each other).
|
||||
|
||||
[section:demo Demonstration Program]
|
||||
|
||||
The program [@../../../../libs/math/test/common_factor_test.cpp common_factor_test.cpp] is a demonstration of the results from
|
||||
The program [@../../../../libs/integer/test/common_factor_test.cpp common_factor_test.cpp] is a demonstration of the results from
|
||||
instantiating various examples of the run-time GCD and LCM function
|
||||
templates and the compile-time GCD and LCM class templates.
|
||||
(The run-time GCD and LCM class templates are tested indirectly through
|
||||
@ -256,13 +256,13 @@ the run-time function templates.)
|
||||
The greatest common divisor and least common multiple functions are
|
||||
greatly used in some numeric contexts, including some of the other
|
||||
Boost libraries. Centralizing these functions to one header improves
|
||||
code factoring and eases maintainence.
|
||||
code factoring and eases maintenance.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:gcd_history History]
|
||||
|
||||
* 24th April 2017 Moved to Jeremy Murphy's improved algorithms, added constexpr and noexcept support,
|
||||
* 24th April 2017 Moved to Jeremy Murphy's improved algorithms, added constexpr and noexcept support,
|
||||
added compiler intrinsic support, added variadic and range based versions of the algorithms.
|
||||
* 13 May 2013 Moved into main Boost.Math Quickbook documentation.
|
||||
* 17 Dec 2005: Converted documentation to Quickbook Format.
|
||||
@ -288,5 +288,3 @@ 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).
|
||||
]
|
||||
|
||||
|
||||
|
@ -1,49 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Removed from library: Standard Integer Types</title>
|
||||
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../index.html" title="Boost.Integer">
|
||||
<link rel="up" href="../index.html" title="Boost.Integer">
|
||||
<link rel="prev" href="history.html" title="History">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
|
||||
<td align="center"><a href="../../../../../index.html">Home</a></td>
|
||||
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||||
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="history.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="boost_integer.cstdint"></a><a class="link" href="cstdint.html" title="Removed from library: Standard Integer Types">Removed from library: Standard Integer
|
||||
Types</a>
|
||||
</h2></div></div></div>
|
||||
<p>
|
||||
The <a href="../../../../../libs/config/doc/html/boost_config/cstdint.html" target="_top">Boost.Config</a>
|
||||
module provides the typedefs useful for writing portable code that requires
|
||||
certain integer widths.
|
||||
</p>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2001-2009 Beman
|
||||
Dawes, Daryle Walker, Gennaro Prota, John Maddock<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="history.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -1,400 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Greatest Common Divisor and Least Common Multiple</title>
|
||||
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../index.html" title="Boost.Integer">
|
||||
<link rel="up" href="../index.html" title="Boost.Integer">
|
||||
<link rel="prev" href="integer.html" title="Integer Type Selection">
|
||||
<link rel="next" href="mask.html" title="Integer Masks">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
|
||||
<td align="center"><a href="../../../../../index.html">Home</a></td>
|
||||
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||||
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="integer.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="mask.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="boost_integer.gcd_lcm"></a><a class="link" href="gcd_lcm.html" title="Greatest Common Divisor and Least Common Multiple">Greatest Common Divisor and Least
|
||||
Common Multiple</a>
|
||||
</h2></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<dt><span class="section"><a href="gcd_lcm.html#boost_integer.gcd_lcm.introduction">Introduction</a></span></dt>
|
||||
<dt><span class="section"><a href="gcd_lcm.html#boost_integer.gcd_lcm.synopsis">Synopsis</a></span></dt>
|
||||
<dt><span class="section"><a href="gcd_lcm.html#boost_integer.gcd_lcm.gcd_function_object">GCD Function
|
||||
Object</a></span></dt>
|
||||
<dt><span class="section"><a href="gcd_lcm.html#boost_integer.gcd_lcm.lcm_function_object">LCM Function
|
||||
Object</a></span></dt>
|
||||
<dt><span class="section"><a href="gcd_lcm.html#boost_integer.gcd_lcm.run_time">Run-time GCD & LCM
|
||||
Determination</a></span></dt>
|
||||
<dt><span class="section"><a href="gcd_lcm.html#boost_integer.gcd_lcm.compile_time">Compile time GCD
|
||||
and LCM determination</a></span></dt>
|
||||
<dt><span class="section"><a href="gcd_lcm.html#boost_integer.gcd_lcm.gcd_header">Header <boost/math/common_factor.hpp></a></span></dt>
|
||||
<dt><span class="section"><a href="gcd_lcm.html#boost_integer.gcd_lcm.demo">Demonstration Program</a></span></dt>
|
||||
<dt><span class="section"><a href="gcd_lcm.html#boost_integer.gcd_lcm.rationale">Rationale</a></span></dt>
|
||||
<dt><span class="section"><a href="gcd_lcm.html#boost_integer.gcd_lcm.gcd_history">History</a></span></dt>
|
||||
<dt><span class="section"><a href="gcd_lcm.html#boost_integer.gcd_lcm.gcd_credits">Credits</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.gcd_lcm.introduction"></a><a class="link" href="gcd_lcm.html#boost_integer.gcd_lcm.introduction" title="Introduction">Introduction</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The class and function templates in <boost/math/common_factor.hpp>
|
||||
provide run-time and compile-time evaluation of the greatest common divisor
|
||||
(GCD) or least common multiple (LCM) of two integers. These facilities are
|
||||
useful for many numeric-oriented generic programming problems.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.gcd_lcm.synopsis"></a><a class="link" href="gcd_lcm.html#boost_integer.gcd_lcm.synopsis" title="Synopsis">Synopsis</a>
|
||||
</h3></div></div></div>
|
||||
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">namespace</span> <span class="identifier">math</span>
|
||||
<span class="special">{</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">IntegerType</span> <span class="special">></span>
|
||||
<span class="keyword">class</span> <span class="identifier">gcd_evaluator</span><span class="special">;</span>
|
||||
<span class="keyword">template</span> <span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">IntegerType</span> <span class="special">></span>
|
||||
<span class="keyword">class</span> <span class="identifier">lcm_evaluator</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">IntegerType</span> <span class="special">></span>
|
||||
<span class="keyword">constexpr</span> <span class="identifier">IntegerType</span> <span class="identifier">gcd</span><span class="special">(</span> <span class="identifier">IntegerType</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">a</span><span class="special">,</span> <span class="identifier">IntegerType</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">b</span> <span class="special">);</span>
|
||||
<span class="keyword">template</span> <span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">IntegerType</span> <span class="special">></span>
|
||||
<span class="keyword">constexpr</span> <span class="identifier">IntegerType</span> <span class="identifier">lcm</span><span class="special">(</span> <span class="identifier">IntegerType</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">a</span><span class="special">,</span> <span class="identifier">IntegerType</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">b</span> <span class="special">);</span>
|
||||
<span class="keyword">template</span> <span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">IntegerType</span><span class="special">,</span> <span class="keyword">typename</span><span class="special">...</span> <span class="identifier">Args</span> <span class="special">></span>
|
||||
<span class="keyword">constexpr</span> <span class="identifier">IntegerType</span> <span class="identifier">gcd</span><span class="special">(</span> <span class="identifier">IntegerType</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">a</span><span class="special">,</span> <span class="identifier">IntegerType</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">b</span><span class="special">,</span> <span class="identifier">Args</span> <span class="keyword">const</span><span class="special">&...</span> <span class="special">);</span>
|
||||
<span class="keyword">template</span> <span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">IntegerType</span><span class="special">,</span> <span class="keyword">typename</span><span class="special">...</span> <span class="identifier">Args</span> <span class="special">></span>
|
||||
<span class="keyword">constexpr</span> <span class="identifier">IntegerType</span> <span class="identifier">lcm</span><span class="special">(</span> <span class="identifier">IntegerType</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">a</span><span class="special">,</span> <span class="identifier">IntegerType</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">b</span><span class="special">,</span> <span class="identifier">Args</span> <span class="keyword">const</span><span class="special">&...</span> <span class="special">);</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">I</span><span class="special">></span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">iterator_traits</span><span class="special"><</span><span class="identifier">I</span><span class="special">>::</span><span class="identifier">value_type</span><span class="special">,</span> <span class="identifier">I</span><span class="special">></span>
|
||||
<span class="identifier">gcd_range</span><span class="special">(</span><span class="identifier">I</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">I</span> <span class="identifier">last</span><span class="special">);</span>
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">I</span><span class="special">></span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">iterator_traits</span><span class="special"><</span><span class="identifier">I</span><span class="special">>::</span><span class="identifier">value_type</span><span class="special">,</span> <span class="identifier">I</span><span class="special">></span>
|
||||
<span class="identifier">lcm_range</span><span class="special">(</span><span class="identifier">I</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">I</span> <span class="identifier">last</span><span class="special">);</span>
|
||||
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>see-below</em></span> <span class="identifier">static_gcd_type</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span> <span class="identifier">static_gcd_type</span> <span class="identifier">Value1</span><span class="special">,</span> <span class="identifier">static_gcd_type</span> <span class="identifier">Value2</span> <span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">static_gcd</span><span class="special">;</span>
|
||||
<span class="keyword">template</span> <span class="special"><</span> <span class="identifier">static_gcd_type</span> <span class="identifier">Value1</span><span class="special">,</span> <span class="identifier">static_gcd_type</span> <span class="identifier">Value2</span> <span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">static_lcm</span><span class="special">;</span>
|
||||
|
||||
<span class="special">}</span>
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.gcd_lcm.gcd_function_object"></a><a class="link" href="gcd_lcm.html#boost_integer.gcd_lcm.gcd_function_object" title="GCD Function Object">GCD Function
|
||||
Object</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
<span class="bold"><strong>Header: </strong></span> <a href="../../../../../boost/math/common_factor_rt.hpp" target="_top"><boost/math/common_factor_rt.hpp></a>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">IntegerType</span> <span class="special">></span>
|
||||
<span class="keyword">class</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">gcd_evaluator</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">public</span><span class="special">:</span>
|
||||
<span class="comment">// Types</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">IntegerType</span> <span class="identifier">result_type</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">IntegerType</span> <span class="identifier">first_argument_type</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">IntegerType</span> <span class="identifier">second_argument_type</span><span class="special">;</span>
|
||||
|
||||
<span class="comment">// Function object interface</span>
|
||||
<span class="keyword">constexpr</span> <span class="identifier">result_type</span> <span class="keyword">operator</span> <span class="special">()(</span>
|
||||
<span class="identifier">first_argument_type</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">a</span><span class="special">,</span>
|
||||
<span class="identifier">second_argument_type</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">b</span> <span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
</pre>
|
||||
<p>
|
||||
The boost::math::gcd_evaluator class template defines a function object class
|
||||
to return the greatest common divisor of two integers. The template is parameterized
|
||||
by a single type, called IntegerType here. This type should be a numeric
|
||||
type that represents integers. The result of the function object is always
|
||||
nonnegative, even if either of the operator arguments is negative.
|
||||
</p>
|
||||
<p>
|
||||
This function object class template is used in the corresponding version
|
||||
of the GCD function template. If a numeric type wants to customize evaluations
|
||||
of its greatest common divisors, then the type should specialize on the gcd_evaluator
|
||||
class template.
|
||||
</p>
|
||||
<p>
|
||||
Note that these function objects are <code class="computeroutput"><span class="keyword">constexpr</span></code>
|
||||
in C++14 and later only. They are also declared <code class="computeroutput"><span class="keyword">noexcept</span></code>
|
||||
when appropriate.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.gcd_lcm.lcm_function_object"></a><a class="link" href="gcd_lcm.html#boost_integer.gcd_lcm.lcm_function_object" title="LCM Function Object">LCM Function
|
||||
Object</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
<span class="bold"><strong>Header: </strong></span> <a href="../../../../../boost/math/common_factor_rt.hpp" target="_top"><boost/math/common_factor_rt.hpp></a>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">IntegerType</span> <span class="special">></span>
|
||||
<span class="keyword">class</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">lcm_evaluator</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">public</span><span class="special">:</span>
|
||||
<span class="comment">// Types</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">IntegerType</span> <span class="identifier">result_type</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">IntegerType</span> <span class="identifier">first_argument_type</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">IntegerType</span> <span class="identifier">second_argument_type</span><span class="special">;</span>
|
||||
|
||||
<span class="comment">// Function object interface</span>
|
||||
<span class="keyword">constexpr</span> <span class="identifier">result_type</span> <span class="keyword">operator</span> <span class="special">()(</span>
|
||||
<span class="identifier">first_argument_type</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">a</span><span class="special">,</span>
|
||||
<span class="identifier">second_argument_type</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">b</span> <span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
</pre>
|
||||
<p>
|
||||
The boost::math::lcm_evaluator class template defines a function object class
|
||||
to return the least common multiple of two integers. The template is parameterized
|
||||
by a single type, called IntegerType here. This type should be a numeric
|
||||
type that represents integers. The result of the function object is always
|
||||
nonnegative, even if either of the operator arguments is negative. If the
|
||||
least common multiple is beyond the range of the integer type, the results
|
||||
are undefined.
|
||||
</p>
|
||||
<p>
|
||||
This function object class template is used in the corresponding version
|
||||
of the LCM function template. If a numeric type wants to customize evaluations
|
||||
of its least common multiples, then the type should specialize on the lcm_evaluator
|
||||
class template.
|
||||
</p>
|
||||
<p>
|
||||
Note that these function objects are constexpr in C++14 and later only. They
|
||||
are also declared <code class="computeroutput"><span class="keyword">noexcept</span></code> when
|
||||
appropriate.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.gcd_lcm.run_time"></a><a class="link" href="gcd_lcm.html#boost_integer.gcd_lcm.run_time" title="Run-time GCD & LCM Determination">Run-time GCD & LCM
|
||||
Determination</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
<span class="bold"><strong>Header: </strong></span> <a href="../../../../../boost/math/common_factor_rt.hpp" target="_top"><boost/math/common_factor_rt.hpp></a>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">IntegerType</span> <span class="special">></span>
|
||||
<span class="keyword">constexpr</span> <span class="identifier">IntegerType</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">gcd</span><span class="special">(</span> <span class="identifier">IntegerType</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">a</span><span class="special">,</span> <span class="identifier">IntegerType</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">b</span> <span class="special">);</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">IntegerType</span> <span class="special">></span>
|
||||
<span class="keyword">constexpr</span> <span class="identifier">IntegerType</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">lcm</span><span class="special">(</span> <span class="identifier">IntegerType</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">a</span><span class="special">,</span> <span class="identifier">IntegerType</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">b</span> <span class="special">);</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">IntegerType</span><span class="special">,</span> <span class="keyword">typename</span><span class="special">...</span> <span class="identifier">Args</span> <span class="special">></span>
|
||||
<span class="keyword">constexpr</span> <span class="identifier">IntegerType</span> <span class="identifier">gcd</span><span class="special">(</span> <span class="identifier">IntegerType</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">a</span><span class="special">,</span> <span class="identifier">IntegerType</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">b</span><span class="special">,</span> <span class="identifier">Args</span> <span class="keyword">const</span><span class="special">&...</span> <span class="special">);</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">IntegerType</span><span class="special">,</span> <span class="keyword">typename</span><span class="special">...</span> <span class="identifier">Args</span> <span class="special">></span>
|
||||
<span class="keyword">constexpr</span> <span class="identifier">IntegerType</span> <span class="identifier">lcm</span><span class="special">(</span> <span class="identifier">IntegerType</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">a</span><span class="special">,</span> <span class="identifier">IntegerType</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">b</span><span class="special">,</span> <span class="identifier">Args</span> <span class="keyword">const</span><span class="special">&...</span> <span class="special">);</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">I</span><span class="special">></span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">iterator_traits</span><span class="special"><</span><span class="identifier">I</span><span class="special">>::</span><span class="identifier">value_type</span><span class="special">,</span> <span class="identifier">I</span><span class="special">></span>
|
||||
<span class="identifier">gcd_range</span><span class="special">(</span><span class="identifier">I</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">I</span> <span class="identifier">last</span><span class="special">);</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">I</span><span class="special">></span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">iterator_traits</span><span class="special"><</span><span class="identifier">I</span><span class="special">>::</span><span class="identifier">value_type</span><span class="special">,</span> <span class="identifier">I</span><span class="special">></span>
|
||||
<span class="identifier">lcm_range</span><span class="special">(</span><span class="identifier">I</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">I</span> <span class="identifier">last</span><span class="special">);</span>
|
||||
</pre>
|
||||
<p>
|
||||
The boost::math::gcd function template returns the greatest common (nonnegative)
|
||||
divisor of the two integers passed to it. <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">gcd_range</span></code>
|
||||
is the iteration of the above gcd algorithm over a range, returning the greatest
|
||||
common divisor of all the elements. The algorithm terminates when the gcd
|
||||
reaches unity or the end of the range. Thus it also returns the iterator
|
||||
after the last element inspected because this may not be equal to the end
|
||||
of the range. The variadic version of <code class="computeroutput"><span class="identifier">gcd</span></code>
|
||||
behaves similarly but does not indicate which input value caused the gcd
|
||||
to reach unity.
|
||||
</p>
|
||||
<p>
|
||||
The boost::math::lcm function template returns the least common (nonnegative)
|
||||
multiple of the two integers passed to it. As with gcd, there are range and
|
||||
variadic versions of the function for more than 2 arguments.
|
||||
</p>
|
||||
<p>
|
||||
Note that these functions are constexpr in C++14 and later only. They are
|
||||
also declared <code class="computeroutput"><span class="keyword">noexcept</span></code> when
|
||||
appropriate.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.gcd_lcm.compile_time"></a><a class="link" href="gcd_lcm.html#boost_integer.gcd_lcm.compile_time" title="Compile time GCD and LCM determination">Compile time GCD
|
||||
and LCM determination</a>
|
||||
</h3></div></div></div>
|
||||
<div class="note"><table border="0" summary="Note">
|
||||
<tr>
|
||||
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../doc/src/images/note.png"></td>
|
||||
<th align="left">Note</th>
|
||||
</tr>
|
||||
<tr><td align="left" valign="top"><p>
|
||||
These functions are deprecated in favor of constexpr <code class="computeroutput"><span class="identifier">gcd</span></code>
|
||||
and <code class="computeroutput"><span class="identifier">lcm</span></code> on C++14 capable
|
||||
compilers.
|
||||
</p></td></tr>
|
||||
</table></div>
|
||||
<p>
|
||||
<span class="bold"><strong>Header: </strong></span> <a href="../../../../../boost/math/common_factor_ct.hpp" target="_top"><boost/math/common_factor_ct.hpp></a>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">typedef</span> <span class="emphasis"><em>unspecified</em></span> <span class="identifier">static_gcd_type</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span> <span class="identifier">static_gcd_type</span> <span class="identifier">Value1</span><span class="special">,</span> <span class="identifier">static_gcd_type</span> <span class="identifier">Value2</span> <span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">static_gcd</span> <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">mpl</span><span class="special">::</span><span class="identifier">integral_c</span><span class="special"><</span><span class="identifier">static_gcd_type</span><span class="special">,</span> <span class="identifier">implementation_defined</span><span class="special">></span>
|
||||
<span class="special">{</span>
|
||||
<span class="special">};</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span> <span class="identifier">static_gcd_type</span> <span class="identifier">Value1</span><span class="special">,</span> <span class="identifier">static_gcd_type</span> <span class="identifier">Value2</span> <span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">static_lcm</span> <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">mpl</span><span class="special">::</span><span class="identifier">integral_c</span><span class="special"><</span><span class="identifier">static_gcd_type</span><span class="special">,</span> <span class="identifier">implementation_defined</span><span class="special">></span>
|
||||
<span class="special">{</span>
|
||||
<span class="special">};</span>
|
||||
</pre>
|
||||
<p>
|
||||
The type <code class="computeroutput"><span class="identifier">static_gcd_type</span></code>
|
||||
is the widest unsigned-integer-type that is supported for use in integral-constant-expressions
|
||||
by the compiler. Usually this the same type as <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">uintmax_t</span></code>,
|
||||
but may fall back to being <code class="computeroutput"><span class="keyword">unsigned</span>
|
||||
<span class="keyword">long</span></code> for some older compilers.
|
||||
</p>
|
||||
<p>
|
||||
The boost::math::static_gcd and boost::math::static_lcm class templates take
|
||||
two value-based template parameters of the <span class="emphasis"><em>static_gcd_type</em></span>
|
||||
type and inherit from the type <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">integral_c</span></code>. Inherited from the base class,
|
||||
they have a member <span class="emphasis"><em>value</em></span> that is the greatest common
|
||||
factor or least common multiple, respectively, of the template arguments.
|
||||
A compile-time error will occur if the least common multiple is beyond the
|
||||
range of <code class="computeroutput"><span class="identifier">static_gcd_type</span></code>.
|
||||
</p>
|
||||
<h4>
|
||||
<a name="boost_integer.gcd_lcm.compile_time.h0"></a>
|
||||
<span class="phrase"><a name="boost_integer.gcd_lcm.compile_time.example"></a></span><a class="link" href="gcd_lcm.html#boost_integer.gcd_lcm.compile_time.example">Example</a>
|
||||
</h4>
|
||||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">common_factor</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">algorithm</span><span class="special">></span>
|
||||
<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iterator</span><span class="special">></span>
|
||||
<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iostream</span><span class="special">></span>
|
||||
|
||||
<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span><span class="special">;</span>
|
||||
<span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
|
||||
<span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"The GCD and LCM of 6 and 15 are "</span>
|
||||
<span class="special"><<</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">gcd</span><span class="special">(</span><span class="number">6</span><span class="special">,</span> <span class="number">15</span><span class="special">)</span> <span class="special"><<</span> <span class="string">" and "</span>
|
||||
<span class="special"><<</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">lcm</span><span class="special">(</span><span class="number">6</span><span class="special">,</span> <span class="number">15</span><span class="special">)</span> <span class="special"><<</span> <span class="string">", respectively."</span>
|
||||
<span class="special"><<</span> <span class="identifier">endl</span><span class="special">;</span>
|
||||
|
||||
<span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"The GCD and LCM of 8 and 9 are "</span>
|
||||
<span class="special"><<</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">static_gcd</span><span class="special"><</span><span class="number">8</span><span class="special">,</span> <span class="number">9</span><span class="special">>::</span><span class="identifier">value</span>
|
||||
<span class="special"><<</span> <span class="string">" and "</span>
|
||||
<span class="special"><<</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">static_lcm</span><span class="special"><</span><span class="number">8</span><span class="special">,</span> <span class="number">9</span><span class="special">>::</span><span class="identifier">value</span>
|
||||
<span class="special"><<</span> <span class="string">", respectively."</span> <span class="special"><<</span> <span class="identifier">endl</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">int</span> <span class="identifier">a</span><span class="special">[]</span> <span class="special">=</span> <span class="special">{</span> <span class="number">4</span><span class="special">,</span> <span class="number">5</span><span class="special">,</span> <span class="number">6</span> <span class="special">},</span> <span class="identifier">b</span><span class="special">[]</span> <span class="special">=</span> <span class="special">{</span> <span class="number">7</span><span class="special">,</span> <span class="number">8</span><span class="special">,</span> <span class="number">9</span> <span class="special">},</span> <span class="identifier">c</span><span class="special">[</span><span class="number">3</span><span class="special">];</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">transform</span><span class="special">(</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">a</span> <span class="special">+</span> <span class="number">3</span><span class="special">,</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">c</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">gcd_evaluator</span><span class="special"><</span><span class="keyword">int</span><span class="special">>()</span> <span class="special">);</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">copy</span><span class="special">(</span> <span class="identifier">c</span><span class="special">,</span> <span class="identifier">c</span> <span class="special">+</span> <span class="number">3</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">ostream_iterator</span><span class="special"><</span><span class="keyword">int</span><span class="special">>(</span><span class="identifier">cout</span><span class="special">,</span> <span class="string">" "</span><span class="special">)</span> <span class="special">);</span>
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.gcd_lcm.gcd_header"></a><a class="link" href="gcd_lcm.html#boost_integer.gcd_lcm.gcd_header" title="Header <boost/math/common_factor.hpp>">Header <boost/math/common_factor.hpp></a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
This header simply includes the headers <a href="../../../../../boost/math/common_factor_ct.hpp" target="_top"><boost/math/common_factor_ct.hpp></a>
|
||||
and <a href="../../../../../boost/math/common_factor_rt.hpp" target="_top"><boost/math/common_factor_rt.hpp></a>.
|
||||
</p>
|
||||
<p>
|
||||
Note this is a legacy header: it used to contain the actual implementation,
|
||||
but the compile-time and run-time facilities were moved to separate headers
|
||||
(since they were independent of each other).
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.gcd_lcm.demo"></a><a class="link" href="gcd_lcm.html#boost_integer.gcd_lcm.demo" title="Demonstration Program">Demonstration Program</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The program <a href="../../../../../libs/math/test/common_factor_test.cpp" target="_top">common_factor_test.cpp</a>
|
||||
is a demonstration of the results from instantiating various examples of
|
||||
the run-time GCD and LCM function templates and the compile-time GCD and
|
||||
LCM class templates. (The run-time GCD and LCM class templates are tested
|
||||
indirectly through the run-time function templates.)
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.gcd_lcm.rationale"></a><a class="link" href="gcd_lcm.html#boost_integer.gcd_lcm.rationale" title="Rationale">Rationale</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The greatest common divisor and least common multiple functions are greatly
|
||||
used in some numeric contexts, including some of the other Boost libraries.
|
||||
Centralizing these functions to one header improves code factoring and eases
|
||||
maintainence.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.gcd_lcm.gcd_history"></a><a class="link" href="gcd_lcm.html#boost_integer.gcd_lcm.gcd_history" title="History">History</a>
|
||||
</h3></div></div></div>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
24th April 2017 Moved to Jeremy Murphy's improved algorithms, added constexpr
|
||||
and noexcept support, added compiler intrinsic support, added variadic
|
||||
and range based versions of the algorithms.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
13 May 2013 Moved into main Boost.Math Quickbook documentation.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
17 Dec 2005: Converted documentation to Quickbook Format.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
2 Jul 2002: Compile-time and run-time items separated to new headers.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
7 Nov 2001: Initial version
|
||||
</li>
|
||||
</ul></div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.gcd_lcm.gcd_credits"></a><a class="link" href="gcd_lcm.html#boost_integer.gcd_lcm.gcd_credits" title="Credits">Credits</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The author of the Boost compilation of GCD and LCM computations is Daryle
|
||||
Walker. The code was prompted by existing code hiding in the implementations
|
||||
of Paul Moore's rational library and Steve Cleary's pool library. The code
|
||||
had updates by Helmut Zeisel.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2001-2009 Beman
|
||||
Dawes, Daryle Walker, Gennaro Prota, John Maddock<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="integer.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="mask.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -1,90 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>History</title>
|
||||
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../index.html" title="Boost.Integer">
|
||||
<link rel="up" href="../index.html" title="Boost.Integer">
|
||||
<link rel="prev" href="minmax.html" title="Compile time min/max calculation">
|
||||
<link rel="next" href="cstdint.html" title="Removed from library: Standard Integer Types">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
|
||||
<td align="center"><a href="../../../../../index.html">Home</a></td>
|
||||
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||||
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="minmax.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="cstdint.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="boost_integer.history"></a><a class="link" href="history.html" title="History">History</a>
|
||||
</h2></div></div></div>
|
||||
<h5>
|
||||
<a name="boost_integer.history.h0"></a>
|
||||
<span class="phrase"><a name="boost_integer.history.1_56_0"></a></span><a class="link" href="history.html#boost_integer.history.1_56_0">1.56.0</a>
|
||||
</h5>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
|
||||
Moved <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">cstdint</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code> into <a href="../../../../../libs/config/index.html" target="_top">Boost.Config</a>.
|
||||
</li></ul></div>
|
||||
<h5>
|
||||
<a name="boost_integer.history.h1"></a>
|
||||
<span class="phrase"><a name="boost_integer.history.1_42_0"></a></span><a class="link" href="history.html#boost_integer.history.1_42_0">1.42.0</a>
|
||||
</h5>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
Reverted Trunk to release branch state (i.e. a "known good state").
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Fixed issues: <a href="https://svn.boost.org/trac/boost/ticket/653" target="_top">653</a>,
|
||||
<a href="https://svn.boost.org/trac/boost/ticket/3084" target="_top">3084</a>,
|
||||
<a href="https://svn.boost.org/trac/boost/ticket/3177" target="_top">3177</a>,
|
||||
<a href="https://svn.boost.org/trac/boost/ticket/3180" target="_top">3180</a>,
|
||||
<a href="https://svn.boost.org/trac/boost/ticket/3548" target="_top">3568</a>,
|
||||
<a href="https://svn.boost.org/trac/boost/ticket/3657" target="_top">3657</a>,
|
||||
<a href="https://svn.boost.org/trac/boost/ticket/2134" target="_top">2134</a>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Added long long support to <code class="literal">boost::static_log2</code>, <code class="literal">boost::static_signed_min</code>,
|
||||
<code class="literal">boost::static_signed_max</code>, <code class="literal">boost::static_unsigned_min</code><code class="literal">boost::static_unsigned_max</code>,
|
||||
when available.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
The argument type and the result type of <code class="literal">boost::static_signed_min</code>
|
||||
etc are now typedef'd. Formerly, they were hardcoded as <code class="literal">unsigned
|
||||
long</code> and <code class="literal">int</code> respectively. Please, use the
|
||||
provided typedefs in new code (and update old code as soon as possible).
|
||||
</li>
|
||||
</ul></div>
|
||||
<h5>
|
||||
<a name="boost_integer.history.h2"></a>
|
||||
<span class="phrase"><a name="boost_integer.history.1_32_0"></a></span><a class="link" href="history.html#boost_integer.history.1_32_0">1.32.0</a>
|
||||
</h5>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
|
||||
The argument type and the result type of <code class="literal">boost::static_log2</code>
|
||||
are now typedef'd. Formerly, they were hardcoded as <code class="literal">unsigned long</code>
|
||||
and <code class="literal">int</code> respectively. Please, use the provided typedefs
|
||||
in new code (and update old code as soon as possible).
|
||||
</li></ul></div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2001-2009 Beman
|
||||
Dawes, Daryle Walker, Gennaro Prota, John Maddock<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="minmax.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="cstdint.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -1,432 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Integer Type Selection</title>
|
||||
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../index.html" title="Boost.Integer">
|
||||
<link rel="up" href="../index.html" title="Boost.Integer">
|
||||
<link rel="prev" href="traits.html" title="Integer Traits">
|
||||
<link rel="next" href="gcd_lcm.html" title="Greatest Common Divisor and Least Common Multiple">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
|
||||
<td align="center"><a href="../../../../../index.html">Home</a></td>
|
||||
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||||
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="traits.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="gcd_lcm.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="boost_integer.integer"></a><a class="link" href="integer.html" title="Integer Type Selection">Integer Type Selection</a>
|
||||
</h2></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<dt><span class="section"><a href="integer.html#boost_integer.integer.synopsis">Synopsis</a></span></dt>
|
||||
<dt><span class="section"><a href="integer.html#boost_integer.integer.easiest">Easiest-to-Manipulate
|
||||
Types</a></span></dt>
|
||||
<dt><span class="section"><a href="integer.html#boost_integer.integer.sized">Sized Types</a></span></dt>
|
||||
<dt><span class="section"><a href="integer.html#boost_integer.integer.example">Example</a></span></dt>
|
||||
<dt><span class="section"><a href="integer.html#boost_integer.integer.demonstration_program">Demonstration
|
||||
Program</a></span></dt>
|
||||
<dt><span class="section"><a href="integer.html#boost_integer.integer.rationale">Rationale</a></span></dt>
|
||||
<dt><span class="section"><a href="integer.html#boost_integer.integer.alternative">Alternative</a></span></dt>
|
||||
<dt><span class="section"><a href="integer.html#boost_integer.integer.credits">Credits</a></span></dt>
|
||||
</dl></div>
|
||||
<p>
|
||||
The <a href="../../../../../boost/integer.hpp" target="_top"><boost/integer.hpp></a>
|
||||
type selection templates allow integer types to be selected based on desired
|
||||
characteristics such as number of bits or maximum value. This facility is particularly
|
||||
useful for solving generic programming problems.
|
||||
</p>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.integer.synopsis"></a><a class="link" href="integer.html#boost_integer.integer.synopsis" title="Synopsis">Synopsis</a>
|
||||
</h3></div></div></div>
|
||||
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span>
|
||||
<span class="special">{</span>
|
||||
<span class="comment">// fast integers from least integers</span>
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">LeastInt</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">int_fast_t</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span> <span class="identifier">type</span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
|
||||
<span class="comment">// signed</span>
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">int</span> <span class="identifier">Bits</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">int_t</span>
|
||||
<span class="special">{</span>
|
||||
<span class="comment">/* Member exact may or may not be defined depending upon Bits */</span>
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span> <span class="identifier">exact</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span> <span class="identifier">least</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">int_fast_t</span><span class="special"><</span><span class="identifier">least</span><span class="special">>::</span><span class="identifier">fast</span> <span class="identifier">fast</span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
|
||||
<span class="comment">// unsigned</span>
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">int</span> <span class="identifier">Bits</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">uint_t</span>
|
||||
<span class="special">{</span>
|
||||
<span class="comment">/* Member exact may or may not be defined depending upon Bits */</span>
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span> <span class="identifier">exact</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span> <span class="identifier">least</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">int_fast_t</span><span class="special"><</span><span class="identifier">least</span><span class="special">>::</span><span class="identifier">fast</span> <span class="identifier">fast</span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
|
||||
<span class="comment">// signed</span>
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">long</span> <span class="keyword">long</span> <span class="identifier">MaxValue</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">int_max_value_t</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span> <span class="identifier">least</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">int_fast_t</span><span class="special"><</span><span class="identifier">least</span><span class="special">>::</span><span class="identifier">fast</span> <span class="identifier">fast</span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">long</span> <span class="keyword">long</span> <span class="identifier">MinValue</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">int_min_value_t</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span> <span class="identifier">least</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">int_fast_t</span><span class="special"><</span><span class="identifier">least</span><span class="special">>::</span><span class="identifier">fast</span> <span class="identifier">fast</span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
|
||||
<span class="comment">// unsigned</span>
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">unsigned</span> <span class="keyword">long</span> <span class="keyword">long</span> <span class="identifier">Value</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">uint_value_t</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span> <span class="identifier">least</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">int_fast_t</span><span class="special"><</span><span class="identifier">least</span><span class="special">>::</span><span class="identifier">fast</span> <span class="identifier">fast</span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
<span class="special">}</span> <span class="comment">// namespace boost</span>
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.integer.easiest"></a><a class="link" href="integer.html#boost_integer.integer.easiest" title="Easiest-to-Manipulate Types">Easiest-to-Manipulate
|
||||
Types</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The <code class="literal">int_fast_t</code> class template maps its input type to the
|
||||
next-largest type that the processor can manipulate the easiest, or to itself
|
||||
if the input type is already an easy-to-manipulate type. For instance, processing
|
||||
a bunch of <code class="literal">char</code> objects may go faster if they were converted
|
||||
to <code class="literal">int</code> objects before processing. The input type, passed
|
||||
as the only template parameter, must be a built-in integral type, except
|
||||
<code class="literal">bool</code>. Unsigned integral types can be used, as well as
|
||||
signed integral types. The output type is given as the nested type <code class="literal">fast</code>.
|
||||
</p>
|
||||
<p>
|
||||
<span class="bold"><strong>Implementation Notes:</strong></span> By default, the output
|
||||
type is identical to the input type. Eventually, this code's implementation
|
||||
should be customized for each platform to give accurate mappings between
|
||||
the built-in types and the easiest-to-manipulate built-in types. Also, there
|
||||
is no guarantee that the output type actually is easier to manipulate than
|
||||
the input type.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.integer.sized"></a><a class="link" href="integer.html#boost_integer.integer.sized" title="Sized Types">Sized Types</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The <code class="literal">int_t</code>, <code class="literal">uint_t</code>, <code class="literal">int_max_value_t</code>,
|
||||
<code class="literal">int_min_value_t</code>, and <code class="literal">uint_value_t</code> class
|
||||
templates find the most appropiate built-in integral type for the given template
|
||||
parameter. This type is given by the nested type <code class="literal">least</code>.
|
||||
The easiest-to-manipulate version of that type is given by the nested type
|
||||
<code class="literal">fast</code>. The following table describes each template's criteria.
|
||||
</p>
|
||||
<div class="table">
|
||||
<a name="boost_integer.integer.sized.criteria_for_the_sized_type_class_templates"></a><p class="title"><b>Table 1. Criteria for the Sized Type Class Templates</b></p>
|
||||
<div class="table-contents"><table class="table" summary="Criteria for the Sized Type Class Templates">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
<p>
|
||||
Class Template
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Template Parameter Mapping
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">boost::int_t<N>::least</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
The smallest, built-in, signed integral type with at least <span class="emphasis"><em>N</em></span>
|
||||
bits, including the sign bit. The parameter should be a positive
|
||||
number. A compile-time error results if the parameter is larger
|
||||
than the number of bits in the largest integer type.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">boost::int_t<N>::fast</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
The easiest-to-manipulate, built-in, signed integral type with
|
||||
at least <span class="emphasis"><em>N</em></span> bits, including the sign bit. The
|
||||
parameter should be a positive number. A compile-time error results
|
||||
if the parameter is larger than the number of bits in the largest
|
||||
integer type.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">boost::int_t<N>::exact</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
A built-in, signed integral type with exactly <span class="emphasis"><em>N</em></span>
|
||||
bits, including the sign bit. The parameter should be a positive
|
||||
number. Note that the member <span class="emphasis"><em>exact</em></span> is defined
|
||||
<span class="bold"><strong>only</strong></span> if there exists a type with
|
||||
exactly <span class="emphasis"><em>N</em></span> bits.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">boost::uint_t<N>::least</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
The smallest, built-in, unsigned integral type with at least <span class="emphasis"><em>N</em></span>
|
||||
bits. The parameter should be a positive number. A compile-time
|
||||
error results if the parameter is larger than the number of bits
|
||||
in the largest integer type.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">boost::uint_t<N>::fast</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
The easiest-to-manipulate, built-in, unsigned integral type with
|
||||
at least <span class="emphasis"><em>N</em></span> bits. The parameter should be a
|
||||
positive number. A compile-time error results if the parameter
|
||||
is larger than the number of bits in the largest integer type.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">boost::uint_t<N>::exact</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
A built-in, unsigned integral type with exactly <span class="emphasis"><em>N</em></span>
|
||||
bits. The parameter should be a positive number. A compile-time
|
||||
error results if the parameter is larger than the number of bits
|
||||
in the largest integer type. Note that the member <span class="emphasis"><em>exact</em></span>
|
||||
is defined <span class="bold"><strong>only</strong></span> if there exists
|
||||
a type with exactly N bits.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">boost::int_max_value_t<V>::last</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
The smallest, built-in, signed integral type that can hold all
|
||||
the values in the inclusive range <span class="emphasis"><em>0 - V</em></span>. The
|
||||
parameter should be a positive number.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">boost::int_max_value_t<V>::fast</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
The easiest-to-manipulate, built-in, signed integral type that
|
||||
can hold all the values in the inclusive range <span class="emphasis"><em>0 - V</em></span>.
|
||||
The parameter should be a positive number.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">boost::int_min_value_t<V>::least</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
The smallest, built-in, signed integral type that can hold all
|
||||
the values in the inclusive range <span class="emphasis"><em>V - 0</em></span>. The
|
||||
parameter should be a negative number.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">boost::int_min_value_t<V>::fast</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
The easiest-to-manipulate, built-in, signed integral type that
|
||||
can hold all the values in the inclusive range <span class="emphasis"><em>V - 0</em></span>.
|
||||
The parameter should be a negative number.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">boost::uint_value_t<V>::least</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
The smallest, built-in, unsigned integral type that can hold all
|
||||
positive values up to and including <span class="emphasis"><em>V</em></span>. The
|
||||
parameter should be a positive number.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">boost::uint_value_t<V>::fast</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
The easiest-to-manipulate, built-in, unsigned integral type that
|
||||
can hold all positive values up to and including <span class="emphasis"><em>V</em></span>.
|
||||
The parameter should be a positive number.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
</div>
|
||||
<br class="table-break">
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.integer.example"></a><a class="link" href="integer.html#boost_integer.integer.example" title="Example">Example</a>
|
||||
</h3></div></div></div>
|
||||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">integer</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
<span class="comment">//...</span>
|
||||
|
||||
<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
|
||||
<span class="special">{</span>
|
||||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">int_t</span><span class="special"><</span><span class="number">24</span><span class="special">>::</span><span class="identifier">least</span> <span class="identifier">my_var</span><span class="special">;</span> <span class="comment">// my_var has at least 24-bits</span>
|
||||
<span class="comment">//...</span>
|
||||
<span class="comment">// This one is guarenteed not to be truncated:</span>
|
||||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">int_max_value_t</span><span class="special"><</span><span class="number">1000</span><span class="special">>::</span><span class="identifier">least</span> <span class="identifier">my1000</span> <span class="special">=</span> <span class="number">1000</span><span class="special">;</span>
|
||||
<span class="comment">//...</span>
|
||||
<span class="comment">// This one is guarenteed not to be truncated, and as fast</span>
|
||||
<span class="comment">// to manipulate as possible, its size may be greater than</span>
|
||||
<span class="comment">// that of my1000:</span>
|
||||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">int_max_value_t</span><span class="special"><</span><span class="number">1000</span><span class="special">>::</span><span class="identifier">fast</span> <span class="identifier">my_fast1000</span> <span class="special">=</span> <span class="number">1000</span><span class="special">;</span>
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.integer.demonstration_program"></a><a class="link" href="integer.html#boost_integer.integer.demonstration_program" title="Demonstration Program">Demonstration
|
||||
Program</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The program <a href="../../../test/integer_test.cpp" target="_top">integer_test.cpp</a>
|
||||
is a simplistic demonstration of the results from instantiating various examples
|
||||
of the sized type class templates.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.integer.rationale"></a><a class="link" href="integer.html#boost_integer.integer.rationale" title="Rationale">Rationale</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The rationale for the design of the templates in this header includes:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
Avoid recursion because of concern about C++'s limited guaranteed recursion
|
||||
depth (17).
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Avoid macros on general principles.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Try to keep the design as simple as possible.
|
||||
</li>
|
||||
</ul></div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.integer.alternative"></a><a class="link" href="integer.html#boost_integer.integer.alternative" title="Alternative">Alternative</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
If the number of bits required is known beforehand, it may be more appropriate
|
||||
to use the types supplied in <a href="../../../../../boost/cstdint.hpp" target="_top"><boost/cstdint.hpp></a>.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.integer.credits"></a><a class="link" href="integer.html#boost_integer.integer.credits" title="Credits">Credits</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The author of most of the Boost integer type choosing templates is <a href="http://www.boost.org/people/beman_dawes.html" target="_top">Beman Dawes</a>. He
|
||||
gives thanks to Valentin Bonnard and <a href="http://www.boost.org/people/kevlin_henney.htm" target="_top">Kevlin
|
||||
Henney</a> for sharing their designs for similar templates. <a href="http://www.boost.org/people/daryle_walker.html" target="_top">Daryle
|
||||
Walker</a> designed the value-based sized templates.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2001-2009 Beman
|
||||
Dawes, Daryle Walker, Gennaro Prota, John Maddock<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="traits.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="gcd_lcm.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -1,151 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Compile Time log2 Calculation</title>
|
||||
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../index.html" title="Boost.Integer">
|
||||
<link rel="up" href="../index.html" title="Boost.Integer">
|
||||
<link rel="prev" href="mask.html" title="Integer Masks">
|
||||
<link rel="next" href="minmax.html" title="Compile time min/max calculation">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
|
||||
<td align="center"><a href="../../../../../index.html">Home</a></td>
|
||||
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||||
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="mask.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="minmax.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="boost_integer.log2"></a><a class="link" href="log2.html" title="Compile Time log2 Calculation">Compile Time log2 Calculation</a>
|
||||
</h2></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<dt><span class="section"><a href="log2.html#boost_integer.log2.synopsis">Synopsis</a></span></dt>
|
||||
<dt><span class="section"><a href="log2.html#boost_integer.log2.usage">Usage</a></span></dt>
|
||||
<dt><span class="section"><a href="log2.html#boost_integer.log2.demonstration_program">Demonstration
|
||||
Program</a></span></dt>
|
||||
<dt><span class="section"><a href="log2.html#boost_integer.log2.rationale">Rationale</a></span></dt>
|
||||
<dt><span class="section"><a href="log2.html#boost_integer.log2.credits">Credits</a></span></dt>
|
||||
</dl></div>
|
||||
<p>
|
||||
The class template in <a href="../../../../../boost/integer/static_log2.hpp" target="_top"><boost/integer/static_log2.hpp></a>
|
||||
determines the position of the highest bit in a given value. This facility
|
||||
is useful for solving generic programming problems.
|
||||
</p>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.log2.synopsis"></a><a class="link" href="log2.html#boost_integer.log2.synopsis" title="Synopsis">Synopsis</a>
|
||||
</h3></div></div></div>
|
||||
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span>
|
||||
<span class="special">{</span>
|
||||
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined</em></span> <span class="identifier">static_log2_argument_type</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined</em></span> <span class="identifier">static_log2_result_type</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="identifier">static_log2_argument_type</span> <span class="identifier">arg</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">static_log2</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">static_log2_result_type</span> <span class="identifier">value</span> <span class="special">=</span> <span class="emphasis"><em>implementation-defined</em></span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span> <span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">static_log2</span><span class="special"><</span> <span class="number">0</span> <span class="special">></span>
|
||||
<span class="special">{</span>
|
||||
<span class="comment">// The logarithm of zero is undefined.</span>
|
||||
<span class="special">};</span>
|
||||
|
||||
|
||||
<span class="special">}</span> <span class="comment">// namespace boost</span>
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.log2.usage"></a><a class="link" href="log2.html#boost_integer.log2.usage" title="Usage">Usage</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The <code class="literal">boost::static_log2</code> class template takes one template
|
||||
parameter, a value of type <code class="literal">static_log2_argument_type</code>.
|
||||
The template only defines one member, <code class="literal">value</code>, which gives
|
||||
the truncated, base-two logarithm of the template argument.
|
||||
</p>
|
||||
<p>
|
||||
Since the logarithm of zero, for any base, is undefined, there is a specialization
|
||||
of <code class="literal">static_log2</code> for a template argument of zero. This specialization
|
||||
has no members, so an attempt to use the base-two logarithm of zero results
|
||||
in a compile-time error.
|
||||
</p>
|
||||
<p>
|
||||
Note:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
<code class="literal">static_log2_argument_type</code> is an <span class="emphasis"><em>unsigned
|
||||
integer type</em></span> (C++ standard, 3.9.1p3).
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<code class="literal">static_log2_result_type</code> is an <span class="emphasis"><em>integer type</em></span>
|
||||
(C++ standard, 3.9.1p7).
|
||||
</li>
|
||||
</ul></div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.log2.demonstration_program"></a><a class="link" href="log2.html#boost_integer.log2.demonstration_program" title="Demonstration Program">Demonstration
|
||||
Program</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The program <a href="../../../test/static_log2_test.cpp" target="_top">static_log2_test.cpp</a>
|
||||
is a simplistic demonstration of the results from instantiating various examples
|
||||
of the binary logarithm class template.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.log2.rationale"></a><a class="link" href="log2.html#boost_integer.log2.rationale" title="Rationale">Rationale</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The base-two (binary) logarithm, abbreviated lb, function is occasionally
|
||||
used to give order-estimates of computer algorithms. The truncated logarithm
|
||||
can be considered the highest power-of-two in a value, which corresponds
|
||||
to the value's highest set bit (for binary integers). Sometimes the highest-bit
|
||||
position could be used in generic programming, which requires the position
|
||||
to be available statically (<span class="emphasis"><em>i.e.</em></span> at compile-time).
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.log2.credits"></a><a class="link" href="log2.html#boost_integer.log2.credits" title="Credits">Credits</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The original version of the Boost binary logarithm class template was written
|
||||
by <a href="http://www.boost.org/people/daryle_walker.html" target="_top">Daryle Walker</a>
|
||||
and then enhanced by Giovanni Bajo with support for compilers without partial
|
||||
template specialization. The current version was suggested, together with
|
||||
a reference implementation, by Vesa Karvonen. Gennaro Prota wrote the actual
|
||||
source file.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2001-2009 Beman
|
||||
Dawes, Daryle Walker, Gennaro Prota, John Maddock<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="mask.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="minmax.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -1,380 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Integer Masks</title>
|
||||
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../index.html" title="Boost.Integer">
|
||||
<link rel="up" href="../index.html" title="Boost.Integer">
|
||||
<link rel="prev" href="gcd_lcm.html" title="Greatest Common Divisor and Least Common Multiple">
|
||||
<link rel="next" href="log2.html" title="Compile Time log2 Calculation">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
|
||||
<td align="center"><a href="../../../../../index.html">Home</a></td>
|
||||
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||||
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="gcd_lcm.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="log2.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="boost_integer.mask"></a><a class="link" href="mask.html" title="Integer Masks">Integer Masks</a>
|
||||
</h2></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<dt><span class="section"><a href="mask.html#boost_integer.mask.overview">Overview</a></span></dt>
|
||||
<dt><span class="section"><a href="mask.html#boost_integer.mask.synopsis">Synopsis</a></span></dt>
|
||||
<dt><span class="section"><a href="mask.html#boost_integer.mask.single_bit_mask_class_template">Single
|
||||
Bit-Mask Class Template</a></span></dt>
|
||||
<dt><span class="section"><a href="mask.html#boost_integer.mask.group_bit_mask_class_template">Group
|
||||
Bit-Mask Class Template</a></span></dt>
|
||||
<dt><span class="section"><a href="mask.html#boost_integer.mask.implementation_notes">Implementation
|
||||
Notes</a></span></dt>
|
||||
<dt><span class="section"><a href="mask.html#boost_integer.mask.example">Example</a></span></dt>
|
||||
<dt><span class="section"><a href="mask.html#boost_integer.mask.demonstration_program">Demonstration
|
||||
Program</a></span></dt>
|
||||
<dt><span class="section"><a href="mask.html#boost_integer.mask.rationale">Rationale</a></span></dt>
|
||||
<dt><span class="section"><a href="mask.html#boost_integer.mask.credits">Credits</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.mask.overview"></a><a class="link" href="mask.html#boost_integer.mask.overview" title="Overview">Overview</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The class templates in <a href="../../../../../boost/integer/integer_mask.hpp" target="_top"><boost/integer/integer_mask.hpp></a>
|
||||
provide bit masks for a certain bit position or a contiguous-bit pack of
|
||||
a certain size. The types of the masking constants come from the <a class="link" href="integer.html" title="Integer Type Selection">integer
|
||||
type selection templates</a> header.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.mask.synopsis"></a><a class="link" href="mask.html#boost_integer.mask.synopsis" title="Synopsis">Synopsis</a>
|
||||
</h3></div></div></div>
|
||||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">cstddef</span><span class="special">></span> <span class="comment">// for std::size_t</span>
|
||||
|
||||
<span class="keyword">namespace</span> <span class="identifier">boost</span>
|
||||
<span class="special">{</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">Bit</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">high_bit_mask_t</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span> <span class="identifier">least</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span> <span class="identifier">fast</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">least</span> <span class="identifier">high_bit</span> <span class="special">=</span> <span class="emphasis"><em>implementation-defined</em></span><span class="special">;</span>
|
||||
<span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">fast</span> <span class="identifier">high_bit_fast</span> <span class="special">=</span> <span class="emphasis"><em>implementation-defined</em></span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">bit_position</span> <span class="special">=</span> <span class="identifier">Bit</span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">Bits</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">low_bits_mask_t</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span> <span class="identifier">least</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span> <span class="identifier">fast</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">least</span> <span class="identifier">sig_bits</span> <span class="special">=</span> <span class="emphasis"><em>implementation-defined</em></span><span class="special">;</span>
|
||||
<span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">fast</span> <span class="identifier">sig_bits_fast</span> <span class="special">=</span> <span class="emphasis"><em>implementation-defined</em></span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">bit_count</span> <span class="special">=</span> <span class="identifier">Bits</span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
|
||||
<span class="comment">// Specializations for low_bits_mask_t exist for certain bit counts.</span>
|
||||
|
||||
<span class="special">}</span> <span class="comment">// namespace boost</span>
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.mask.single_bit_mask_class_template"></a><a class="link" href="mask.html#boost_integer.mask.single_bit_mask_class_template" title="Single Bit-Mask Class Template">Single
|
||||
Bit-Mask Class Template</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The <code class="literal">boost::high_bit_mask_t</code> class template provides constants
|
||||
for bit masks representing the bit at a certain position. The masks are equivalent
|
||||
to the value 2<sup>Bit</sup>, where <code class="literal">Bit</code> is the template parameter.
|
||||
The bit position must be a nonnegative number from zero to <span class="emphasis"><em>Max</em></span>,
|
||||
where Max is one less than the number of bits supported by the largest unsigned
|
||||
built-in integral type. The following table describes the members of an instantiation
|
||||
of <code class="literal">high_bit_mask_t</code>.
|
||||
</p>
|
||||
<div class="table">
|
||||
<a name="boost_integer.mask.single_bit_mask_class_template.members_of_the__boost__high_bit_mask_t__class_template"></a><p class="title"><b>Table 2. Members of the <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">high_bit_mask_t</span></code>
|
||||
Class Template</b></p>
|
||||
<div class="table-contents"><table class="table" summary="Members of the boost::high_bit_mask_t
|
||||
Class Template">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
<p>
|
||||
Member
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Meaning
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">least</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
The smallest, unsigned, built-in type that supports the given bit
|
||||
position.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">fast</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
The easiest-to-manipulate analog of <code class="literal">least</code>.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">high_bit</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
A <code class="literal">least</code> constant of the value 2<sup>Bit</sup>.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">high_bit_fast</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
A <code class="literal">fast</code> analog of <code class="literal">high_bit</code>.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">bit_position</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
The value of the template parameter, in case its needed from a
|
||||
renamed instantiation of the class template.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
</div>
|
||||
<br class="table-break">
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.mask.group_bit_mask_class_template"></a><a class="link" href="mask.html#boost_integer.mask.group_bit_mask_class_template" title="Group Bit-Mask Class Template">Group
|
||||
Bit-Mask Class Template</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The <code class="literal">boost::low_bits_mask_t</code> class template provides constants
|
||||
for bit masks equivalent to the value (2<sup>Bits</sup> - 1), where <code class="literal">Bits</code>
|
||||
is the template parameter. The parameter <code class="literal">Bits</code> must be
|
||||
a non-negative integer from zero to <span class="emphasis"><em>Max</em></span>, where Max is
|
||||
the number of bits supported by the largest, unsigned, built-in integral
|
||||
type. The following table describes the members of <code class="literal">low_bits_mask_t</code>.
|
||||
</p>
|
||||
<div class="table">
|
||||
<a name="boost_integer.mask.group_bit_mask_class_template.members_of_the___boost__low_bits_mask_t__class_template"></a><p class="title"><b>Table 3. Members of the <code class="literal">boost::low_bits_mask_t</code> Class Template</b></p>
|
||||
<div class="table-contents"><table class="table" summary="Members of the boost::low_bits_mask_t Class Template">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
<p>
|
||||
Member
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Meaning
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">least</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
The smallest, unsigned built-in type that supports the given bit
|
||||
count.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">fast</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
The easiest-to-manipulate analog of <code class="literal">least</code>.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">sig_bits</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
A <code class="literal">least</code> constant of the desired bit-masking
|
||||
value.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">sig_bits_fast</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
A <code class="literal">fast</code> analog of <code class="literal">sig_bits</code>.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">bit_count</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
The value of the template parameter, in case its needed from a
|
||||
renamed instantiation of the class template.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
</div>
|
||||
<br class="table-break">
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.mask.implementation_notes"></a><a class="link" href="mask.html#boost_integer.mask.implementation_notes" title="Implementation Notes">Implementation
|
||||
Notes</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
When <code class="literal">Bits</code> is the exact size of a built-in unsigned type,
|
||||
the implementation has to change to prevent undefined behavior. Therefore,
|
||||
there are specializations of <code class="literal">low_bits_mask_t</code> at those
|
||||
bit counts.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.mask.example"></a><a class="link" href="mask.html#boost_integer.mask.example" title="Example">Example</a>
|
||||
</h3></div></div></div>
|
||||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">integer</span><span class="special">/</span><span class="identifier">integer_mask</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
<span class="comment">//...</span>
|
||||
|
||||
<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">high_bit_mask_t</span><span class="special"><</span><span class="number">29</span><span class="special">></span> <span class="identifier">mask1_type</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">low_bits_mask_t</span><span class="special"><</span><span class="number">15</span><span class="special">></span> <span class="identifier">mask2_type</span><span class="special">;</span>
|
||||
|
||||
<span class="identifier">mask1_type</span><span class="special">::</span><span class="identifier">least</span> <span class="identifier">my_var1</span><span class="special">;</span>
|
||||
<span class="identifier">mask2_type</span><span class="special">::</span><span class="identifier">fast</span> <span class="identifier">my_var2</span><span class="special">;</span>
|
||||
<span class="comment">//...</span>
|
||||
|
||||
<span class="identifier">my_var1</span> <span class="special">|=</span> <span class="identifier">mask1_type</span><span class="special">::</span><span class="identifier">high_bit</span><span class="special">;</span>
|
||||
<span class="identifier">my_var2</span> <span class="special">&=</span> <span class="identifier">mask2_type</span><span class="special">::</span><span class="identifier">sig_bits_fast</span><span class="special">;</span>
|
||||
|
||||
<span class="comment">//...</span>
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.mask.demonstration_program"></a><a class="link" href="mask.html#boost_integer.mask.demonstration_program" title="Demonstration Program">Demonstration
|
||||
Program</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The program <a href="../../../test/integer_mask_test.cpp" target="_top">integer_mask_test.cpp</a>
|
||||
is a simplistic demonstration of the results from instantiating various examples
|
||||
of the bit mask class templates.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.mask.rationale"></a><a class="link" href="mask.html#boost_integer.mask.rationale" title="Rationale">Rationale</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The class templates in this header are an extension of the <a class="link" href="integer.html" title="Integer Type Selection">integer
|
||||
type selection class templates</a>. The new class templates provide the
|
||||
same sized types, but also convenient masks to use when extracting the highest
|
||||
or all the significant bits when the containing built-in type contains more
|
||||
bits. This prevents contamination of values by the higher, unused bits.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.mask.credits"></a><a class="link" href="mask.html#boost_integer.mask.credits" title="Credits">Credits</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The author of the Boost bit mask class templates is <a href="http://www.boost.org/people/daryle_walker.html" target="_top">Daryle
|
||||
Walker</a>.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2001-2009 Beman
|
||||
Dawes, Daryle Walker, Gennaro Prota, John Maddock<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="gcd_lcm.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="log2.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -1,160 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Compile time min/max calculation</title>
|
||||
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../index.html" title="Boost.Integer">
|
||||
<link rel="up" href="../index.html" title="Boost.Integer">
|
||||
<link rel="prev" href="log2.html" title="Compile Time log2 Calculation">
|
||||
<link rel="next" href="history.html" title="History">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
|
||||
<td align="center"><a href="../../../../../index.html">Home</a></td>
|
||||
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||||
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="log2.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="history.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="boost_integer.minmax"></a><a class="link" href="minmax.html" title="Compile time min/max calculation">Compile time min/max calculation</a>
|
||||
</h2></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<dt><span class="section"><a href="minmax.html#boost_integer.minmax.synopsis">Synopsis</a></span></dt>
|
||||
<dt><span class="section"><a href="minmax.html#boost_integer.minmax.usage">Usage</a></span></dt>
|
||||
<dt><span class="section"><a href="minmax.html#boost_integer.minmax.example">Example</a></span></dt>
|
||||
<dt><span class="section"><a href="minmax.html#boost_integer.minmax.demonstration_program">Demonstration
|
||||
Program</a></span></dt>
|
||||
<dt><span class="section"><a href="minmax.html#boost_integer.minmax.rationale">Rationale</a></span></dt>
|
||||
<dt><span class="section"><a href="minmax.html#boost_integer.minmax.credits">Credits</a></span></dt>
|
||||
</dl></div>
|
||||
<p>
|
||||
The class templates in <a href="../../../../../boost/integer/static_min_max.hpp" target="_top"><boost/integer/static_min_max.hpp></a>
|
||||
provide a compile-time evaluation of the minimum or maximum of two integers.
|
||||
These facilities are useful for generic programming problems.
|
||||
</p>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.minmax.synopsis"></a><a class="link" href="minmax.html#boost_integer.minmax.synopsis" title="Synopsis">Synopsis</a>
|
||||
</h3></div></div></div>
|
||||
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span>
|
||||
<span class="special">{</span>
|
||||
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined</em></span> <span class="identifier">static_min_max_signed_type</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined</em></span> <span class="identifier">static_min_max_unsigned_type</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="identifier">static_min_max_signed_type</span> <span class="identifier">Value1</span><span class="special">,</span> <span class="identifier">static_min_max_signed_type</span> <span class="identifier">Value2</span> <span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">static_signed_min</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="identifier">static_min_max_signed_type</span> <span class="identifier">Value1</span><span class="special">,</span> <span class="identifier">static_min_max_signed_type</span> <span class="identifier">Value2</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">static_signed_max</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="identifier">static_min_max_unsigned_type</span> <span class="identifier">Value1</span><span class="special">,</span> <span class="identifier">static_min_max_unsigned_type</span> <span class="identifier">Value2</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">static_unsigned_min</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="identifier">static_min_max_unsigned_type</span> <span class="identifier">Value1</span><span class="special">,</span> <span class="identifier">static_min_max_unsigned_type</span> <span class="identifier">Value2</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">static_unsigned_max</span><span class="special">;</span>
|
||||
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.minmax.usage"></a><a class="link" href="minmax.html#boost_integer.minmax.usage" title="Usage">Usage</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The four class templates provide the combinations for finding the minimum
|
||||
or maximum of two <code class="literal">signed</code> or <code class="literal">unsigned</code>
|
||||
(<code class="literal">long</code>) parameters, <span class="emphasis"><em>Value1</em></span> and <span class="emphasis"><em>Value2</em></span>,
|
||||
at compile-time. Each template has a single static data member, <code class="literal">value</code>,
|
||||
which is set to the respective minimum or maximum of the template's parameters.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.minmax.example"></a><a class="link" href="minmax.html#boost_integer.minmax.example" title="Example">Example</a>
|
||||
</h3></div></div></div>
|
||||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">integer</span><span class="special">/</span><span class="identifier">static_min_max</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span> <span class="keyword">unsigned</span> <span class="keyword">long</span> <span class="identifier">AddendSize1</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="keyword">long</span> <span class="identifier">AddendSize2</span> <span class="special">></span>
|
||||
<span class="keyword">class</span> <span class="identifier">adder</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">public</span><span class="special">:</span>
|
||||
<span class="keyword">static</span> <span class="keyword">unsigned</span> <span class="keyword">long</span> <span class="keyword">const</span> <span class="identifier">addend1_size</span> <span class="special">=</span> <span class="identifier">AddendSize1</span><span class="special">;</span>
|
||||
<span class="keyword">static</span> <span class="keyword">unsigned</span> <span class="keyword">long</span> <span class="keyword">const</span> <span class="identifier">addend2_size</span> <span class="special">=</span> <span class="identifier">AddendSize2</span><span class="special">;</span>
|
||||
<span class="keyword">static</span> <span class="keyword">unsigned</span> <span class="keyword">long</span> <span class="keyword">const</span> <span class="identifier">sum_size</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">static_unsigned_max</span><span class="special"><</span><span class="identifier">AddendSize1</span><span class="special">,</span> <span class="identifier">AddendSize2</span><span class="special">>::</span><span class="identifier">value</span> <span class="special">+</span> <span class="number">1</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">typedef</span> <span class="keyword">int</span> <span class="identifier">addend1_type</span><span class="special">[</span> <span class="identifier">addend1_size</span> <span class="special">];</span>
|
||||
<span class="keyword">typedef</span> <span class="keyword">int</span> <span class="identifier">addend2_type</span><span class="special">[</span> <span class="identifier">addend2_size</span> <span class="special">];</span>
|
||||
<span class="keyword">typedef</span> <span class="keyword">int</span> <span class="identifier">sum_type</span><span class="special">[</span> <span class="identifier">sum_size</span> <span class="special">];</span>
|
||||
|
||||
<span class="keyword">void</span> <span class="keyword">operator</span> <span class="special">()(</span> <span class="identifier">addend1_type</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">a1</span><span class="special">,</span> <span class="identifier">addend2_type</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">a2</span><span class="special">,</span> <span class="identifier">sum_type</span> <span class="special">&</span><span class="identifier">s</span> <span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
|
||||
<span class="comment">//...</span>
|
||||
|
||||
<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">int</span> <span class="keyword">const</span> <span class="identifier">a1</span><span class="special">[]</span> <span class="special">=</span> <span class="special">{</span> <span class="number">0</span><span class="special">,</span> <span class="number">4</span><span class="special">,</span> <span class="number">3</span> <span class="special">};</span> <span class="comment">// 340</span>
|
||||
<span class="keyword">int</span> <span class="keyword">const</span> <span class="identifier">a2</span><span class="special">[]</span> <span class="special">=</span> <span class="special">{</span> <span class="number">9</span><span class="special">,</span> <span class="number">8</span> <span class="special">};</span> <span class="comment">// 89</span>
|
||||
<span class="keyword">int</span> <span class="identifier">s</span><span class="special">[</span> <span class="number">4</span> <span class="special">];</span>
|
||||
<span class="identifier">adder</span><span class="special"><</span><span class="number">3</span><span class="special">,</span><span class="number">2</span><span class="special">></span> <span class="identifier">obj</span><span class="special">;</span>
|
||||
|
||||
<span class="identifier">obj</span><span class="special">(</span> <span class="identifier">a1</span><span class="special">,</span> <span class="identifier">a2</span><span class="special">,</span> <span class="identifier">s</span> <span class="special">);</span> <span class="comment">// 's' should be 429 or { 9, 2, 4, 0 }</span>
|
||||
<span class="comment">//...</span>
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.minmax.demonstration_program"></a><a class="link" href="minmax.html#boost_integer.minmax.demonstration_program" title="Demonstration Program">Demonstration
|
||||
Program</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The program <a href="../../../test/static_min_max_test.cpp" target="_top">static_min_max_test.cpp</a>
|
||||
is a simplistic demonstration of various comparisons using the compile-time
|
||||
extrema class templates.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.minmax.rationale"></a><a class="link" href="minmax.html#boost_integer.minmax.rationale" title="Rationale">Rationale</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
Sometimes the minimum or maximum of several values needs to be found for
|
||||
later compile-time processing, <span class="emphasis"><em>e.g.</em></span> for a bound for
|
||||
another class template.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.minmax.credits"></a><a class="link" href="minmax.html#boost_integer.minmax.credits" title="Credits">Credits</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The author of the Boost compile-time extrema class templates is <a href="http://www.boost.org/people/daryle_walker.html" target="_top">Daryle
|
||||
Walker</a>.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2001-2009 Beman
|
||||
Dawes, Daryle Walker, Gennaro Prota, John Maddock<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="log2.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="history.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -1,215 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Integer Traits</title>
|
||||
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../index.html" title="Boost.Integer">
|
||||
<link rel="up" href="../index.html" title="Boost.Integer">
|
||||
<link rel="prev" href="../index.html" title="Boost.Integer">
|
||||
<link rel="next" href="integer.html" title="Integer Type Selection">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
|
||||
<td align="center"><a href="../../../../../index.html">Home</a></td>
|
||||
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||||
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../index.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="integer.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="boost_integer.traits"></a><a class="link" href="traits.html" title="Integer Traits">Integer Traits</a>
|
||||
</h2></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<dt><span class="section"><a href="traits.html#boost_integer.traits.motivation">Motivation</a></span></dt>
|
||||
<dt><span class="section"><a href="traits.html#boost_integer.traits.synopsis">Synopsis</a></span></dt>
|
||||
<dt><span class="section"><a href="traits.html#boost_integer.traits.description">Description</a></span></dt>
|
||||
<dt><span class="section"><a href="traits.html#boost_integer.traits.test_program">Test Program</a></span></dt>
|
||||
<dt><span class="section"><a href="traits.html#boost_integer.traits.acknowledgements">Acknowledgements</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.traits.motivation"></a><a class="link" href="traits.html#boost_integer.traits.motivation" title="Motivation">Motivation</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The C++ Standard Library <limits> header supplies a class template
|
||||
<code class="computeroutput"><span class="identifier">numeric_limits</span><span class="special"><></span></code>
|
||||
with specializations for each fundamental type.
|
||||
</p>
|
||||
<p>
|
||||
For integer types, the interesting members of <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><></span></code> are:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">bool</span> <span class="identifier">is_specialized</span><span class="special">;</span> <span class="comment">// Will be true for integer types.</span>
|
||||
<span class="keyword">static</span> <span class="identifier">T</span> <span class="identifier">min</span><span class="special">()</span> <span class="keyword">throw</span><span class="special">();</span> <span class="comment">// Smallest representable value.</span>
|
||||
<span class="keyword">static</span> <span class="identifier">T</span> <span class="identifier">max</span><span class="special">()</span> <span class="keyword">throw</span><span class="special">();</span> <span class="comment">// Largest representable value.</span>
|
||||
<span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">int</span> <span class="identifier">digits</span><span class="special">;</span> <span class="comment">// For integers, the number of value bits.</span>
|
||||
<span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">int</span> <span class="identifier">digits10</span><span class="special">;</span> <span class="comment">// The number of base 10 digits that can be represented.</span>
|
||||
<span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">bool</span> <span class="identifier">is_signed</span><span class="special">;</span> <span class="comment">// True if the type is signed.</span>
|
||||
<span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">bool</span> <span class="identifier">is_integer</span><span class="special">;</span> <span class="comment">// Will be true for all integer types.</span>
|
||||
</pre>
|
||||
<p>
|
||||
For many uses, these are sufficient. But min() and max() are problematical
|
||||
because they are not constant expressions (std::5.19), yet some usages require
|
||||
constant expressions.
|
||||
</p>
|
||||
<p>
|
||||
The template class <code class="literal">integer_traits</code> addresses this problem.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.traits.synopsis"></a><a class="link" href="traits.html#boost_integer.traits.synopsis" title="Synopsis">Synopsis</a>
|
||||
</h3></div></div></div>
|
||||
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span>
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span>
|
||||
<span class="keyword">class</span> <span class="identifier">integer_traits</span> <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">public</span><span class="special">:</span>
|
||||
<span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">bool</span> <span class="identifier">is_integral</span> <span class="special">=</span> <span class="keyword">false</span><span class="special">;</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="comment">// These members are defined only if T is a built-in</span>
|
||||
<span class="comment">// integal type:</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">T</span> <span class="identifier">const_min</span> <span class="special">=</span> <span class="emphasis"><em>implementation-defined</em></span><span class="special">;</span>
|
||||
<span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">T</span> <span class="identifier">const_max</span> <span class="special">=</span> <span class="emphasis"><em>implementation-defined</em></span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.traits.description"></a><a class="link" href="traits.html#boost_integer.traits.description" title="Description">Description</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
Template class <code class="literal">integer_traits</code> is derived from <code class="literal">std::numeric_limits</code>.
|
||||
The primary specialization adds the single <code class="literal">bool</code> member
|
||||
<code class="literal">is_integral</code> with the compile-time constant value <code class="literal">false</code>.
|
||||
However, for all integral types <code class="literal">T</code> (std::3.9.1/7 [basic.fundamental]),
|
||||
there are specializations provided with the following compile-time constants
|
||||
defined:
|
||||
</p>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
<p>
|
||||
member
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
type
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
value
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">is_integral</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
bool
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">true</code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">const_min</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">T</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
equivalent to <code class="literal">std::numeric_limits<T>::min()</code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">const_max</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal">T</code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
equivalent to <code class="literal">std::numeric_limits<T>::max()</code>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
<p>
|
||||
Note: The <span class="emphasis"><em>is_integral</em></span> flag is provided, because a user-defined
|
||||
integer class should specialize <code class="literal">std::numeric_limits<>::is_integer
|
||||
= true</code>, while compile-time constants <code class="literal">const_min</code>
|
||||
and <code class="literal">const_max</code> are not provided for that user-defined class,
|
||||
unless boost::integer_traits is also specialized.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.traits.test_program"></a><a class="link" href="traits.html#boost_integer.traits.test_program" title="Test Program">Test Program</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The program <code class="literal"><a href="../../../test/integer_traits_test.cpp" target="_top">integer_traits_test.cpp</a></code>
|
||||
exercises the <code class="literal">integer_traits</code> class.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.traits.acknowledgements"></a><a class="link" href="traits.html#boost_integer.traits.acknowledgements" title="Acknowledgements">Acknowledgements</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
Beman Dawes, Ed Brey, Steve Cleary, and Nathan Myers discussed the integer
|
||||
traits idea on the boost mailing list in August 1999.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2001-2009 Beman
|
||||
Dawes, Daryle Walker, Gennaro Prota, John Maddock<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../index.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="integer.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -1,251 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Boost.Integer</title>
|
||||
<link rel="stylesheet" href="../../../../doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="index.html" title="Boost.Integer">
|
||||
<link rel="next" href="boost_integer/traits.html" title="Integer Traits">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../boost.png"></td>
|
||||
<td align="center"><a href="../../../../index.html">Home</a></td>
|
||||
<td align="center"><a href="../../../../libs/libraries.htm">Libraries</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||||
<td align="center"><a href="../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav"><a accesskey="n" href="boost_integer/traits.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a></div>
|
||||
<div class="article">
|
||||
<div class="titlepage">
|
||||
<div>
|
||||
<div><h2 class="title">
|
||||
<a name="boost_integer"></a>Boost.Integer</h2></div>
|
||||
<div><div class="authorgroup">
|
||||
<div class="author"><h3 class="author">
|
||||
<span class="firstname">Beman</span> <span class="surname">Dawes</span>
|
||||
</h3></div>
|
||||
<div class="author"><h3 class="author">
|
||||
<span class="firstname">Daryle</span> <span class="surname">Walker</span>
|
||||
</h3></div>
|
||||
<div class="author"><h3 class="author">
|
||||
<span class="firstname">Gennaro</span> <span class="surname">Prota</span>
|
||||
</h3></div>
|
||||
<div class="author"><h3 class="author">
|
||||
<span class="firstname">John</span> <span class="surname">Maddock</span>
|
||||
</h3></div>
|
||||
</div></div>
|
||||
<div><p class="copyright">Copyright © 2001-2009 Beman
|
||||
Dawes, Daryle Walker, Gennaro Prota, John Maddock</p></div>
|
||||
<div><div class="legalnotice">
|
||||
<a name="boost_integer.legal"></a><p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></div>
|
||||
</div>
|
||||
<hr>
|
||||
</div>
|
||||
<div class="toc">
|
||||
<p><b>Table of Contents</b></p>
|
||||
<dl>
|
||||
<dt><span class="section"><a href="index.html#boost_integer.overview">Overview</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_integer/traits.html">Integer Traits</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_integer/integer.html">Integer Type Selection</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_integer/gcd_lcm.html">Greatest Common Divisor and Least
|
||||
Common Multiple</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_integer/mask.html">Integer Masks</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_integer/log2.html">Compile Time log2 Calculation</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_integer/minmax.html">Compile time min/max calculation</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_integer/history.html">History</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_integer/cstdint.html">Removed from library: Standard Integer
|
||||
Types</a></span></dt>
|
||||
</dl>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="boost_integer.overview"></a><a class="link" href="index.html#boost_integer.overview" title="Overview">Overview</a>
|
||||
</h2></div></div></div>
|
||||
<p>
|
||||
Boost.Integer provides integer type support, particularly helpful in generic
|
||||
programming. It provides the means to select an integer type based upon its
|
||||
properties, like the number of bits or the maximum supported value, as well
|
||||
as compile-time bit mask selection. There is a derivative of std::numeric_limits
|
||||
that provides integral constant expressions for <code class="computeroutput"><span class="identifier">min</span></code>
|
||||
and <code class="computeroutput"><span class="identifier">max</span></code>. Finally, it provides
|
||||
two compile-time algorithms: determining the highest power of two in a compile-time
|
||||
value; and computing min and max of constant expressions.
|
||||
</p>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
<p>
|
||||
Component
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Header
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Purpose
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
Forward Declarations.
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal"><a href="../../../../boost/integer_fwd.hpp" target="_top"><boost/integer_fwd.hpp></a></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Forward declarations of classes and class templates - for use when
|
||||
just the name of a class is needed.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<a class="link" href="boost_integer/traits.html" title="Integer Traits">Integer Traits</a>.
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal"><a href="../../../../boost/integer_traits.hpp" target="_top"><boost/integer_traits.hpp></a></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Class template <code class="literal">boost::integer_traits</code>, derives
|
||||
from <code class="literal">std::numeric_limits</code> and adds <code class="literal">const_min</code>
|
||||
and <code class="literal">const_max</code> members.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<a class="link" href="boost_integer/integer.html" title="Integer Type Selection">Integer Type Selection</a>.
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal"><a href="../../../../boost/integer.hpp" target="_top"><boost/integer.hpp></a></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Templates for integer type selection based on properties such as
|
||||
maximum value or number of bits: Use to select the type of an integer
|
||||
when some property such as maximum value or number of bits is known.
|
||||
Useful for generic programming.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<a class="link" href="boost_integer/gcd_lcm.html" title="Greatest Common Divisor and Least Common Multiple">Greatest Common Divisor and
|
||||
Least Common Multiple</a>.
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal"><a href="../../../../boost/integer/common_factor_rt.hpp" target="_top"><boost/integer/common_factor_rt.hpp></a></code>
|
||||
and <code class="literal"><a href="../../../../boost/integer/common_factor_ct.hpp" target="_top"><boost/integer/common_factor_ct.hpp></a></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Functions <code class="computeroutput"><span class="identifier">gcd</span></code> and
|
||||
<code class="computeroutput"><span class="identifier">lcm</span></code> plus function
|
||||
objects and compile time versions.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<a class="link" href="boost_integer/mask.html" title="Integer Masks">Integer Masks</a>.
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal"><a href="../../../../boost/integer/integer_mask.hpp" target="_top"><boost/integer/integer_mask.hpp></a></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Templates for the selection of integer masks, single or lowest group,
|
||||
based on the number of bits: Use to select a particular mask when
|
||||
the bit position(s) are based on a compile-time variable. Useful
|
||||
for generic programming.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<a class="link" href="boost_integer/log2.html" title="Compile Time log2 Calculation">Compile time log2 Calculation</a>.
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal"><a href="../../../../boost/integer/static_log2.hpp" target="_top"><boost/integer/static_log2.hpp></a></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Template for finding the highest power of two in a number: Use to
|
||||
find the bit-size/range based on a maximum value. Useful for generic
|
||||
programming.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<a class="link" href="boost_integer/minmax.html" title="Compile time min/max calculation">Compile time min/max calculation</a>.
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal"><a href="../../../../boost/integer/static_min_max.hpp" target="_top"><boost/integer/static_min_max.hpp></a></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Templates for finding the extrema of two numbers: Use to find a bound
|
||||
based on a minimum or maximum value. Useful for generic programming.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
</div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"><p><small>Last revised: April 24, 2017 at 17:49:59 GMT</small></p></td>
|
||||
<td align="right"><div class="copyright-footer"></div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav"><a accesskey="n" href="boost_integer/traits.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a></div>
|
||||
</body>
|
||||
</html>
|
270
doc/integer.qbk
270
doc/integer.qbk
@ -2,7 +2,6 @@
|
||||
[quickbook 1.6]
|
||||
[compatibility-mode 1.5]
|
||||
[copyright 2001-2009 Beman Dawes, Daryle Walker, Gennaro Prota, John Maddock]
|
||||
[purpose Integer Type Selection]
|
||||
[license
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -17,13 +16,13 @@
|
||||
[section:overview Overview]
|
||||
|
||||
Boost.Integer provides integer type support, particularly helpful in generic programming.
|
||||
It provides the means to select an integer type based upon its properties, like the number of bits or
|
||||
It provides the means to select an integer type based upon its properties, like the number of bits or
|
||||
the maximum supported value, as well as compile-time bit mask selection. There is a derivative of
|
||||
std::numeric_limits that provides integral constant expressions for `min` and `max`.
|
||||
Finally, it provides two compile-time algorithms: determining the highest power of two in a
|
||||
std::numeric_limits that provides integral constant expressions for `min` and `max`.
|
||||
Finally, it provides two compile-time algorithms: determining the highest power of two in a
|
||||
compile-time value; and computing min and max of constant expressions.
|
||||
|
||||
[table
|
||||
[table
|
||||
[[Component][Header][Purpose]]
|
||||
[
|
||||
[Forward Declarations.]
|
||||
@ -38,8 +37,8 @@ compile-time value; and computing min and max of constant expressions.
|
||||
[
|
||||
[[link boost_integer.integer Integer Type Selection].]
|
||||
[[^[@../../../../boost/integer.hpp <boost/integer.hpp>]]]
|
||||
[Templates for integer type selection based on properties such as maximum value or number of bits:
|
||||
Use to select the type of an integer when some property such as maximum value or number of bits is known.
|
||||
[Templates for integer type selection based on properties such as maximum value or number of bits:
|
||||
Use to select the type of an integer when some property such as maximum value or number of bits is known.
|
||||
Useful for generic programming. ]
|
||||
]
|
||||
[
|
||||
@ -50,21 +49,33 @@ compile-time value; and computing min and max of constant expressions.
|
||||
[
|
||||
[[link boost_integer.mask Integer Masks].]
|
||||
[[^[@../../../../boost/integer/integer_mask.hpp <boost/integer/integer_mask.hpp>]]]
|
||||
[Templates for the selection of integer masks, single or lowest group, based on the number of bits:
|
||||
[Templates for the selection of integer masks, single or lowest group, based on the number of bits:
|
||||
Use to select a particular mask when the bit position(s) are based on a compile-time variable. Useful for generic programming. ]
|
||||
]
|
||||
[
|
||||
[[link boost_integer.log2 Compile time log2 Calculation].]
|
||||
[[^[@../../../../boost/integer/static_log2.hpp <boost/integer/static_log2.hpp>]]]
|
||||
[Template for finding the highest power of two in a number:
|
||||
[Template for finding the highest power of two in a number:
|
||||
Use to find the bit-size/range based on a maximum value. Useful for generic programming. ]
|
||||
]
|
||||
[
|
||||
[[link boost_integer.minmax Compile time min/max calculation].]
|
||||
[[^[@../../../../boost/integer/static_min_max.hpp <boost/integer/static_min_max.hpp>]]]
|
||||
[Templates for finding the extrema of two numbers:
|
||||
[Templates for finding the extrema of two numbers:
|
||||
Use to find a bound based on a minimum or maximum value. Useful for generic programming. ]
|
||||
]
|
||||
[
|
||||
[[link boost_integer.extended_euclidean Extended Euclidean algorithm].]
|
||||
[[^[@../../../../boost/integer/extended_euclidean.hpp <boost/integer/extended_euclidean.hpp>]]]
|
||||
[Solves /mx + ny = gcd(x,y)/ for /x/ and /y/.]
|
||||
]
|
||||
[
|
||||
[[link boost_integer.mod_inverse Modular multiplicative inverse].]
|
||||
[[^[@../../../../boost/integer/mod_inverse.hpp <boost/integer/mod_inverse.hpp>]]]
|
||||
[Given /a/ and /m/, solves /ax/ = 1 mod /m/ for /x/.]
|
||||
]
|
||||
|
||||
|
||||
]
|
||||
|
||||
[endsect]
|
||||
@ -75,7 +86,7 @@ compile-time value; and computing min and max of constant expressions.
|
||||
|
||||
The C++ Standard Library <limits> header supplies a class template `numeric_limits<>` with specializations for each fundamental type.
|
||||
|
||||
For integer types, the interesting members of `std::numeric_limits<>` are:
|
||||
For integer types, the interesting members of `std::numeric_limits<>` are:
|
||||
|
||||
static const bool is_specialized; // Will be true for integer types.
|
||||
static T min() throw(); // Smallest representable value.
|
||||
@ -85,13 +96,13 @@ For integer types, the interesting members of `std::numeric_limits<>` are:
|
||||
static const bool is_signed; // True if the type is signed.
|
||||
static const bool is_integer; // Will be true for all integer types.
|
||||
|
||||
For many uses, these are sufficient.
|
||||
But min() and max() are problematical because they are not constant expressions (std::5.19),
|
||||
yet some usages require constant expressions.
|
||||
For many uses, these are sufficient.
|
||||
But min() and max() are problematical because they are not constant expressions (std::5.19),
|
||||
yet some usages require constant expressions.
|
||||
|
||||
The template class [^integer_traits] addresses this problem.
|
||||
The template class [^integer_traits] addresses this problem.
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
||||
[section Synopsis]
|
||||
|
||||
@ -110,33 +121,33 @@ The template class [^integer_traits] addresses this problem.
|
||||
};
|
||||
}
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
||||
[section Description]
|
||||
|
||||
Template class [^integer_traits] is derived from [^std::numeric_limits]. The primary specialization adds the single
|
||||
[^bool] member [^is_integral] with the compile-time constant value [^false].
|
||||
However, for all integral types [^T] (std::3.9.1/7 [basic.fundamental]), there are specializations
|
||||
provided with the following compile-time constants defined:
|
||||
Template class [^integer_traits] is derived from [^std::numeric_limits]. The primary specialization adds the single
|
||||
[^bool] member [^is_integral] with the compile-time constant value [^false].
|
||||
However, for all integral types [^T] (std::3.9.1/7 [basic.fundamental]), there are specializations
|
||||
provided with the following compile-time constants defined:
|
||||
|
||||
[table
|
||||
[table
|
||||
[[member][type][value]]
|
||||
[[[^is_integral]][bool][[^true]]]
|
||||
[[[^const_min]][[^T]][equivalent to [^std::numeric_limits<T>::min()]]]
|
||||
[[[^const_max]][[^T]][equivalent to [^std::numeric_limits<T>::max()]]]
|
||||
]
|
||||
|
||||
Note: The /is_integral/ flag is provided, because a user-defined integer class should specialize
|
||||
[^std::numeric_limits<>::is_integer = true], while compile-time constants
|
||||
[^const_min] and [^const_max] are not provided for that user-defined class, unless boost::integer_traits is also specialized.
|
||||
Note: The /is_integral/ flag is provided, because a user-defined integer class should specialize
|
||||
[^std::numeric_limits<>::is_integer = true], while compile-time constants
|
||||
[^const_min] and [^const_max] are not provided for that user-defined class, unless boost::integer_traits is also specialized.
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
||||
[section Test Program]
|
||||
|
||||
The program [^[@../../test/integer_traits_test.cpp integer_traits_test.cpp]] exercises the [^integer_traits] class.
|
||||
The program [^[@../../test/integer_traits_test.cpp integer_traits_test.cpp]] exercises the [^integer_traits] class.
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
||||
[section Acknowledgements]
|
||||
|
||||
@ -147,8 +158,8 @@ Beman Dawes, Ed Brey, Steve Cleary, and Nathan Myers discussed the integer trait
|
||||
|
||||
[section:integer Integer Type Selection]
|
||||
|
||||
The [@../../../../boost/integer.hpp <boost/integer.hpp>] type selection templates allow
|
||||
integer types to be selected based on desired characteristics such as number of bits or maximum value.
|
||||
The [@../../../../boost/integer.hpp <boost/integer.hpp>] type selection templates allow
|
||||
integer types to be selected based on desired characteristics such as number of bits or maximum value.
|
||||
This facility is particularly useful for solving generic programming problems.
|
||||
|
||||
[section:synopsis Synopsis]
|
||||
@ -164,7 +175,7 @@ This facility is particularly useful for solving generic programming problems.
|
||||
|
||||
// signed
|
||||
template<int Bits>
|
||||
struct int_t
|
||||
struct int_t
|
||||
{
|
||||
/* Member exact may or may not be defined depending upon Bits */
|
||||
typedef ``['implementation-defined-type]`` exact;
|
||||
@ -174,7 +185,7 @@ This facility is particularly useful for solving generic programming problems.
|
||||
|
||||
// unsigned
|
||||
template<int Bits>
|
||||
struct uint_t
|
||||
struct uint_t
|
||||
{
|
||||
/* Member exact may or may not be defined depending upon Bits */
|
||||
typedef ``['implementation-defined-type]`` exact;
|
||||
@ -184,14 +195,14 @@ This facility is particularly useful for solving generic programming problems.
|
||||
|
||||
// signed
|
||||
template<long long MaxValue>
|
||||
struct int_max_value_t
|
||||
struct int_max_value_t
|
||||
{
|
||||
typedef ``['implementation-defined-type]`` least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
};
|
||||
|
||||
template<long long MinValue>
|
||||
struct int_min_value_t
|
||||
struct int_min_value_t
|
||||
{
|
||||
typedef ``['implementation-defined-type]`` least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
@ -199,7 +210,7 @@ This facility is particularly useful for solving generic programming problems.
|
||||
|
||||
// unsigned
|
||||
template<unsigned long long Value>
|
||||
struct uint_value_t
|
||||
struct uint_value_t
|
||||
{
|
||||
typedef ``['implementation-defined-type]`` least;
|
||||
typedef int_fast_t<least>::fast fast;
|
||||
@ -210,25 +221,25 @@ This facility is particularly useful for solving generic programming problems.
|
||||
|
||||
[section:easiest Easiest-to-Manipulate Types]
|
||||
|
||||
The [^int_fast_t] class template maps its input type to the next-largest type that the processor
|
||||
can manipulate the easiest, or to itself if the input type is already an easy-to-manipulate type.
|
||||
For instance, processing a bunch of [^char] objects may go faster if they were converted to [^int] objects before processing.
|
||||
The input type, passed as the only template parameter, must be a built-in integral type, except [^bool].
|
||||
Unsigned integral types can be used, as well as signed integral types.
|
||||
The [^int_fast_t] class template maps its input type to the next-largest type that the processor
|
||||
can manipulate the easiest, or to itself if the input type is already an easy-to-manipulate type.
|
||||
For instance, processing a bunch of [^char] objects may go faster if they were converted to [^int] objects before processing.
|
||||
The input type, passed as the only template parameter, must be a built-in integral type, except [^bool].
|
||||
Unsigned integral types can be used, as well as signed integral types.
|
||||
The output type is given as the nested type [^fast].
|
||||
|
||||
[*Implementation Notes:]
|
||||
By default, the output type is identical to the input type. Eventually, this code's implementation should
|
||||
be customized for each platform to give accurate mappings between the built-in types and the easiest-to-manipulate
|
||||
[*Implementation Notes:]
|
||||
By default, the output type is identical to the input type. Eventually, this code's implementation should
|
||||
be customized for each platform to give accurate mappings between the built-in types and the easiest-to-manipulate
|
||||
built-in types. Also, there is no guarantee that the output type actually is easier to manipulate than the input type.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:sized Sized Types]
|
||||
|
||||
The [^int_t], [^uint_t], [^int_max_value_t], [^int_min_value_t], and [^uint_value_t] class templates find
|
||||
the most appropiate built-in integral type for the given template parameter. This type is given by the
|
||||
nested type [^least]. The easiest-to-manipulate version of that type is given by the nested type [^fast].
|
||||
The [^int_t], [^uint_t], [^int_max_value_t], [^int_min_value_t], and [^uint_value_t] class templates find
|
||||
the most appropiate built-in integral type for the given template parameter. This type is given by the
|
||||
nested type [^least]. The easiest-to-manipulate version of that type is given by the nested type [^fast].
|
||||
The following table describes each template's criteria.
|
||||
|
||||
[table Criteria for the Sized Type Class Templates
|
||||
@ -237,60 +248,60 @@ The following table describes each template's criteria.
|
||||
]
|
||||
[
|
||||
[[^boost::int_t<N>::least]]
|
||||
[The smallest, built-in, signed integral type with at least /N/ bits, including the sign bit.
|
||||
The parameter should be a positive number. A compile-time error results if the parameter is
|
||||
[The smallest, built-in, signed integral type with at least /N/ bits, including the sign bit.
|
||||
The parameter should be a positive number. A compile-time error results if the parameter is
|
||||
larger than the number of bits in the largest integer type.]
|
||||
]
|
||||
[
|
||||
[[^boost::int_t<N>::fast]]
|
||||
[The easiest-to-manipulate, built-in, signed integral type with at least /N/ bits, including the sign bit.
|
||||
The parameter should be a positive number. A compile-time error results if the parameter is
|
||||
[The easiest-to-manipulate, built-in, signed integral type with at least /N/ bits, including the sign bit.
|
||||
The parameter should be a positive number. A compile-time error results if the parameter is
|
||||
larger than the number of bits in the largest integer type.]
|
||||
]
|
||||
[
|
||||
[[^boost::int_t<N>::exact]]
|
||||
[A built-in, signed integral type with exactly /N/ bits, including the sign bit.
|
||||
[A built-in, signed integral type with exactly /N/ bits, including the sign bit.
|
||||
The parameter should be a positive number. Note that the member /exact/ is defined
|
||||
[*only] if there exists a type with exactly /N/ bits.]
|
||||
]
|
||||
[
|
||||
[[^boost::uint_t<N>::least]]
|
||||
[The smallest, built-in, unsigned integral type with at least /N/ bits.
|
||||
The parameter should be a positive number. A compile-time error results if the
|
||||
[The smallest, built-in, unsigned integral type with at least /N/ bits.
|
||||
The parameter should be a positive number. A compile-time error results if the
|
||||
parameter is larger than the number of bits in the largest integer type.]
|
||||
]
|
||||
[
|
||||
[[^boost::uint_t<N>::fast]]
|
||||
[The easiest-to-manipulate, built-in, unsigned integral type with at least /N/ bits.
|
||||
The parameter should be a positive number. A compile-time error results if the
|
||||
[The easiest-to-manipulate, built-in, unsigned integral type with at least /N/ bits.
|
||||
The parameter should be a positive number. A compile-time error results if the
|
||||
parameter is larger than the number of bits in the largest integer type.]
|
||||
]
|
||||
[
|
||||
[[^boost::uint_t<N>::exact]]
|
||||
[A built-in, unsigned integral type with exactly /N/ bits.
|
||||
The parameter should be a positive number. A compile-time error results if the
|
||||
parameter is larger than the number of bits in the largest integer type.
|
||||
[A built-in, unsigned integral type with exactly /N/ bits.
|
||||
The parameter should be a positive number. A compile-time error results if the
|
||||
parameter is larger than the number of bits in the largest integer type.
|
||||
Note that the member /exact/ is defined
|
||||
[*only] if there exists a type with exactly N bits.]
|
||||
]
|
||||
[
|
||||
[[^boost::int_max_value_t<V>::last]]
|
||||
[The smallest, built-in, signed integral type that can hold all the values in the inclusive range ['0 - V].
|
||||
[The smallest, built-in, signed integral type that can hold all the values in the inclusive range ['0 - V].
|
||||
The parameter should be a positive number.]
|
||||
]
|
||||
[
|
||||
[[^boost::int_max_value_t<V>::fast]]
|
||||
[The easiest-to-manipulate, built-in, signed integral type that can hold all the values in the inclusive range ['0 - V].
|
||||
[The easiest-to-manipulate, built-in, signed integral type that can hold all the values in the inclusive range ['0 - V].
|
||||
The parameter should be a positive number.]
|
||||
]
|
||||
[
|
||||
[[^boost::int_min_value_t<V>::least]]
|
||||
[The smallest, built-in, signed integral type that can hold all the values in the inclusive range ['V - 0].
|
||||
[The smallest, built-in, signed integral type that can hold all the values in the inclusive range ['V - 0].
|
||||
The parameter should be a negative number.]
|
||||
]
|
||||
[
|
||||
[[^boost::int_min_value_t<V>::fast]]
|
||||
[The easiest-to-manipulate, built-in, signed integral type that can hold all the values in the inclusive range ['V - 0].
|
||||
[The easiest-to-manipulate, built-in, signed integral type that can hold all the values in the inclusive range ['V - 0].
|
||||
The parameter should be a negative number.]
|
||||
]
|
||||
[
|
||||
@ -317,10 +328,10 @@ The following table describes each template's criteria.
|
||||
{
|
||||
boost::int_t<24>::least my_var; // my_var has at least 24-bits
|
||||
//...
|
||||
// This one is guarenteed not to be truncated:
|
||||
// This one is guaranteed not to be truncated:
|
||||
boost::int_max_value_t<1000>::least my1000 = 1000;
|
||||
//...
|
||||
// This one is guarenteed not to be truncated, and as fast
|
||||
// This one is guaranteed not to be truncated, and as fast
|
||||
// to manipulate as possible, its size may be greater than
|
||||
// that of my1000:
|
||||
boost::int_max_value_t<1000>::fast my_fast1000 = 1000;
|
||||
@ -330,7 +341,7 @@ The following table describes each template's criteria.
|
||||
|
||||
[section Demonstration Program]
|
||||
|
||||
The program [@../../test/integer_test.cpp integer_test.cpp] is a simplistic demonstration of the results from instantiating
|
||||
The program [@../../test/integer_test.cpp integer_test.cpp] is a simplistic demonstration of the results from instantiating
|
||||
various examples of the sized type class templates.
|
||||
|
||||
[endsect]
|
||||
@ -347,31 +358,32 @@ The rationale for the design of the templates in this header includes:
|
||||
|
||||
[section Alternative]
|
||||
|
||||
If the number of bits required is known beforehand, it may be more appropriate to use the types supplied
|
||||
If the number of bits required is known beforehand, it may be more appropriate to use the types supplied
|
||||
in [@../../../../boost/cstdint.hpp <boost/cstdint.hpp>].
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Credits]
|
||||
|
||||
The author of most of the Boost integer type choosing templates is
|
||||
[@http://www.boost.org/people/beman_dawes.html Beman Dawes].
|
||||
He gives thanks to Valentin Bonnard and [@http://www.boost.org/people/kevlin_henney.htm Kevlin Henney]
|
||||
for sharing their designs for similar templates.
|
||||
The author of most of the Boost integer type choosing templates is
|
||||
[@http://www.boost.org/people/beman_dawes.html Beman Dawes].
|
||||
He gives thanks to Valentin Bonnard and [@http://www.boost.org/people/kevlin_henney.htm Kevlin Henney]
|
||||
for sharing their designs for similar templates.
|
||||
[@http://www.boost.org/people/daryle_walker.html Daryle Walker] designed the value-based sized templates.
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
||||
[include gcd/math-gcd.qbk]
|
||||
|
||||
[include modular_arithmetic/extended_euclidean.qbk]
|
||||
[include modular_arithmetic/mod_inverse.qbk]
|
||||
|
||||
[section:mask Integer Masks]
|
||||
|
||||
[section Overview]
|
||||
|
||||
The class templates in [@../../../../boost/integer/integer_mask.hpp <boost/integer/integer_mask.hpp>]
|
||||
provide bit masks for a certain bit position or a contiguous-bit pack of a certain size.
|
||||
The class templates in [@../../../../boost/integer/integer_mask.hpp <boost/integer/integer_mask.hpp>]
|
||||
provide bit masks for a certain bit position or a contiguous-bit pack of a certain size.
|
||||
The types of the masking constants come from the [link boost_integer.integer integer type selection templates] header.
|
||||
|
||||
[endsect]
|
||||
@ -411,14 +423,14 @@ The types of the masking constants come from the [link boost_integer.integer int
|
||||
|
||||
} // namespace boost
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
||||
[section Single Bit-Mask Class Template]
|
||||
|
||||
The [^boost::high_bit_mask_t] class template provides constants for bit masks representing the bit at a
|
||||
certain position. The masks are equivalent to the value 2[super Bit], where [^Bit] is the template parameter.
|
||||
The bit position must be a nonnegative number from zero to ['Max], where Max is one less than the
|
||||
number of bits supported by the largest unsigned built-in integral type. The following table describes
|
||||
The [^boost::high_bit_mask_t] class template provides constants for bit masks representing the bit at a
|
||||
certain position. The masks are equivalent to the value 2[super Bit], where [^Bit] is the template parameter.
|
||||
The bit position must be a nonnegative number from zero to ['Max], where Max is one less than the
|
||||
number of bits supported by the largest unsigned built-in integral type. The following table describes
|
||||
the members of an instantiation of [^high_bit_mask_t].
|
||||
|
||||
[table Members of the `boost::high_bit_mask_t` Class Template
|
||||
@ -430,14 +442,14 @@ the members of an instantiation of [^high_bit_mask_t].
|
||||
[[[^bit_position]][The value of the template parameter, in case its needed from a renamed instantiation of the class template.]]
|
||||
]
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
||||
[section Group Bit-Mask Class Template]
|
||||
|
||||
The [^boost::low_bits_mask_t] class template provides constants for bit masks
|
||||
equivalent to the value (2[super Bits] - 1), where [^Bits] is the template parameter.
|
||||
The parameter [^Bits] must be a non-negative integer from
|
||||
zero to ['Max], where Max is the number of bits supported by the largest, unsigned, built-in integral type.
|
||||
The [^boost::low_bits_mask_t] class template provides constants for bit masks
|
||||
equivalent to the value (2[super Bits] - 1), where [^Bits] is the template parameter.
|
||||
The parameter [^Bits] must be a non-negative integer from
|
||||
zero to ['Max], where Max is the number of bits supported by the largest, unsigned, built-in integral type.
|
||||
The following table describes the members of [^low_bits_mask_t].
|
||||
|
||||
[table Members of the [^boost::low_bits_mask_t] Class Template
|
||||
@ -453,7 +465,7 @@ The following table describes the members of [^low_bits_mask_t].
|
||||
|
||||
[section Implementation Notes]
|
||||
|
||||
When [^Bits] is the exact size of a built-in unsigned type, the implementation has to change to
|
||||
When [^Bits] is the exact size of a built-in unsigned type, the implementation has to change to
|
||||
prevent undefined behavior. Therefore, there are specializations of [^low_bits_mask_t] at those bit counts.
|
||||
|
||||
[endsect]
|
||||
@ -479,23 +491,23 @@ prevent undefined behavior. Therefore, there are specializations of [^low_bits_m
|
||||
//...
|
||||
}
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
||||
[section Demonstration Program]
|
||||
|
||||
The program [@../../test/integer_mask_test.cpp integer_mask_test.cpp] is a simplistic demonstration of the
|
||||
The program [@../../test/integer_mask_test.cpp integer_mask_test.cpp] is a simplistic demonstration of the
|
||||
results from instantiating various examples of the bit mask class templates.
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
||||
[section Rationale]
|
||||
|
||||
The class templates in this header are an extension of the [link boost_integer.integer integer type selection class templates].
|
||||
The new class templates provide the same sized types, but also convenient masks to use when extracting the
|
||||
highest or all the significant bits when the containing built-in type contains more bits.
|
||||
The class templates in this header are an extension of the [link boost_integer.integer integer type selection class templates].
|
||||
The new class templates provide the same sized types, but also convenient masks to use when extracting the
|
||||
highest or all the significant bits when the containing built-in type contains more bits.
|
||||
This prevents contamination of values by the higher, unused bits.
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
||||
[section Credits]
|
||||
|
||||
@ -506,7 +518,7 @@ The author of the Boost bit mask class templates is [@http://www.boost.org/peopl
|
||||
|
||||
[section:log2 Compile Time log2 Calculation]
|
||||
|
||||
The class template in [@../../../../boost/integer/static_log2.hpp <boost/integer/static_log2.hpp>]
|
||||
The class template in [@../../../../boost/integer/static_log2.hpp <boost/integer/static_log2.hpp>]
|
||||
determines the position of the highest bit in a given value. This facility is useful for solving generic programming problems.
|
||||
|
||||
[section Synopsis]
|
||||
@ -533,47 +545,47 @@ determines the position of the highest bit in a given value. This facility is us
|
||||
|
||||
} // namespace boost
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
||||
[section Usage]
|
||||
|
||||
The [^boost::static_log2] class template takes one template parameter, a value of type
|
||||
[^static_log2_argument_type]. The template only defines one member, [^value], which gives the
|
||||
The [^boost::static_log2] class template takes one template parameter, a value of type
|
||||
[^static_log2_argument_type]. The template only defines one member, [^value], which gives the
|
||||
truncated, base-two logarithm of the template argument.
|
||||
|
||||
Since the logarithm of zero, for any base, is undefined, there is a specialization of [^static_log2]
|
||||
for a template argument of zero. This specialization has no members, so an attempt to use the base-two
|
||||
Since the logarithm of zero, for any base, is undefined, there is a specialization of [^static_log2]
|
||||
for a template argument of zero. This specialization has no members, so an attempt to use the base-two
|
||||
logarithm of zero results in a compile-time error.
|
||||
|
||||
Note:
|
||||
Note:
|
||||
|
||||
* [^static_log2_argument_type] is an ['unsigned integer type] (C++ standard, 3.9.1p3).
|
||||
* [^static_log2_result_type] is an ['integer type] (C++ standard, 3.9.1p7).
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
||||
[section Demonstration Program]
|
||||
|
||||
The program [@../../test/static_log2_test.cpp static_log2_test.cpp] is a simplistic
|
||||
The program [@../../test/static_log2_test.cpp static_log2_test.cpp] is a simplistic
|
||||
demonstration of the results from instantiating various examples of the binary logarithm class template.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Rationale]
|
||||
|
||||
The base-two (binary) logarithm, abbreviated lb, function is occasionally used to give order-estimates
|
||||
of computer algorithms. The truncated logarithm can be considered the highest power-of-two in a value,
|
||||
which corresponds to the value's highest set bit (for binary integers). Sometimes the highest-bit position
|
||||
The base-two (binary) logarithm, abbreviated lb, function is occasionally used to give order-estimates
|
||||
of computer algorithms. The truncated logarithm can be considered the highest power-of-two in a value,
|
||||
which corresponds to the value's highest set bit (for binary integers). Sometimes the highest-bit position
|
||||
could be used in generic programming, which requires the position to be available statically (['i.e.] at compile-time).
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
||||
[section Credits]
|
||||
|
||||
The original version of the Boost binary logarithm class template was
|
||||
written by [@http://www.boost.org/people/daryle_walker.html Daryle Walker] and then
|
||||
enhanced by Giovanni Bajo with support for compilers without partial template specialization.
|
||||
The current version was suggested, together with a reference implementation, by Vesa Karvonen.
|
||||
The original version of the Boost binary logarithm class template was
|
||||
written by [@http://www.boost.org/people/daryle_walker.html Daryle Walker] and then
|
||||
enhanced by Giovanni Bajo with support for compilers without partial template specialization.
|
||||
The current version was suggested, together with a reference implementation, by Vesa Karvonen.
|
||||
Gennaro Prota wrote the actual source file.
|
||||
|
||||
[endsect]
|
||||
@ -581,15 +593,15 @@ Gennaro Prota wrote the actual source file.
|
||||
|
||||
[section:minmax Compile time min/max calculation]
|
||||
|
||||
The class templates in [@../../../../boost/integer/static_min_max.hpp <boost/integer/static_min_max.hpp>]
|
||||
provide a compile-time evaluation of the minimum or maximum of two integers. These facilities are useful
|
||||
The class templates in [@../../../../boost/integer/static_min_max.hpp <boost/integer/static_min_max.hpp>]
|
||||
provide a compile-time evaluation of the minimum or maximum of two integers. These facilities are useful
|
||||
for generic programming problems.
|
||||
|
||||
[section Synopsis]
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
||||
typedef ``['implementation-defined]`` static_min_max_signed_type;
|
||||
typedef ``['implementation-defined]`` static_min_max_unsigned_type;
|
||||
|
||||
@ -607,15 +619,15 @@ for generic programming problems.
|
||||
|
||||
}
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
||||
[section Usage]
|
||||
|
||||
The four class templates provide the combinations for finding the minimum or maximum of two [^signed] or
|
||||
[^unsigned] ([^long]) parameters, /Value1/ and /Value2/, at compile-time. Each template has a single static data member,
|
||||
The four class templates provide the combinations for finding the minimum or maximum of two [^signed] or
|
||||
[^unsigned] ([^long]) parameters, /Value1/ and /Value2/, at compile-time. Each template has a single static data member,
|
||||
[^value], which is set to the respective minimum or maximum of the template's parameters.
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
||||
[section Example]
|
||||
|
||||
@ -653,14 +665,14 @@ The four class templates provide the combinations for finding the minimum or max
|
||||
|
||||
[section Demonstration Program]
|
||||
|
||||
The program [@../../test/static_min_max_test.cpp static_min_max_test.cpp] is a simplistic demonstration of
|
||||
The program [@../../test/static_min_max_test.cpp static_min_max_test.cpp] is a simplistic demonstration of
|
||||
various comparisons using the compile-time extrema class templates.
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
|
||||
[section Rationale]
|
||||
|
||||
Sometimes the minimum or maximum of several values needs to be found for later compile-time processing,
|
||||
Sometimes the minimum or maximum of several values needs to be found for later compile-time processing,
|
||||
['e.g.] for a bound for another class template.
|
||||
|
||||
[endsect]
|
||||
@ -682,23 +694,23 @@ The author of the Boost compile-time extrema class templates is [@http://www.boo
|
||||
[h4 1.42.0]
|
||||
|
||||
* Reverted Trunk to release branch state (i.e. a "known good state").
|
||||
* Fixed issues: [@https://svn.boost.org/trac/boost/ticket/653 653],
|
||||
[@https://svn.boost.org/trac/boost/ticket/3084 3084],
|
||||
[@https://svn.boost.org/trac/boost/ticket/3177 3177],
|
||||
[@https://svn.boost.org/trac/boost/ticket/3180 3180],
|
||||
[@https://svn.boost.org/trac/boost/ticket/3548 3568],
|
||||
[@https://svn.boost.org/trac/boost/ticket/3657 3657],
|
||||
* Fixed issues: [@https://svn.boost.org/trac/boost/ticket/653 653],
|
||||
[@https://svn.boost.org/trac/boost/ticket/3084 3084],
|
||||
[@https://svn.boost.org/trac/boost/ticket/3177 3177],
|
||||
[@https://svn.boost.org/trac/boost/ticket/3180 3180],
|
||||
[@https://svn.boost.org/trac/boost/ticket/3548 3568],
|
||||
[@https://svn.boost.org/trac/boost/ticket/3657 3657],
|
||||
[@https://svn.boost.org/trac/boost/ticket/2134 2134].
|
||||
* Added long long support to [^boost::static_log2], [^boost::static_signed_min], [^boost::static_signed_max],
|
||||
* Added long long support to [^boost::static_log2], [^boost::static_signed_min], [^boost::static_signed_max],
|
||||
[^boost::static_unsigned_min][^boost::static_unsigned_max], when available.
|
||||
* The argument type and the result type of [^boost::static_signed_min] etc are now typedef'd.
|
||||
Formerly, they were hardcoded as [^unsigned long] and [^int] respectively. Please, use the
|
||||
* The argument type and the result type of [^boost::static_signed_min] etc are now typedef'd.
|
||||
Formerly, they were hardcoded as [^unsigned long] and [^int] respectively. Please, use the
|
||||
provided typedefs in new code (and update old code as soon as possible).
|
||||
|
||||
[h4 1.32.0]
|
||||
|
||||
* The argument type and the result type of [^boost::static_log2] are now typedef'd.
|
||||
Formerly, they were hardcoded as [^unsigned long] and [^int] respectively. Please, use the
|
||||
* The argument type and the result type of [^boost::static_log2] are now typedef'd.
|
||||
Formerly, they were hardcoded as [^unsigned long] and [^int] respectively. Please, use the
|
||||
provided typedefs in new code (and update old code as soon as possible).
|
||||
|
||||
[endsect]
|
||||
|
53
doc/modular_arithmetic/extended_euclidean.qbk
Normal file
53
doc/modular_arithmetic/extended_euclidean.qbk
Normal file
@ -0,0 +1,53 @@
|
||||
[section:extended_euclidean Extended Euclidean Algorithm]
|
||||
|
||||
[section Introduction]
|
||||
|
||||
The extended Euclidean algorithm solves the integer relation /mx + ny/ = gcd(/m/, /n/) for /x/ and /y/.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Synopsis]
|
||||
|
||||
#include <boost/integer/extended_euclidean.hpp>
|
||||
|
||||
namespace boost { namespace integer {
|
||||
|
||||
template<class Z>
|
||||
struct euclidean_result_t {
|
||||
Z gcd;
|
||||
Z x;
|
||||
Z y;
|
||||
};
|
||||
|
||||
|
||||
template<class Z>
|
||||
euclidean_result_t<Z> extended_euclidean(Z m, Z n);
|
||||
|
||||
}}
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Usage]
|
||||
|
||||
int m = 12;
|
||||
int n = 15;
|
||||
auto res = extended_euclidean(m, n);
|
||||
|
||||
int gcd = res.gcd;
|
||||
int x = res.x;
|
||||
int y = res.y;
|
||||
// mx + ny = gcd(m,n) should now hold
|
||||
|
||||
[endsect]
|
||||
|
||||
[section References]
|
||||
Wagstaff, Samuel S., ['The Joy of Factoring], Vol. 68. American Mathematical Soc., 2013.
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
[/
|
||||
Copyright 2018 Nick Thompson.
|
||||
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).
|
||||
]
|
50
doc/modular_arithmetic/mod_inverse.qbk
Normal file
50
doc/modular_arithmetic/mod_inverse.qbk
Normal file
@ -0,0 +1,50 @@
|
||||
[section:mod_inverse Modular Multiplicative Inverse]
|
||||
|
||||
[section Introduction]
|
||||
|
||||
The modular multiplicative inverse of a number /a/ is that number /x/ which satisfies /ax/ = 1 mod /p/.
|
||||
A fast algorithm for computing modular multiplicative inverses based on the extended Euclidean algorithm exists and is provided by Boost.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Synopsis]
|
||||
|
||||
#include <boost/integer/mod_inverse.hpp>
|
||||
|
||||
namespace boost { namespace integer {
|
||||
|
||||
template<class Z>
|
||||
Z mod_inverse(Z a, Z m);
|
||||
|
||||
}}
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Usage]
|
||||
|
||||
int x = mod_inverse(2, 5);
|
||||
// prints x = 3:
|
||||
std::cout << "x = " << x << "\n";
|
||||
|
||||
int y = mod_inverse(2, 4);
|
||||
if (y == 0)
|
||||
{
|
||||
std::cout << "There is no inverse of 2 mod 4\n";
|
||||
}
|
||||
|
||||
Multiplicative modular inverses exist if and only if /a/ and /m/ are coprime.
|
||||
If /a/ and /m/ share a common factor, then `mod_inverse(a, m)` returns zero.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section References]
|
||||
Wagstaff, Samuel S., ['The Joy of Factoring], Vol. 68. American Mathematical Soc., 2013.
|
||||
|
||||
[endsect]
|
||||
[endsect]
|
||||
[/
|
||||
Copyright 2018 Nick Thompson.
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
http://www.boost.org/LICENSE_1_0.txt).
|
||||
]
|
@ -83,9 +83,9 @@ namespace boost {
|
||||
}
|
||||
#endif
|
||||
|
||||
template <class T, bool a =
|
||||
template <class T, bool a =
|
||||
#ifndef BOOST_NO_CXX11_HDR_TYPE_TRAITS
|
||||
std::is_unsigned<T>::value ||
|
||||
std::is_unsigned<T>::value ||
|
||||
#endif
|
||||
(std::numeric_limits<T>::is_specialized && !std::numeric_limits<T>::is_signed)>
|
||||
struct gcd_traits_abs_defaults
|
||||
@ -210,28 +210,28 @@ namespace boost {
|
||||
// this works for signed types too, as by the time these functions
|
||||
// are called, all values are > 0.
|
||||
//
|
||||
template <> struct gcd_traits<long> : public gcd_traits_defaults<long>
|
||||
template <> struct gcd_traits<long> : public gcd_traits_defaults<long>
|
||||
{ BOOST_FORCEINLINE static unsigned make_odd(long& val)BOOST_NOEXCEPT{ unsigned result = gcd_traits<unsigned long>::find_lsb(val); val >>= result; return result; } };
|
||||
template <> struct gcd_traits<unsigned int> : public gcd_traits_defaults<unsigned int>
|
||||
template <> struct gcd_traits<unsigned int> : public gcd_traits_defaults<unsigned int>
|
||||
{ BOOST_FORCEINLINE static unsigned make_odd(unsigned int& val)BOOST_NOEXCEPT{ unsigned result = gcd_traits<unsigned long>::find_lsb(val); val >>= result; return result; } };
|
||||
template <> struct gcd_traits<int> : public gcd_traits_defaults<int>
|
||||
template <> struct gcd_traits<int> : public gcd_traits_defaults<int>
|
||||
{ BOOST_FORCEINLINE static unsigned make_odd(int& val)BOOST_NOEXCEPT{ unsigned result = gcd_traits<unsigned long>::find_lsb(val); val >>= result; return result; } };
|
||||
template <> struct gcd_traits<unsigned short> : public gcd_traits_defaults<unsigned short>
|
||||
template <> struct gcd_traits<unsigned short> : public gcd_traits_defaults<unsigned short>
|
||||
{ BOOST_FORCEINLINE static unsigned make_odd(unsigned short& val)BOOST_NOEXCEPT{ unsigned result = gcd_traits<unsigned long>::find_lsb(val); val >>= result; return result; } };
|
||||
template <> struct gcd_traits<short> : public gcd_traits_defaults<short>
|
||||
template <> struct gcd_traits<short> : public gcd_traits_defaults<short>
|
||||
{ BOOST_FORCEINLINE static unsigned make_odd(short& val)BOOST_NOEXCEPT{ unsigned result = gcd_traits<unsigned long>::find_lsb(val); val >>= result; return result; } };
|
||||
template <> struct gcd_traits<unsigned char> : public gcd_traits_defaults<unsigned char>
|
||||
template <> struct gcd_traits<unsigned char> : public gcd_traits_defaults<unsigned char>
|
||||
{ BOOST_FORCEINLINE static unsigned make_odd(unsigned char& val)BOOST_NOEXCEPT{ unsigned result = gcd_traits<unsigned long>::find_lsb(val); val >>= result; return result; } };
|
||||
template <> struct gcd_traits<signed char> : public gcd_traits_defaults<signed char>
|
||||
{ BOOST_FORCEINLINE static signed make_odd(signed char& val)BOOST_NOEXCEPT{ signed result = gcd_traits<unsigned long>::find_lsb(val); val >>= result; return result; } };
|
||||
template <> struct gcd_traits<char> : public gcd_traits_defaults<char>
|
||||
template <> struct gcd_traits<signed char> : public gcd_traits_defaults<signed char>
|
||||
{ BOOST_FORCEINLINE static unsigned make_odd(signed char& val)BOOST_NOEXCEPT{ unsigned result = gcd_traits<unsigned long>::find_lsb(val); val >>= result; return result; } };
|
||||
template <> struct gcd_traits<char> : public gcd_traits_defaults<char>
|
||||
{ BOOST_FORCEINLINE static unsigned make_odd(char& val)BOOST_NOEXCEPT{ unsigned result = gcd_traits<unsigned long>::find_lsb(val); val >>= result; return result; } };
|
||||
#ifndef BOOST_NO_INTRINSIC_WCHAR_T
|
||||
template <> struct gcd_traits<wchar_t> : public gcd_traits_defaults<wchar_t>
|
||||
template <> struct gcd_traits<wchar_t> : public gcd_traits_defaults<wchar_t>
|
||||
{ BOOST_FORCEINLINE static unsigned make_odd(wchar_t& val)BOOST_NOEXCEPT{ unsigned result = gcd_traits<unsigned long>::find_lsb(val); val >>= result; return result; } };
|
||||
#endif
|
||||
#ifdef _M_X64
|
||||
template <> struct gcd_traits<__int64> : public gcd_traits_defaults<__int64>
|
||||
template <> struct gcd_traits<__int64> : public gcd_traits_defaults<__int64>
|
||||
{ BOOST_FORCEINLINE static unsigned make_odd(__int64& val)BOOST_NOEXCEPT{ unsigned result = gcd_traits<unsigned __int64>::find_lsb(val); val >>= result; return result; } };
|
||||
#endif
|
||||
|
||||
@ -310,7 +310,7 @@ namespace boost {
|
||||
};
|
||||
template <> struct gcd_traits<signed char> : public gcd_traits_defaults<signed char>
|
||||
{
|
||||
BOOST_FORCEINLINE static BOOST_CXX14_CONSTEXPR signed make_odd(signed char& val)BOOST_NOEXCEPT { signed result = gcd_traits<unsigned>::find_lsb(val); val >>= result; return result; }
|
||||
BOOST_FORCEINLINE static BOOST_CXX14_CONSTEXPR unsigned make_odd(signed char& val)BOOST_NOEXCEPT { unsigned result = gcd_traits<unsigned>::find_lsb(val); val >>= result; return result; }
|
||||
};
|
||||
template <> struct gcd_traits<char> : public gcd_traits_defaults<char>
|
||||
{
|
||||
@ -360,7 +360,7 @@ namespace boost {
|
||||
}
|
||||
|
||||
/** Stein gcd (aka 'binary gcd')
|
||||
*
|
||||
*
|
||||
* From Mathematics to Generic Programming, Alexander Stepanov, Daniel Rose
|
||||
*/
|
||||
template <typename SteinDomain>
|
||||
@ -373,8 +373,8 @@ namespace boost {
|
||||
if (n == SteinDomain(0))
|
||||
return m;
|
||||
// m > 0 && n > 0
|
||||
int d_m = gcd_traits<SteinDomain>::make_odd(m);
|
||||
int d_n = gcd_traits<SteinDomain>::make_odd(n);
|
||||
unsigned d_m = gcd_traits<SteinDomain>::make_odd(m);
|
||||
unsigned d_n = gcd_traits<SteinDomain>::make_odd(n);
|
||||
// odd(m) && odd(n)
|
||||
while (m != n)
|
||||
{
|
||||
@ -388,11 +388,11 @@ namespace boost {
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Euclidean algorithm
|
||||
*
|
||||
*
|
||||
* From Mathematics to Generic Programming, Alexander Stepanov, Daniel Rose
|
||||
*
|
||||
*
|
||||
*/
|
||||
template <typename EuclideanDomain>
|
||||
inline BOOST_CXX14_CONSTEXPR EuclideanDomain Euclid_gcd(EuclideanDomain a, EuclideanDomain b) BOOST_GCD_NOEXCEPT(EuclideanDomain)
|
||||
@ -494,10 +494,10 @@ inline typename boost::enable_if_c<std::numeric_limits<Integer>::is_specialized,
|
||||
*
|
||||
* Knuth counts down from n to zero but we naturally go from first to last.
|
||||
* We also return the termination position because it might be useful to know.
|
||||
*
|
||||
* Partly by quirk, partly by design, this algorithm is defined for n = 1,
|
||||
*
|
||||
* Partly by quirk, partly by design, this algorithm is defined for n = 1,
|
||||
* because the gcd of {x} is x. It is not defined for n = 0.
|
||||
*
|
||||
*
|
||||
* @tparam I Input iterator.
|
||||
* @return The gcd of the range and the iterator position at termination.
|
||||
*/
|
||||
@ -507,12 +507,13 @@ gcd_range(I first, I last) BOOST_GCD_NOEXCEPT(I)
|
||||
{
|
||||
BOOST_ASSERT(first != last);
|
||||
typedef typename std::iterator_traits<I>::value_type T;
|
||||
|
||||
T d = *first++;
|
||||
|
||||
T d = *first;
|
||||
++first;
|
||||
while (d != T(1) && first != last)
|
||||
{
|
||||
d = gcd(d, *first);
|
||||
first++;
|
||||
++first;
|
||||
}
|
||||
return std::make_pair(d, first);
|
||||
}
|
||||
@ -522,12 +523,13 @@ lcm_range(I first, I last) BOOST_GCD_NOEXCEPT(I)
|
||||
{
|
||||
BOOST_ASSERT(first != last);
|
||||
typedef typename std::iterator_traits<I>::value_type T;
|
||||
|
||||
T d = *first++;
|
||||
while (d != T(1) && first != last)
|
||||
|
||||
T d = *first;
|
||||
++first;
|
||||
while (d != T(0) && first != last)
|
||||
{
|
||||
d = lcm(d, *first);
|
||||
first++;
|
||||
++first;
|
||||
}
|
||||
return std::make_pair(d, first);
|
||||
}
|
||||
@ -544,7 +546,7 @@ public:
|
||||
typedef IntegerType second_argument_type;
|
||||
typedef IntegerType result_type;
|
||||
#endif
|
||||
IntegerType operator()(IntegerType const &a, IntegerType const &b)const
|
||||
IntegerType operator()(IntegerType const &a, IntegerType const &b) const
|
||||
{
|
||||
return boost::integer::gcd(a, b);
|
||||
}
|
||||
|
83
include/boost/integer/extended_euclidean.hpp
Normal file
83
include/boost/integer/extended_euclidean.hpp
Normal file
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* (C) Copyright Nick Thompson 2018.
|
||||
* Use, modification and distribution are subject to the
|
||||
* Boost Software License, Version 1.0. (See accompanying file
|
||||
* LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#ifndef BOOST_INTEGER_EXTENDED_EUCLIDEAN_HPP
|
||||
#define BOOST_INTEGER_EXTENDED_EUCLIDEAN_HPP
|
||||
#include <limits>
|
||||
#include <stdexcept>
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <boost/core/swap.hpp>
|
||||
#include <boost/core/enable_if.hpp>
|
||||
|
||||
namespace boost { namespace integer {
|
||||
|
||||
// From "The Joy of Factoring", Algorithm 2.7, with a small optimization to remove tmps from Wikipedia.
|
||||
// Solves mx + ny = gcd(m,n). Returns tuple with (gcd(m,n), x, y).
|
||||
|
||||
template<class Z>
|
||||
struct euclidean_result_t
|
||||
{
|
||||
Z gcd;
|
||||
Z x;
|
||||
Z y;
|
||||
};
|
||||
|
||||
template<class Z>
|
||||
typename boost::enable_if_c< std::numeric_limits< Z >::is_signed, euclidean_result_t< Z > >::type
|
||||
extended_euclidean(Z m, Z n)
|
||||
{
|
||||
if (m < 1 || n < 1)
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(std::domain_error("extended_euclidean: arguments must be strictly positive"));
|
||||
}
|
||||
|
||||
bool swapped = false;
|
||||
if (m < n)
|
||||
{
|
||||
swapped = true;
|
||||
boost::swap(m, n);
|
||||
}
|
||||
Z u0 = m;
|
||||
Z u1 = 1;
|
||||
Z u2 = 0;
|
||||
Z v0 = n;
|
||||
Z v1 = 0;
|
||||
Z v2 = 1;
|
||||
Z w0;
|
||||
Z w1;
|
||||
Z w2;
|
||||
while(v0 > 0)
|
||||
{
|
||||
Z q = u0/v0;
|
||||
w0 = u0 - q*v0;
|
||||
w1 = u1 - q*v1;
|
||||
w2 = u2 - q*v2;
|
||||
u0 = v0;
|
||||
u1 = v1;
|
||||
u2 = v2;
|
||||
v0 = w0;
|
||||
v1 = w1;
|
||||
v2 = w2;
|
||||
}
|
||||
|
||||
euclidean_result_t< Z > result;
|
||||
result.gcd = u0;
|
||||
if (!swapped)
|
||||
{
|
||||
result.x = u1;
|
||||
result.y = u2;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.x = u2;
|
||||
result.y = u1;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}}
|
||||
#endif
|
53
include/boost/integer/mod_inverse.hpp
Normal file
53
include/boost/integer/mod_inverse.hpp
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* (C) Copyright Nick Thompson 2018.
|
||||
* Use, modification and distribution are subject to the
|
||||
* Boost Software License, Version 1.0. (See accompanying file
|
||||
* LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#ifndef BOOST_INTEGER_MOD_INVERSE_HPP
|
||||
#define BOOST_INTEGER_MOD_INVERSE_HPP
|
||||
#include <stdexcept>
|
||||
#include <boost/throw_exception.hpp>
|
||||
#include <boost/integer/extended_euclidean.hpp>
|
||||
|
||||
namespace boost { namespace integer {
|
||||
|
||||
// From "The Joy of Factoring", Algorithm 2.7.
|
||||
// Here's some others names I've found for this function:
|
||||
// PowerMod[a, -1, m] (Mathematica)
|
||||
// mpz_invert (gmplib)
|
||||
// modinv (some dude on stackoverflow)
|
||||
// Would mod_inverse be sometimes mistaken as the modular *additive* inverse?
|
||||
// In any case, I think this is the best name we can get for this function without agonizing.
|
||||
template<class Z>
|
||||
Z mod_inverse(Z a, Z modulus)
|
||||
{
|
||||
if (modulus < Z(2))
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(std::domain_error("mod_inverse: modulus must be > 1"));
|
||||
}
|
||||
// make sure a < modulus:
|
||||
a = a % modulus;
|
||||
if (a == Z(0))
|
||||
{
|
||||
// a doesn't have a modular multiplicative inverse:
|
||||
return Z(0);
|
||||
}
|
||||
boost::integer::euclidean_result_t<Z> u = boost::integer::extended_euclidean(a, modulus);
|
||||
if (u.gcd > Z(1))
|
||||
{
|
||||
return Z(0);
|
||||
}
|
||||
// x might not be in the range 0 < x < m, let's fix that:
|
||||
while (u.x <= Z(0))
|
||||
{
|
||||
u.x += modulus;
|
||||
}
|
||||
// While indeed this is an inexpensive and comforting check,
|
||||
// the multiplication overflows and hence makes the check itself buggy.
|
||||
//BOOST_ASSERT(u.x*a % modulus == 1);
|
||||
return u.x;
|
||||
}
|
||||
|
||||
}}
|
||||
#endif
|
@ -1,9 +1,9 @@
|
||||
#ifndef BOOST_PENDING_INTEGER_LOG2_HPP
|
||||
#define BOOST_PENDING_INTEGER_LOG2_HPP
|
||||
|
||||
// The header file at this path is deprecated;
|
||||
// use boost/integer/integer_log2.hpp instead.
|
||||
|
||||
#include <boost/integer/integer_log2.hpp>
|
||||
#include <boost/config/header_deprecated.hpp>
|
||||
|
||||
BOOST_HEADER_DEPRECATED("<boost/integer/integer_log2.hpp>");
|
||||
|
||||
#endif
|
||||
|
@ -7,6 +7,7 @@
|
||||
],
|
||||
"authors": "",
|
||||
"maintainers": [
|
||||
"Daryle Walker <darylew -at- hotmail.com>"
|
||||
"Daryle Walker <darylew -at- hotmail.com>",
|
||||
"Andrey Semashev <andrey.semashev -at- gmail.com>"
|
||||
]
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
#~ (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
import testing ;
|
||||
import ../../config/checks/config : requires ;
|
||||
|
||||
project : requirements <warnings>all <toolset>gcc:<cxxflags>-Wextra ;
|
||||
|
||||
@ -10,20 +11,22 @@ obj has_gmpxx : has_gmpxx.cpp ;
|
||||
explicit has_gmpxx ;
|
||||
|
||||
test-suite integer
|
||||
:
|
||||
:
|
||||
[ run integer_traits_test.cpp ]
|
||||
[ run integer_test.cpp : : : <toolset>gcc:<cxxflags>-Wno-long-long <toolset>darwin:<cxxflags>-Wno-long-long <toolset>sun:<cxxflags>"-Qoption ccfe -tmpldepth=128" ]
|
||||
[ run integer_mask_test.cpp ]
|
||||
[ run static_log2_test.cpp ]
|
||||
[ run static_min_max_test.cpp ]
|
||||
[ run extended_euclidean_test.cpp ]
|
||||
[ run mod_inverse_test.cpp ]
|
||||
[ compile integer_traits_include_test.cpp ]
|
||||
[ compile integer_include_test.cpp ]
|
||||
[ compile integer_mask_include_test.cpp ]
|
||||
[ compile static_log2_include_test.cpp ]
|
||||
[ compile static_min_max_include_test.cpp ]
|
||||
[ compile integer_fwd_include_test.cpp ]
|
||||
[ compile gcd_constexpr14_test.cpp ]
|
||||
[ compile gcd_noexcept_test.cpp ]
|
||||
[ compile gcd_constexpr14_test.cpp ]
|
||||
[ compile gcd_noexcept_test.cpp ]
|
||||
[ compile-fail fail_int_exact.cpp ]
|
||||
[ compile-fail fail_int_fast.cpp ]
|
||||
[ compile-fail fail_int_least.cpp ]
|
||||
|
@ -34,9 +34,7 @@
|
||||
#include <gmpxx.h>
|
||||
#endif
|
||||
|
||||
#if (defined(BOOST_MSVC) && (BOOST_MSVC < 1500)) || (defined(__clang_major__) && (__clang_major__ == 3) && (__clang_minor__ < 2))
|
||||
#define DISABLE_MP_TESTS
|
||||
#endif
|
||||
#include "multiprecision_config.hpp"
|
||||
|
||||
#ifndef DISABLE_MP_TESTS
|
||||
#include <boost/multiprecision/cpp_int.hpp>
|
||||
@ -256,7 +254,7 @@ public:
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC,<1300)
|
||||
// MSVC 6.0 lacks operator<< for __int64, see
|
||||
// http://support.microsoft.com/default.aspx?scid=kb;en-us;168440
|
||||
// https://support.microsoft.com/kb/168440/
|
||||
|
||||
inline ostream& operator<<(ostream& os, __int64 i)
|
||||
{
|
||||
@ -544,6 +542,15 @@ void variadics()
|
||||
BOOST_TEST_EQ(boost::integer::gcd_range(i, i + 4).second, i + 4);
|
||||
BOOST_TEST_EQ(boost::integer::lcm_range(i, i + 4).first, 11704);
|
||||
BOOST_TEST_EQ(boost::integer::lcm_range(i, i + 4).second, i + 4);
|
||||
|
||||
unsigned i_gcd_unity[] = { 44, 56, 1, 88 };
|
||||
BOOST_TEST_EQ(boost::integer::gcd_range(i_gcd_unity, i_gcd_unity + 4).first, 1);
|
||||
BOOST_TEST_EQ(boost::integer::gcd_range(i_gcd_unity, i_gcd_unity + 4).second, i_gcd_unity + 3);
|
||||
|
||||
unsigned i_lcm_unity[] = { 44, 56, 0, 88 };
|
||||
BOOST_TEST_EQ(boost::integer::lcm_range(i_lcm_unity, i_lcm_unity + 4).first, 0);
|
||||
BOOST_TEST_EQ(boost::integer::lcm_range(i_lcm_unity, i_lcm_unity + 4).second, i_lcm_unity + 3);
|
||||
|
||||
#ifndef BOOST_NO_CXX11_VARIADIC_TEMPLATES
|
||||
BOOST_TEST_EQ(boost::integer::gcd(i[0], i[1], i[2], i[3]), 4);
|
||||
BOOST_TEST_EQ(boost::integer::lcm(i[0], i[1], i[2], i[3]), 11704);
|
||||
|
58
test/extended_euclidean_test.cpp
Normal file
58
test/extended_euclidean_test.cpp
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* (C) Copyright Nick Thompson 2018.
|
||||
* Use, modification and distribution are subject to the
|
||||
* Boost Software License, Version 1.0. (See accompanying file
|
||||
* LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
|
||||
#include "multiprecision_config.hpp"
|
||||
|
||||
#ifndef DISABLE_MP_TESTS
|
||||
#include <boost/integer/extended_euclidean.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/multiprecision/cpp_int.hpp>
|
||||
#include <boost/integer/common_factor.hpp>
|
||||
|
||||
using boost::multiprecision::int128_t;
|
||||
using boost::multiprecision::int256_t;
|
||||
using boost::integer::extended_euclidean;
|
||||
using boost::integer::gcd;
|
||||
|
||||
template<class Z>
|
||||
void test_extended_euclidean()
|
||||
{
|
||||
// Stress test:
|
||||
//Z max_arg = std::numeric_limits<Z>::max();
|
||||
Z max_arg = 500;
|
||||
for (Z m = max_arg; m > 0; --m)
|
||||
{
|
||||
for (Z n = max_arg; n > 0; --n)
|
||||
{
|
||||
boost::integer::euclidean_result_t<Z> u = extended_euclidean(m, n);
|
||||
int256_t gcdmn = gcd(m, n);
|
||||
int256_t x = u.x;
|
||||
int256_t y = u.y;
|
||||
BOOST_TEST_EQ(u.gcd, gcdmn);
|
||||
BOOST_TEST_EQ(m*x + n*y, gcdmn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
test_extended_euclidean<boost::int16_t>();
|
||||
test_extended_euclidean<boost::int32_t>();
|
||||
test_extended_euclidean<boost::int64_t>();
|
||||
test_extended_euclidean<int128_t>();
|
||||
|
||||
return boost::report_errors();;
|
||||
}
|
||||
#else
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
@ -5,3 +5,11 @@
|
||||
|
||||
#include <gmpxx.h>
|
||||
|
||||
// On Linux, libgmpxx is built with gcc and libstdc++. When the user application, such as tests, are built against libc++,
|
||||
// linking fails because of the C++ standard library symbol names mismatch. So fail the test if we're not using libstdc++.
|
||||
#if defined(__linux__) || defined(__linux) || defined(linux)
|
||||
#include <utility>
|
||||
#if !defined(__GLIBCPP__) && !defined(__GLIBCXX__)
|
||||
#error "libgmpxx is not supported on this platform with this C++ standard library"
|
||||
#endif
|
||||
#endif
|
||||
|
71
test/mod_inverse_test.cpp
Normal file
71
test/mod_inverse_test.cpp
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* (C) Copyright Nick Thompson 2018.
|
||||
* Use, modification and distribution are subject to the
|
||||
* Boost Software License, Version 1.0. (See accompanying file
|
||||
* LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
|
||||
#include "multiprecision_config.hpp"
|
||||
|
||||
#ifndef DISABLE_MP_TESTS
|
||||
#include <boost/integer/mod_inverse.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <boost/optional/optional.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/multiprecision/cpp_int.hpp>
|
||||
#include <boost/integer/common_factor.hpp>
|
||||
|
||||
using boost::multiprecision::int128_t;
|
||||
using boost::multiprecision::int256_t;
|
||||
using boost::integer::mod_inverse;
|
||||
using boost::integer::gcd;
|
||||
|
||||
template<class Z>
|
||||
void test_mod_inverse()
|
||||
{
|
||||
//Z max_arg = std::numeric_limits<Z>::max();
|
||||
Z max_arg = 500;
|
||||
for (Z modulus = 2; modulus < max_arg; ++modulus)
|
||||
{
|
||||
if (modulus % 1000 == 0)
|
||||
{
|
||||
std::cout << "Testing all inverses modulo " << modulus << std::endl;
|
||||
}
|
||||
for (Z a = 1; a < modulus; ++a)
|
||||
{
|
||||
Z gcdam = gcd(a, modulus);
|
||||
Z inv_a = mod_inverse(a, modulus);
|
||||
// Should fail if gcd(a, mod) != 1:
|
||||
if (gcdam > 1)
|
||||
{
|
||||
BOOST_TEST(inv_a == 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_TEST(inv_a > 0);
|
||||
// Cast to a bigger type so the multiplication won't overflow.
|
||||
int256_t a_inv = inv_a;
|
||||
int256_t big_a = a;
|
||||
int256_t m = modulus;
|
||||
int256_t outta_be_one = (a_inv*big_a) % m;
|
||||
BOOST_TEST_EQ(outta_be_one, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test_mod_inverse<boost::int16_t>();
|
||||
test_mod_inverse<boost::int32_t>();
|
||||
test_mod_inverse<boost::int64_t>();
|
||||
test_mod_inverse<int128_t>();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
#else
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
18
test/multiprecision_config.hpp
Normal file
18
test/multiprecision_config.hpp
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright (c) 2018 Andrey Semashev
|
||||
//
|
||||
// Use, modification, and distribution is subject to the Boost Software
|
||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_INTEGER_TEST_MULTIPRECISION_CONFIG_HPP_INCLUDED_
|
||||
#define BOOST_INTEGER_TEST_MULTIPRECISION_CONFIG_HPP_INCLUDED_
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#if (defined(BOOST_MSVC) && (BOOST_MSVC < 1500)) || \
|
||||
(defined(__clang_major__) && (__clang_major__ == 3) && (__clang_minor__ < 2)) || \
|
||||
(defined(BOOST_GCC) && defined(BOOST_GCC_CXX11) && BOOST_GCC < 40800)
|
||||
#define DISABLE_MP_TESTS
|
||||
#endif
|
||||
|
||||
#endif // BOOST_INTEGER_TEST_MULTIPRECISION_CONFIG_HPP_INCLUDED_
|
Reference in New Issue
Block a user