mirror of
https://github.com/boostorg/numeric_conversion.git
synced 2026-07-21 13:33:43 +00:00
Compare commits
51 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 50a1eae942 | |||
| 7c846ddf63 | |||
| 902588b6bd | |||
| 95c9f7f918 | |||
| db44689f4f | |||
| 1bc71b7971 | |||
| f9397e9cba | |||
| ccb153a506 | |||
| 07d5e56494 | |||
| 8c30716176 | |||
| 6c83ad8c57 | |||
| aab2ea1fed | |||
| 1d856f673f | |||
| de92292140 | |||
| 53de752e1f | |||
| a83247065b | |||
| a4d54f8f89 | |||
| a8467a8723 | |||
| 721dc89e7f | |||
| 36f969a4c5 | |||
| b900379a74 | |||
| 8ad516370a | |||
| c993894676 | |||
| 1da5d0d8fe | |||
| 5a45a8d824 | |||
| 3ae7d59e7a | |||
| 54d571dde2 | |||
| 4505bc3808 | |||
| 7f3a74cb74 | |||
| 278025d9c6 | |||
| 7436ca7113 | |||
| c9d7a49b4a | |||
| 736745061d | |||
| a6681748be | |||
| 30d2e6d9f6 | |||
| d76eb6fa72 | |||
| c90517da96 | |||
| 907ae79790 | |||
| 86f8af551c | |||
| cda4506afe | |||
| 718767f1e6 | |||
| 69a46fea8a | |||
| 056045e503 | |||
| d4a8c7049a | |||
| 0fc4c240b9 | |||
| c9e3ffd511 | |||
| e7b5847b5a | |||
| 0ab23addef | |||
| 5d344f7463 | |||
| 6bd888475f | |||
| 4c8e454bbb |
@@ -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
|
||||
@@ -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()
|
||||
|
||||
@@ -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
@@ -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"; }
|
||||
};
|
||||
|
||||
|
||||
@@ -453,7 +453,7 @@ namespace boost { namespace numeric { namespace convdetail
|
||||
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 ;
|
||||
@@ -561,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 ) };
|
||||
|
||||
|
||||
Executable → Regular
+7
-38
@@ -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:
|
||||
//
|
||||
|
||||
@@ -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
@@ -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
@@ -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
|
||||
|
||||
@@ -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
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
@@ -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
@@ -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
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user