Compare commits

...

52 Commits

Author SHA1 Message Date
Peter Dimov 50a1eae942 Change mpl::integral_c to boost::integral_constant to avoid Clang 16 errors when constructing out of range enums (refs #24, https://github.com/boostorg/mpl/issues/69) 2022-11-16 10:43:31 +02:00
Peter Dimov 7c846ddf63 Add missing include 2022-11-16 02:55:31 +02:00
Peter Dimov 902588b6bd Hardcode LIBRARY in ci.yml 2022-11-16 02:44:49 +02:00
Peter Dimov 95c9f7f918 Add .github/workflows/ci.yml 2022-11-16 02:30:35 +02:00
Glen Fernandes db44689f4f Switch from deprecated test to Lightweight Test 2021-06-09 17:48:22 -04:00
Peter Dimov 1bc71b7971 Add CMakeLists.txt 2021-03-18 17:39:55 +02:00
Brandon Kohn f9397e9cba Merge pull request #23 from eldiener/develop
[skip ci] Add "cxxstd" json field
2021-02-17 09:04:32 -05:00
Edward Diener ccb153a506 [skip ci] Add "cxxstd" json field. The "cxxstd" json field is being added to each Boost library's meta json information for libraries in order to specify the minumum C++ standard compilation level. The value of this field matches one of the values for 'cxxstd' in Boost.Build. The purpose of doing this is to provide information for the Boost website documentation for each library which will specify the minimum C++ standard compilation that an end-user must employ in order to use the particular library. This will aid end-users who want to know if they can successfully use a Boost library based on their C++ compiler's compilation level, without having to search the library's documentation to find this out. 2021-01-20 23:00:18 -05:00
Peter Dimov 07d5e56494 Merge branch 'master' into develop 2020-11-03 00:50:13 +02:00
Brandon Kohn 8c30716176 Merge pull request #21 from EugeneZelenko/use-boost-override
Use BOOST_OVERRIDE
2020-06-15 13:53:48 -04:00
Eugene Zelenko 6c83ad8c57 Use BOOST_OVERRIDE to fix GCC -Wsuggest-override and Clang-tidy modernize-use-override warnings.
Alphabetical order of STL headers.
2020-05-24 16:10:39 -07:00
Brandon Kohn aab2ea1fed Merge pull request #19 from eldiener/develop
Changes for Embarcadero C++ clang-based compilers, targeting Boost 1.74. Change __BORLANDC__ to BOOST_BORLANDC, which is defined in Boost conf…
2020-04-22 11:12:58 -04:00
Edward Diener 1d856f673f Change __BORLANDC__ to BOOST_BORLANDC, which is defined in Boost config for the Embarcadero non-clang-based compilers. 2020-03-31 11:58:06 -04:00
Nikita Kniazev de92292140 Tests: Fix C1128 error on msvc-14.1+
traits_test fails on msvc-14.1+ in 64bit debug mode with C1128 error

Fixes #15
2019-04-18 12:43:43 -04:00
Romain Geissler 53de752e1f Use BOOST_NOEXCEPT_OR_NOTHROW in public headers to prepare for C++20 2019-04-18 12:43:28 -04:00
Brandon Kohn a83247065b Merge pull request #16 from Kojoley/patch-1
Tests: Fix C1128 error on msvc-14.1+
2019-04-18 11:52:42 -04:00
Nikita Kniazev a4d54f8f89 Tests: Fix C1128 error on msvc-14.1+
traits_test fails on msvc-14.1+ in 64bit debug mode with C1128 error

Fixes #15
2019-03-31 20:12:53 +03:00
Brandon Kohn a8467a8723 Merge pull request #14 from Romain-Geissler-1A/noexcept
Use BOOST_NOEXCEPT_OR_NOTHROW in public headers to prepare for C++20
2018-11-19 09:16:26 -05:00
Romain Geissler 721dc89e7f Use BOOST_NOEXCEPT_OR_NOTHROW in public headers to prepare for C++20 2018-11-13 23:39:51 +00:00
Fernando Cacciola 36f969a4c5 Merge pull request #12 from boostorg/develop
Merged latest fixes
2018-03-07 16:59:38 -03:00
Fernando Cacciola b900379a74 Merge pull request #11 from boostorg/revert-7-fix-compiling
Revert "Fix compilation on lastest MSVC"
2018-03-06 15:35:32 -03:00
Fernando Cacciola 8ad516370a Revert "Fix compilation on lastest MSVC" 2018-03-06 15:34:11 -03:00
Fernando Cacciola c993894676 Merge pull request #10 from boostorg/danieljames-patch-1
Link to latest version of documentation
2018-03-05 15:27:04 -03:00
Daniel James 1da5d0d8fe Link to latest version of documentation
Putting 'release' instead of the version number will redirect to the latest documentation.
2018-03-05 18:23:34 +00:00
Fernando Cacciola 5a45a8d824 Merge pull request #9 from lakshayg/readme
add a short description and link to official docs
2018-02-27 18:14:45 -03:00
Lakshay Garg 3ae7d59e7a add a short description and link to official docs 2017-10-30 02:40:01 +05:30
Fernando Cacciola 54d571dde2 Merge pull request #7 from BlowaXD/fix-compiling
Fix compilation on lastest MSVC
2017-10-25 20:53:44 +02:00
Unknown 4505bc3808 Fix compilation on lastest MSVC
std::unary_function has been removed from C++ 17 standard so it does not compile anymore on MSVC
2017-09-27 12:39:34 +02:00
Brandon Kohn 7f3a74cb74 Merge pull request #6 from eldiener/develop
Removed executable attribute from file.
2017-09-23 18:42:25 -04:00
Edward Diener 278025d9c6 Removed executable attribute from file. 2017-09-17 10:46:51 -04:00
Brandon Kohn 7436ca7113 Merge-commit for hotfix/remove_std_unary_function. 2017-08-22 14:00:49 -04:00
Brandon Kohn ebfded1d7d Remove the deprecated uses of std::unary_function (again). 2017-08-22 13:39:34 -04:00
Brandon Kohn c9d7a49b4a Removed redundant typedefs for argument_type and result_type 2016-07-06 07:10:36 -04:00
Brandon Kohn 736745061d Merge branch 'hotfix/remove_std_unary_function' into develop 2016-07-05 21:40:31 -04:00
Brandon Kohn a6681748be Merged Jamfile.v2 test changes to conform to requirements. 2016-06-17 14:30:58 -04:00
Brandon Kohn 30d2e6d9f6 Revert "Modified Jamfile.v2 to conform to boost test requirements."
This reverts commit d76eb6fa72.
2016-06-17 14:20:27 -04:00
Brandon Kohn d76eb6fa72 Modified Jamfile.v2 to conform to boost test requirements. 2016-06-17 14:04:13 -04:00
brandon-kohn c90517da96 Merge pull request #3 from danieljames/metadata
Create metadata file.
2014-08-18 11:52:55 -04:00
Daniel James 907ae79790 Add metadata file. 2014-08-18 15:08:01 +01:00
Peter Dimov 86f8af551c Merge pull request #2 from apolukhin/develop
Moved cast.hpp file from Conversion library. It was decided that this fi...
2014-06-10 21:52:01 +03:00
Antony Polukhin cda4506afe Moved cast.hpp file from Conversion library. It was decided that this file must be in NumericCast library to reduce dependencies 2014-06-09 13:27:11 +04:00
brandon-kohn 718767f1e6 Merge pull request #1 from danieljames/develop
Remove old Visual C++ 6 workaround
2014-06-05 06:23:46 -04:00
Daniel James 69a46fea8a Remove old Visual C++ 6 workaround
From 41473987e5 - it was never released,
and Visual C++6 isn't supported anymore.
2014-06-02 10:11:42 +01:00
Daniel James 056045e503 Rebuild documentation.
Rebuilding documentation on develop and master to avoid unnecessary
differences.
2014-06-02 10:05:00 +01:00
Stephen Kelly d4a8c7049a Numeric: Remove obsolete MSVC version checks.
[SVN r86053]
2013-09-30 11:23:20 +00:00
Antony Polukhin 0fc4c240b9 Fixes #5731, fixes #5076, fixes #5393, fixes #5800
Now numeric_cast (and lexical_cast) can be compiled with disabled exceptions

[SVN r77234]
2012-03-05 17:11:20 +00:00
Brandon Kohn c9e3ffd511 Changed long long and unsigned long long to use the boost::(u)long_long_type typedefs in the numeric_cast_traits base specializations.
[SVN r76808]
2012-01-31 14:27:10 +00:00
Brandon Kohn e7b5847b5a Fixes for https://svn.boost.org/trac/boost/ticket/6158 numeric_cast_traits.
[SVN r76765]
2012-01-28 19:59:35 +00:00
Brandon Kohn 0ab23addef Replaced special copyright character with (c) in numeric cast traits files.
[SVN r74356]
2011-09-12 14:35:29 +00:00
Brandon Kohn 5d344f7463 Simplified custom numeric type in numeric_cast_traits_test.cpp to reduce template depth.
[SVN r73701]
2011-08-12 13:09:15 +00:00
Brandon Kohn 6bd888475f Changed numeric_cast_traits_test.cpp to explicitly use the boost namespace.
[SVN r73700]
2011-08-12 12:46:00 +00:00
Daniel James 4c8e454bbb Conversion: Fix preprocessor iteration.
Some preprocessors process all the 'elif' clauses even if it's known
that they're not going to be used which was resulting in errors.

[SVN r73691]
2011-08-12 06:55:07 +00:00
25 changed files with 403 additions and 228 deletions
+235
View File
@@ -0,0 +1,235 @@
name: CI
on:
pull_request:
push:
branches:
- master
- develop
- feature/**
env:
UBSAN_OPTIONS: print_stacktrace=1
LIBRARY: numeric/conversion
jobs:
posix:
strategy:
fail-fast: false
matrix:
include:
- toolset: gcc-4.8
cxxstd: "03,11"
os: ubuntu-latest
container: ubuntu:18.04
install: g++-4.8-multilib
address-model: 32,64
- toolset: gcc-5
cxxstd: "03,11,14,1z"
os: ubuntu-latest
container: ubuntu:18.04
install: g++-5-multilib
address-model: 32,64
- toolset: gcc-6
cxxstd: "03,11,14,1z"
os: ubuntu-latest
container: ubuntu:18.04
install: g++-6-multilib
address-model: 32,64
- toolset: gcc-7
cxxstd: "03,11,14,17"
os: ubuntu-latest
container: ubuntu:18.04
install: g++-7-multilib
address-model: 32,64
- toolset: gcc-8
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
install: g++-8-multilib
address-model: 32,64
- toolset: gcc-9
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
install: g++-9-multilib
address-model: 32,64
- toolset: gcc-10
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
install: g++-10-multilib
address-model: 32,64
- toolset: gcc-11
cxxstd: "03,11,14,17,20"
os: ubuntu-20.04
install: g++-11-multilib
address-model: 32,64
- toolset: gcc-12
cxxstd: "03,11,14,17,20,2b"
os: ubuntu-22.04
install: g++-12-multilib
address-model: 32,64
- toolset: clang
compiler: clang++-3.9
cxxstd: "03,11,14"
os: ubuntu-latest
container: ubuntu:18.04
install: clang-3.9
- toolset: clang
compiler: clang++-4.0
cxxstd: "03,11,14"
os: ubuntu-latest
container: ubuntu:18.04
install: clang-4.0
- toolset: clang
compiler: clang++-5.0
cxxstd: "03,11,14,1z"
os: ubuntu-latest
container: ubuntu:18.04
install: clang-5.0
- toolset: clang
compiler: clang++-6.0
cxxstd: "03,11,14,17"
os: ubuntu-20.04
install: clang-6.0
- toolset: clang
compiler: clang++-7
cxxstd: "03,11,14,17"
os: ubuntu-20.04
install: clang-7
- toolset: clang
compiler: clang++-8
cxxstd: "03,11,14,17"
os: ubuntu-20.04
install: clang-8
- toolset: clang
compiler: clang++-9
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
install: clang-9
- toolset: clang
compiler: clang++-10
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
- toolset: clang
compiler: clang++-11
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
- toolset: clang
compiler: clang++-12
cxxstd: "03,11,14,17,20"
os: ubuntu-20.04
- toolset: clang
compiler: clang++-13
cxxstd: "03,11,14,17,20,2b"
os: ubuntu-22.04
install: clang-13
- toolset: clang
compiler: clang++-14
cxxstd: "03,11,14,17,20,2b"
os: ubuntu-22.04
install: clang-14
- toolset: clang
cxxstd: "03,11,14,17,2a"
os: macos-11
runs-on: ${{matrix.os}}
container: ${{matrix.container}}
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v3
- name: Setup container environment
if: matrix.container
run: |
apt-get update
apt-get -y install sudo python git g++
- name: Install packages
if: matrix.install
run: sudo apt-get -y install ${{matrix.install}}
- name: Setup Boost
run: |
echo GITHUB_BASE_REF: $GITHUB_BASE_REF
echo GITHUB_REF: $GITHUB_REF
REF=${GITHUB_BASE_REF:-$GITHUB_REF}
REF=${REF#refs/heads/}
echo REF: $REF
BOOST_BRANCH=develop && [ "$REF" == "master" ] && BOOST_BRANCH=master || true
echo BOOST_BRANCH: $BOOST_BRANCH
cd ..
git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
cd boost-root
cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY
git submodule update --init tools/boostdep
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY
./bootstrap.sh
./b2 -d0 headers
- name: Create user-config.jam
if: matrix.compiler
run: |
echo "using ${{matrix.toolset}} : : ${{matrix.compiler}} ;" > ~/user-config.jam
- name: Run tests
run: |
cd ../boost-root
./b2 -j3 libs/$LIBRARY/test toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} ${ADDRMD:+address-model=$ADDRMD} variant=debug,release
windows:
strategy:
fail-fast: false
matrix:
include:
- toolset: msvc-14.0
cxxstd: 14,latest
addrmd: 32,64
os: windows-2019
- toolset: msvc-14.2
cxxstd: "14,17,20,latest"
addrmd: 32,64
os: windows-2019
- toolset: msvc-14.3
cxxstd: "14,17,20,latest"
addrmd: 32,64
os: windows-2022
- toolset: clang-win
cxxstd: "14,17,latest"
addrmd: 32,64
os: windows-2022
- toolset: gcc
cxxstd: "03,11,14,17,2a"
addrmd: 64
os: windows-2019
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v3
- name: Setup Boost
shell: cmd
run: |
echo GITHUB_BASE_REF: %GITHUB_BASE_REF%
echo GITHUB_REF: %GITHUB_REF%
if "%GITHUB_BASE_REF%" == "" set GITHUB_BASE_REF=%GITHUB_REF%
set BOOST_BRANCH=develop
for /f %%i in ("%GITHUB_BASE_REF%") do if "%%~nxi" == "master" set BOOST_BRANCH=master
echo BOOST_BRANCH: %BOOST_BRANCH%
cd ..
git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root
cd boost-root
xcopy /s /e /q %GITHUB_WORKSPACE% libs\%LIBRARY:/=\%\
git submodule update --init tools/boostdep
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" %LIBRARY%
cmd /c bootstrap
b2 -d0 headers
- name: Run tests
shell: cmd
run: |
cd ../boost-root
b2 -j3 libs/%LIBRARY%/test toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} address-model=${{matrix.addrmd}} variant=debug,release embed-manifest-via=linker
+31
View File
@@ -0,0 +1,31 @@
# Generated by `boostdep --cmake numeric~conversion`
# Copyright 2020 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# https://www.boost.org/LICENSE_1_0.txt
cmake_minimum_required(VERSION 3.5...3.16)
project(boost_numeric_conversion VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)
add_library(boost_numeric_conversion INTERFACE)
add_library(Boost::numeric_conversion ALIAS boost_numeric_conversion)
target_include_directories(boost_numeric_conversion INTERFACE include)
target_link_libraries(boost_numeric_conversion
INTERFACE
Boost::config
Boost::conversion
Boost::core
Boost::mpl
Boost::preprocessor
Boost::throw_exception
Boost::type_traits
)
if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")
add_subdirectory(test)
endif()
+8
View File
@@ -0,0 +1,8 @@
# Boost.NumericConversion
The Boost Numeric Conversion library is a collection of tools to describe and perform conversions between values of different [numeric types][1].
The documentation for the library can be found [here][2]
[1]: http://www.boost.org/doc/libs/release/libs/numeric/conversion/doc/html/boost_numericconversion/definitions.html#boost_numericconversion.definitions.numeric_types
[2]: http://www.boost.org/doc/libs/release/libs/numeric/conversion/doc/html/index.html#numeric_conversion.overview
Executable → Regular
View File
+1 -1
View File
@@ -23,7 +23,7 @@
#include <boost/detail/workaround.hpp>
#if BOOST_WORKAROUND(BOOST_MSVC, < 1300) || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
#if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x582))
# include<boost/numeric/conversion/detail/old_numeric_cast.hpp>
@@ -21,13 +21,6 @@ template<class T, class S>
struct conversion_traits
: convdetail::get_conversion_traits<T,S>::type
{
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
typedef typename convdetail::get_conversion_traits<T,S>::type base_;
typedef typename base_::target_type target_type;
typedef typename base_::source_type source_type;
typedef typename base_::result_type result_type;
typedef typename base_::argument_type argument_type;
#endif
} ;
} } // namespace boost::numeric
@@ -10,13 +10,13 @@
#ifndef BOOST_NUMERIC_CONVERSION_CONVERTER_POLICIES_FLC_12NOV2002_HPP
#define BOOST_NUMERIC_CONVERSION_CONVERTER_POLICIES_FLC_12NOV2002_HPP
#include <functional>
#include <typeinfo> // for std::bad_cast
#include <boost/config.hpp>
#include <boost/config/no_tr1/cmath.hpp> // for std::floor and std::ceil
#include <boost/throw_exception.hpp>
#include <functional>
#include "boost/type_traits/is_arithmetic.hpp"
#include "boost/mpl/if.hpp"
@@ -136,7 +136,7 @@ class bad_numeric_cast : public std::bad_cast
{
public:
virtual const char * what() const throw()
const char * what() const BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE
{ return "bad numeric conversion: overflow"; }
};
@@ -144,14 +144,14 @@ class negative_overflow : public bad_numeric_cast
{
public:
virtual const char * what() const throw()
const char * what() const BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE
{ return "bad numeric conversion: negative overflow"; }
};
class positive_overflow : public bad_numeric_cast
{
public:
virtual const char * what() const throw()
const char * what() const BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE
{ return "bad numeric conversion: positive overflow"; }
};
@@ -450,13 +450,10 @@ namespace boost { namespace numeric { namespace convdetail
// Trivial Converter : used when (cv-unqualified) T == (cv-unqualified) S
//
template<class Traits>
struct trivial_converter_impl : public std::unary_function< BOOST_DEDUCED_TYPENAME Traits::argument_type
,BOOST_DEDUCED_TYPENAME Traits::result_type
>
,public dummy_range_checker<Traits>
struct trivial_converter_impl : public dummy_range_checker<Traits>
{
typedef Traits traits ;
typedef typename Traits::source_type source_type ;
typedef typename Traits::argument_type argument_type ;
typedef typename Traits::result_type result_type ;
@@ -471,10 +468,7 @@ namespace boost { namespace numeric { namespace convdetail
// Rounding Converter : used for float to integral conversions.
//
template<class Traits,class RangeChecker,class RawConverter,class Float2IntRounder>
struct rounding_converter : public std::unary_function< BOOST_DEDUCED_TYPENAME Traits::argument_type
,BOOST_DEDUCED_TYPENAME Traits::result_type
>
,public RangeChecker
struct rounding_converter : public RangeChecker
,public Float2IntRounder
,public RawConverter
{
@@ -501,10 +495,7 @@ namespace boost { namespace numeric { namespace convdetail
// Non-Rounding Converter : used for all other conversions.
//
template<class Traits,class RangeChecker,class RawConverter>
struct non_rounding_converter : public std::unary_function< BOOST_DEDUCED_TYPENAME Traits::argument_type
,BOOST_DEDUCED_TYPENAME Traits::result_type
>
,public RangeChecker
struct non_rounding_converter : public RangeChecker
,public RawConverter
{
typedef RangeChecker RangeCheckerBase ;
@@ -570,7 +561,7 @@ namespace boost { namespace numeric { namespace convdetail
>
struct get_converter_impl
{
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT( 0x0561 ) )
#if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT( 0x0561 ) )
// bcc55 prefers sometimes template parameters to be explicit local types.
// (notice that is is illegal to reuse the names like this)
typedef Traits Traits ;
@@ -16,15 +16,15 @@
#include "boost/numeric/conversion/int_float_mixture_enum.hpp"
#include "boost/numeric/conversion/detail/meta.hpp"
#include "boost/mpl/integral_c.hpp"
#include "boost/type_traits/integral_constant.hpp"
namespace boost { namespace numeric { namespace convdetail
{
// Integral Constants for 'IntFloatMixture'
typedef mpl::integral_c<int_float_mixture_enum, integral_to_integral> int2int_c ;
typedef mpl::integral_c<int_float_mixture_enum, integral_to_float> int2float_c ;
typedef mpl::integral_c<int_float_mixture_enum, float_to_integral> float2int_c ;
typedef mpl::integral_c<int_float_mixture_enum, float_to_float> float2float_c ;
typedef boost::integral_constant<int_float_mixture_enum, integral_to_integral> int2int_c ;
typedef boost::integral_constant<int_float_mixture_enum, integral_to_float> int2float_c ;
typedef boost::integral_constant<int_float_mixture_enum, float_to_integral> float2int_c ;
typedef boost::integral_constant<int_float_mixture_enum, float_to_float> float2float_c ;
// Metafunction:
//
@@ -25,7 +25,7 @@ namespace boost { namespace numeric { namespace convdetail
template< class T1, class T2>
struct equal_to
{
#if !defined(__BORLANDC__)
#if !defined(BOOST_BORLANDC)
enum { x = ( BOOST_MPL_AUX_VALUE_WKND(T1)::value == BOOST_MPL_AUX_VALUE_WKND(T2)::value ) };
+7 -38
View File
@@ -8,6 +8,8 @@
// See http://www.boost.org/libs/conversion for Documentation.
// Revision History
// 02 Jun 14 Remove VC6 workarounds.
// 16 Jul 11 Bugfixes for VC6.
// 23 JUN 05 Code extracted from /boost/cast.hpp into this new header.
// Keeps this legacy version of numeric_cast<> for old compilers
// wich can't compile the new version in /boost/numeric/conversion/cast.hpp
@@ -53,19 +55,6 @@
# include <boost/limits.hpp>
# include <boost/numeric/conversion/converter_policies.hpp>
// It has been demonstrated numerous times that MSVC 6.0 fails silently at link
// time if you use a template function which has template parameters that don't
// appear in the function's argument list.
//
// TODO: Add this to config.hpp?
// FLC: This macro is repeated in boost/cast.hpp but only locally (is undefined at the bottom)
// so is OK to reproduce it here.
# if defined(BOOST_MSVC) && BOOST_MSVC < 1300
# define BOOST_EXPLICIT_DEFAULT_TARGET , ::boost::type<Target>* = 0
# else
# define BOOST_EXPLICIT_DEFAULT_TARGET
# endif
namespace boost
{
using numeric::bad_numeric_cast;
@@ -214,24 +203,6 @@ namespace boost
template <class X, class Y>
static inline bool check(X x, Y)
{ return x >= 0 && static_cast<X>(static_cast<Y>(x)) != x; }
# if defined(BOOST_MSVC) && BOOST_MSVC < 1300
// MSVC6 can't static_cast unsigned __int64 -> floating types
# define BOOST_UINT64_CAST(src_type) \
static inline bool check(src_type x, unsigned __int64) \
{ \
if (x < 0) return false; \
unsigned __int64 y = static_cast<unsigned __int64>(x); \
bool odd = y & 0x1; \
__int64 div2 = static_cast<__int64>(y >> 1); \
return ((static_cast<src_type>(div2) * 2.0) + odd) != x; \
}
BOOST_UINT64_CAST(long double);
BOOST_UINT64_CAST(double);
BOOST_UINT64_CAST(float);
# undef BOOST_UINT64_CAST
# endif
};
template<>
@@ -260,7 +231,7 @@ namespace boost
# pragma warning(push)
# pragma warning(disable : 4018)
# pragma warning(disable : 4146)
#elif defined(__BORLANDC__)
#elif defined(BOOST_BORLANDC)
# pragma option push -w-8041
# endif
@@ -277,7 +248,7 @@ namespace boost
# if BOOST_MSVC
# pragma warning(pop)
#elif defined(__BORLANDC__)
#elif defined(BOOST_BORLANDC)
# pragma option pop
# endif
} // namespace detail
@@ -285,7 +256,7 @@ namespace boost
#endif
template<typename Target, typename Source>
inline Target numeric_cast(Source arg BOOST_EXPLICIT_DEFAULT_TARGET)
inline Target numeric_cast(Source arg)
{
// typedefs abbreviating respective trait classes
typedef detail::fixed_numeric_limits<Source> arg_traits;
@@ -314,7 +285,7 @@ namespace boost
# if BOOST_MSVC
# pragma warning(push)
# pragma warning(disable : 4018)
#elif defined(__BORLANDC__)
#elif defined(BOOST_BORLANDC)
#pragma option push -w-8012
# endif
if ((arg < 0 && !result_traits::is_signed) // loss of negative range
@@ -322,7 +293,7 @@ namespace boost
|| arg > (result_traits::max)()) // overflow
# if BOOST_MSVC
# pragma warning(pop)
#elif defined(__BORLANDC__)
#elif defined(BOOST_BORLANDC)
#pragma option pop
# endif
#endif
@@ -332,8 +303,6 @@ namespace boost
return static_cast<Target>(arg);
} // numeric_cast
# undef BOOST_EXPLICIT_DEFAULT_TARGET
} // namespace boost
#endif // BOOST_OLD_NUMERIC_CAST_HPP
@@ -16,15 +16,15 @@
#include "boost/numeric/conversion/sign_mixture_enum.hpp"
#include "boost/numeric/conversion/detail/meta.hpp"
#include "boost/mpl/integral_c.hpp"
#include "boost/type_traits/integral_constant.hpp"
namespace boost { namespace numeric { namespace convdetail
{
// Integral Constants for 'SignMixture'
typedef mpl::integral_c<sign_mixture_enum, unsigned_to_unsigned> unsig2unsig_c ;
typedef mpl::integral_c<sign_mixture_enum, signed_to_signed> sig2sig_c ;
typedef mpl::integral_c<sign_mixture_enum, signed_to_unsigned> sig2unsig_c ;
typedef mpl::integral_c<sign_mixture_enum, unsigned_to_signed> unsig2sig_c ;
typedef boost::integral_constant<sign_mixture_enum, unsigned_to_unsigned> unsig2unsig_c ;
typedef boost::integral_constant<sign_mixture_enum, signed_to_signed> sig2sig_c ;
typedef boost::integral_constant<sign_mixture_enum, signed_to_unsigned> sig2unsig_c ;
typedef boost::integral_constant<sign_mixture_enum, unsigned_to_signed> unsig2sig_c ;
// Metafunction:
//
@@ -15,15 +15,15 @@
#include "boost/numeric/conversion/udt_builtin_mixture_enum.hpp"
#include "boost/numeric/conversion/detail/meta.hpp"
#include "boost/mpl/integral_c.hpp"
#include "boost/type_traits/integral_constant.hpp"
namespace boost { namespace numeric { namespace convdetail
{
// Integral Constants for 'UdtMixture'
typedef mpl::integral_c<udt_builtin_mixture_enum, builtin_to_builtin> builtin2builtin_c ;
typedef mpl::integral_c<udt_builtin_mixture_enum, builtin_to_udt> builtin2udt_c ;
typedef mpl::integral_c<udt_builtin_mixture_enum, udt_to_builtin> udt2builtin_c ;
typedef mpl::integral_c<udt_builtin_mixture_enum, udt_to_udt> udt2udt_c ;
typedef boost::integral_constant<udt_builtin_mixture_enum, builtin_to_builtin> builtin2builtin_c ;
typedef boost::integral_constant<udt_builtin_mixture_enum, builtin_to_udt> builtin2udt_c ;
typedef boost::integral_constant<udt_builtin_mixture_enum, udt_to_builtin> udt2builtin_c ;
typedef boost::integral_constant<udt_builtin_mixture_enum, udt_to_udt> udt2udt_c ;
// Metafunction:
//
+17
View File
@@ -0,0 +1,17 @@
{
"key": "numeric/conversion",
"name": "Numeric Conversion",
"authors": [
"Fernando Cacciola"
],
"description": "Optimized Policy-based Numeric Conversions.",
"category": [
"Math",
"Miscellaneous"
],
"maintainers": [
"Fernando Cacciola <fernando_cacciola -at- ciudad.com.ar>",
"Brandon Kohn <blkohn -at- hotmail.com>"
],
"cxxstd": "03"
}
+1 -1
View File
@@ -19,7 +19,7 @@ project numeric_conversion_unit_tests
test-suite minimal
:
[ run bounds_test.cpp ]
[ run traits_test.cpp ]
[ run traits_test.cpp : : : <toolset>msvc:<cxxflags>/bigobj ]
[ run converter_test.cpp ]
[ run udt_support_test.cpp ]
[ run numeric_cast_test.cpp ]
+6 -12
View File
@@ -13,7 +13,7 @@
#include "boost/numeric/conversion/bounds.hpp"
#ifdef __BORLANDC__
#ifdef BOOST_BORLANDC
#pragma hdrstop
#endif
@@ -32,17 +32,11 @@ void test_bounds( T expected_lowest, T expected_highest, T expected_smallest )
T highest = bounds<T>::highest () ;
T smallest = bounds<T>::smallest() ;
BOOST_CHECK_MESSAGE ( lowest == expected_lowest,
"bounds<" << typeid(T).name() << ">::lowest() = " << printable(lowest) << ". Expected " << printable(expected_lowest)
) ;
BOOST_TEST_EQ(lowest, expected_lowest);
BOOST_CHECK_MESSAGE ( highest == expected_highest,
"bounds<" << typeid(T).name() << ">::highest() = " << printable(highest) << ". Expected " << printable(expected_highest)
) ;
BOOST_TEST_EQ(highest, expected_highest);
BOOST_CHECK_MESSAGE ( smallest == expected_smallest,
"bounds<" << typeid(T).name() << ">::smallest() = " << printable(smallest) << ". Expected " << printable(expected_smallest)
) ;
BOOST_TEST_EQ(smallest, expected_smallest);
}
@@ -90,12 +84,12 @@ void test_bounds()
}
int test_main( int, char * [] )
int main( )
{
cout << setprecision( std::numeric_limits<long double>::digits10 ) ;
test_bounds();
return 0;
return boost::report_errors();
}
@@ -16,7 +16,6 @@
#include <boost/preprocessor/tuple/elem.hpp>
#include <boost/preprocessor/seq/elem.hpp>
#include <boost/preprocessor/seq/size.hpp>
#include <boost/test/minimal.hpp>
//! Generate default traits for the specified source and target.
#define BOOST_NUMERIC_CONVERSION_GENERATE_CAST_TRAITS(r, state) \
@@ -109,12 +108,6 @@ namespace boost { namespace numeric {
#endif
}}//namespace boost::numeric;
int test_main( int argc, char * argv[] )
{
//! This test should not compile.
return 1;
}
#undef BOOST_NUMERIC_CONVERSION_GENERATE_BUILTIN_CAST_TRAITS
#undef BOOST_NUMERIC_CONVERSION_GENERATE_CAST_TARGET_STEP
#undef BOOST_NUMERIC_CONVERSION_INC_OP
+7 -7
View File
@@ -22,7 +22,7 @@
//
// Borland 5.5 lacks the following math overloads
//
#if BOOST_WORKAROUND(__BORLANDC__, <= 0x551)
#if BOOST_WORKAROUND(BOOST_BORLANDC, <= 0x551)
namespace std
{
@@ -37,7 +37,7 @@ inline long double floor (long double x) { return std::floorl(x); }
#include "boost/numeric/conversion/converter.hpp"
#include "boost/numeric/conversion/cast.hpp"
#ifdef __BORLANDC__
#ifdef BOOST_BORLANDC
#pragma hdrstop
#endif
@@ -368,7 +368,7 @@ void test_round_style( MATCH_FNTPL_ARG(T), MATCH_FNTPL_ARG(S) )
void test_round_even( double n, double x )
{
double r = boost::numeric::RoundEven<double>::nearbyint(n);
BOOST_CHECK( r == x ) ;
BOOST_TEST( r == x ) ;
}
void test_round_even()
@@ -419,7 +419,7 @@ void test_converter_as_function_object()
// Match 'w' and 'i' which should be equal.
bool double_to_int_OK = std::equal(W.begin(),W.end(),I.begin()) ;
BOOST_CHECK_MESSAGE(double_to_int_OK, "converter (int,double) as function object");
BOOST_TEST(double_to_int_OK);
// Create a sequence of double values from s using a default numeric::converter (which should be the trivial conv).
std::vector<double> D ;
@@ -431,7 +431,7 @@ void test_converter_as_function_object()
// Match 's' and 'd' which should be equal.
bool double_to_double_OK = std::equal(S.begin(),S.end(),D.begin()) ;
BOOST_CHECK_MESSAGE(double_to_double_OK, "converter (double,double) as function object");
BOOST_TEST(double_to_double_OK);
}
#if BOOST_WORKAROUND(__IBMCPP__, <= 600 ) // VCAPP6
@@ -545,7 +545,7 @@ void test_optimizations()
//---------------------------------
}
int test_main( int, char* argv[] )
int main()
{
std::cout << std::setprecision( std::numeric_limits<long double>::digits10 ) ;
@@ -556,7 +556,7 @@ int test_main( int, char* argv[] )
test_converter_as_function_object();
test_optimizations() ;
return 0;
return boost::report_errors();
}
//---------------------------------------------------------------------------
+17 -34
View File
@@ -15,7 +15,7 @@
#include <boost/numeric/conversion/cast.hpp>
#include "boost/test/minimal.hpp"
#include <boost/core/lightweight_test.hpp>
# if SCHAR_MAX == LONG_MAX
# error "This test program doesn't work if SCHAR_MAX == LONG_MAX"
@@ -24,7 +24,7 @@
using namespace boost;
using std::cout;
int test_main( int argc, char * argv[] )
int main()
{
# ifdef NDEBUG
@@ -47,51 +47,34 @@ int test_main( int argc, char * argv[] )
c = large_value; // see if compiler generates warning
c = numeric_cast<signed char>( small_value );
BOOST_CHECK( c == 1 );
BOOST_TEST( c == 1 );
c = 0;
c = numeric_cast<signed char>( small_value );
BOOST_CHECK( c == 1 );
BOOST_TEST( c == 1 );
c = 0;
c = numeric_cast<signed char>( small_negative_value );
BOOST_CHECK( c == -1 );
BOOST_TEST( c == -1 );
// These tests courtesy of Joe R NWP Swatosh<joe.r.swatosh@usace.army.mil>
BOOST_CHECK( 0.0f == numeric_cast<float>( 0.0 ) );
BOOST_CHECK( 0.0 == numeric_cast<double>( 0.0 ) );
BOOST_TEST( 0.0f == numeric_cast<float>( 0.0 ) );
BOOST_TEST( 0.0 == numeric_cast<double>( 0.0 ) );
// tests which should result in errors being detected
bool caught_exception = false;
try { c = numeric_cast<signed char>( large_value ); }
catch ( numeric::bad_numeric_cast )
{ cout<<"caught bad_numeric_cast #1\n"; caught_exception = true; }
BOOST_CHECK ( caught_exception );
BOOST_TEST_THROWS( numeric_cast<signed char>(large_value),
numeric::bad_numeric_cast );
caught_exception = false;
try { c = numeric_cast<signed char>( large_negative_value ); }
catch ( numeric::bad_numeric_cast )
{ cout<<"caught bad_numeric_cast #2\n"; caught_exception = true; }
BOOST_CHECK ( caught_exception );
BOOST_TEST_THROWS( numeric_cast<signed char>(large_negative_value),
numeric::bad_numeric_cast );
unsigned long ul;
caught_exception = false;
try { ul = numeric_cast<unsigned long>( large_negative_value ); }
catch ( numeric::bad_numeric_cast )
{ cout<<"caught bad_numeric_cast #3\n"; caught_exception = true; }
BOOST_CHECK ( caught_exception );
BOOST_TEST_THROWS( numeric_cast<signed char>(large_negative_value),
numeric::bad_numeric_cast );
caught_exception = false;
try { ul = numeric_cast<unsigned long>( small_negative_value ); }
catch ( numeric::bad_numeric_cast )
{ cout<<"caught bad_numeric_cast #4\n"; caught_exception = true; }
BOOST_CHECK ( caught_exception );
BOOST_TEST_THROWS( numeric_cast<unsigned long>(small_negative_value),
numeric::bad_numeric_cast );
caught_exception = false;
try { numeric_cast<int>( DBL_MAX ); }
catch ( numeric::bad_numeric_cast )
{ cout<<"caught bad_numeric_cast #5\n"; caught_exception = true; }
BOOST_CHECK ( caught_exception );
BOOST_TEST_THROWS( numeric_cast<int>(DBL_MAX), numeric::bad_numeric_cast );
return 0 ;
return boost::report_errors() ;
} // main
+11 -14
View File
@@ -12,7 +12,8 @@
#include <boost/mpl/for_each.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/cstdint.hpp>
#include <boost/test/minimal.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/static_assert.hpp>
//! Define a simple custom number
struct Double
@@ -314,15 +315,11 @@ namespace boost { namespace numeric {
}}//namespace boost::numeric;
#define BOOST_TEST_CATCH_CUSTOM_POSITIVE_OVERFLOW( CastCode ) \
try { CastCode; BOOST_CHECK( false ); } \
catch( custom::positive_overflow& ){} \
catch(...){ BOOST_CHECK( false ); } \
BOOST_TEST_THROWS( CastCode, custom::positive_overflow )
/***/
#define BOOST_TEST_CATCH_CUSTOM_NEGATIVE_OVERFLOW( CastCode ) \
try { CastCode; BOOST_CHECK( false ); } \
catch( custom::negative_overflow& ){} \
catch(...){ BOOST_CHECK( false ); } \
BOOST_TEST_THROWS( CastCode, custom::negative_overflow )
/***/
struct test_cast_traits
@@ -331,9 +328,9 @@ struct test_cast_traits
void operator()(T) const
{
Double d = boost::numeric_cast<Double>( static_cast<T>(50) );
BOOST_CHECK( d.v == 50. );
BOOST_TEST( d.v == 50. );
T v = boost::numeric_cast<T>( d );
BOOST_CHECK( v == 50 );
BOOST_TEST( v == 50 );
}
};
@@ -360,20 +357,20 @@ void test_numeric_cast_traits()
//! Check overflow handler.
Double d( 56.0 );
BOOST_TEST_CATCH_CUSTOM_POSITIVE_OVERFLOW( d = boost::numeric_cast<Double>( 101 ) );
BOOST_CHECK( d.v == 56. );
BOOST_TEST( d.v == 56. );
BOOST_TEST_CATCH_CUSTOM_NEGATIVE_OVERFLOW( d = boost::numeric_cast<Double>( -101 ) );
BOOST_CHECK( d.v == 56.);
BOOST_TEST( d.v == 56.);
//! Check custom round policy.
d = 5.9;
int five = boost::numeric_cast<int>( d );
BOOST_CHECK( five == 5 );
BOOST_TEST( five == 5 );
}
int test_main( int argc, char * argv[] )
int main()
{
test_numeric_cast_traits();
return 0;
return boost::report_errors();
}
#undef BOOST_TEST_CATCH_CUSTOM_POSITIVE_OVERFLOW
+3 -2
View File
@@ -16,7 +16,8 @@
#include "boost/limits.hpp"
#include "boost/utility.hpp"
#include "boost/test/included/test_exec_monitor.hpp"
#include <boost/core/lightweight_test.hpp>
#include <stdexcept> // std::runtime_error
// Convenience macros to help with compilers which don't parse
// explicit template function instantiations (MSVC6)
@@ -118,7 +119,7 @@ class numeric_limits<MyUDT::MyFloat> : public numeric_limits<double>
// should be found by koenig loopkup, but some compilers don't do it right
// so we inyect them into namespace std so ordinary overload resolution
// can found them.
#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) || defined(__BORLANDC__) || defined(__GNUC__)
#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) || defined(BOOST_BORLANDC) || defined(__GNUC__)
namespace std {
using MyUDT::floor ;
using MyUDT::ceil ;
+6 -35
View File
@@ -69,51 +69,22 @@ void test_conv_base( Instance const& conv )
{
result_type result = converter::convert(source);
if ( conv.post == c_converted )
if (BOOST_TEST_EQ(conv.post, c_converted))
{
BOOST_CHECK_MESSAGE( result == conv.result,
conv.to_string() << printable(source) << ")= " << printable(result) << ". Expected:" << printable(conv.result)
) ;
}
else
{
BOOST_ERROR( conv.to_string() << printable(source) << ") = " << printable(result)
<< ". Expected:" << ( conv.post == c_neg_overflow ? " negative_overflow" : "positive_overflow" )
) ;
BOOST_TEST_EQ(result, conv.result);
}
}
catch ( boost::numeric::negative_overflow const& )
{
if ( conv.post == c_neg_overflow )
{
BOOST_CHECK_MESSAGE( true, conv.to_string() << printable(source) << ") = negative_overflow, as expected" ) ;
}
else
{
BOOST_ERROR( conv.to_string() << printable(source) << ") = negative_overflow. Expected:" << printable(conv.result) ) ;
}
{
BOOST_TEST_EQ(conv.post, c_neg_overflow);
}
catch ( boost::numeric::positive_overflow const& )
{
if ( conv.post == c_pos_overflow )
{
BOOST_CHECK_MESSAGE( true, conv.to_string() << printable(source) << ") = positive_overflow, as expected" ) ;
}
else
{
BOOST_ERROR( conv.to_string() << printable(source) << ") = positive_overflow. Expected:" << printable(conv.result) ) ;
}
BOOST_TEST_EQ(conv.post, c_pos_overflow);
}
catch ( boost::numeric::bad_numeric_cast const& )
{
if ( conv.post == c_overflow )
{
BOOST_CHECK_MESSAGE( true, conv.to_string() << printable(source) << ") = bad_numeric_cast, as expected" ) ;
}
else
{
BOOST_ERROR( conv.to_string() << printable(source) << ") = bad_numeric_cast. Expected:" << printable(conv.result) ) ;
}
BOOST_TEST_EQ(conv.post, c_overflow);
}
}
+5 -13
View File
@@ -22,7 +22,7 @@
#include <boost/numeric/conversion/udt_builtin_mixture.hpp>
#include <boost/numeric/conversion/is_subranged.hpp>
#ifdef __BORLANDC__
#ifdef BOOST_BORLANDC
#pragma hdrstop
#endif
@@ -258,11 +258,7 @@ struct generate_expected_traits
#define TEST_VALUE_FIELD(Name) \
typedef typename traits::Name BOOST_PP_CAT(t,Name) ; \
typedef typename expected::Name BOOST_PP_CAT(x,Name) ; \
BOOST_CHECK_MESSAGE ( ( BOOST_PP_CAT(t,Name)::value == BOOST_PP_CAT(x,Name)::value ) , \
"conversion_traits<" << typeid(T).name() << "," << typeid(S).name() \
<< ">::" << #Name << " = " << to_string(BOOST_PP_CAT(t,Name)::value) \
<< ". Expected: " << to_string(BOOST_PP_CAT(x,Name)::value) \
) ;
BOOST_TEST( ( BOOST_PP_CAT(t,Name)::value == BOOST_PP_CAT(x,Name)::value ) ) ;
// This macro generates the code that compares a type field
// in numeric::conversion_traits<> with its corresponding field
@@ -271,11 +267,7 @@ struct generate_expected_traits
#define TEST_TYPE_FIELD(Name) \
typedef typename traits::Name BOOST_PP_CAT(t,Name) ; \
typedef typename expected::Name BOOST_PP_CAT(x,Name) ; \
BOOST_CHECK_MESSAGE ( ( typeid(BOOST_PP_CAT(t,Name)) == typeid(BOOST_PP_CAT(x,Name)) ) , \
"conversion_traits<" << typeid(T).name() << "," << typeid(S).name() \
<< ">::" << #Name << " = " << typeid(BOOST_PP_CAT(t,Name)).name() \
<< ". Expected: " << typeid(BOOST_PP_CAT(x,Name)).name() \
) ;
BOOST_TEST ( ( typeid(BOOST_PP_CAT(t,Name)) == typeid(BOOST_PP_CAT(x,Name)) ) ) ;
//
// Test core.
@@ -329,13 +321,13 @@ void test_traits()
test_traits_from( SET_FNTPL_ARG(MyFloat) );
}
int test_main( int, char * [])
int main()
{
std::cout << std::setprecision( std::numeric_limits<long double>::digits10 ) ;
test_traits();
return 0;
return boost::report_errors();
}
//---------------------------------------------------------------------------
+19 -19
View File
@@ -16,7 +16,7 @@
#include<cmath>
#include "boost/test/included/test_exec_monitor.hpp"
#include <boost/core/lightweight_test.hpp>
#include "boost/numeric/conversion/cast.hpp"
@@ -58,13 +58,13 @@ void simplest_case()
//
// conversion_traits<>::udt_builtin_mixture works out of the box as long as boost::is_arithmetic<UDT> yields false
//
BOOST_CHECK( (conversion_traits<double,Double>::udt_builtin_mixture::value == udt_to_builtin) ) ;
BOOST_CHECK( (conversion_traits<Double,double>::udt_builtin_mixture::value == builtin_to_udt) ) ;
BOOST_CHECK( (conversion_traits<Double,Double>::udt_builtin_mixture::value == udt_to_udt ) ) ;
BOOST_TEST( (conversion_traits<double,Double>::udt_builtin_mixture::value == udt_to_builtin) ) ;
BOOST_TEST( (conversion_traits<Double,double>::udt_builtin_mixture::value == builtin_to_udt) ) ;
BOOST_TEST( (conversion_traits<Double,Double>::udt_builtin_mixture::value == udt_to_udt ) ) ;
// BY DEFINITION, a conversion from UDT to Builtin is subranged. No attempt is made to actually compare ranges.
BOOST_CHECK( (conversion_traits<double,Double>::subranged::value) == true ) ;
BOOST_CHECK( (conversion_traits<Double,double>::subranged::value) == false ) ;
BOOST_TEST( (conversion_traits<double,Double>::subranged::value) == true ) ;
BOOST_TEST( (conversion_traits<Double,double>::subranged::value) == false ) ;
@@ -72,18 +72,18 @@ void simplest_case()
// Conversions to/from FLOATING types, if already supported by an UDT
// are also supported out-of-the-box by converter<> in its default configuration.
//
BOOST_CHECK( numeric_cast<double>(Dv) == static_cast<double>(Dv) ) ;
BOOST_CHECK( numeric_cast<Double>(dv) == static_cast<Double>(dv) ) ;
BOOST_TEST( numeric_cast<double>(Dv) == static_cast<double>(Dv) ) ;
BOOST_TEST( numeric_cast<Double>(dv) == static_cast<Double>(dv) ) ;
BOOST_CHECK( numeric_cast<float> (Dv) == static_cast<float> (Dv) ) ;
BOOST_CHECK( numeric_cast<Double>(fv) == static_cast<Double>(fv) ) ;
BOOST_TEST( numeric_cast<float> (Dv) == static_cast<float> (Dv) ) ;
BOOST_TEST( numeric_cast<Double>(fv) == static_cast<Double>(fv) ) ;
//
// Range checking is disabled by default if an UDT is either the source or target of the conversion.
//
BOOST_CHECK( (converter<float,double>::out_of_range(dv) == cPosOverflow) );
BOOST_CHECK( (converter<float,Double>::out_of_range(Dv) == cInRange) );
BOOST_TEST( (converter<float,double>::out_of_range(dv) == cPosOverflow) );
BOOST_TEST( (converter<float,Double>::out_of_range(Dv) == cInRange) );
}
@@ -110,7 +110,7 @@ Double ceil ( Double v ) { return Double(std::ceil (v.mV)) ; }
void rounding()
{
BOOST_CHECK( numeric_cast<int>(Dv) == static_cast<int>(Dv) ) ;
BOOST_TEST( numeric_cast<int>(Dv) == static_cast<int>(Dv) ) ;
}
@@ -135,7 +135,7 @@ void custom_rounding()
>
DoubleToIntConverter ;
BOOST_CHECK( DoubleToIntConverter::convert(Dv) == static_cast<int>(Dv) ) ;
BOOST_TEST( DoubleToIntConverter::convert(Dv) == static_cast<int>(Dv) ) ;
}
//
@@ -187,8 +187,8 @@ void custom_raw_converter()
Int i (12);
Float fi(12);
BOOST_CHECK(numeric_cast<Int> (f).mV == i .mV ) ;
BOOST_CHECK(numeric_cast<Float>(i).mV == fi.mV ) ;
BOOST_TEST(numeric_cast<Int> (f).mV == i .mV ) ;
BOOST_TEST(numeric_cast<Float>(i).mV == fi.mV ) ;
}
//
@@ -219,10 +219,10 @@ void custom_raw_converter2()
>
Float2IntConverter ;
BOOST_CHECK(Float2IntConverter::convert(f).mV == i .mV ) ;
BOOST_TEST(Float2IntConverter::convert(f).mV == i .mV ) ;
}
int test_main( int, char* [] )
int main()
{
cout << setprecision( numeric_limits<long double>::digits10 ) ;
@@ -232,7 +232,7 @@ int test_main( int, char* [] )
custom_raw_converter();
custom_raw_converter2();
return 0;
return boost::report_errors();
}
+3 -3
View File
@@ -14,7 +14,7 @@
#include "boost/numeric/conversion/converter.hpp"
#ifdef __BORLANDC__
#ifdef BOOST_BORLANDC
#pragma hdrstop
#endif
@@ -292,14 +292,14 @@ void test_udt_conversions_with_custom_range_checking()
}
int test_main( int, char* [] )
int main()
{
cout << setprecision( numeric_limits<long double>::digits10 ) ;
test_udt_conversions_with_defaults();
test_udt_conversions_with_custom_range_checking();
return 0;
return boost::report_errors();
}