diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cb61471bb..3cabb5bd2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -763,3 +763,315 @@ jobs: - name: Run tests run: ci/build.sh + + + posix-cmake-subdir-modules: + runs-on: ubuntu-latest + container: ubuntu:24.10 + + steps: + - uses: actions/checkout@v4 + + - name: Install packages + run: | + export DEBIAN_FRONTEND=noninteractive + apt-get update + apt-get install -y --no-install-recommends ninja-build cmake git ca-certificates python3 python-is-python3 \ + clang-19 llvm-19 libclang-rt-19-dev libc++-19-dev libc++abi-19-dev clang-tools-19 + + - name: Setup Boost + run: | + echo GITHUB_REPOSITORY: $GITHUB_REPOSITORY + LIBRARY=${GITHUB_REPOSITORY#*/} + echo LIBRARY: $LIBRARY + echo "LIBRARY=$LIBRARY" >> $GITHUB_ENV + 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 $LIBRARY + python libs/charconv/tools/setup_boost_with_modules.py # Temporary + + - name: Use library with add_subdirectory + run: | + cd ../boost-root/libs/$LIBRARY/test/cmake_subdir_test + mkdir __build__ && cd __build__ + cmake -DBOOST_USE_MODULES=1 -DCMAKE_C_COMPILER=clang-19 -DCMAKE_CXX_COMPILER=clang++-19 -DCMAKE_CXX_FLAGS=-stdlib=libc++ -DCMAKE_EXE_LINKER_FLAGS=-stdlib=libc++ -DCMAKE_CXX_STANDARD=23 -DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD=0e5b6991-d74f-4b3d-a41c-cf096e0b2508 -G Ninja .. + cmake --build . + ctest --output-on-failure --no-tests=error + + posix-cmake-install-modules: + env: + CMAKE_ARGS: -DCMAKE_CXX_COMPILER=clang++-19 -DCMAKE_CXX_FLAGS=-stdlib=libc++ -DCMAKE_EXE_LINKER_FLAGS=-stdlib=libc++ -DCMAKE_CXX_STANDARD=23 -DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD=0e5b6991-d74f-4b3d-a41c-cf096e0b2508 -G Ninja + + runs-on: ubuntu-latest + container: ubuntu:24.10 + + steps: + - uses: actions/checkout@v4 + + - name: Install packages + run: | + export DEBIAN_FRONTEND=noninteractive + apt-get update + apt-get install -y --no-install-recommends ninja-build cmake git ca-certificates python3 python-is-python3 \ + clang-19 llvm-19 libclang-rt-19-dev libc++-19-dev libc++abi-19-dev clang-tools-19 + + - name: Setup Boost + run: | + echo GITHUB_REPOSITORY: $GITHUB_REPOSITORY + LIBRARY=${GITHUB_REPOSITORY#*/} + echo LIBRARY: $LIBRARY + echo "LIBRARY=$LIBRARY" >> $GITHUB_ENV + 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 $LIBRARY + python libs/charconv/tools/setup_boost_with_modules.py # Temporary + + - name: Configure + run: | + cd ../boost-root + mkdir __build__ && cd __build__ + cmake -DBOOST_INCLUDE_LIBRARIES=$LIBRARY -DCMAKE_INSTALL_PREFIX=~/.local -DBOOST_USE_MODULES=1 \ + -DCMAKE_C_COMPILER=clang-19 $CMAKE_ARGS .. + + - name: Install + run: | + cd ../boost-root/__build__ + cmake --build . --target install + + - name: Use the installed library + run: | + cd ../boost-root/libs/$LIBRARY/test/cmake_install_test && mkdir __build__ && cd __build__ + cmake -DCMAKE_INSTALL_PREFIX=~/.local $CMAKE_ARGS .. + cmake --build . + ctest --output-on-failure --no-tests=error + + posix-cmake-test-modules: + strategy: + fail-fast: false + matrix: + include: + - cmake-build-type: Debug + - cmake-build-type: Release + + runs-on: ubuntu-latest + container: ubuntu:24.10 + + steps: + - uses: actions/checkout@v4 + + - name: Install packages + run: | + export DEBIAN_FRONTEND=noninteractive + apt-get update + apt-get install -y --no-install-recommends ninja-build cmake git ca-certificates python3 python-is-python3 \ + clang-19 llvm-19 libclang-rt-19-dev libc++-19-dev libc++abi-19-dev clang-tools-19 + + - name: Setup Boost + run: | + echo GITHUB_REPOSITORY: $GITHUB_REPOSITORY + LIBRARY=${GITHUB_REPOSITORY#*/} + echo LIBRARY: $LIBRARY + echo "LIBRARY=$LIBRARY" >> $GITHUB_ENV + 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 + python3 tools/boostdep/depinst/depinst.py $LIBRARY + python3 libs/charconv/tools/setup_boost_with_modules.py # Temporary + + - name: Configure + run: | + cd ../boost-root + mkdir __build__ && cd __build__ + cmake -DBOOST_INCLUDE_LIBRARIES=$LIBRARY -DBUILD_TESTING=ON -DCMAKE_BUILD_TYPE=${{matrix.cmake-build-type}} -DBOOST_USE_MODULES=1 -DCMAKE_C_COMPILER=clang-19 -DCMAKE_CXX_COMPILER=clang++-19 -DCMAKE_CXX_FLAGS=-stdlib=libc++ -DCMAKE_EXE_LINKER_FLAGS=-stdlib=libc++ -DCMAKE_CXX_STANDARD=23 -DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD=0e5b6991-d74f-4b3d-a41c-cf096e0b2508 -G Ninja .. + + - name: Build tests + run: | + cd ../boost-root/__build__ + cmake --build . --target tests + + - name: Run tests + run: | + cd ../boost-root/__build__ + ctest --output-on-failure --no-tests=error + + windows-cmake-subdir-modules: + runs-on: windows-2022 + + steps: + - uses: actions/checkout@v4 + + - name: Install packages + run: choco install --no-progress ninja + + - name: Setup Boost + shell: cmd + run: | + echo GITHUB_REPOSITORY: %GITHUB_REPOSITORY% + for /f %%i in ("%GITHUB_REPOSITORY%") do set LIBRARY=%%~nxi + echo LIBRARY: %LIBRARY% + echo LIBRARY=%LIBRARY%>>%GITHUB_ENV% + 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% + python libs/charconv/tools/setup_boost_with_modules.py # Temporary + + - name: Use library with add_subdirectory + shell: cmd + run: | + call "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Auxiliary/Build/vcvarsall.bat" x64 + cd ../boost-root/libs/%LIBRARY%/test/cmake_subdir_test + mkdir __build__ && cd __build__ + cmake -DBOOST_USE_MODULES=1 -DCMAKE_CXX_STANDARD=23 -DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD=0e5b6991-d74f-4b3d-a41c-cf096e0b2508 -G Ninja .. + cmake --build . + ctest --output-on-failure --no-tests=error + + windows-cmake-install-modules: + runs-on: windows-2022 + + steps: + - uses: actions/checkout@v4 + + - name: Install packages + run: choco install --no-progress ninja + + - name: Setup Boost + shell: cmd + run: | + echo GITHUB_REPOSITORY: %GITHUB_REPOSITORY% + for /f %%i in ("%GITHUB_REPOSITORY%") do set LIBRARY=%%~nxi + echo LIBRARY: %LIBRARY% + echo LIBRARY=%LIBRARY%>>%GITHUB_ENV% + 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% + python libs/charconv/tools/setup_boost_with_modules.py # Temporary + + - name: Configure + shell: cmd + run: | + call "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Auxiliary/Build/vcvarsall.bat" x64 + cd ../boost-root + mkdir __build__ && cd __build__ + cmake -DBOOST_INCLUDE_LIBRARIES=%LIBRARY% -DCMAKE_INSTALL_PREFIX=C:/cmake-prefix -DBOOST_USE_MODULES=1 -DCMAKE_CXX_STANDARD=23 -DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD=0e5b6991-d74f-4b3d-a41c-cf096e0b2508 -G Ninja .. + + - name: Install + shell: cmd + run: | + call "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Auxiliary/Build/vcvarsall.bat" x64 + cd ../boost-root/__build__ + cmake --build . --target install + + - name: Use the installed library + shell: cmd + run: | + call "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Auxiliary/Build/vcvarsall.bat" x64 + cd ../boost-root/libs/%LIBRARY%/test/cmake_install_test && mkdir __build__ && cd __build__ + cmake -DCMAKE_INSTALL_PREFIX=C:/cmake-prefix -DCMAKE_CXX_STANDARD=23 -DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD=0e5b6991-d74f-4b3d-a41c-cf096e0b2508 -G Ninja .. + cmake --build . + ctest --output-on-failure --no-tests=error + + windows-cmake-test-modules: + strategy: + fail-fast: false + matrix: + include: + - cmake-build-type: Debug + - cmake-build-type: Release + + runs-on: windows-2022 + + steps: + - uses: actions/checkout@v4 + + - name: Install packages + run: choco install --no-progress ninja + + - name: Setup Boost + shell: cmd + run: | + echo GITHUB_REPOSITORY: %GITHUB_REPOSITORY% + for /f %%i in ("%GITHUB_REPOSITORY%") do set LIBRARY=%%~nxi + echo LIBRARY: %LIBRARY% + echo LIBRARY=%LIBRARY%>>%GITHUB_ENV% + 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% + python libs/charconv/tools/setup_boost_with_modules.py # Temporary + + - name: Configure + shell: cmd + run: | + call "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Auxiliary/Build/vcvarsall.bat" x64 + cd ../boost-root + mkdir __build__ && cd __build__ + cmake -DBOOST_INCLUDE_LIBRARIES=%LIBRARY% -DBUILD_TESTING=ON -DBOOST_USE_MODULES=1 -DCMAKE_CXX_STANDARD=23 -DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD=0e5b6991-d74f-4b3d-a41c-cf096e0b2508 -DCMAKE_BUILD_TYPE=${{matrix.cmake-build-type}} -G Ninja .. + + - name: Build tests + shell: cmd + run: | + call "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Auxiliary/Build/vcvarsall.bat" x64 + cd ../boost-root/__build__ + cmake --build . --target tests + + - name: Run tests + shell: cmd + run: | + call "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Auxiliary/Build/vcvarsall.bat" x64 + cd ../boost-root/__build__ + ctest --output-on-failure --no-tests=error diff --git a/CMakeLists.txt b/CMakeLists.txt index 2804a17e6..bce35c041 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ # Distributed under the Boost Software License, Version 1.0. # https://www.boost.org/LICENSE_1_0.txt -cmake_minimum_required(VERSION 3.8...3.20) +cmake_minimum_required(VERSION 3.8...3.31) project(boost_charconv VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX) @@ -14,6 +14,15 @@ add_library(boost_charconv add_library(Boost::charconv ALIAS boost_charconv) +if (BOOST_USE_MODULES) + target_sources(boost_charconv PUBLIC FILE_SET CXX_MODULES BASE_DIRS modules FILES modules/boost_charconv.cppm) + + # Enable and propagate C++23, import std, and the modules macro + target_compile_features(boost_charconv PUBLIC cxx_std_23) + set_target_properties(boost_charconv PROPERTIES CXX_MODULE_STD 1) + target_compile_definitions(boost_charconv PUBLIC BOOST_USE_MODULES) +endif() + target_include_directories(boost_charconv PUBLIC include) diff --git a/include/boost/charconv/chars_format.hpp b/include/boost/charconv/chars_format.hpp index 0542372bf..ffbc42d47 100644 --- a/include/boost/charconv/chars_format.hpp +++ b/include/boost/charconv/chars_format.hpp @@ -5,6 +5,12 @@ #ifndef BOOST_CHARCONV_CHARS_FORMAT_HPP #define BOOST_CHARCONV_CHARS_FORMAT_HPP +#if defined(BOOST_USE_MODULES) && !defined(BOOST_CHARCONV_SOURCE) + +import boost.charconv; + +#else + namespace boost { namespace charconv { // Floating-point format for primitive numerical conversion @@ -19,4 +25,6 @@ enum class chars_format : unsigned }} // Namespaces +#endif + #endif // BOOST_CHARCONV_CHARS_FORMAT_HPP diff --git a/include/boost/charconv/config.hpp b/include/boost/charconv/config.hpp index 0d94ccd4a..04f5b912a 100644 --- a/include/boost/charconv/config.hpp +++ b/include/boost/charconv/config.hpp @@ -7,7 +7,7 @@ // https://www.boost.org/LICENSE_1_0.txt #include -#include +#include // This header implements separate compilation features as described in // http://www.boost.org/more/separate_compilation.html diff --git a/include/boost/charconv/detail/apply_sign.hpp b/include/boost/charconv/detail/apply_sign.hpp index ef6db7143..9b6680df2 100644 --- a/include/boost/charconv/detail/apply_sign.hpp +++ b/include/boost/charconv/detail/apply_sign.hpp @@ -5,10 +5,11 @@ #ifndef BOOST_CHARCONV_DETAIL_APPLY_SIGN_HPP #define BOOST_CHARCONV_DETAIL_APPLY_SIGN_HPP -#include #include #include -#include +#include +#include + // We are purposefully converting values here #ifdef BOOST_MSVC diff --git a/include/boost/charconv/detail/bit_layouts.hpp b/include/boost/charconv/detail/bit_layouts.hpp index c163ce06a..2266c096c 100644 --- a/include/boost/charconv/detail/bit_layouts.hpp +++ b/include/boost/charconv/detail/bit_layouts.hpp @@ -7,8 +7,9 @@ #include #include -#include -#include +#include +#include + // Layouts of floating point types as specified by IEEE 754 // See page 23 of IEEE 754-2008 @@ -56,7 +57,7 @@ struct ieee754_binary64 }; // 80 bit long double (e.g. x86-64) -#if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 +#if BOOST_CHARCONV_LDBL_BITS == 80 struct IEEEl2bits { @@ -83,10 +84,8 @@ struct ieee754_binary80 static constexpr int decimal_digits = 18; }; -#define BOOST_CHARCONV_LDBL_BITS 80 - // 128 bit long double (e.g. s390x, ppcle64) -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 +#elif BOOST_CHARCONV_LDBL_BITS == 128 struct IEEEl2bits { @@ -103,10 +102,8 @@ struct IEEEl2bits #endif }; -#define BOOST_CHARCONV_LDBL_BITS 128 - // 64 bit long double (double == long double on ARM) -#elif LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 +#elif BOOST_CHARCONV_LDBL_BITS == 64 struct IEEEl2bits { @@ -123,11 +120,6 @@ struct IEEEl2bits #endif }; -#define BOOST_CHARCONV_LDBL_BITS 64 - -#else // Unsupported long double representation -# define BOOST_CHARCONV_UNSUPPORTED_LONG_DOUBLE -# define BOOST_CHARCONV_LDBL_BITS -1 #endif struct IEEEbinary128 diff --git a/include/boost/charconv/detail/buffer_sizing.hpp b/include/boost/charconv/detail/buffer_sizing.hpp index 3115ee39e..d61e03b17 100644 --- a/include/boost/charconv/detail/buffer_sizing.hpp +++ b/include/boost/charconv/detail/buffer_sizing.hpp @@ -7,7 +7,8 @@ #include #include -#include +#include + namespace boost { namespace charconv { diff --git a/include/boost/charconv/detail/compute_float32.hpp b/include/boost/charconv/detail/compute_float32.hpp index 85ece7f8c..351f61b91 100644 --- a/include/boost/charconv/detail/compute_float32.hpp +++ b/include/boost/charconv/detail/compute_float32.hpp @@ -6,9 +6,9 @@ #define BOOST_CHARCONV_DETAIL_COMPUTE_FLOAT32_HPP #include -#include -#include -#include +#include +#include +#include namespace boost { namespace charconv { namespace detail { @@ -27,7 +27,7 @@ inline float compute_float32(std::int64_t power, std::uint64_t i, bool negative, if (d > static_cast((std::numeric_limits::max)()) || d < static_cast((std::numeric_limits::lowest)())) { - return_val = negative ? -HUGE_VALF : HUGE_VALF; + return_val = negative ? -std::numeric_limits::infinity() : std::numeric_limits::infinity(); success = false; } else @@ -39,7 +39,7 @@ inline float compute_float32(std::int64_t power, std::uint64_t i, bool negative, { if (power > 38) { - return_val = negative ? -HUGE_VALF : HUGE_VALF; + return_val = negative ? -std::numeric_limits::infinity() : std::numeric_limits::infinity(); } else { diff --git a/include/boost/charconv/detail/compute_float64.hpp b/include/boost/charconv/detail/compute_float64.hpp index 3cb83537f..c9b1c8793 100644 --- a/include/boost/charconv/detail/compute_float64.hpp +++ b/include/boost/charconv/detail/compute_float64.hpp @@ -10,10 +10,12 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include +#include // UINT64_C + namespace boost { namespace charconv { namespace detail { @@ -95,7 +97,7 @@ inline double compute_float64(std::int64_t power, std::uint64_t i, bool negative } else if (power > largest_power) { - return negative ? -HUGE_VAL : HUGE_VAL; + return negative ? -std::numeric_limits::infinity() : std::numeric_limits::infinity(); } const std::uint64_t factor_significand = significands_table::significand_64[power - smallest_power]; diff --git a/include/boost/charconv/detail/compute_float80.hpp b/include/boost/charconv/detail/compute_float80.hpp index ad1e51486..239c09423 100644 --- a/include/boost/charconv/detail/compute_float80.hpp +++ b/include/boost/charconv/detail/compute_float80.hpp @@ -8,20 +8,20 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include - +#include +#include +#include +#include +#include +#include +#include #ifdef BOOST_CHARCONV_DEBUG_FLOAT128 -#include -#include #include +#include +#include #endif + namespace boost { namespace charconv { namespace detail { #if BOOST_CHARCONV_LDBL_BITS > 64 @@ -95,7 +95,7 @@ inline ResultType compute_float80(std::int64_t q, Unsigned_Integer w, bool negat else if (q > largest_power) { success = std::errc::result_out_of_range; - return negative ? -HUGE_VALL : HUGE_VALL; + return negative ? -std::numeric_limits::infinity() : std::numeric_limits::infinity(); } else if (q < smallest_power) { diff --git a/include/boost/charconv/detail/config.hpp b/include/boost/charconv/detail/config.hpp index 9ccfb0d68..8de10fd51 100644 --- a/include/boost/charconv/detail/config.hpp +++ b/include/boost/charconv/detail/config.hpp @@ -5,11 +5,11 @@ #ifndef BOOST_CHARCONV_DETAIL_CONFIG_HPP #define BOOST_CHARCONV_DETAIL_CONFIG_HPP +#include +#include #include -#include -#include +#include -#include #define BOOST_CHARCONV_ASSERT(expr) BOOST_ASSERT(expr) #define BOOST_CHARCONV_ASSERT_MSG(expr, msg) BOOST_ASSERT_MSG(expr, msg) @@ -167,9 +167,9 @@ static_assert((BOOST_CHARCONV_ENDIAN_BIG_BYTE || BOOST_CHARCONV_ENDIAN_LITTLE_BY // Detection for C++23 fixed width floating point types // All of these types are optional so check for each of them individually -#if (defined(_MSVC_LANG) && _MSVC_LANG > 202002L) || __cplusplus > 202002L +#if ((defined(_MSVC_LANG) && _MSVC_LANG > 202002L) || __cplusplus > 202002L) # if __has_include() -# include +# include # endif #endif #ifdef __STDCPP_FLOAT16_T__ diff --git a/include/boost/charconv/detail/dragonbox/dragonbox.hpp b/include/boost/charconv/detail/dragonbox/dragonbox.hpp index f2d3449ac..9de3a879a 100644 --- a/include/boost/charconv/detail/dragonbox/dragonbox.hpp +++ b/include/boost/charconv/detail/dragonbox/dragonbox.hpp @@ -30,10 +30,10 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include // UINT64_C #ifdef BOOST_MSVC # pragma warning(push) diff --git a/include/boost/charconv/detail/dragonbox/dragonbox_common.hpp b/include/boost/charconv/detail/dragonbox/dragonbox_common.hpp index 0bee7d091..8241b70cd 100644 --- a/include/boost/charconv/detail/dragonbox/dragonbox_common.hpp +++ b/include/boost/charconv/detail/dragonbox/dragonbox_common.hpp @@ -29,12 +29,12 @@ #include #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include // UINT64_C +#include // CHAR_BIT namespace boost { namespace charconv { namespace detail { diff --git a/include/boost/charconv/detail/dragonbox/floff.hpp b/include/boost/charconv/detail/dragonbox/floff.hpp index 32d138b37..85bb7cfb8 100644 --- a/include/boost/charconv/detail/dragonbox/floff.hpp +++ b/include/boost/charconv/detail/dragonbox/floff.hpp @@ -31,12 +31,12 @@ #include #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include // UINT64_C #ifdef BOOST_MSVC # pragma warning(push) diff --git a/include/boost/charconv/detail/emulated128.hpp b/include/boost/charconv/detail/emulated128.hpp index 281b031cb..e83946038 100644 --- a/include/boost/charconv/detail/emulated128.hpp +++ b/include/boost/charconv/detail/emulated128.hpp @@ -11,11 +11,13 @@ #include #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include // UINT64_C + namespace boost { namespace charconv { namespace detail { @@ -825,7 +827,7 @@ BOOST_CHARCONV_CXX14_CONSTEXPR uint128 &uint128::operator%=(uint128 v) noexcept return *this; } -static inline std::uint64_t umul64(std::uint32_t x, std::uint32_t y) noexcept +inline std::uint64_t umul64(std::uint32_t x, std::uint32_t y) noexcept { // __emulu is not available on ARM https://learn.microsoft.com/en-us/cpp/intrinsics/emul-emulu?view=msvc-170 #if defined(BOOST_CHARCONV_HAS_MSVC_32BIT_INTRINSICS) && !defined(_M_ARM) diff --git a/include/boost/charconv/detail/fallback_routines.hpp b/include/boost/charconv/detail/fallback_routines.hpp index 94f87b82b..80963dde2 100644 --- a/include/boost/charconv/detail/fallback_routines.hpp +++ b/include/boost/charconv/detail/fallback_routines.hpp @@ -10,12 +10,13 @@ #include #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include namespace boost { namespace charconv { @@ -156,7 +157,7 @@ from_chars_result from_chars_strtod_impl(const char* first, const char* last, T& return_value = std::strtof(buffer, &str_end); #ifndef __INTEL_LLVM_COMPILER - if (return_value == HUGE_VALF) + if (return_value == std::numeric_limits::infinity()) #else if (return_value >= (std::numeric_limits::max)()) #endif @@ -169,7 +170,7 @@ from_chars_result from_chars_strtod_impl(const char* first, const char* last, T& return_value = std::strtod(buffer, &str_end); #ifndef __INTEL_LLVM_COMPILER - if (return_value == HUGE_VAL) + if (return_value == std::numeric_limits::infinity()) #else if (return_value >= (std::numeric_limits::max)()) #endif @@ -182,7 +183,7 @@ from_chars_result from_chars_strtod_impl(const char* first, const char* last, T& return_value = std::strtold(buffer, &str_end); #ifndef __INTEL_LLVM_COMPILER - if (return_value == HUGE_VALL) + if (return_value == std::numeric_limits::infinity()) #else if (return_value >= (std::numeric_limits::max)()) #endif diff --git a/include/boost/charconv/detail/fast_float/ascii_number.hpp b/include/boost/charconv/detail/fast_float/ascii_number.hpp index 159a7661d..89e88abe8 100644 --- a/include/boost/charconv/detail/fast_float/ascii_number.hpp +++ b/include/boost/charconv/detail/fast_float/ascii_number.hpp @@ -9,10 +9,10 @@ #define BOOST_CHARCONV_DETAIL_FASTFLOAT_ASCII_NUMBER_HPP #include -#include -#include -#include -#include +#include +#include +#include +#include namespace boost { namespace charconv { namespace detail { namespace fast_float { @@ -45,7 +45,7 @@ uint64_t read_u64(const char *chars) { return val; } uint64_t val; - ::memcpy(&val, chars, sizeof(uint64_t)); + std::memcpy(&val, chars, sizeof(uint64_t)); #if BOOST_CHARCONV_FASTFLOAT_IS_BIG_ENDIAN == 1 // Need to read as-if the number was in little-endian order. val = byteswap(val); @@ -67,7 +67,7 @@ void write_u64(uint8_t *chars, uint64_t val) { // Need to read as-if the number was in little-endian order. val = byteswap(val); #endif - ::memcpy(chars, &val, sizeof(uint64_t)); + std::memcpy(chars, &val, sizeof(uint64_t)); } // credit @aqrit diff --git a/include/boost/charconv/detail/fast_float/bigint.hpp b/include/boost/charconv/detail/fast_float/bigint.hpp index fd98590cd..c3dbf9e71 100644 --- a/include/boost/charconv/detail/fast_float/bigint.hpp +++ b/include/boost/charconv/detail/fast_float/bigint.hpp @@ -9,10 +9,10 @@ #define BOOST_CHARCONV_DETAIL_FASTFLOAT_BIGINT_HPP #include -#include -#include -#include -#include +#include +#include +#include +#include namespace boost { namespace charconv { namespace detail { namespace fast_float { diff --git a/include/boost/charconv/detail/fast_float/decimal_to_binary.hpp b/include/boost/charconv/detail/fast_float/decimal_to_binary.hpp index 4a76a6eeb..5a107d2a0 100644 --- a/include/boost/charconv/detail/fast_float/decimal_to_binary.hpp +++ b/include/boost/charconv/detail/fast_float/decimal_to_binary.hpp @@ -10,12 +10,12 @@ #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include namespace boost { namespace charconv { namespace detail { namespace fast_float { diff --git a/include/boost/charconv/detail/fast_float/digit_comparison.hpp b/include/boost/charconv/detail/fast_float/digit_comparison.hpp index 231279410..3b223649c 100644 --- a/include/boost/charconv/detail/fast_float/digit_comparison.hpp +++ b/include/boost/charconv/detail/fast_float/digit_comparison.hpp @@ -11,10 +11,10 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include namespace boost { namespace charconv { namespace detail { namespace fast_float { @@ -165,7 +165,7 @@ BOOST_FORCEINLINE BOOST_CHARCONV_FASTFLOAT_CONSTEXPR20 void skip_zeros(UC const * & first, UC const * last) noexcept { uint64_t val; while (!cpp20_and_in_constexpr() && std::distance(first, last) >= int_cmp_len()) { - ::memcpy(&val, first, sizeof(uint64_t)); + std::memcpy(&val, first, sizeof(uint64_t)); if (val != int_cmp_zeros()) { break; } @@ -187,7 +187,7 @@ bool is_truncated(UC const * first, UC const * last) noexcept { // do 8-bit optimizations, can just compare to 8 literal 0s. uint64_t val; while (!cpp20_and_in_constexpr() && std::distance(first, last) >= int_cmp_len()) { - ::memcpy(&val, first, sizeof(uint64_t)); + std::memcpy(&val, first, sizeof(uint64_t)); if (val != int_cmp_zeros()) { return true; } diff --git a/include/boost/charconv/detail/fast_float/fast_table.hpp b/include/boost/charconv/detail/fast_float/fast_table.hpp index e08eb3145..ce9b13adf 100644 --- a/include/boost/charconv/detail/fast_float/fast_table.hpp +++ b/include/boost/charconv/detail/fast_float/fast_table.hpp @@ -9,7 +9,7 @@ #define BOOST_CHARCONV_DETAIL_FASTFLOAT_FAST_TABLE_HPP #include -#include +#include namespace boost { namespace charconv { namespace detail { namespace fast_float { diff --git a/include/boost/charconv/detail/fast_float/float_common.hpp b/include/boost/charconv/detail/fast_float/float_common.hpp index 0b9d3aee5..e303470c5 100644 --- a/include/boost/charconv/detail/fast_float/float_common.hpp +++ b/include/boost/charconv/detail/fast_float/float_common.hpp @@ -12,12 +12,13 @@ #include #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include // UINT64_C namespace boost { namespace charconv { namespace detail { namespace fast_float { @@ -37,8 +38,8 @@ using parse_options = parse_options_t; }}}} -#if BOOST_CHARCONV_FASTFLOAT_HAS_BIT_CAST -#include +#if BOOST_CHARCONV_FASTFLOAT_HAS_BIT_CAST && !defined(BOOST_USE_MODULES) +#include #endif #if (defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) \ @@ -288,23 +289,23 @@ struct binary_format_lookup_tables; template struct binary_format : binary_format_lookup_tables { using equiv_uint = typename std::conditional::type; - static inline constexpr int mantissa_explicit_bits(); - static inline constexpr int minimum_exponent(); - static inline constexpr int infinite_power(); - static inline constexpr int sign_index(); - static inline constexpr int min_exponent_fast_path(); // used when fegetround() == FE_TONEAREST - static inline constexpr int max_exponent_fast_path(); - static inline constexpr int max_exponent_round_to_even(); - static inline constexpr int min_exponent_round_to_even(); - static inline constexpr uint64_t max_mantissa_fast_path(int64_t power); - static inline constexpr uint64_t max_mantissa_fast_path(); // used when fegetround() == FE_TONEAREST - static inline constexpr int largest_power_of_ten(); - static inline constexpr int smallest_power_of_ten(); - static inline constexpr T exact_power_of_ten(int64_t power); - static inline constexpr size_t max_digits(); - static inline constexpr equiv_uint exponent_mask(); - static inline constexpr equiv_uint mantissa_mask(); - static inline constexpr equiv_uint hidden_bit_mask(); + static constexpr int mantissa_explicit_bits(); + static constexpr int minimum_exponent(); + static constexpr int infinite_power(); + static constexpr int sign_index(); + static constexpr int min_exponent_fast_path(); // used when fegetround() == FE_TONEAREST + static constexpr int max_exponent_fast_path(); + static constexpr int max_exponent_round_to_even(); + static constexpr int min_exponent_round_to_even(); + static constexpr uint64_t max_mantissa_fast_path(int64_t power); + static constexpr uint64_t max_mantissa_fast_path(); // used when fegetround() == FE_TONEAREST + static constexpr int largest_power_of_ten(); + static constexpr int smallest_power_of_ten(); + static constexpr T exact_power_of_ten(int64_t power); + static constexpr size_t max_digits(); + static constexpr equiv_uint exponent_mask(); + static constexpr equiv_uint mantissa_mask(); + static constexpr equiv_uint hidden_bit_mask(); }; template diff --git a/include/boost/charconv/detail/fast_float/parse_number.hpp b/include/boost/charconv/detail/fast_float/parse_number.hpp index 9f71d45c2..0aef862bd 100644 --- a/include/boost/charconv/detail/fast_float/parse_number.hpp +++ b/include/boost/charconv/detail/fast_float/parse_number.hpp @@ -12,11 +12,10 @@ #include #include #include - -#include -#include -#include -#include +#include +#include +#include +#include namespace boost { namespace charconv { namespace detail { namespace fast_float { @@ -99,7 +98,7 @@ BOOST_FORCEINLINE bool rounds_to_nearest() noexcept { // https://lemire.me/blog/2022/11/16/a-fast-function-to-check-your-floating-point-rounding-mode/ // // This function is meant to be equivalent to : - // prior: #include + // prior: #include // return fegetround() == FE_TONEAREST; // However, it is expected to be much faster than the fegetround() // function call. diff --git a/include/boost/charconv/detail/from_chars_integer_impl.hpp b/include/boost/charconv/detail/from_chars_integer_impl.hpp index a069fd968..5de5eafae 100644 --- a/include/boost/charconv/detail/from_chars_integer_impl.hpp +++ b/include/boost/charconv/detail/from_chars_integer_impl.hpp @@ -12,17 +12,17 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include namespace boost { namespace charconv { namespace detail { -static constexpr unsigned char uchar_values[] = +BOOST_INLINE_CONSTEXPR unsigned char uchar_values[] = {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, @@ -42,7 +42,7 @@ static constexpr unsigned char uchar_values[] = static_assert(sizeof(uchar_values) == 256, "uchar_values should represent all 256 values of unsigned char"); -static constexpr double log_2_table[] = +BOOST_INLINE_CONSTEXPR double log_2_table[] = { 0.0, 0.0, diff --git a/include/boost/charconv/detail/from_chars_result.hpp b/include/boost/charconv/detail/from_chars_result.hpp index e4302cfab..b44fa8d51 100644 --- a/include/boost/charconv/detail/from_chars_result.hpp +++ b/include/boost/charconv/detail/from_chars_result.hpp @@ -5,7 +5,8 @@ #ifndef BOOST_CHARCONV_DETAIL_FROM_CHARS_RESULT_HPP #define BOOST_CHARCONV_DETAIL_FROM_CHARS_RESULT_HPP -#include +#include + namespace boost { namespace charconv { diff --git a/include/boost/charconv/detail/integer_search_trees.hpp b/include/boost/charconv/detail/integer_search_trees.hpp index 9b4de0913..9d139185d 100644 --- a/include/boost/charconv/detail/integer_search_trees.hpp +++ b/include/boost/charconv/detail/integer_search_trees.hpp @@ -10,9 +10,10 @@ #include #include -#include -#include -#include +#include +#include +#include +#include // UINT64_C namespace boost { namespace charconv { namespace detail { diff --git a/include/boost/charconv/detail/issignaling.hpp b/include/boost/charconv/detail/issignaling.hpp index 0780c2e89..f9f759fc3 100644 --- a/include/boost/charconv/detail/issignaling.hpp +++ b/include/boost/charconv/detail/issignaling.hpp @@ -7,13 +7,15 @@ #include #include -#include -#include +#include +#include +#include // UINT64_C + namespace boost { namespace charconv { namespace detail { template -inline bool issignaling BOOST_PREVENT_MACRO_SUBSTITUTION (T x) noexcept; +bool issignaling BOOST_PREVENT_MACRO_SUBSTITUTION (T x) noexcept; #if BOOST_CHARCONV_LDBL_BITS == 128 || defined(BOOST_CHARCONV_HAS_QUADMATH) diff --git a/include/boost/charconv/detail/macros.hpp b/include/boost/charconv/detail/macros.hpp new file mode 100644 index 000000000..2c82b430e --- /dev/null +++ b/include/boost/charconv/detail/macros.hpp @@ -0,0 +1,72 @@ +// Copyright 2023 Matt Borland +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#ifndef BOOST_CHARCONV_DETAIL_MACROS_HPP +#define BOOST_CHARCONV_DETAIL_MACROS_HPP + +// Extracted from config.hpp, with macros that should be public +// or are used in the tests +#include +#include + +// Use 128-bit integers and suppress warnings for using extensions +#if defined(BOOST_HAS_INT128) +# define BOOST_CHARCONV_HAS_INT128 +# define BOOST_CHARCONV_INT128_MAX static_cast((static_cast(1) << 127) - 1) +# define BOOST_CHARCONV_INT128_MIN (-BOOST_CHARCONV_INT128_MAX - 1) +# define BOOST_CHARCONV_UINT128_MAX (2 * static_cast(BOOST_CHARCONV_INT128_MAX) + 1) +#endif + +#ifndef BOOST_NO_CXX14_CONSTEXPR +# define BOOST_CHARCONV_CXX14_CONSTEXPR BOOST_CXX14_CONSTEXPR +# define BOOST_CHARCONV_CXX14_CONSTEXPR_NO_INLINE BOOST_CXX14_CONSTEXPR +#else +# define BOOST_CHARCONV_CXX14_CONSTEXPR inline +# define BOOST_CHARCONV_CXX14_CONSTEXPR_NO_INLINE +#endif + +#if defined(__GNUC__) && __GNUC__ == 5 +# define BOOST_CHARCONV_GCC5_CONSTEXPR inline +#else +# define BOOST_CHARCONV_GCC5_CONSTEXPR BOOST_CHARCONV_CXX14_CONSTEXPR +#endif + +// C++17 allowed for constexpr lambdas +#if defined(__cpp_constexpr) && __cpp_constexpr >= 201603L +# define BOOST_CHARCONV_CXX17_CONSTEXPR constexpr +#else +# define BOOST_CHARCONV_CXX17_CONSTEXPR inline +#endif + +// Detection for C++23 fixed width floating point types +// All of these types are optional so check for each of them individually +#ifdef __STDCPP_FLOAT16_T__ +# define BOOST_CHARCONV_HAS_FLOAT16 +#endif +#ifdef __STDCPP_FLOAT32_T__ +# define BOOST_CHARCONV_HAS_FLOAT32 +#endif +#ifdef __STDCPP_FLOAT64_T__ +# define BOOST_CHARCONV_HAS_FLOAT64 +#endif +#ifdef __STDCPP_FLOAT128_T__ +# define BOOST_CHARCONV_HAS_STDFLOAT128 +#endif +#ifdef __STDCPP_BFLOAT16_T__ +# define BOOST_CHARCONV_HAS_BRAINFLOAT16 +#endif + +// Long double support +#if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 // 80 bit long double (e.g. x86-64) +# define BOOST_CHARCONV_LDBL_BITS 80 +#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 // 128 bit long double (e.g. s390x, ppcle64) +# define BOOST_CHARCONV_LDBL_BITS 128 +#elif LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 // 64 bit long double (double == long double on ARM) +# define BOOST_CHARCONV_LDBL_BITS 64 +#else // Unsupported long double representation +# define BOOST_CHARCONV_UNSUPPORTED_LONG_DOUBLE +# define BOOST_CHARCONV_LDBL_BITS -1 +#endif + +#endif // BOOST_CHARCONV_DETAIL_CONFIG_HPP diff --git a/include/boost/charconv/detail/memcpy.hpp b/include/boost/charconv/detail/memcpy.hpp index 1e68315f4..a614b2dc4 100644 --- a/include/boost/charconv/detail/memcpy.hpp +++ b/include/boost/charconv/detail/memcpy.hpp @@ -6,8 +6,8 @@ #define BOOST_CHARCONV_DETAIL_MEMCPY_HPP #include -#include -#include +#include +#include // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89689 // GCC 10 added checks for length of memcpy which yields the following warning (converted to error with -Werror) diff --git a/include/boost/charconv/detail/parser.hpp b/include/boost/charconv/detail/parser.hpp index 660de6884..c851a62d2 100644 --- a/include/boost/charconv/detail/parser.hpp +++ b/include/boost/charconv/detail/parser.hpp @@ -11,12 +11,12 @@ #include #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #if defined(__GNUC__) && __GNUC__ < 5 && !defined(__clang__) # pragma GCC diagnostic push diff --git a/include/boost/charconv/detail/ryu/generic_128.hpp b/include/boost/charconv/detail/ryu/generic_128.hpp index 23c5234dd..4a9f508b6 100644 --- a/include/boost/charconv/detail/ryu/generic_128.hpp +++ b/include/boost/charconv/detail/ryu/generic_128.hpp @@ -9,7 +9,8 @@ #include #include #include -#include +#include +#include // UINT64_C #define BOOST_CHARCONV_POW5_TABLE_SIZE 56 #define BOOST_CHARCONV_POW5_BITCOUNT 249 diff --git a/include/boost/charconv/detail/ryu/ryu_generic_128.hpp b/include/boost/charconv/detail/ryu/ryu_generic_128.hpp index 2047d9a70..b41c023ac 100644 --- a/include/boost/charconv/detail/ryu/ryu_generic_128.hpp +++ b/include/boost/charconv/detail/ryu/ryu_generic_128.hpp @@ -6,17 +6,18 @@ #ifndef BOOST_CHARCONV_DETAIL_RYU_RYU_GENERIC_128_HPP #define BOOST_CHARCONV_DETAIL_RYU_RYU_GENERIC_128_HPP +#include #include #include -#include +#include #include #include -#include -#include -#include +#include +#include +#include #ifdef BOOST_CHARCONV_DEBUG -# include +# include #endif namespace boost { namespace charconv { namespace detail { namespace ryu { @@ -354,14 +355,14 @@ static inline int copy_special_str(char* result, const std::ptrdiff_t result_siz if (result_size >= 3 + static_cast(fd.sign)) { - memcpy(result, "inf", 3); + std::memcpy(result, "inf", 3); return static_cast(fd.sign) + 3; } return -1; } -static inline int generic_to_chars_fixed(const struct floating_decimal_128 v, char* result, const ptrdiff_t result_size, int precision) noexcept +static inline int generic_to_chars_fixed(const struct floating_decimal_128 v, char* result, const std::ptrdiff_t result_size, int precision) noexcept { if (v.exponent == fd128_exceptional_exponent) { @@ -397,7 +398,7 @@ static inline int generic_to_chars_fixed(const struct floating_decimal_128 v, ch if (precision > 0) { result[current_len++] = '.'; - memset(result+current_len, '0', static_cast(precision)); + std::memset(result+current_len, '0', static_cast(precision)); current_len += precision; precision = 0; } @@ -412,7 +413,7 @@ static inline int generic_to_chars_fixed(const struct floating_decimal_128 v, ch } result = r.ptr; - memset(result, '0', static_cast(v.exponent)); + std::memset(result, '0', static_cast(v.exponent)); result += static_cast(v.exponent); *result++ = '.'; current_len += v.exponent + 1; @@ -425,10 +426,10 @@ static inline int generic_to_chars_fixed(const struct floating_decimal_128 v, ch return -static_cast(std::errc::result_out_of_range); } - memmove(result + current_len + v.exponent + 1, result + current_len + v.exponent, static_cast(-v.exponent)); + std::memmove(result + current_len + v.exponent + 1, result + current_len + v.exponent, static_cast(-v.exponent)); const auto shift = result + current_len + v.exponent; const auto shift_width = (shift - result) + 1; - memcpy(shift, ".", 1U); + std::memcpy(shift, ".", 1U); ++current_len; if (current_len - shift_width > precision) { @@ -480,9 +481,9 @@ static inline int generic_to_chars_fixed(const struct floating_decimal_128 v, ch return -static_cast(std::errc::value_too_large); } - memmove(result - v.exponent - current_len + 2, result, static_cast(current_len)); - memcpy(result, "0.", 2U); - memset(result + 2, '0', static_cast(0 - v.exponent - current_len)); + std::memmove(result - v.exponent - current_len + 2, result, static_cast(current_len)); + std::memcpy(result, "0.", 2U); + std::memset(result + 2, '0', static_cast(0 - v.exponent - current_len)); current_len = -v.exponent + 2; precision -= current_len - 2; result += current_len; @@ -495,7 +496,7 @@ static inline int generic_to_chars_fixed(const struct floating_decimal_128 v, ch return -static_cast(std::errc::result_out_of_range); } - memset(result, '0', static_cast(precision)); + std::memset(result, '0', static_cast(precision)); current_len += precision; } @@ -509,7 +510,7 @@ static inline int generic_to_chars_fixed(const struct floating_decimal_128 v, ch // Maximal char buffer requirement: // sign + mantissa digits + decimal dot + 'E' + exponent sign + exponent digits // = 1 + 39 + 1 + 1 + 1 + 10 = 53 -static inline int generic_to_chars(const struct floating_decimal_128 v, char* result, const ptrdiff_t result_size, +static inline int generic_to_chars(const struct floating_decimal_128 v, char* result, const std::ptrdiff_t result_size, chars_format fmt = chars_format::general, int precision = -1) noexcept { if (v.exponent == fd128_exceptional_exponent) diff --git a/include/boost/charconv/detail/significand_tables.hpp b/include/boost/charconv/detail/significand_tables.hpp index 51dd71f45..b55d4cb2c 100644 --- a/include/boost/charconv/detail/significand_tables.hpp +++ b/include/boost/charconv/detail/significand_tables.hpp @@ -7,7 +7,7 @@ #define BOOST_CHARCONV_DETAIL_SIGNIFICAND_TABLES_HPP #include -#include +#include // The significand of a floating point number is often referred to as the mantissa. // Using the term mantissa is discouraged by IEEE 1516 diff --git a/include/boost/charconv/detail/to_chars_integer_impl.hpp b/include/boost/charconv/detail/to_chars_integer_impl.hpp index 1ef54a2f0..0bbc82302 100644 --- a/include/boost/charconv/detail/to_chars_integer_impl.hpp +++ b/include/boost/charconv/detail/to_chars_integer_impl.hpp @@ -13,23 +13,27 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // UINT64_C +#include // CHAR_BIT + namespace boost { namespace charconv { namespace detail { -static constexpr char radix_table[] = { +BOOST_INLINE_CONSTEXPR char radix_table[] = { '0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6', '0', '7', '0', '8', '0', '9', '1', '0', '1', '1', '1', '2', '1', '3', '1', '4', @@ -52,7 +56,7 @@ static constexpr char radix_table[] = { '9', '5', '9', '6', '9', '7', '9', '8', '9', '9' }; -static constexpr char digit_table[] = { +BOOST_INLINE_CONSTEXPR char digit_table[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', diff --git a/include/boost/charconv/detail/to_chars_result.hpp b/include/boost/charconv/detail/to_chars_result.hpp index e564fe6cd..60b2e18e7 100644 --- a/include/boost/charconv/detail/to_chars_result.hpp +++ b/include/boost/charconv/detail/to_chars_result.hpp @@ -5,7 +5,7 @@ #ifndef BOOST_CHARCONV_DETAIL_TO_CHARS_RESULT_HPP #define BOOST_CHARCONV_DETAIL_TO_CHARS_RESULT_HPP -#include +#include // 22.13.2, Primitive numerical output conversion diff --git a/include/boost/charconv/detail/type_traits.hpp b/include/boost/charconv/detail/type_traits.hpp index 416055516..3400d845e 100644 --- a/include/boost/charconv/detail/type_traits.hpp +++ b/include/boost/charconv/detail/type_traits.hpp @@ -6,7 +6,7 @@ #define BOOST_CHARCONV_DETAIL_TYPE_TRAITS_HPP #include -#include +#include namespace boost { namespace charconv { namespace detail { diff --git a/include/boost/charconv/from_chars.hpp b/include/boost/charconv/from_chars.hpp index 0bef0b5f5..dbf2d176c 100644 --- a/include/boost/charconv/from_chars.hpp +++ b/include/boost/charconv/from_chars.hpp @@ -6,6 +6,13 @@ #ifndef BOOST_CHARCONV_FROM_CHARS_HPP_INCLUDED #define BOOST_CHARCONV_FROM_CHARS_HPP_INCLUDED +#if defined(BOOST_USE_MODULES) && !defined(BOOST_CHARCONV_SOURCE) + +#include +import boost.charconv; + +#else + #include #include #include @@ -13,7 +20,7 @@ #include #include #include -#include +#include namespace boost { namespace charconv { @@ -252,4 +259,6 @@ BOOST_CHARCONV_DECL from_chars_result from_chars(boost::core::string_view sv, st } // namespace charconv } // namespace boost +#endif + #endif // #ifndef BOOST_CHARCONV_FROM_CHARS_HPP_INCLUDED diff --git a/include/boost/charconv/limits.hpp b/include/boost/charconv/limits.hpp index f62809f30..7669a0d7e 100644 --- a/include/boost/charconv/limits.hpp +++ b/include/boost/charconv/limits.hpp @@ -5,9 +5,16 @@ #ifndef BOOST_CHARCONV_LIMITS_HPP #define BOOST_CHARCONV_LIMITS_HPP +#if defined(BOOST_USE_MODULES) && !defined(BOOST_CHARCONV_SOURCE) + +#include +import boost.charconv; + +#else + #include -#include -#include +#include +#include namespace boost { namespace charconv { @@ -93,4 +100,6 @@ template BOOST_ATTRIBUTE_UNUSED constexpr int limits::max_chars; }} // namespace boost::charconv +#endif + #endif // BOOST_CHARCONV_LIMITS_HPP diff --git a/include/boost/charconv/to_chars.hpp b/include/boost/charconv/to_chars.hpp index 7192fda57..f7105f259 100644 --- a/include/boost/charconv/to_chars.hpp +++ b/include/boost/charconv/to_chars.hpp @@ -7,6 +7,13 @@ #ifndef BOOST_CHARCONV_TO_CHARS_HPP_INCLUDED #define BOOST_CHARCONV_TO_CHARS_HPP_INCLUDED +#if defined(BOOST_USE_MODULES) && !defined(BOOST_CHARCONV_SOURCE) + +#include +import boost.charconv; + +#else + #include #include #include @@ -144,4 +151,6 @@ BOOST_CHARCONV_DECL to_chars_result to_chars(char* first, char* last, std::bfloa } // namespace charconv } // namespace boost +#endif + #endif // #ifndef BOOST_CHARCONV_TO_CHARS_HPP_INCLUDED diff --git a/modules/boost_charconv.cppm b/modules/boost_charconv.cppm new file mode 100644 index 000000000..4a4dcbfa9 --- /dev/null +++ b/modules/boost_charconv.cppm @@ -0,0 +1,17 @@ +module; + +#include + +export module boost.charconv; + +export namespace boost::charconv { + +using charconv::chars_format; +using charconv::from_chars; +using charconv::from_chars_erange; +using charconv::limits; +using charconv::to_chars; +using charconv::from_chars_result; +using charconv::to_chars_result; + +} diff --git a/src/float128_impl.hpp b/src/float128_impl.hpp index 3b9e44ab6..670f2792e 100644 --- a/src/float128_impl.hpp +++ b/src/float128_impl.hpp @@ -11,9 +11,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include // Only add in float128 support if the build system says it can #ifdef BOOST_CHARCONV_HAS_QUADMATH diff --git a/src/from_chars.cpp b/src/from_chars.cpp index 2c01e73cf..9eabda114 100644 --- a/src/from_chars.cpp +++ b/src/from_chars.cpp @@ -3,6 +3,10 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt +#ifdef BOOST_USE_MODULES +module; +#endif + // https://stackoverflow.com/questions/38060411/visual-studio-2015-wont-suppress-error-c4996 #ifndef _SCL_SECURE_NO_WARNINGS # define _SCL_SECURE_NO_WARNINGS @@ -11,27 +15,34 @@ # define NO_WARN_MBCS_MFC_DEPRECATION #endif +#include // must be before import std #include "float128_impl.hpp" #include "from_chars_float_impl.hpp" #include #include #include -#include -#include -#include -#include -#include -#include - +#include +#include +#include +#include +#include +#include #if BOOST_CHARCONV_LDBL_BITS > 64 # include # include #endif +#ifdef BOOST_USE_MODULES +module boost.charconv; +#endif + + #if defined(__GNUC__) && __GNUC__ < 5 # pragma GCC diagnostic ignored "-Wmissing-field-initializers" #endif +extern "C++" { + boost::charconv::from_chars_result boost::charconv::from_chars_erange(const char* first, const char* last, float& value, boost::charconv::chars_format fmt) noexcept { if (fmt != boost::charconv::chars_format::hex) @@ -73,7 +84,7 @@ boost::charconv::from_chars_result boost::charconv::from_chars_erange(const char #if BOOST_CHARCONV_HAS_BUILTIN(__builtin_inf) value = sign ? -static_cast<__float128>(__builtin_inf()) : static_cast<__float128>(__builtin_inf()); #else // Conversion from HUGE_VALL should work - value = sign ? -static_cast<__float128>(HUGE_VALL) : static_cast<__float128>(HUGE_VALL); + value = sign ? -static_cast<__float128>(std::numeric_limits::infinity()) : static_cast<__float128>(std::numeric_limits::infinity()); #endif return r; @@ -505,3 +516,5 @@ boost::charconv::from_chars_result boost::charconv::from_chars(boost::core::stri return from_chars_strict_impl(sv.data(), sv.data() + sv.size(), value, fmt); } #endif + +} // extern "C++" diff --git a/src/from_chars_float_impl.hpp b/src/from_chars_float_impl.hpp index b0ed68d6b..fcefcceee 100644 --- a/src/from_chars_float_impl.hpp +++ b/src/from_chars_float_impl.hpp @@ -14,9 +14,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include namespace boost { namespace charconv { namespace detail { @@ -104,7 +104,7 @@ from_chars_result from_chars_float_impl(const char* first, const char* last, T& BOOST_IF_CONSTEXPR (std::is_same::value) { #ifndef __INTEL_LLVM_COMPILER - if (return_val == HUGE_VALF || return_val == -HUGE_VALF) + if (return_val == std::numeric_limits::infinity() || return_val == -std::numeric_limits::infinity()) #else if (return_val >= (std::numeric_limits::max)() || return_val <= std::numeric_limits::lowest()) #endif @@ -125,7 +125,7 @@ from_chars_result from_chars_float_impl(const char* first, const char* last, T& else BOOST_IF_CONSTEXPR (std::is_same::value) { #ifndef __INTEL_LLVM_COMPILER - if (return_val == HUGE_VAL || return_val == -HUGE_VAL) + if (return_val == std::numeric_limits::infinity() || return_val == -std::numeric_limits::infinity()) #else if (return_val >= (std::numeric_limits::max)() || return_val <= std::numeric_limits::lowest()) #endif @@ -146,7 +146,7 @@ from_chars_result from_chars_float_impl(const char* first, const char* last, T& else BOOST_IF_CONSTEXPR (std::is_same::value) { #ifndef __INTEL_LLVM_COMPILER - if (return_val == HUGE_VALL || return_val == -HUGE_VALL) + if (return_val == std::numeric_limits::infinity() || return_val == -std::numeric_limits::infinity()) #else if (return_val >= (std::numeric_limits::max)() || return_val <= std::numeric_limits::lowest()) #endif diff --git a/src/to_chars.cpp b/src/to_chars.cpp index ab0c77d72..dd44d8911 100644 --- a/src/to_chars.cpp +++ b/src/to_chars.cpp @@ -4,15 +4,25 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt +#ifdef BOOST_USE_MODULES +module; +#endif + +#include // must be before import std #include "float128_impl.hpp" #include "to_chars_float_impl.hpp" #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include + +#ifdef BOOST_USE_MODULES +module boost.charconv; +#endif + namespace boost { namespace charconv { namespace detail { namespace to_chars_detail { @@ -549,6 +559,8 @@ namespace boost { namespace charconv { namespace detail { namespace to_chars_det }}}} // Namespaces +extern "C++" { + boost::charconv::to_chars_result boost::charconv::to_chars(char* first, char* last, float value, boost::charconv::chars_format fmt) noexcept { @@ -753,3 +765,5 @@ boost::charconv::to_chars_result boost::charconv::to_chars(char* first, char* la return boost::charconv::detail::to_chars_float_impl(first, last, static_cast(value), fmt, precision); } #endif + +} // extern "C++" diff --git a/src/to_chars_float_impl.hpp b/src/to_chars_float_impl.hpp index 4c74e04db..10e5822e8 100644 --- a/src/to_chars_float_impl.hpp +++ b/src/to_chars_float_impl.hpp @@ -22,34 +22,34 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef BOOST_CHARCONV_DEBUG_FIXED -#include -#include -#endif #if (BOOST_CHARCONV_LDBL_BITS == 80 || BOOST_CHARCONV_LDBL_BITS == 128) # include # include #endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef BOOST_CHARCONV_DEBUG_FIXED +#include +#include +#endif + namespace boost { namespace charconv { namespace detail { template -inline to_chars_result to_chars_nonfinite(char* first, char* last, Real value, int classification) noexcept; +to_chars_result to_chars_nonfinite(char* first, char* last, Real value, int classification) noexcept; #if BOOST_CHARCONV_LDBL_BITS == 128 || defined(BOOST_CHARCONV_HAS_STDFLOAT128) || defined(BOOST_CHARCONV_HAS_FLOAT16) || defined(BOOST_CHARCONV_HAS_BRAINFLOAT16) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7bf0e6e09..6e2c396d6 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -6,8 +6,6 @@ include(BoostTestJamfile OPTIONAL RESULT_VARIABLE HAVE_BOOST_TEST) if(HAVE_BOOST_TEST) -# https://crascit.com/2015/03/28/enabling-cxx11-in-cmake/ -set(CMAKE_CXX_EXTENSIONS OFF) boost_test_jamfile(FILE Jamfile LINK_LIBRARIES Boost::charconv Boost::core Boost::assert) endif() diff --git a/test/P2497.cpp b/test/P2497.cpp index 9359f9c03..eceb4a3d7 100644 --- a/test/P2497.cpp +++ b/test/P2497.cpp @@ -2,6 +2,12 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt +#ifdef BOOST_USE_MODULES +#include +import std; +import boost.core; +import boost.charconv; +#else #include #include #include @@ -11,6 +17,8 @@ #include #include #include +#endif + // No overflows, negative numbers, locales, etc. template diff --git a/test/cmake_install_test/CMakeLists.txt b/test/cmake_install_test/CMakeLists.txt index a2531dec8..d2fbffdf9 100644 --- a/test/cmake_install_test/CMakeLists.txt +++ b/test/cmake_install_test/CMakeLists.txt @@ -2,7 +2,7 @@ # Distributed under the Boost Software License, Version 1.0. # See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt -cmake_minimum_required(VERSION 3.5...3.16) +cmake_minimum_required(VERSION 3.5...3.31) project(cmake_install_test LANGUAGES CXX) diff --git a/test/cmake_subdir_test/CMakeLists.txt b/test/cmake_subdir_test/CMakeLists.txt index bac5b891a..f50e84334 100644 --- a/test/cmake_subdir_test/CMakeLists.txt +++ b/test/cmake_subdir_test/CMakeLists.txt @@ -2,7 +2,7 @@ # Distributed under the Boost Software License, Version 1.0. # See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt -cmake_minimum_required(VERSION 3.5...3.20) +cmake_minimum_required(VERSION 3.5...3.31) project(cmake_subdir_test LANGUAGES CXX) diff --git a/test/from_chars.cpp b/test/from_chars.cpp index 091091e66..f72009da3 100644 --- a/test/from_chars.cpp +++ b/test/from_chars.cpp @@ -5,17 +5,16 @@ #include #include -#include -#include -#include -#include -#include -#include -#include - +#include +#include +#include +#include +#include +#include +#include #if defined(__has_include) # if __has_include() -# include +# include # endif #endif diff --git a/test/from_chars_float.cpp b/test/from_chars_float.cpp index cf810b559..fc5358afc 100644 --- a/test/from_chars_float.cpp +++ b/test/from_chars_float.cpp @@ -2,18 +2,20 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt +#include // Needs to be before import std in modular builds #include "../src/from_chars_float_impl.hpp" #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + template void spot_value(const std::string& buffer, T expected_value, boost::charconv::chars_format fmt = boost::charconv::chars_format::general) diff --git a/test/from_chars_float2.cpp b/test/from_chars_float2.cpp index 8e0e64260..178db296e 100644 --- a/test/from_chars_float2.cpp +++ b/test/from_chars_float2.cpp @@ -5,7 +5,8 @@ #include #include #include -#include +#include +#include // stderr static boost::detail::splitmix64 rng; diff --git a/test/from_chars_string_view.cpp b/test/from_chars_string_view.cpp index 358894281..f9cf6a6b9 100644 --- a/test/from_chars_string_view.cpp +++ b/test/from_chars_string_view.cpp @@ -2,19 +2,20 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt + #include #include #include #include -#include -#include -#include -#include - +#include +#include +#include +#include #if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW) -# include +# include #endif + static std::mt19937_64 rng(42); constexpr std::size_t N = 1024; diff --git a/test/github_issue_110.cpp b/test/github_issue_110.cpp index 7a196d8c0..dba529704 100644 --- a/test/github_issue_110.cpp +++ b/test/github_issue_110.cpp @@ -4,6 +4,7 @@ #include #include +#include template void overflow_spot_value(const std::string& buffer, boost::charconv::chars_format fmt = boost::charconv::chars_format::general) diff --git a/test/github_issue_122.cpp b/test/github_issue_122.cpp index c8495b285..49cfe3859 100644 --- a/test/github_issue_122.cpp +++ b/test/github_issue_122.cpp @@ -3,10 +3,10 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#include -#include -#include #include +#include +#include +#include #include template diff --git a/test/github_issue_152.cpp b/test/github_issue_152.cpp index 51c188df9..66de8b9af 100644 --- a/test/github_issue_152.cpp +++ b/test/github_issue_152.cpp @@ -4,12 +4,12 @@ #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include constexpr std::size_t N = 1024; static std::mt19937_64 rng(42); diff --git a/test/github_issue_152_float128.cpp b/test/github_issue_152_float128.cpp index 6c64ea4d8..106fe854e 100644 --- a/test/github_issue_152_float128.cpp +++ b/test/github_issue_152_float128.cpp @@ -2,8 +2,14 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include #ifdef BOOST_CHARCONV_HAS_QUADMATH @@ -25,14 +31,6 @@ std::ostream& operator<<( std::ostream& os, std::float128_t v ) } #endif -#include -#include -#include -#include -#include -#include -#include - constexpr std::size_t N = 1024; static std::mt19937_64 rng(42); diff --git a/test/github_issue_158.cpp b/test/github_issue_158.cpp index f1333e037..ee3a71ffa 100644 --- a/test/github_issue_158.cpp +++ b/test/github_issue_158.cpp @@ -7,6 +7,7 @@ #include #include +#include void test_values_with_negative_exp() { diff --git a/test/github_issue_166_float128.cpp b/test/github_issue_166_float128.cpp index 9812bdb71..6e375efce 100644 --- a/test/github_issue_166_float128.cpp +++ b/test/github_issue_166_float128.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include template void test() diff --git a/test/github_issue_186.cpp b/test/github_issue_186.cpp index 628da1e7f..83c41d3b4 100644 --- a/test/github_issue_186.cpp +++ b/test/github_issue_186.cpp @@ -6,8 +6,8 @@ #include #include -#include -#include +#include +#include template void force_overflow(T value) diff --git a/test/github_issue_212.cpp b/test/github_issue_212.cpp index 110774e2d..64bad2d4d 100644 --- a/test/github_issue_212.cpp +++ b/test/github_issue_212.cpp @@ -4,9 +4,9 @@ #include #include -#include +#include +#include #include -#include template void test() diff --git a/test/limits.cpp b/test/limits.cpp index 7fe02ca76..ebfa47a51 100644 --- a/test/limits.cpp +++ b/test/limits.cpp @@ -4,16 +4,19 @@ // https://www.boost.org/LICENSE_1_0.txt #include +#include +#include +#include +#include +#include +#include +#include +#include #ifdef BOOST_HAS_INT128 -// We need to define these operator<< overloads before -// including boost/core/lightweight_test.hpp, or they -// won't be visible to BOOST_TEST_EQ // LCOV_EXCL_START -#include - static char* mini_to_chars( char (&buffer)[ 64 ], boost::uint128_type v ) { char* p = buffer + 64; @@ -60,13 +63,7 @@ std::ostream& operator<<( std::ostream& os, boost::int128_type v ) #endif // #ifdef BOOST_HAS_INT128 -#include -#include -#include -#include -#include -#include -#include + void test_odr_use( int const* ); @@ -158,7 +155,7 @@ template void test_floating_point( T value ) T v2 = 0; auto r2 = boost::charconv::from_chars( buffer, r.ptr, v2 ); - if (!BOOST_TEST(r2.ec == std::errc()) && BOOST_TEST_EQ( v2, value )) + if (!BOOST_TEST(r2.ec == std::errc()) && BOOST_TEST( v2 == value )) { // LCOV_EXCL_START std::cerr << " Value: " << value @@ -185,7 +182,7 @@ template void test_floating_point( T value ) T v2 = 0; auto r2 = boost::charconv::from_chars( buffer, r.ptr, v2 ); - if (!BOOST_TEST(r2.ec == std::errc()) && BOOST_TEST_EQ( v2, value )) + if (!BOOST_TEST(r2.ec == std::errc()) && BOOST_TEST( v2 == value )) { // LCOV_EXCL_START std::cerr << " Value: " << value diff --git a/test/limits_link_1.cpp b/test/limits_link_1.cpp index a7b2eaf9b..cb61e962b 100644 --- a/test/limits_link_1.cpp +++ b/test/limits_link_1.cpp @@ -3,7 +3,6 @@ // https://www.boost.org/LICENSE_1_0.txt #include -#include void test_odr_use( int const* ); diff --git a/test/limits_link_2.cpp b/test/limits_link_2.cpp index b45c627fd..b6c2ff05a 100644 --- a/test/limits_link_2.cpp +++ b/test/limits_link_2.cpp @@ -3,7 +3,6 @@ // https://www.boost.org/LICENSE_1_0.txt #include -#include void test_odr_use( int const* ); diff --git a/test/roundtrip.cpp b/test/roundtrip.cpp index 6c16cb65e..f71d6a220 100644 --- a/test/roundtrip.cpp +++ b/test/roundtrip.cpp @@ -3,16 +3,23 @@ // https://www.boost.org/LICENSE_1_0.txt #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #ifdef BOOST_HAS_INT128 -// We need to define these operator<< overloads before -// including boost/core/lightweight_test.hpp, or they -// won't be visible to BOOST_TEST_EQ // LCOV_EXCL_START -#include - static char* mini_to_chars( char (&buffer)[ 64 ], boost::uint128_type v ) { char* p = buffer + 64; @@ -59,18 +66,6 @@ std::ostream& operator<<( std::ostream& os, boost::int128_type v ) #endif // #ifdef BOOST_HAS_INT128 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - int const N = 1024; static boost::detail::splitmix64 rng; @@ -250,7 +245,7 @@ template void test_roundtrip( T value, boost::charconv::chars_format fm T v2 = 0; auto r2 = boost::charconv::from_chars( buffer, r.ptr, v2, fmt ); - if( BOOST_TEST( r2.ec == std::errc() ) && BOOST_TEST_EQ( v2, value ) && BOOST_TEST( r2.ptr == r.ptr) ) + if( BOOST_TEST( r2.ec == std::errc() ) && BOOST_TEST( v2 == value ) && BOOST_TEST( r2.ptr == r.ptr) ) { } else @@ -296,7 +291,7 @@ int64_t ToOrdinal(FPType x) // Number of normal representable numbers for each exponent. static const auto - NumbersPerExponent = static_cast(scalbn(Radix-1, SignificandDigits-1)); + NumbersPerExponent = static_cast(std::scalbn(Radix-1, SignificandDigits-1)); if (x == 0) return 0; @@ -319,7 +314,7 @@ int64_t ToOrdinal(FPType x) /* Start with the number of representable numbers in preceding normal exponent ranges. */ - auto count = static_cast(static_cast(exponent - MinimumExponent) * NumbersPerExponent); + auto count = static_cast(static_cast(exponent - MinimumExponent) * NumbersPerExponent); /* For subnormal numbers, fraction * radix ** SignificandDigits is the number of representable numbers from 0 to x. For normal numbers, diff --git a/test/test_128bit_emulation.cpp b/test/test_128bit_emulation.cpp index 570e764c6..82df66828 100644 --- a/test/test_128bit_emulation.cpp +++ b/test/test_128bit_emulation.cpp @@ -2,17 +2,17 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#include +#include +#include +#include +#include +#include +#include // CHAR_BIT #ifdef BOOST_HAS_INT128 -// We need to define these operator<< overloads before -// including boost/core/lightweight_test.hpp, or they -// won't be visible to BOOST_TEST_EQ // LCOV_EXCL_START -#include - static char* mini_to_chars( char (&buffer)[ 64 ], boost::uint128_type v ) { char* p = buffer + 64; @@ -59,13 +59,6 @@ std::ostream& operator<<( std::ostream& os, boost::int128_type v ) #endif // #ifdef BOOST_HAS_INT128 -#include -#include -#include -#include -#include -#include - using boost::charconv::detail::uint128; using boost::charconv::detail::trivial_uint128; diff --git a/test/test_128bit_native.cpp b/test/test_128bit_native.cpp index cd96a8eb8..e5873da41 100644 --- a/test/test_128bit_native.cpp +++ b/test/test_128bit_native.cpp @@ -2,11 +2,12 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#include #include -#include +#include +#include #include + void test128() { auto r1 = boost::charconv::detail::umul128(1, 1); diff --git a/test/test_boost_json_values.cpp b/test/test_boost_json_values.cpp index fb3e5963c..11dfe9fc8 100644 --- a/test/test_boost_json_values.cpp +++ b/test/test_boost_json_values.cpp @@ -9,16 +9,17 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include +#include // stderr template void grind(const std::string& str, const T expected_value) diff --git a/test/test_compute_float32.cpp b/test/test_compute_float32.cpp index d3fa83465..7e7e9d606 100644 --- a/test/test_compute_float32.cpp +++ b/test/test_compute_float32.cpp @@ -4,9 +4,8 @@ #include #include -#include -#include -#include +#include +#include using boost::charconv::detail::compute_float32; @@ -20,7 +19,7 @@ inline void simple_test() BOOST_TEST_EQ(compute_float32(38, 1, false, success), 1e38F); // out of range - BOOST_TEST_EQ(compute_float32(310, 5, false, success), HUGE_VALF); + BOOST_TEST_EQ(compute_float32(310, 5, false, success), std::numeric_limits::infinity()); BOOST_TEST_EQ(compute_float32(-325, 5, false, success), 0.0F); // Composite diff --git a/test/test_compute_float64.cpp b/test/test_compute_float64.cpp index 945276281..e9cc2d051 100644 --- a/test/test_compute_float64.cpp +++ b/test/test_compute_float64.cpp @@ -4,10 +4,9 @@ #include #include -#include -#include +#include +#include #include -#include using boost::charconv::detail::compute_float64; @@ -21,7 +20,7 @@ inline void simple_test() BOOST_TEST_EQ(compute_float64(308, 1, false, success), 1e308); // out of range - BOOST_TEST_EQ(compute_float64(310, 5, false, success), HUGE_VAL); + BOOST_TEST_EQ(compute_float64(310, 5, false, success), std::numeric_limits::infinity()); BOOST_TEST_EQ(compute_float64(-325, 5, false, success), 0); // Composite diff --git a/test/test_compute_float80.cpp b/test/test_compute_float80.cpp index a800f9572..85031cea6 100644 --- a/test/test_compute_float80.cpp +++ b/test/test_compute_float80.cpp @@ -2,16 +2,16 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt +#include #include #include #include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include // MSVC uses long double = double // Darwin sometimes uses double-double instead of long double diff --git a/test/test_float128.cpp b/test/test_float128.cpp index 823666c7c..4288cadb3 100644 --- a/test/test_float128.cpp +++ b/test/test_float128.cpp @@ -2,15 +2,25 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#include + +#include "../src/float128_impl.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include #if defined(BOOST_CHARCONV_HAS_QUADMATH) && defined(BOOST_HAS_INT128) -#include +#include #include #ifdef BOOST_CHARCONV_HAS_STDFLOAT128 -#include +#include std::ostream& operator<<( std::ostream& os, __float128 v ) { @@ -83,17 +93,6 @@ std::ostream& operator<<( std::ostream& os, boost::int128_type v ) } -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "../src/float128_impl.hpp" - constexpr int N = 1024; static boost::detail::splitmix64 rng; diff --git a/test/test_num_digits.cpp b/test/test_num_digits.cpp index fde6d28d5..79996c3dc 100644 --- a/test/test_num_digits.cpp +++ b/test/test_num_digits.cpp @@ -2,12 +2,12 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt +#include #include #include #include -#include -#include -#include +#include +#include #if defined(__GNUC__) && (__GNUC__ < 7) # pragma GCC diagnostic push diff --git a/test/test_parser.cpp b/test/test_parser.cpp index c1fef8468..f35aa92ce 100644 --- a/test/test_parser.cpp +++ b/test/test_parser.cpp @@ -2,15 +2,15 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#include +#include #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include void test_integer() { diff --git a/test/to_chars.cpp b/test/to_chars.cpp index 91a605f15..243f74033 100644 --- a/test/to_chars.cpp +++ b/test/to_chars.cpp @@ -5,12 +5,16 @@ #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // UINT64_C +#include // INT_MIN #ifdef BOOST_CHARCONV_HAS_INT128 template diff --git a/test/to_chars_float.cpp b/test/to_chars_float.cpp index 301c0df7f..9c2de8a38 100644 --- a/test/to_chars_float.cpp +++ b/test/to_chars_float.cpp @@ -3,21 +3,21 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#include #include +#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // These numbers diverge from what the formatting is using printf // See: https://godbolt.org/z/zd34KcWMW @@ -52,7 +52,7 @@ void integer_general_format() BOOST_TEST(r1.ec == std::errc()); BOOST_TEST_CSTR_EQ(buffer1, "1217.2772861138403"); T return_v1; - auto r1_return = boost::charconv::from_chars(buffer1, buffer1 + strlen(buffer1), return_v1); + auto r1_return = boost::charconv::from_chars(buffer1, buffer1 + std::strlen(buffer1), return_v1); BOOST_TEST(r1_return.ec == std::errc()); BOOST_TEST_EQ(return_v1, v1); } diff --git a/test/to_chars_sprintf.cpp b/test/to_chars_sprintf.cpp index 3b1d73ab8..7cbc6dad4 100644 --- a/test/to_chars_sprintf.cpp +++ b/test/to_chars_sprintf.cpp @@ -6,15 +6,15 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include int const N = 1024; diff --git a/tools/setup_boost_with_modules.py b/tools/setup_boost_with_modules.py new file mode 100644 index 000000000..e0842e953 --- /dev/null +++ b/tools/setup_boost_with_modules.py @@ -0,0 +1,29 @@ +#!/usr/bin/python3 + +# This is a temporary workaround to make CIs use the +# "Boost with C++20 modules" proposal, instead of the regular develop branch +# Call it instead of depinst + +from subprocess import run +import os + +def main(): + + submodules = [ + ('tools/cmake', 'https://github.com/anarthal/boost-cmake'), + ('libs/assert', 'https://github.com/anarthal/assert'), + ('libs/core', 'https://github.com/anarthal/core'), + ('libs/config', 'https://github.com/anarthal/config'), + ('libs/throw_exception','https://github.com/anarthal/throw_exception'), + ] + + for submodule, url in submodules: + os.chdir(submodule) + run(['git', 'remote', 'add', 'modules', url]) + run(['git', 'fetch', '--depth', '1', 'modules', 'feature/cxx20-modules']) + run(['git', 'checkout', 'modules/feature/cxx20-modules']) + os.chdir('../..') + + +if __name__ == '__main__': + main()