Compare commits

...

19 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
22 changed files with 373 additions and 175 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()
+1 -1
View File
@@ -23,7 +23,7 @@
#include <boost/detail/workaround.hpp>
#if 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>
@@ -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"; }
};
@@ -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 ) };
@@ -231,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
@@ -248,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 +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
@@ -293,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
@@ -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:
//
+2 -1
View File
@@ -12,5 +12,6 @@
"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();
}