Compare commits

...

21 Commits

Author SHA1 Message Date
Fedor Osetrov 35d8af6ce2 fix ci: turn on import std tests, fix libc++ build (#96)
This PR:
- enables tests with `import std` usage in CI
- add all tests to build with cmake_subdir_test (because there was only a subset of tests supported)
- fixes tests build with `libc++`
- disables some tests with wchar_t with 'libc++'
2026-04-24 18:03:48 +03:00
Andrey Semashev 4b0d10a1f3 Remove dependencies on Boost.StaticAssert. (#95)
Boost.StaticAssert has been merged into Boost.Config, so remove
the dependency.
2026-01-26 17:58:24 +03:00
Antony Polukhin 184f7e43f0 Update copyright years 2026-01-04 11:10:09 +03:00
dependabot[bot] 4cc0fa77b4 Bump actions/checkout from 2 to 6 (#94)
Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 6.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2...v6)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-26 22:05:36 +03:00
Antony Polukhin 4d1e18cf4c Add dependabot 2025-12-24 20:21:04 +03:00
Antony Polukhin d57771ecf1 CI fixes (#93) 2025-12-23 20:25:26 +03:00
Antony Polukhin 1b804c7a31 Implement initial version of C++20 module boost.lexical_cast (#84) 2025-12-11 22:17:21 +03:00
Antony Polukhin 275844e651 Fix regression in unsigned short to wstring casting without wchar_t b… (#92)
…uiltin type

Fixes: https://github.com/boostorg/lexical_cast/issues/89
2025-10-16 09:15:33 +03:00
Antony Polukhin 1084d98719 More tests and fixes for floating-point special value conversions to integers and bool (#91)
Fixes: https://github.com/boostorg/lexical_cast/issues/81
2025-10-11 17:36:58 +03:00
Antony Polukhin 7f60da84c3 Run all the tests in CMake, add CMake runs into CI. Drop dependency on Boost.TypeTraits (#90) 2025-10-07 20:25:13 +03:00
Romain Geissler @ Amadeus 8fc8a19931 Reduce dependency on Boost.TypeTraits now that C++ >= 11 is required. (#87)
This allows to workaround the following error when using clang >= 21 on the following code:

```
#include <string>
#include <iostream>
#include "boost/lexical_cast.hpp"

enum SomeEnum
{
    OneValue
};

int main()
{
    std::cout << boost::lexical_cast<std::string>(SomeEnum::OneValue) << std::endl;
}
```

Results in:

```
/app/boost/include/boost/type_traits/is_signed.hpp:37:25: error: in-class initializer for static data member is not a constant expression
   37 |    static const no_cv_t minus_one = (static_cast<no_cv_t>(-1));

... (snapped)

/app/boost/include/boost/type_traits/is_signed.hpp:37:38: note: integer value -1 is outside the valid range of values [0, 1] for the enumeration type 'SomeEnum'
   37 |    static const no_cv_t minus_one = (static_cast<no_cv_t>(-1));
```
2025-10-05 12:14:47 +03:00
Antony Polukhin 4862e296d0 CI fixes (#88) 2025-09-08 09:02:39 +03:00
bmagistro a16040a73c Switch from implicit to explicit type conversion (#85)
Signed-off-by: Ben Magistro <koncept1@gmail.com>
2025-08-22 10:33:58 +03:00
ivanpanch 46ee1c3528 Fix mistakes (#86) 2025-08-22 10:32:30 +03:00
Antony Polukhin 5326b49475 Do not permit implicit conversions to floating point types in decltype(shl_real_type(x, buffer)) substitution (fixes #82) (#83) 2025-05-13 19:32:21 +03:00
Antony Polukhin 1c89e3a56c Update copyright years 2025-01-05 19:41:20 +03:00
René Ferdinand Rivera Morell 71a184d20f Add support for modular build structure. (#78)
This is part of the effort to make the Boost libraries "modular" for build and consumption. See https://lists.boost.org/Archives/boost/2024/01/255704.php and https://github.com/grafikrobot/boost-b2-modular/blob/b2-modular/README.adoc for more information.

This PR depends on the following other PRs being merged to both develop and master branches of the respective repos:

- https://github.com/boostorg/boost/pull/854
2024-08-25 09:57:23 +03:00
Antony Polukhin 7f121f8ce3 Drop Boost.Integer dependency (#79) 2024-08-14 21:15:33 +03:00
Antony Polukhin ff2f0496b0 Fixed conversion of std::basic_string_view and boost::basic_string_view containing one or more \0 characters.
Issue was introduced in 1.85.0
2024-07-07 20:08:13 +03:00
Antony Polukhin 7861401ac4 Always use the boost::core::*printf functions and rely on Boost.Core workarounds (#77) 2024-04-13 09:55:14 +03:00
René Ferdinand Rivera Morell 92e55e842e Add macOS testing. (#75)
Fixes https://github.com/boostorg/lexical_cast/issues/76
---------

Co-authored-by: Antony Polukhin <antoshkka@gmail.com>
2024-04-12 19:12:54 +03:00
63 changed files with 1186 additions and 399 deletions
+11
View File
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
version: 2
updates:
- package-ecosystem: "github-actions" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
+110 -19
View File
@@ -17,6 +17,10 @@ jobs:
fail-fast: false
matrix:
include:
- toolset: gcc-14 # Do not remove! It is the only toolset that tests CMake tests down below
cxxstd: "03,11,14,17,20"
os: ubuntu-24.04
compiler: g++-14
- toolset: gcc-12
cxxstd: "03,11,14,17,2a"
os: ubuntu-22.04
@@ -24,24 +28,26 @@ jobs:
linkflags: "linkflags=--coverage -lasan -lubsan"
gcov_tool: "gcov-12"
launcher: "testing.launcher=LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libasan.so.8"
- toolset: gcc-9
- toolset: gcc-11
cxxstd: "03,11,14,17,2a"
os: ubuntu-22.04
- toolset: clang
compiler: clang++-10
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
cxxflags: "cxxflags=-fsanitize=address,undefined,integer -fno-sanitize-recover=undefined,integer"
linkflags: "linkflags=-fsanitize=address,undefined,integer"
- toolset: clang
compiler: clang++-14
cxxstd: "03,11,14,17,2a"
os: ubuntu-22.04
- toolset: clang
cxxstd: "11,14,17,20"
os: macos-latest
- toolset: clang-19
cxxstd: "20,23"
os: ubuntu-24.04
compiler: clang++-19
install: clang-19 llvm-19 libclang-rt-19-dev libc++-19-dev libc++abi-19-dev clang-tools-19
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v6
- name: Install packages
if: matrix.install
@@ -69,8 +75,52 @@ jobs:
cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY
python tools/boostdep/depinst/depinst.py --include benchmark --include example --include examples --include tools --git_args "--depth 10 --jobs 3" $LIBRARY
./bootstrap.sh
./b2 -d0 headers
./b2 -j4 variant=debug tools/inspect/build
./b2 -j4 variant=debug tools/inspect
- name: Run modules tests without 'import std;'
if: ${{matrix.toolset == 'clang-19'}}
run: |
cd ../boost-root/libs/lexical_cast
cmake -S test/cmake_subdir_test -B build_module \
-GNinja \
-DBUILD_TESTING=1 \
-DBOOST_USE_MODULES=1 \
-DCMAKE_CXX_COMPILER=clang++-19 \
-DCMAKE_C_COMPILER=clang-19
cmake --build build_module
ctest --test-dir build_module -V --no-tests=error
rm -rf build_module
- name: Run modules tests
if: ${{matrix.toolset == 'clang-19'}}
run: |
cd ../boost-root/libs/lexical_cast
cmake -S test/cmake_subdir_test -B build_module \
-GNinja \
-DBUILD_TESTING=1 \
-DBOOST_USE_MODULES=1 \
-DCMAKE_CXX_COMPILER=clang++-19 \
-DCMAKE_C_COMPILER=clang-19 \
-DCMAKE_CXX_FLAGS=-stdlib=libc++ \
-DCMAKE_CXX_STANDARD=23 \
-DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD=0e5b6991-d74f-4b3d-a41c-cf096e0b2508 \
-DCMAKE_CXX_MODULE_STD=ON
cmake --build build_module
ctest --test-dir build_module -V --no-tests=error
rm -rf build_module
- name: Run CMake tests
if: ${{matrix.toolset == 'gcc-14' || matrix.toolset == 'clang-19'}}
run: |
cd ../boost-root/
cmake -S . -B __build \
-DBUILD_TESTING=1 \
-DBOOST_INCLUDE_LIBRARIES=lexical_cast \
-DCMAKE_CXX_COMPILER=${{matrix.compiler}} \
-DCMAKE_C_COMPILER=${{matrix.toolset}}
cmake --build __build --target tests
ctest --test-dir __build --output-on-failure --no-tests=error
rm -rf __build
- name: Run tests
run: |
@@ -111,23 +161,23 @@ jobs:
fail-fast: false
matrix:
include:
- toolset: msvc
cxxstd: "14,17,latest"
- toolset: msvc-14.3
cxxstd: "14,17,20,latest"
addrmd: 32,64
os: windows-2022
- toolset: msvc-14.2
- toolset: msvc
cxxstd: "14,17,latest"
addrmd: 32,64
os: windows-2019
addrmd: 64
os: windows-2025
- toolset: gcc
cxxstd: "03,11,14,17,2a"
addrmd: 64
os: windows-2019
os: windows-2022
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v6
- name: Setup Boost
shell: cmd
@@ -146,10 +196,51 @@ jobs:
git clone -b %BOOST_BRANCH% --depth 10 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
git submodule update --init tools/boostdep libs/test
python tools/boostdep/depinst/depinst.py --include benchmark --include example --include examples --include tools --git_args "--jobs 3" %LIBRARY%
cmd /c bootstrap
b2 -d0 headers
- name: Run CMake tests
if: ${{matrix.toolset == 'msvc-14.3'}}
shell: cmd
run: |
choco install --no-progress ninja
call "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Auxiliary/Build/vcvarsall.bat" x64
cd ../boost-root/
mkdir __build
cd __build
cmake -DBUILD_TESTING=1 -DBOOST_INCLUDE_LIBRARIES=lexical_cast -G Ninja ..
cmake --build . --target tests --config Debug
ctest --output-on-failure --no-tests=error -C Debug
- name: Run modules tests
if: false
#if: ${{matrix.toolset == 'msvc-14.3'}}
shell: cmd
run: |
choco install --no-progress ninja
call "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Auxiliary/Build/vcvarsall.bat" x64
cd ../boost-root/libs/lexical_cast
rm -rf build_module
mkdir build_module
cd build_module
cmake -DBOOST_USE_MODULES=1 -DCMAKE_CXX_STANDARD=23 -DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD=0e5b6991-d74f-4b3d-a41c-cf096e0b2508 -G Ninja ../test/cmake_subdir_test/
cmake --build .
ctest --no-tests=error -V
- name: Run modules tests without 'import std;'
if: ${{matrix.toolset == 'msvc-14.3'}}
shell: cmd
run: |
choco install --no-progress ninja
call "C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Auxiliary/Build/vcvarsall.bat" x64
cd ../boost-root/libs/lexical_cast
rm -rf build_module
mkdir build_module
cd build_module
cmake -DBOOST_USE_MODULES=1 -DCMAKE_CXX_STANDARD=20 -G Ninja ../test/cmake_subdir_test/
cmake --build .
ctest --no-tests=error -V
- name: Run tests
shell: cmd
+25 -9
View File
@@ -3,28 +3,44 @@
# 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)
cmake_minimum_required(VERSION 3.5...4.0)
project(boost_lexical_cast VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)
add_library(boost_lexical_cast INTERFACE)
add_library(Boost::lexical_cast ALIAS boost_lexical_cast)
target_include_directories(boost_lexical_cast INTERFACE include)
if (BOOST_USE_MODULES)
add_library(boost_lexical_cast)
target_sources(boost_lexical_cast PUBLIC
FILE_SET modules_public TYPE CXX_MODULES FILES
${CMAKE_CURRENT_LIST_DIR}/modules/boost_lexical_cast.cppm
)
target_compile_features(boost_lexical_cast PUBLIC cxx_std_20)
target_compile_definitions(boost_lexical_cast PUBLIC BOOST_USE_MODULES)
if (CMAKE_CXX_COMPILER_IMPORT_STD)
target_compile_definitions(boost_lexical_cast PRIVATE BOOST_LEXICAL_CAST_USE_STD_MODULE)
message(STATUS "Using `import std;`")
else()
message(STATUS "`import std;` is not available")
endif()
set(__scope PUBLIC)
else()
add_library(boost_lexical_cast INTERFACE)
set(__scope INTERFACE)
endif()
target_include_directories(boost_lexical_cast ${__scope} include)
target_link_libraries(boost_lexical_cast
INTERFACE
${__scope}
Boost::config
Boost::container
Boost::core
Boost::integer
Boost::throw_exception
Boost::type_traits
)
if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")
add_library(Boost::lexical_cast ALIAS boost_lexical_cast)
if(BUILD_TESTING)
add_subdirectory(test)
endif()
+26
View File
@@ -0,0 +1,26 @@
# Copyright René Ferdinand Rivera Morell 2023-2024
# 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)
require-b2 5.2 ;
constant boost_dependencies :
/boost/config//boost_config
/boost/container//boost_container
/boost/core//boost_core
/boost/throw_exception//boost_throw_exception ;
project /boost/lexical_cast
: common-requirements
<include>include
;
explicit
[ alias boost_lexical_cast : : : : <library>$(boost_dependencies) ]
[ alias all : boost_lexical_cast test ]
;
call-if : boost-library lexical_cast
;
+1 -1
View File
@@ -1,4 +1,4 @@
# Copyright Antony Polukhin, 2011-2024.
# Copyright Antony Polukhin, 2011-2026.
#
# Use, modification, and distribution are
# subject to the Boost Software License, Version 1.0. (See accompanying
+47 -5
View File
@@ -3,7 +3,7 @@
[version 1.0]
[copyright 2000-2005 Kevlin Henney]
[copyright 2006-2010 Alexander Nasonov]
[copyright 2011-2024 Antony Polukhin]
[copyright 2011-2026 Antony Polukhin]
[category String and text processing]
[category Miscellaneous]
[license
@@ -203,7 +203,7 @@ Read a good C++ book, study `std::sentry` and [@boost:libs/io/doc/ios_state.html
[pre
]
* [*Question:] Why `std::cout << boost::lexical_cast<unsigned int>("-1");` does not throw, but outputs 4294967295?
* [*Question:] Why does `std::cout << boost::lexical_cast<unsigned int>("-1");` not throw, but outputs 4294967295?
* [*Answer:] `boost::lexical_cast` has the behavior of `std::stringstream`, which uses `num_get` functions of
`std::locale` to convert numbers. If we look at the Programming languages — C++, we'll see, that `num_get` uses
the rules of `scanf` for conversions. And in the C99 standard for unsigned input value minus sign is optional, so
@@ -212,7 +212,7 @@ if a negative number is read, no errors will arise and the result will be the tw
[pre
]
* [*Question:] Why `boost::lexical_cast<int>(L'A');` outputs 65 and `boost::lexical_cast<wchar_t>(L"65");` does not throw?
* [*Question:] Why does `boost::lexical_cast<int>(L'A');` output 65 and `boost::lexical_cast<wchar_t>(L"65");` not throw?
* [*Answer:] If you are using an old version of Visual Studio or compile code with /Zc:wchar_t- flag,
`boost::lexical_cast` sees single `wchar_t` character as `unsigned short`. It is not a `boost::lexical_cast` mistake, but a
limitation of compiler options that you use.
@@ -220,7 +220,7 @@ limitation of compiler options that you use.
[pre
]
* [*Question:] Why `boost::lexical_cast<double>("-1.#IND");` throws `boost::bad_lexical_cast`?
* [*Question:] Why does `boost::lexical_cast<double>("-1.#IND");` throw `boost::bad_lexical_cast`?
* [*Answer:] `"-1.#IND"` is a compiler extension, that violates standard. You shall input `"-nan"`, `"nan"`, `"inf"`
, `"-inf"` (case insensitive) strings to get NaN and Inf values. `boost::lexical_cast<string>` outputs `"-nan"`, `"nan"`,
`"inf"`, `"-inf"` strings, when has NaN or Inf input values.
@@ -229,12 +229,54 @@ limitation of compiler options that you use.
]
* [*Question:] What is the fastest way to convert a non zero terminated string or a substring using `boost::lexical_cast`?
* [*Answer:] Use `boost::iterator_range` for conversion or `lexical_cast` overload with two parameters. For example, if you whant to convert to `int` two characters from a string `str`, you shall write `lexical_cast<int>(make_iterator_range(str.data(), str.data() + 2));` or `lexical_cast<int>(str.data(), 2);`.
* [*Answer:] Use `boost::iterator_range` for conversion or `lexical_cast` overload with two parameters. For example, if you want to convert to `int` two characters from a string `str`, you shall write `lexical_cast<int>(make_iterator_range(str.data(), str.data() + 2));` or `lexical_cast<int>(str.data(), 2);`.
[endsect]
[section C++20 module]
[caution C++20 module support is on early stage, targets, flags and behavior may change in the future]
If using modern CMake define CMake option `-DBOOST_USE_MODULES=1` to build a C++20 module and
make the `Boost::lexical_cast` CMake target provide it. After that an explicit usage of C++20 module `boost.lexical_cast` is allowed:
[import ../modules/usage_sample.cpp]
[lexical_cast_module_example]
The `Boost::lexical_cast` CMake target gives an ability to mix includes and imports of the library in different translation units. Moreover,
if `BOOST_USE_MODULES` macro is defined then all the `boost/lexical_cast...` includes implicitly do `import boost.lexical_cast;` to give all the
benefits of modules without changing the existing code.
[note For better compile times make sure that `import std;` is available when building the `boost.lexical_cast` module (in CMake logs there should be
a 'Using `import std;`' message). ]
If not using CMake, then the module could be build manually from the `modules/boost_lexical_cast.cppm` file.
For manual module build the following commands could be used for clang compiler:
```
cd lexical_cast/modules
clang++ -I ../include -std=c++20 --precompile -x c++-module boost_lexical_cast.cppm
```
After that, the module could be used in the following way:
```
clang++ -std=c++20 -fmodule-file=boost_lexical_cast.pcm boost_lexical_cast.pcm usage_sample.cpp
```
[endsect]
[section Changes]
* [*boost 1.91.0 :]
* Added C++20 modules support.
* [*boost 1.86.0 :]
* Fixed conversion of `std::basic_string_view` and `boost::basic_string_view`
containing one or more `\0` characters. Issue was introduced in 1.85.0.
* [*boost 1.85.0 :]
* Significant rewrite of the internal logic to separate optimized and C++ Standard Library IO-based streams:
+3 -2
View File
@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2013-2024.
// Copyright Antony Polukhin, 2013-2026.
// Distributed under the Boost Software License, Version 1.0.
// (See the accompanying file LICENSE_1_0.txt
@@ -7,9 +7,10 @@
//[lexical_cast_args_example
//`The following example treats command line arguments as a sequence of numeric data
#include <boost/lexical_cast.hpp>
#include <vector>
#include <boost/lexical_cast.hpp>
int main(int /*argc*/, char * argv[])
{
using boost::lexical_cast;
+8 -6
View File
@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2013-2024.
// Copyright Antony Polukhin, 2013-2026.
// Distributed under the Boost Software License, Version 1.0.
// (See the accompanying file LICENSE_1_0.txt
@@ -14,12 +14,18 @@
In this example we'll make a `stringize` method that accepts a sequence, converts
each element of the sequence into string and appends that string to the result.
Example is based on the example from the [@http://www.packtpub.com/boost-cplusplus-application-development-cookbook/book Boost C++ Application Development Cookbook]
Example is based on the example from the Boost C++ Application Development Cookbook
by Antony Polukhin, ISBN 9781849514880. Russian translation: [@https://dmkpress.com/catalog/computer/programming/c/978-5-97060-868-5/ ISBN: 9785970608685].
Step 1: Making a functor that converts any type to a string and remembers result:
*/
#include <string>
#include <boost/fusion/include/for_each.hpp>
#include <boost/fusion/adapted/std_tuple.hpp>
#include <boost/fusion/adapted/std_pair.hpp>
#include <boost/lexical_cast.hpp>
struct stringize_functor {
@@ -38,7 +44,6 @@ public:
};
//` Step 2: Applying `stringize_functor` to each element in sequence:
#include <boost/fusion/include/for_each.hpp>
template <class Sequence>
std::string stringize(const Sequence& seq) {
std::string result;
@@ -47,9 +52,6 @@ std::string stringize(const Sequence& seq) {
}
//` Step 3: Using the `stringize` with different types:
#include <boost/fusion/adapted/std_tuple.hpp>
#include <boost/fusion/adapted/std_pair.hpp>
int main() {
std::tuple<char, int, char, int> decim('-', 10, 'e', 5);
if (stringize(decim) != "-10e5") {
+4 -3
View File
@@ -1,15 +1,16 @@
// Copyright Antony Polukhin, 2013-2024.
// Copyright Antony Polukhin, 2013-2026.
// Distributed under the Boost Software License, Version 1.0.
// (See the accompanying file LICENSE_1_0.txt
// or a copy at <http://www.boost.org/LICENSE_1_0.txt>.)
#include <boost/lexical_cast.hpp>
#include <array>
#include <string>
#include <string.h>
#include <cstdio>
#include <boost/lexical_cast.hpp>
#ifdef BOOST_MSVC
# pragma warning(disable: 4996) // `strerror` is not safe
#endif
+6 -2
View File
@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2013-2024.
// Copyright Antony Polukhin, 2013-2026.
// Distributed under the Boost Software License, Version 1.0.
// (See the accompanying file LICENSE_1_0.txt
@@ -10,9 +10,13 @@
In this example we'll make a `to_long_double` method that converts value of the Boost.Variant to `long double`.
*/
#include <boost/lexical_cast.hpp>
#ifdef BOOST_USE_MODULES
#include <compare>
#endif
#include <boost/variant.hpp>
#include <boost/lexical_cast.hpp>
struct to_long_double_functor: boost::static_visitor<long double> {
template <class T>
long double operator()(const T& v) const {
+1 -2
View File
@@ -19,7 +19,6 @@
#endif
#include <boost/config.hpp>
#include <boost/integer.hpp>
#include <streambuf>
@@ -73,7 +72,7 @@ template<class charT, class BufferT>
typename basic_pointerbuf<charT, BufferT>::pos_type
basic_pointerbuf<charT, BufferT>::seekoff(off_type off, ::std::ios_base::seekdir way, ::std::ios_base::openmode which)
{
typedef typename boost::int_t<sizeof(way) * CHAR_BIT>::least cast_type;
typedef ::std::ios_base::seekdir cast_type;
if(which & ::std::ios_base::out)
return pos_type(off_type(-1));
+11 -1
View File
@@ -1,6 +1,6 @@
// Copyright Kevlin Henney, 2000-2005.
// Copyright Alexander Nasonov, 2006-2010.
// Copyright Antony Polukhin, 2011-2024.
// Copyright Antony Polukhin, 2011-2026.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -18,10 +18,16 @@
#ifndef BOOST_LEXICAL_CAST_INCLUDED
#define BOOST_LEXICAL_CAST_INCLUDED
#include <boost/lexical_cast/detail/config.hpp>
#if !defined(BOOST_USE_MODULES) || defined(BOOST_LEXICAL_CAST_INTERFACE_UNIT)
#ifndef BOOST_LEXICAL_CAST_INTERFACE_UNIT
#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif
#endif
#if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_WSTRING)
#define BOOST_LCAST_NO_WCHAR_T
@@ -34,6 +40,7 @@
namespace boost
{
BOOST_LEXICAL_CAST_BEGIN_MODULE_EXPORT
template <typename Target, typename Source>
inline Target lexical_cast(const Source &arg)
{
@@ -94,9 +101,12 @@ namespace boost
);
}
BOOST_LEXICAL_CAST_END_MODULE_EXPORT
} // namespace boost
#undef BOOST_LCAST_NO_WCHAR_T
#endif // #if !defined(BOOST_USE_MODULES) || defined(BOOST_LEXICAL_CAST_INTERFACE_UNIT)
#endif // BOOST_LEXICAL_CAST_INCLUDED
@@ -1,6 +1,6 @@
// Copyright Kevlin Henney, 2000-2005.
// Copyright Alexander Nasonov, 2006-2010.
// Copyright Antony Polukhin, 2011-2024.
// Copyright Antony Polukhin, 2011-2026.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -18,6 +18,11 @@
#ifndef BOOST_LEXICAL_CAST_BAD_LEXICAL_CAST_HPP
#define BOOST_LEXICAL_CAST_BAD_LEXICAL_CAST_HPP
#include <boost/lexical_cast/detail/config.hpp>
#if !defined(BOOST_USE_MODULES) || defined(BOOST_LEXICAL_CAST_INTERFACE_UNIT)
#ifndef BOOST_LEXICAL_CAST_INTERFACE_UNIT
#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
@@ -26,9 +31,11 @@
#include <exception>
#include <typeinfo>
#include <boost/throw_exception.hpp>
#endif
namespace boost
{
BOOST_LEXICAL_CAST_BEGIN_MODULE_EXPORT
// exception used to indicate runtime lexical_cast failure
class BOOST_SYMBOL_VISIBLE bad_lexical_cast :
// workaround MSVC bug with std::bad_cast when _HAS_EXCEPTIONS == 0
@@ -80,6 +87,7 @@ namespace boost
const type_info_t *target;
#endif
};
BOOST_LEXICAL_CAST_END_MODULE_EXPORT
namespace conversion { namespace detail {
#ifdef BOOST_NO_TYPEID
@@ -97,4 +105,6 @@ namespace boost
} // namespace boost
#endif // #if !defined(BOOST_USE_MODULES) || defined(BOOST_LEXICAL_CAST_INTERFACE_UNIT)
#endif // BOOST_LEXICAL_CAST_BAD_LEXICAL_CAST_HPP
@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2011-2024.
// Copyright Antony Polukhin, 2011-2026.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -7,12 +7,18 @@
#ifndef BOOST_LEXICAL_CAST_DETAIL_BUFFER_VIEW_HPP
#define BOOST_LEXICAL_CAST_DETAIL_BUFFER_VIEW_HPP
#include <boost/lexical_cast/detail/config.hpp>
#if !defined(BOOST_USE_MODULES) || defined(BOOST_LEXICAL_CAST_INTERFACE_UNIT)
#ifndef BOOST_LEXICAL_CAST_INTERFACE_UNIT
#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif
#include <iosfwd>
#endif
namespace boost { namespace conversion { namespace detail {
@@ -55,5 +61,7 @@ namespace boost { namespace conversion { namespace detail {
}}} // namespace boost::conversion::detail
#endif // #if !defined(BOOST_USE_MODULES) || defined(BOOST_LEXICAL_CAST_INTERFACE_UNIT)
#endif // BOOST_LEXICAL_CAST_DETAIL_BUFFER_VIEW_HPP
@@ -0,0 +1,22 @@
// Copyright Antony Polukhin, 2021-2026.
//
// 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)
#ifndef BOOST_LEXICAL_CAST_DETAIL_CONFIG_HPP
#define BOOST_LEXICAL_CAST_DETAIL_CONFIG_HPP
#ifdef BOOST_LEXICAL_CAST_INTERFACE_UNIT
# define BOOST_LEXICAL_CAST_BEGIN_MODULE_EXPORT export {
# define BOOST_LEXICAL_CAST_END_MODULE_EXPORT }
#else
# define BOOST_LEXICAL_CAST_BEGIN_MODULE_EXPORT
# define BOOST_LEXICAL_CAST_END_MODULE_EXPORT
#endif
#if defined(BOOST_USE_MODULES) && !defined(BOOST_LEXICAL_CAST_INTERFACE_UNIT)
import boost.lexical_cast;
#endif
#endif // #ifndef BOOST_LEXICAL_CAST_DETAIL_CONFIG_HPP
@@ -1,6 +1,6 @@
// Copyright Kevlin Henney, 2000-2005.
// Copyright Alexander Nasonov, 2006-2010.
// Copyright Antony Polukhin, 2011-2024.
// Copyright Antony Polukhin, 2011-2026.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -18,6 +18,11 @@
#ifndef BOOST_LEXICAL_CAST_DETAIL_CONVERTER_LEXICAL_HPP
#define BOOST_LEXICAL_CAST_DETAIL_CONVERTER_LEXICAL_HPP
#include <boost/lexical_cast/detail/config.hpp>
#if !defined(BOOST_USE_MODULES) || defined(BOOST_LEXICAL_CAST_INTERFACE_UNIT)
#ifndef BOOST_LEXICAL_CAST_INTERFACE_UNIT
#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
@@ -27,18 +32,11 @@
#define BOOST_LCAST_NO_WCHAR_T
#endif
#include <array>
#include <cstddef>
#include <string>
#include <type_traits>
#include <boost/limits.hpp>
#include <boost/type_traits/integral_constant.hpp>
#include <boost/type_traits/type_identity.hpp>
#include <boost/type_traits/conditional.hpp>
#include <boost/type_traits/is_integral.hpp>
#include <boost/type_traits/is_float.hpp>
#include <boost/detail/lcast_precision.hpp>
#include <boost/lexical_cast/detail/widest_char.hpp>
#include <boost/lexical_cast/detail/is_character.hpp>
#include <array>
@@ -46,9 +44,14 @@
#include <string_view>
#endif
#include <boost/lexical_cast/detail/buffer_view.hpp>
#include <boost/container/container_fwd.hpp>
#endif // #ifndef BOOST_LEXICAL_CAST_INTERFACE_UNIT
#include <boost/lexical_cast/detail/lcast_precision.hpp>
#include <boost/lexical_cast/detail/widest_char.hpp>
#include <boost/lexical_cast/detail/is_character.hpp>
#include <boost/lexical_cast/detail/buffer_view.hpp>
#include <boost/lexical_cast/detail/converter_lexical_streams.hpp>
namespace boost {
@@ -68,19 +71,19 @@ namespace boost {
template < class Char >
struct normalize_single_byte_char
{
typedef Char type;
using type = Char;
};
template <>
struct normalize_single_byte_char< signed char >
{
typedef char type;
using type = char;
};
template <>
struct normalize_single_byte_char< unsigned char >
{
typedef char type;
using type = char;
};
}
@@ -97,21 +100,21 @@ namespace boost {
// Returns one of char, wchar_t, char16_t, char32_t or deduce_character_type_later<T> types
// Executed on Stage 1 (See deduce_source_char<T> and deduce_target_char<T>)
template < typename Type >
struct stream_char_common: public boost::conditional<
struct stream_char_common: public std::conditional<
boost::detail::is_character< Type >::value,
Type,
boost::detail::deduce_character_type_later< Type >
> {};
template < typename Char >
struct stream_char_common< Char* >: public boost::conditional<
struct stream_char_common< Char* >: public std::conditional<
boost::detail::is_character< Char >::value,
Char,
boost::detail::deduce_character_type_later< Char* >
> {};
template < typename Char >
struct stream_char_common< const Char* >: public boost::conditional<
struct stream_char_common< const Char* >: public std::conditional<
boost::detail::is_character< Char >::value,
Char,
boost::detail::deduce_character_type_later< const Char* >
@@ -120,18 +123,18 @@ namespace boost {
template < typename Char >
struct stream_char_common< boost::conversion::detail::buffer_view< Char > >
{
typedef Char type;
using type = Char;
};
template < typename Char >
struct stream_char_common< boost::iterator_range< Char* > >: public boost::conditional<
struct stream_char_common< boost::iterator_range< Char* > >: public std::conditional<
boost::detail::is_character< Char >::value,
Char,
boost::detail::deduce_character_type_later< boost::iterator_range< Char* > >
> {};
template < typename Char >
struct stream_char_common< boost::iterator_range< const Char* > >: public boost::conditional<
struct stream_char_common< boost::iterator_range< const Char* > >: public std::conditional<
boost::detail::is_character< Char >::value,
Char,
boost::detail::deduce_character_type_later< boost::iterator_range< const Char* > >
@@ -140,24 +143,24 @@ namespace boost {
template < class Char, class Traits, class Alloc >
struct stream_char_common< std::basic_string< Char, Traits, Alloc > >
{
typedef Char type;
using type = Char;
};
template < class Char, class Traits, class Alloc >
struct stream_char_common< boost::container::basic_string< Char, Traits, Alloc > >
{
typedef Char type;
using type = Char;
};
template < typename Char, std::size_t N >
struct stream_char_common< boost::array< Char, N > >: public boost::conditional<
struct stream_char_common< boost::array< Char, N > >: public std::conditional<
boost::detail::is_character< Char >::value,
Char,
boost::detail::deduce_character_type_later< boost::array< Char, N > >
> {};
template < typename Char, std::size_t N >
struct stream_char_common< boost::array< const Char, N > >: public boost::conditional<
struct stream_char_common< boost::array< const Char, N > >: public std::conditional<
boost::detail::is_character< Char >::value,
Char,
boost::detail::deduce_character_type_later< boost::array< const Char, N > >
@@ -165,14 +168,14 @@ namespace boost {
#ifndef BOOST_NO_CXX11_HDR_ARRAY
template < typename Char, std::size_t N >
struct stream_char_common< std::array<Char, N > >: public boost::conditional<
struct stream_char_common< std::array<Char, N > >: public std::conditional<
boost::detail::is_character< Char >::value,
Char,
boost::detail::deduce_character_type_later< std::array< Char, N > >
> {};
template < typename Char, std::size_t N >
struct stream_char_common< std::array< const Char, N > >: public boost::conditional<
struct stream_char_common< std::array< const Char, N > >: public std::conditional<
boost::detail::is_character< Char >::value,
Char,
boost::detail::deduce_character_type_later< std::array< const Char, N > >
@@ -183,25 +186,31 @@ namespace boost {
template < class Char, class Traits >
struct stream_char_common< std::basic_string_view< Char, Traits > >
{
typedef Char type;
using type = Char;
};
#endif
template < class Char, class Traits >
struct stream_char_common< boost::basic_string_view< Char, Traits > >
{
typedef Char type;
using type = Char;
};
#ifdef BOOST_HAS_INT128
template <> struct stream_char_common< boost::int128_type >: public boost::type_identity< char > {};
template <> struct stream_char_common< boost::uint128_type >: public boost::type_identity< char > {};
template <> struct stream_char_common< boost::int128_type >
{
using type = char;
};
template <> struct stream_char_common< boost::uint128_type >
{
using type = char;
};
#endif
#if !defined(BOOST_LCAST_NO_WCHAR_T) && defined(BOOST_NO_INTRINSIC_WCHAR_T)
template <>
struct stream_char_common< wchar_t >
{
typedef char type;
using type = char;
};
#endif
}
@@ -363,7 +372,7 @@ namespace boost {
// When is_specialized is false, the whole expression is 0.
template <class Source>
struct lcast_src_length<
Source, typename boost::enable_if<boost::is_integral<Source> >::type
Source, typename std::enable_if<boost::detail::lcast::is_integral<Source>::value >::type
>
{
BOOST_STATIC_CONSTANT(std::size_t, value =
@@ -385,7 +394,7 @@ namespace boost {
// sign + leading digit + decimal point + "e" + exponent sign == 5
template<class Source>
struct lcast_src_length<
Source, typename boost::enable_if<boost::is_float<Source> >::type
Source, typename std::enable_if<std::is_floating_point<Source>::value >::type
>
{
static_assert(
@@ -404,7 +413,7 @@ namespace boost {
template <class Source, class Target>
struct lexical_cast_stream_traits {
typedef typename boost::detail::array_to_pointer_decay<Source>::type src;
typedef typename boost::remove_cv<src>::type no_cv_src;
typedef typename std::remove_cv<src>::type no_cv_src;
typedef boost::detail::deduce_source_char<no_cv_src> deduce_src_char_metafunc;
typedef typename deduce_src_char_metafunc::type src_char_t;
@@ -415,13 +424,13 @@ namespace boost {
>::type char_type;
#if !defined(BOOST_NO_CXX11_CHAR16_T) && defined(BOOST_NO_CXX11_UNICODE_LITERALS)
static_assert(!boost::is_same<char16_t, src_char_t>::value
&& !boost::is_same<char16_t, target_char_t>::value,
static_assert(!std::is_same<char16_t, src_char_t>::value
&& !std::is_same<char16_t, target_char_t>::value,
"Your compiler does not have full support for char16_t" );
#endif
#if !defined(BOOST_NO_CXX11_CHAR32_T) && defined(BOOST_NO_CXX11_UNICODE_LITERALS)
static_assert(!boost::is_same<char32_t, src_char_t>::value
&& !boost::is_same<char32_t, target_char_t>::value,
static_assert(!std::is_same<char32_t, src_char_t>::value
&& !std::is_same<char32_t, target_char_t>::value,
"Your compiler does not have full support for char32_t" );
#endif
@@ -476,5 +485,7 @@ namespace boost {
#undef BOOST_LCAST_NO_WCHAR_T
#endif // #if !defined(BOOST_USE_MODULES) || defined(BOOST_LEXICAL_CAST_INTERFACE_UNIT)
#endif // BOOST_LEXICAL_CAST_DETAIL_CONVERTER_LEXICAL_HPP
@@ -1,6 +1,6 @@
// Copyright Kevlin Henney, 2000-2005.
// Copyright Alexander Nasonov, 2006-2010.
// Copyright Antony Polukhin, 2011-2024.
// Copyright Antony Polukhin, 2011-2026.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -18,12 +18,16 @@
#ifndef BOOST_LEXICAL_CAST_DETAIL_CONVERTER_LEXICAL_STREAMS_HPP
#define BOOST_LEXICAL_CAST_DETAIL_CONVERTER_LEXICAL_STREAMS_HPP
#include <boost/lexical_cast/detail/config.hpp>
#if !defined(BOOST_USE_MODULES) || defined(BOOST_LEXICAL_CAST_INTERFACE_UNIT)
#ifndef BOOST_LEXICAL_CAST_INTERFACE_UNIT
#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif
#if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_WSTRING)
#define BOOST_LCAST_NO_WCHAR_T
#endif
@@ -32,14 +36,10 @@
#include <string>
#include <cstring>
#include <cstdio>
#include <type_traits>
#include <boost/limits.hpp>
#include <boost/type_traits/conditional.hpp>
#include <boost/type_traits/is_enum.hpp>
#include <boost/type_traits/is_signed.hpp>
#include <boost/type_traits/is_unsigned.hpp>
#include <boost/type_traits/is_pointer.hpp>
#include <boost/detail/lcast_precision.hpp>
#include <boost/detail/workaround.hpp>
#include <boost/config/workaround.hpp>
#include <boost/core/snprintf.hpp>
#ifndef BOOST_NO_STD_LOCALE
@@ -61,26 +61,27 @@
#include <sstream>
#endif
#include <array>
#ifndef BOOST_NO_CWCHAR
# include <cwchar>
#endif
#include <istream>
#include <boost/container/container_fwd.hpp>
#ifndef BOOST_NO_CWCHAR
# include <cwchar>
#endif
#endif // #ifndef BOOST_LEXICAL_CAST_INTERFACE_UNIT
#include <boost/lexical_cast/detail/buffer_view.hpp>
#include <boost/lexical_cast/detail/lcast_char_constants.hpp>
#include <boost/lexical_cast/detail/lcast_unsigned_converters.hpp>
#include <boost/lexical_cast/detail/lcast_basic_unlockedbuf.hpp>
#include <boost/lexical_cast/detail/inf_nan.hpp>
#include <istream>
#include <array>
#include <boost/type_traits/make_unsigned.hpp>
#include <boost/type_traits/is_integral.hpp>
#include <boost/type_traits/is_float.hpp>
#include <boost/type_traits/is_const.hpp>
#include <boost/type_traits/is_reference.hpp>
#include <boost/container/container_fwd.hpp>
#include <boost/core/enable_if.hpp>
#ifndef BOOST_NO_CWCHAR
# include <cwchar>
#endif
#include <boost/lexical_cast/detail/lcast_precision.hpp>
#include <boost/lexical_cast/detail/type_traits.hpp>
// Forward declarations
namespace boost {
@@ -97,8 +98,8 @@ namespace boost { namespace detail { namespace lcast {
template <typename T>
struct exact {
static_assert(!boost::is_const<T>::value, "");
static_assert(!boost::is_reference<T>::value, "");
static_assert(!std::is_const<T>::value, "");
static_assert(!std::is_reference<T>::value, "");
const T& payload;
};
@@ -185,7 +186,7 @@ namespace boost { namespace detail { namespace lcast {
template <class T>
inline bool shl_signed(const T n) {
CharT* tmp_finish = buffer + CharacterBufferSize;
typedef typename boost::make_unsigned<T>::type utype;
typedef typename boost::detail::lcast::make_unsigned<T>::type utype;
CharT* tmp_start = lcast_put_unsigned<Traits, utype, CharT>(lcast_to_unsigned(n), tmp_finish).convert();
if (n < 0) {
--tmp_start;
@@ -197,69 +198,70 @@ namespace boost { namespace detail { namespace lcast {
return true;
}
bool shl_real_type(float val, char* begin) {
using namespace std;
const double val_as_double = val;
bool shl_real_type(lcast::exact<float> val, char* begin) {
const double val_as_double = static_cast<double>(val.payload);
finish = start +
boost::core::snprintf(begin, CharacterBufferSize,
"%.*g", static_cast<int>(boost::detail::lcast_get_precision<float>()), val_as_double);
"%.*g", static_cast<int>(boost::detail::lcast_precision<float>::value), val_as_double);
return finish > start;
}
bool shl_real_type(double val, char* begin) {
using namespace std;
bool shl_real_type(lcast::exact<double> val, char* begin) {
finish = start +
boost::core::snprintf(begin, CharacterBufferSize,
"%.*g", static_cast<int>(boost::detail::lcast_get_precision<double>()), val);
"%.*g", static_cast<int>(boost::detail::lcast_precision<double>::value), val.payload);
return finish > start;
}
#ifndef __MINGW32__
bool shl_real_type(long double val, char* begin) {
using namespace std;
bool shl_real_type(lcast::exact<long double> val, char* begin) {
finish = start +
boost::core::snprintf(begin, CharacterBufferSize,
"%.*Lg", static_cast<int>(boost::detail::lcast_get_precision<long double>()), val );
"%.*Lg", static_cast<int>(boost::detail::lcast_precision<long double>::value), val.payload );
return finish > start;
}
#else
bool shl_real_type(long double val, char* begin) {
return shl_real_type(static_cast<double>(val), begin);
bool shl_real_type(lcast::exact<long double> val, char* begin) {
return shl_real_type(lcast::exact<double>{static_cast<double>(val.payload)}, begin);
}
#endif
#if !defined(BOOST_LCAST_NO_WCHAR_T) && !defined(BOOST_NO_SWPRINTF) && !defined(__MINGW32__)
bool shl_real_type(float val, wchar_t* begin) {
using namespace std;
const double val_as_double = val;
finish = start + swprintf(begin, CharacterBufferSize,
L"%.*g",
static_cast<int>(boost::detail::lcast_get_precision<float >()),
val_as_double );
#if !defined(BOOST_LCAST_NO_WCHAR_T)
bool shl_real_type(lcast::exact<float> val, wchar_t* begin) {
const double val_as_double = static_cast<double>(val.payload);
finish = start + boost::core::swprintf(
begin, CharacterBufferSize, L"%.*g",
static_cast<int>(boost::detail::lcast_precision<float>::value),
val_as_double
);
return finish > start;
}
bool shl_real_type(double val, wchar_t* begin) {
using namespace std;
finish = start + swprintf(begin, CharacterBufferSize,
L"%.*g", static_cast<int>(boost::detail::lcast_get_precision<double >()), val );
bool shl_real_type(lcast::exact<double> val, wchar_t* begin) {
finish = start + boost::core::swprintf(
begin, CharacterBufferSize, L"%.*g",
static_cast<int>(boost::detail::lcast_precision<double>::value),
val.payload
);
return finish > start;
}
bool shl_real_type(long double val, wchar_t* begin) {
using namespace std;
finish = start + swprintf(begin, CharacterBufferSize,
L"%.*Lg", static_cast<int>(boost::detail::lcast_get_precision<long double >()), val );
bool shl_real_type(lcast::exact<long double> val, wchar_t* begin) {
finish = start + boost::core::swprintf(
begin, CharacterBufferSize, L"%.*Lg",
static_cast<int>(boost::detail::lcast_precision<long double>::value),
val.payload
);
return finish > start;
}
#endif
public:
template <class C>
using enable_if_compatible_char_t = typename boost::enable_if_c<
boost::is_same<const C, const CharT>::value || (
boost::is_same<const char, const CharT>::value && (
boost::is_same<const C, const unsigned char>::value ||
boost::is_same<const C, const signed char>::value
using enable_if_compatible_char_t = typename std::enable_if<
std::is_same<const C, const CharT>::value || (
std::is_same<const char, const CharT>::value && (
std::is_same<const C, const unsigned char>::value ||
std::is_same<const C, const signed char>::value
)
), bool
>::type;
@@ -301,32 +303,34 @@ namespace boost { namespace detail { namespace lcast {
bool stream_in(lcast::exact<char> x) { return shl_char(x.payload); }
bool stream_in(lcast::exact<unsigned char> x) { return shl_char(static_cast<char>(x.payload)); }
bool stream_in(lcast::exact<signed char> x) { return shl_char(static_cast<char>(x.payload)); }
#if !defined(BOOST_NO_INTRINSIC_WCHAR_T)
template <class C>
typename boost::enable_if_c<boost::detail::is_character<C>::value, bool>::type
typename std::enable_if<boost::detail::is_character<C>::value, bool>::type
stream_in(lcast::exact<C> x) { return shl_char(x.payload); }
#endif
template <class Type>
enable_if_compatible_char_t<Type>
stream_in(lcast::exact<Type*> x) { return shl_char_array(reinterpret_cast<CharT const*>(x.payload)); }
template <class Type>
typename boost::enable_if_c<boost::is_signed<Type>::value && !boost::is_enum<Type>::value, bool>::type
typename std::enable_if<!std::is_floating_point<Type>::value && boost::detail::lcast::is_signed<Type>::value && !std::is_enum<Type>::value, bool>::type
stream_in(lcast::exact<Type> x) { return shl_signed(x.payload); }
template <class Type>
typename boost::enable_if_c<boost::is_unsigned<Type>::value && !boost::is_enum<Type>::value, bool>::type
typename std::enable_if<boost::detail::lcast::is_unsigned<Type>::value && !std::is_enum<Type>::value, bool>::type
stream_in(lcast::exact<Type> x) { return shl_unsigned(x.payload); }
template <class Type>
auto stream_in(lcast::exact<Type> x) -> decltype(shl_real_type(x.payload, buffer)) {
auto stream_in(lcast::exact<Type> x) -> decltype(shl_real_type(x, buffer)) {
const CharT* inf_nan = detail::get_inf_nan(x.payload, CharT());
if (inf_nan) {
start = inf_nan;
finish = start + Traits::length(inf_nan);
return true;
}
return shl_real_type(x.payload, buffer);
return shl_real_type(x, buffer);
}
template <class C, std::size_t N>
@@ -345,13 +349,17 @@ namespace boost { namespace detail { namespace lcast {
template <class C, class CharTraits>
enable_if_compatible_char_t<C>
stream_in(lcast::exact<std::basic_string_view<C, CharTraits>> x) noexcept {
return shl_char_array_limited(reinterpret_cast<const CharT*>(x.payload.data()), x.payload.size());
start = reinterpret_cast<const CharT*>(x.payload.data());
finish = start + x.payload.size();
return true;
}
#endif
template <class C, class CharTraits>
enable_if_compatible_char_t<C>
stream_in(lcast::exact<boost::basic_string_view<C, CharTraits>> x) noexcept {
return shl_char_array_limited(reinterpret_cast<const CharT*>(x.payload.data()), x.payload.size());
start = reinterpret_cast<const CharT*>(x.payload.data());
finish = start + x.payload.size();
return true;
}
};
@@ -393,7 +401,7 @@ namespace boost { namespace detail { namespace lcast {
#if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_LOCALE)
// If you have compilation error at this point, than your STL library
// does not support such conversions. Try updating it.
static_assert(boost::is_same<char, CharT>::value, "");
static_assert(std::is_same<char, CharT>::value, "");
#endif
#ifndef BOOST_NO_EXCEPTIONS
@@ -429,17 +437,17 @@ namespace boost { namespace detail { namespace lcast {
return true;
}
lcast_set_precision(out_stream, &val);
boost::detail::lcast_set_precision(out_stream, &val);
return shl_input_streamable(val);
}
public:
template <class Type>
typename boost::enable_if_c<boost::detail::is_character<Type>::value && sizeof(char) == sizeof(Type), bool>::type
typename std::enable_if<boost::detail::is_character<Type>::value && sizeof(char) == sizeof(Type), bool>::type
stream_in(lcast::exact<const Type*> x) { return shl_char_array(reinterpret_cast<char const*>(x.payload)); }
template <class Type>
typename boost::enable_if_c<boost::detail::is_character<Type>::value && sizeof(char) != sizeof(Type), bool>::type
typename std::enable_if<boost::detail::is_character<Type>::value && sizeof(char) != sizeof(Type), bool>::type
stream_in(lcast::exact<const Type*> x) { return shl_char_array(x.payload); }
bool stream_in(lcast::exact<float> x) { return shl_real(x.payload); }
@@ -453,14 +461,14 @@ namespace boost { namespace detail { namespace lcast {
}
template <class C>
typename boost::enable_if_c<boost::detail::is_character<C>::value, bool>::type
typename std::enable_if<boost::detail::is_character<C>::value, bool>::type
stream_in(lcast::exact<iterator_range<C*>> x) noexcept {
auto buf = boost::conversion::detail::make_buffer_view(x.payload.begin(), x.payload.end());
return stream_in(lcast::exact<decltype(buf)>{buf});
}
template <class C>
typename boost::enable_if_c<boost::detail::is_character<C>::value, bool>::type
typename std::enable_if<boost::detail::is_character<C>::value, bool>::type
stream_in(lcast::exact<iterator_range<const C*>> x) noexcept {
auto buf = boost::conversion::detail::make_buffer_view(x.payload.begin(), x.payload.end());
return stream_in(lcast::exact<decltype(buf)>{buf});
@@ -521,7 +529,7 @@ namespace boost { namespace detail { namespace lcast {
if (start == finish) return false;
CharT const minus = lcast_char_constants<CharT>::minus;
CharT const plus = lcast_char_constants<CharT>::plus;
typedef typename make_unsigned<Type>::type utype;
typedef typename boost::detail::lcast::make_unsigned<Type>::type utype;
utype out_tmp = 0;
bool const has_minus = Traits::eq(minus, *start);
@@ -547,12 +555,12 @@ namespace boost { namespace detail { namespace lcast {
bool shr_using_base_class(InputStreamable& output)
{
static_assert(
!boost::is_pointer<InputStreamable>::value,
!std::is_pointer<InputStreamable>::value,
"boost::lexical_cast can not convert to pointers"
);
#if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_LOCALE)
static_assert(boost::is_same<char, CharT>::value,
static_assert(std::is_same<char, CharT>::value,
"boost::lexical_cast can not convert, because your STL library does not "
"support such conversions. Try updating it."
);
@@ -578,7 +586,7 @@ namespace boost { namespace detail { namespace lcast {
try {
#endif
stream.unsetf(std::ios::skipws);
lcast_set_precision(stream, static_cast<InputStreamable*>(0));
boost::detail::lcast_set_precision(stream, static_cast<InputStreamable*>(0));
return (stream >> output)
&& (stream.get() == Traits::eof());
@@ -749,5 +757,7 @@ namespace boost { namespace detail { namespace lcast {
#undef BOOST_LCAST_NO_WCHAR_T
#endif // #if !defined(BOOST_USE_MODULES) || defined(BOOST_LEXICAL_CAST_INTERFACE_UNIT)
#endif // BOOST_LEXICAL_CAST_DETAIL_CONVERTER_LEXICAL_HPP
@@ -1,6 +1,6 @@
// Copyright Kevlin Henney, 2000-2005.
// Copyright Alexander Nasonov, 2006-2010.
// Copyright Antony Polukhin, 2011-2024.
// Copyright Antony Polukhin, 2011-2026.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -18,20 +18,23 @@
#ifndef BOOST_LEXICAL_CAST_DETAIL_CONVERTER_NUMERIC_HPP
#define BOOST_LEXICAL_CAST_DETAIL_CONVERTER_NUMERIC_HPP
#include <boost/lexical_cast/detail/config.hpp>
#if !defined(BOOST_USE_MODULES) || defined(BOOST_LEXICAL_CAST_INTERFACE_UNIT)
#ifndef BOOST_LEXICAL_CAST_INTERFACE_UNIT
#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif
#include <type_traits>
#include <boost/core/cmath.hpp>
#include <boost/core/enable_if.hpp>
#include <boost/limits.hpp>
#include <boost/type_traits/type_identity.hpp>
#include <boost/type_traits/conditional.hpp>
#include <boost/type_traits/make_unsigned.hpp>
#include <boost/type_traits/is_signed.hpp>
#include <boost/type_traits/is_arithmetic.hpp>
#include <boost/type_traits/is_float.hpp>
#endif // #ifndef BOOST_LEXICAL_CAST_INTERFACE_UNIT
#include <boost/lexical_cast/detail/type_traits.hpp>
namespace boost { namespace detail {
@@ -46,14 +49,15 @@ bool ios_numeric_comparer_float(Source x, Source y) noexcept {
template <class RangeType, class T>
constexpr bool is_out_of_range_for(T value) noexcept {
return value > static_cast<T>((std::numeric_limits<RangeType>::max)())
|| value < static_cast<T>((std::numeric_limits<RangeType>::min)());
|| value < static_cast<T>((std::numeric_limits<RangeType>::min)())
|| boost::core::isnan(value);
}
// integral -> integral
template <typename Target, typename Source>
typename boost::enable_if_c<
!boost::is_floating_point<Source>::value && !boost::is_floating_point<Target>::value, bool
typename std::enable_if<
!std::is_floating_point<Source>::value && !std::is_floating_point<Target>::value, bool
>::type noexcept_numeric_convert(Source arg, Target& result) noexcept {
const Target target_tmp = static_cast<Target>(arg);
const Source arg_restored = static_cast<Source>(target_tmp);
@@ -66,8 +70,8 @@ typename boost::enable_if_c<
// integral -> floating point
template <typename Target, typename Source>
typename boost::enable_if_c<
!boost::is_floating_point<Source>::value && boost::is_floating_point<Target>::value, bool
typename std::enable_if<
!std::is_floating_point<Source>::value && std::is_floating_point<Target>::value, bool
>::type noexcept_numeric_convert(Source arg, Target& result) noexcept {
const Target target_tmp = static_cast<Target>(arg);
result = target_tmp;
@@ -77,8 +81,8 @@ typename boost::enable_if_c<
// floating point -> floating point
template <typename Target, typename Source>
typename boost::enable_if_c<
boost::is_floating_point<Source>::value && boost::is_floating_point<Target>::value, bool
typename std::enable_if<
std::is_floating_point<Source>::value && std::is_floating_point<Target>::value, bool
>::type noexcept_numeric_convert(Source arg, Target& result) noexcept {
const Target target_tmp = static_cast<Target>(arg);
const Source arg_restored = static_cast<Source>(target_tmp);
@@ -92,8 +96,8 @@ typename boost::enable_if_c<
// floating point -> integral
template <typename Target, typename Source>
typename boost::enable_if_c<
boost::is_floating_point<Source>::value && !boost::is_floating_point<Target>::value, bool
typename std::enable_if<
std::is_floating_point<Source>::value && !std::is_floating_point<Target>::value, bool
>::type noexcept_numeric_convert(Source arg, Target& result) noexcept {
if (detail::is_out_of_range_for<Target>(arg)) {
return false;
@@ -101,7 +105,7 @@ typename boost::enable_if_c<
const Target target_tmp = static_cast<Target>(arg);
const Source arg_restored = static_cast<Source>(target_tmp);
if (detail::ios_numeric_comparer_float<Source, Target>(arg, arg_restored)) {
if (arg == arg_restored /* special values are handled in detail::is_out_of_range_for */) {
result = target_tmp;
return true;
}
@@ -124,10 +128,10 @@ struct lexical_cast_dynamic_num_ignoring_minus
__attribute__((no_sanitize("unsigned-integer-overflow")))
#endif
static inline bool try_convert(Source arg, Target& result) noexcept {
typedef typename boost::conditional<
boost::is_float<Source>::value,
boost::type_identity<Source>,
boost::make_unsigned<Source>
typedef typename std::conditional<
std::is_floating_point<Source>::value,
std::conditional<true, Source, Source>, // std::type_identity emulation
boost::detail::lcast::make_unsigned<Source>
>::type usource_lazy_t;
typedef typename usource_lazy_t::type usource_t;
@@ -165,11 +169,11 @@ template <typename Target, typename Source>
struct dynamic_num_converter_impl
{
static inline bool try_convert(Source arg, Target& result) noexcept {
typedef typename boost::conditional<
boost::is_unsigned<Target>::value &&
(boost::is_signed<Source>::value || boost::is_float<Source>::value) &&
!(boost::is_same<Source, bool>::value) &&
!(boost::is_same<Target, bool>::value),
typedef typename std::conditional<
boost::detail::lcast::is_unsigned<Target>::value &&
(boost::detail::lcast::is_signed<Source>::value || std::is_floating_point<Source>::value) &&
!(std::is_same<Source, bool>::value) &&
!(std::is_same<Target, bool>::value),
lexical_cast_dynamic_num_ignoring_minus,
lexical_cast_dynamic_num_not_ignoring_minus
>::type caster_type;
@@ -180,5 +184,7 @@ struct dynamic_num_converter_impl
}} // namespace boost::detail
#endif // #if !defined(BOOST_USE_MODULES) || defined(BOOST_LEXICAL_CAST_INTERFACE_UNIT)
#endif // BOOST_LEXICAL_CAST_DETAIL_CONVERTER_NUMERIC_HPP
+10 -2
View File
@@ -1,6 +1,6 @@
// Copyright Kevlin Henney, 2000-2005.
// Copyright Alexander Nasonov, 2006-2010.
// Copyright Antony Polukhin, 2011-2024.
// Copyright Antony Polukhin, 2011-2026.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -18,6 +18,11 @@
#ifndef BOOST_LEXICAL_CAST_DETAIL_INF_NAN_HPP
#define BOOST_LEXICAL_CAST_DETAIL_INF_NAN_HPP
#include <boost/lexical_cast/detail/config.hpp>
#if !defined(BOOST_USE_MODULES) || defined(BOOST_LEXICAL_CAST_INTERFACE_UNIT)
#ifndef BOOST_LEXICAL_CAST_INTERFACE_UNIT
#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
@@ -28,10 +33,11 @@
#endif
#include <boost/limits.hpp>
#include <boost/detail/workaround.hpp>
#include <boost/config/workaround.hpp>
#include <boost/core/cmath.hpp>
#include <cstddef>
#include <cstring>
#endif // #ifndef BOOST_LEXICAL_CAST_INTERFACE_UNIT
#include <boost/lexical_cast/detail/lcast_char_constants.hpp>
@@ -183,5 +189,7 @@ namespace boost {
#undef BOOST_LCAST_NO_WCHAR_T
#endif // #if !defined(BOOST_USE_MODULES) || defined(BOOST_LEXICAL_CAST_INTERFACE_UNIT)
#endif // BOOST_LEXICAL_CAST_DETAIL_INF_NAN_HPP
@@ -1,6 +1,6 @@
// Copyright Kevlin Henney, 2000-2005.
// Copyright Alexander Nasonov, 2006-2010.
// Copyright Antony Polukhin, 2011-2024.
// Copyright Antony Polukhin, 2011-2026.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -18,35 +18,43 @@
#ifndef BOOST_LEXICAL_CAST_DETAIL_IS_CHARACTER_HPP
#define BOOST_LEXICAL_CAST_DETAIL_IS_CHARACTER_HPP
#include <boost/lexical_cast/detail/config.hpp>
#if !defined(BOOST_USE_MODULES) || defined(BOOST_LEXICAL_CAST_INTERFACE_UNIT)
#ifndef BOOST_LEXICAL_CAST_INTERFACE_UNIT
#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif
#include <boost/type_traits/integral_constant.hpp>
#include <boost/type_traits/is_same.hpp>
#include <type_traits>
#endif // #ifndef BOOST_LEXICAL_CAST_INTERFACE_UNIT
namespace boost { namespace detail {
// returns true, if T is one of the character types
template < typename T >
using is_character = boost::integral_constant<
using is_character = std::integral_constant<
bool,
boost::is_same< T, char >::value ||
std::is_same< T, char >::value ||
#if !defined(BOOST_NO_STRINGSTREAM) && !defined(BOOST_NO_STD_WSTRING)
boost::is_same< T, wchar_t >::value ||
std::is_same< T, wchar_t >::value ||
#endif
#ifndef BOOST_NO_CXX11_CHAR16_T
boost::is_same< T, char16_t >::value ||
std::is_same< T, char16_t >::value ||
#endif
#ifndef BOOST_NO_CXX11_CHAR32_T
boost::is_same< T, char32_t >::value ||
std::is_same< T, char32_t >::value ||
#endif
boost::is_same< T, unsigned char >::value ||
boost::is_same< T, signed char >::value
std::is_same< T, unsigned char >::value ||
std::is_same< T, signed char >::value
>;
}}
#endif // #if !defined(BOOST_USE_MODULES) || defined(BOOST_LEXICAL_CAST_INTERFACE_UNIT)
#endif // BOOST_LEXICAL_CAST_DETAIL_IS_CHARACTER_HPP
@@ -1,6 +1,6 @@
// Copyright Kevlin Henney, 2000-2005.
// Copyright Alexander Nasonov, 2006-2010.
// Copyright Antony Polukhin, 2011-2024.
// Copyright Antony Polukhin, 2011-2026.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -9,6 +9,12 @@
#ifndef BOOST_LEXICAL_CAST_DETAIL_CONVERTER_LEXICAL_BASIC_UNLOCKEDBUF_HPP
#define BOOST_LEXICAL_CAST_DETAIL_CONVERTER_LEXICAL_BASIC_UNLOCKEDBUF_HPP
#include <boost/lexical_cast/detail/config.hpp>
#if !defined(BOOST_USE_MODULES) || defined(BOOST_LEXICAL_CAST_INTERFACE_UNIT)
#ifndef BOOST_LEXICAL_CAST_INTERFACE_UNIT
#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
@@ -25,6 +31,7 @@
#ifndef BOOST_NO_CWCHAR
# include <cwchar>
#endif
#endif // #ifndef BOOST_LEXICAL_CAST_INTERFACE_UNIT
namespace boost { namespace detail { namespace lcast {
@@ -69,5 +76,7 @@ namespace boost { namespace detail { namespace lcast {
}}} // namespace boost::detail::lcast
#endif // #if !defined(BOOST_USE_MODULES) || defined(BOOST_LEXICAL_CAST_INTERFACE_UNIT)
#endif // BOOST_LEXICAL_CAST_DETAIL_CONVERTER_LEXICAL_BASIC_UNLOCKEDBUF_HPP
@@ -1,6 +1,6 @@
// Copyright Kevlin Henney, 2000-2005.
// Copyright Alexander Nasonov, 2006-2010.
// Copyright Antony Polukhin, 2011-2024.
// Copyright Antony Polukhin, 2011-2026.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -18,10 +18,16 @@
#ifndef BOOST_LEXICAL_CAST_DETAIL_LCAST_CHAR_CONSTANTS_HPP
#define BOOST_LEXICAL_CAST_DETAIL_LCAST_CHAR_CONSTANTS_HPP
#include <boost/lexical_cast/detail/config.hpp>
#if !defined(BOOST_USE_MODULES) || defined(BOOST_LEXICAL_CAST_INTERFACE_UNIT)
#ifndef BOOST_LEXICAL_CAST_INTERFACE_UNIT
#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif
#endif // #ifndef BOOST_LEXICAL_CAST_INTERFACE_UNIT
namespace boost
{
@@ -41,6 +47,7 @@ namespace boost
}
} // namespace boost
#endif // #if !defined(BOOST_USE_MODULES) || defined(BOOST_LEXICAL_CAST_INTERFACE_UNIT)
#endif // BOOST_LEXICAL_CAST_DETAIL_LCAST_CHAR_CONSTANTS_HPP
@@ -8,52 +8,58 @@
#ifndef BOOST_DETAIL_LCAST_PRECISION_HPP_INCLUDED
#define BOOST_DETAIL_LCAST_PRECISION_HPP_INCLUDED
#include <boost/lexical_cast/detail/config.hpp>
#if !defined(BOOST_USE_MODULES) || defined(BOOST_LEXICAL_CAST_INTERFACE_UNIT)
#ifndef BOOST_LEXICAL_CAST_INTERFACE_UNIT
#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif
#include <climits>
#include <ios>
#include <limits>
#include <boost/config.hpp>
#include <boost/integer_traits.hpp>
#endif // #ifndef BOOST_LEXICAL_CAST_INTERFACE_UNIT
namespace boost { namespace detail {
class lcast_abstract_stub {};
// Calculate an argument to pass to std::ios_base::precision from
// lexical_cast. See alternative implementation for broken standard
// libraries in lcast_get_precision below. Keep them in sync, please.
// lexical_cast.
template<class T>
struct lcast_precision
{
using limits = std::numeric_limits<T>;
BOOST_STATIC_CONSTANT(bool, use_default_precision =
static constexpr bool use_default_precision =
!limits::is_specialized || limits::is_exact
);
;
BOOST_STATIC_CONSTANT(bool, is_specialized_bin =
static constexpr bool is_specialized_bin =
!use_default_precision &&
limits::radix == 2 && limits::digits > 0
);
;
BOOST_STATIC_CONSTANT(bool, is_specialized_dec =
static constexpr bool is_specialized_dec =
!use_default_precision &&
limits::radix == 10 && limits::digits10 > 0
);
;
BOOST_STATIC_CONSTANT(std::streamsize, streamsize_max =
boost::integer_traits<std::streamsize>::const_max
);
static constexpr std::streamsize streamsize_max =
(std::numeric_limits<std::streamsize>::max)()
;
BOOST_STATIC_CONSTANT(unsigned int, precision_dec = limits::digits10 + 1U);
static constexpr unsigned int precision_dec = limits::digits10 + 1U;
static_assert(!is_specialized_dec ||
precision_dec <= streamsize_max + 0UL
, "");
BOOST_STATIC_CONSTANT(unsigned long, precision_bin =
static constexpr unsigned long precision_bin =
2UL + limits::digits * 30103UL / 100000UL
);
;
static_assert(!is_specialized_bin ||
(limits::digits + 0UL < ULONG_MAX / 30103UL &&
@@ -61,34 +67,29 @@ struct lcast_precision
precision_bin <= streamsize_max + 0UL)
, "");
BOOST_STATIC_CONSTANT(std::streamsize, value =
static constexpr std::streamsize value =
is_specialized_bin ? precision_bin
: is_specialized_dec ? precision_dec : 6
);
;
};
template<class T>
inline std::streamsize lcast_get_precision(T* = 0)
{
return lcast_precision<T>::value;
}
template<class T>
inline void lcast_set_precision(std::ios_base& stream, T*)
{
stream.precision(lcast_get_precision<T>());
stream.precision(lcast_precision<T>::value);
}
template<class Source, class Target>
inline void lcast_set_precision(std::ios_base& stream, Source*, Target*)
{
std::streamsize const s = lcast_get_precision(static_cast<Source*>(0));
std::streamsize const t = lcast_get_precision(static_cast<Target*>(0));
std::streamsize const s = lcast_precision<Source>::value;
std::streamsize const t = lcast_precision<Target*>::value;
stream.precision(s > t ? s : t);
}
}}
#endif // #if !defined(BOOST_USE_MODULES) || defined(BOOST_LEXICAL_CAST_INTERFACE_UNIT)
#endif // BOOST_DETAIL_LCAST_PRECISION_HPP_INCLUDED
@@ -1,6 +1,6 @@
// Copyright Kevlin Henney, 2000-2005.
// Copyright Alexander Nasonov, 2006-2010.
// Copyright Antony Polukhin, 2011-2024.
// Copyright Antony Polukhin, 2011-2026.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -18,6 +18,11 @@
#ifndef BOOST_LEXICAL_CAST_DETAIL_LCAST_UNSIGNED_CONVERTERS_HPP
#define BOOST_LEXICAL_CAST_DETAIL_LCAST_UNSIGNED_CONVERTERS_HPP
#include <boost/lexical_cast/detail/config.hpp>
#if !defined(BOOST_USE_MODULES) || defined(BOOST_LEXICAL_CAST_INTERFACE_UNIT)
#ifndef BOOST_LEXICAL_CAST_INTERFACE_UNIT
#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
@@ -28,9 +33,10 @@
#include <string>
#include <cstring>
#include <cstdio>
#include <type_traits>
#include <boost/limits.hpp>
#include <boost/type_traits/conditional.hpp>
#include <boost/detail/workaround.hpp>
#include <boost/config/workaround.hpp>
#include <boost/lexical_cast/detail/type_traits.hpp>
#ifndef BOOST_NO_STD_LOCALE
@@ -47,9 +53,10 @@
#endif
#include <boost/lexical_cast/detail/lcast_char_constants.hpp>
#include <boost/type_traits/make_unsigned.hpp>
#include <boost/type_traits/is_signed.hpp>
#include <boost/core/noncopyable.hpp>
#endif // #ifndef BOOST_LEXICAL_CAST_INTERFACE_UNIT
#include <boost/lexical_cast/detail/lcast_char_constants.hpp>
namespace boost
{
@@ -60,8 +67,8 @@ namespace boost
__attribute__((no_sanitize("unsigned-integer-overflow")))
#endif
inline
typename boost::make_unsigned<T>::type lcast_to_unsigned(const T value) noexcept {
typedef typename boost::make_unsigned<T>::type result_type;
typename boost::detail::lcast::make_unsigned<T>::type lcast_to_unsigned(const T value) noexcept {
typedef typename boost::detail::lcast::make_unsigned<T>::type result_type;
return value < 0
? static_cast<result_type>(0u - static_cast<result_type>(value))
: static_cast<result_type>(value);
@@ -73,7 +80,7 @@ namespace boost
template <class Traits, class T, class CharT>
class lcast_put_unsigned: boost::noncopyable {
typedef typename Traits::int_type int_type;
typename boost::conditional<
typename std::conditional<
(sizeof(unsigned) > sizeof(T))
, unsigned
, T
@@ -295,5 +302,7 @@ namespace boost
}
} // namespace boost
#endif // #if !defined(BOOST_USE_MODULES) || defined(BOOST_LEXICAL_CAST_INTERFACE_UNIT)
#endif // BOOST_LEXICAL_CAST_DETAIL_LCAST_UNSIGNED_CONVERTERS_HPP
@@ -0,0 +1,81 @@
// Copyright Peter Dimov, 2025.
// Copyright Romain Geissler, 2025.
//
// 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)
#ifndef BOOST_LEXICAL_CAST_DETAIL_TYPE_TRAITS_HPP
#define BOOST_LEXICAL_CAST_DETAIL_TYPE_TRAITS_HPP
#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif
#include <type_traits>
namespace boost { namespace detail { namespace lcast {
// libstdc++ from gcc <= 15 doesn't provide support for __int128 in the standard traits,
// so define them explicitly.
// This was fixed with gcc >= 16, so we may eventually remove this workaround and use
// directly the standard type_traits.
template<class T> struct is_integral: public std::is_integral<T>
{
};
template<class T> struct is_signed: public std::is_signed<T>
{
};
template<class T> struct is_unsigned: public std::is_unsigned<T>
{
};
template<class T> struct make_unsigned: public std::make_unsigned<T>
{
};
#if defined(__SIZEOF_INT128__)
template<> struct is_integral<__int128_t>: public std::true_type
{
};
template<> struct is_integral<__uint128_t>: public std::true_type
{
};
template<> struct is_signed<__int128_t>: public std::true_type
{
};
template<> struct is_signed<__uint128_t>: public std::false_type
{
};
template<> struct is_unsigned<__int128_t>: public std::false_type
{
};
template<> struct is_unsigned<__uint128_t>: public std::true_type
{
};
template<> struct make_unsigned<__int128_t>
{
typedef __uint128_t type;
};
template<> struct make_unsigned<__uint128_t>
{
typedef __uint128_t type;
};
#endif
}}} // namespace boost::detail::lcast
#endif // BOOST_LEXICAL_CAST_DETAIL_TYPE_TRAITS_HPP
@@ -1,6 +1,6 @@
// Copyright Kevlin Henney, 2000-2005.
// Copyright Alexander Nasonov, 2006-2010.
// Copyright Antony Polukhin, 2011-2024.
// Copyright Antony Polukhin, 2011-2026.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -18,18 +18,24 @@
#ifndef BOOST_LEXICAL_CAST_DETAIL_WIDEST_CHAR_HPP
#define BOOST_LEXICAL_CAST_DETAIL_WIDEST_CHAR_HPP
#include <boost/lexical_cast/detail/config.hpp>
#if !defined(BOOST_USE_MODULES) || defined(BOOST_LEXICAL_CAST_INTERFACE_UNIT)
#ifndef BOOST_LEXICAL_CAST_INTERFACE_UNIT
#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif
#include <type_traits>
#include <boost/type_traits/conditional.hpp>
#endif // #ifndef BOOST_LEXICAL_CAST_INTERFACE_UNIT
namespace boost { namespace detail {
template <typename TargetChar, typename SourceChar>
using widest_char = boost::conditional<
using widest_char = std::conditional<
(sizeof(TargetChar) > sizeof(SourceChar))
, TargetChar
, SourceChar
@@ -37,5 +43,7 @@ using widest_char = boost::conditional<
}} // namespace boost::detail
#endif // #if !defined(BOOST_USE_MODULES) || defined(BOOST_LEXICAL_CAST_INTERFACE_UNIT)
#endif // BOOST_LEXICAL_CAST_DETAIL_WIDEST_CHAR_HPP
@@ -1,6 +1,6 @@
// Copyright Kevlin Henney, 2000-2005.
// Copyright Alexander Nasonov, 2006-2010.
// Copyright Antony Polukhin, 2011-2024.
// Copyright Antony Polukhin, 2011-2026.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -18,13 +18,18 @@
#ifndef BOOST_LEXICAL_CAST_TRY_LEXICAL_CONVERT_HPP
#define BOOST_LEXICAL_CAST_TRY_LEXICAL_CONVERT_HPP
#include <boost/lexical_cast/detail/config.hpp>
#if !defined(BOOST_USE_MODULES) || defined(BOOST_LEXICAL_CAST_INTERFACE_UNIT)
#ifndef BOOST_LEXICAL_CAST_INTERFACE_UNIT
#include <boost/config.hpp>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif
#include <boost/type_traits/conditional.hpp>
#include <boost/type_traits/is_arithmetic.hpp>
#include <type_traits>
#endif
#include <boost/lexical_cast/detail/buffer_view.hpp>
#include <boost/lexical_cast/detail/is_character.hpp>
@@ -35,22 +40,24 @@ namespace boost {
namespace detail
{
template<typename Target, typename Source>
using is_arithmetic_and_not_xchars = boost::integral_constant<
using is_arithmetic_and_not_xchars = std::integral_constant<
bool,
!(boost::detail::is_character<Target>::value) &&
!(boost::detail::is_character<Source>::value) &&
boost::is_arithmetic<Source>::value &&
boost::is_arithmetic<Target>::value
std::is_arithmetic<Source>::value &&
std::is_arithmetic<Target>::value
>;
}
namespace conversion { namespace detail {
BOOST_LEXICAL_CAST_BEGIN_MODULE_EXPORT
template <typename Target, typename Source>
inline bool try_lexical_convert(const Source& arg, Target& result)
{
static_assert(
!boost::is_volatile<Source>::value,
!std::is_volatile<Source>::value,
"Boost.LexicalCast does not support volatile input");
typedef typename boost::detail::array_to_pointer_decay<Source>::type src;
@@ -58,7 +65,7 @@ namespace boost {
typedef boost::detail::is_arithmetic_and_not_xchars<Target, src >
shall_we_copy_with_dynamic_check_t;
typedef typename boost::conditional<
typedef typename std::conditional<
shall_we_copy_with_dynamic_check_t::value,
boost::detail::dynamic_num_converter_impl<Target, src >,
boost::detail::lexical_converter_impl<Target, src >
@@ -79,15 +86,20 @@ namespace boost {
result
);
}
BOOST_LEXICAL_CAST_END_MODULE_EXPORT
}} // namespace conversion::detail
namespace conversion {
BOOST_LEXICAL_CAST_BEGIN_MODULE_EXPORT
// ADL barrier
using ::boost::conversion::detail::try_lexical_convert;
BOOST_LEXICAL_CAST_END_MODULE_EXPORT
}
} // namespace boost
#endif // #if !defined(BOOST_USE_MODULES) || defined(BOOST_LEXICAL_CAST_INTERFACE_UNIT)
#endif // BOOST_LEXICAL_CAST_TRY_LEXICAL_CONVERT_HPP
+57
View File
@@ -0,0 +1,57 @@
// Copyright (c) 2016-2025 Antony Polukhin
//
// 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)
// To compile manually use a command like the folowing:
// clang++ -I ../include -std=c++20 --precompile -x c++-module boost_lexical_cast.cppm
module;
#include <boost/assert.hpp>
#include <boost/config.hpp>
#include <boost/config/workaround.hpp>
#include <boost/container/container_fwd.hpp>
#include <boost/core/cmath.hpp>
#include <boost/core/noncopyable.hpp>
#include <boost/core/snprintf.hpp>
#include <boost/limits.hpp>
#include <boost/throw_exception.hpp>
#include <boost/detail/basic_pointerbuf.hpp>
#ifndef BOOST_LEXICAL_CAST_USE_STD_MODULE
#include <array>
#include <climits>
#include <cstddef>
#include <cstdio>
#include <cstring>
#ifndef BOOST_NO_CWCHAR
# include <cwchar>
#endif
#include <exception>
#include <iosfwd>
#include <istream>
#ifndef BOOST_NO_STD_LOCALE
# include <locale>
#endif
#include <sstream>
#include <string>
#include <string_view>
#include <typeinfo>
#include <type_traits>
#endif
#define BOOST_LEXICAL_CAST_INTERFACE_UNIT
export module boost.lexical_cast;
#ifdef BOOST_LEXICAL_CAST_USE_STD_MODULE
import std;
#endif
#ifdef __clang__
# pragma clang diagnostic ignored "-Winclude-angled-in-module-purview"
#endif
#include <boost/lexical_cast.hpp>
+16
View File
@@ -0,0 +1,16 @@
// Copyright (c) 2024-2025 Antony Polukhin
//
// 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)
// To compile manually use a command like the following:
// clang++ -std=c++20 -fmodule-file=lexical_cast.pcm lexical_cast.pcm usage_sample.cpp
//[lexical_cast_module_example
import boost.lexical_cast;
int main() {
return boost::lexical_cast<int>("0");
}
//]
+1 -1
View File
@@ -1,5 +1,5 @@
#==============================================================================
# Copyright (c) Antony Polukhin, 2012-2024.
# Copyright Antony Polukhin, 2012-2026.
#
# 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)
+3 -2
View File
@@ -1,4 +1,4 @@
// (C) Copyright Antony Polukhin, 2012-2024.
// (C) Copyright Antony Polukhin, 2012-2026.
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -17,6 +17,7 @@
#include <fstream>
#include <cstring>
#include <string_view>
#include <type_traits>
#include <boost/array.hpp>
#include <boost/chrono.hpp>
@@ -242,7 +243,7 @@ static inline void perf_test_impl(const FromT& in_val, const char* const conv) {
lexical_cast_time.count(),
ss_constr_time.count(),
ss_noconstr_time.count(),
boost::is_same<SprintfT, structure_fake>::value ? fake_test_value : printf_time.count()
std::is_same<SprintfT, structure_fake>::value ? fake_test_value : printf_time.count()
);
}
+84
View File
@@ -0,0 +1,84 @@
# Copyright Antony Polukhin, 2021-2026.
#
# 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
if(NOT TARGET tests)
add_custom_target(tests)
endif()
function(boost_lexical_cast_add_test_impl test_name test_file libs)
add_executable(${test_name} ${test_file})
target_link_libraries(${test_name} PRIVATE ${libs})
add_test(NAME ${test_name} COMMAND ${test_name})
add_dependencies(tests ${test_name})
endfunction()
function(boost_lexical_cast_add_test name libs)
set(test_name lexical_cast_${name})
set(test_file ${name}.cpp)
boost_lexical_cast_add_test_impl(${test_name} ${test_file} "Boost::lexical_cast;${libs}")
endfunction()
boost_lexical_cast_add_test(lexical_cast_test Boost::type_traits)
boost_lexical_cast_add_test(loopback_test "")
boost_lexical_cast_add_test(abstract_test "")
boost_lexical_cast_add_test(noncopyable_test "")
boost_lexical_cast_add_test(vc8_bug_test "")
boost_lexical_cast_add_test(implicit_convert "")
boost_lexical_cast_add_test(wchars_test "")
boost_lexical_cast_add_test(float_types_test "")
if(NOT MSVC)
# Make sure that LexicalCast works the same way as some of the C++ Standard Libraries
boost_lexical_cast_add_test_impl(lexical_cast_float_types_non_opt float_types_test.cpp Boost::lexical_cast)
target_compile_definitions(lexical_cast_float_types_non_opt PRIVATE BOOST_LEXICAL_CAST_DETAIL_TEST_ON_OLD)
endif()
boost_lexical_cast_add_test(inf_nan_test "")
boost_lexical_cast_add_test(containers_test "")
boost_lexical_cast_add_test(empty_input_test Boost::range)
boost_lexical_cast_add_test(pointers_test "")
if(MSVC)
add_executable(lexical_cast_typedefed_wchar_test_compile typedefed_wchar_test.cpp)
target_compile_options(lexical_cast_typedefed_wchar_test_compile PRIVATE "/Zc:wchar_t-")
boost_lexical_cast_add_test(typedefed_wchar_test_runtime "")
target_compile_options(lexical_cast_typedefed_wchar_test_runtime PRIVATE "/Zc:wchar_t-")
endif()
boost_lexical_cast_add_test(no_locale_test Boost::range)
target_compile_definitions(lexical_cast_no_locale_test
PRIVATE
BOOST_NO_STD_LOCALE
BOOST_LEXICAL_CAST_ASSUME_C_LOCALE
)
boost_lexical_cast_add_test_impl(lexical_cast_no_exceptions_test no_exceptions_test.cpp "Boost::container;Boost::range")
target_include_directories(lexical_cast_no_exceptions_test PRIVATE ../include)
target_compile_definitions(lexical_cast_no_exceptions_test
PRIVATE
_HAS_EXCEPTIONS=0 # MSVC stdlib
_STLP_NO_EXCEPTIONS # STLPort
)
if(MSVC)
target_compile_definitions(lexical_cast_no_exceptions_test PRIVATE BOOST_NO_EXCEPTIONS)
endif()
target_compile_options(lexical_cast_no_exceptions_test PRIVATE "-fno-exceptions")
boost_lexical_cast_add_test(iterator_range_test Boost::range)
boost_lexical_cast_add_test(string_view_test Boost::utility)
boost_lexical_cast_add_test(arrays_test Boost::array)
boost_lexical_cast_add_test(integral_types_test Boost::type_traits)
boost_lexical_cast_add_test(stream_detection_test "")
boost_lexical_cast_add_test(stream_traits_test "Boost::array;Boost::range;Boost::utility")
boost_lexical_cast_add_test(filesystem_test Boost::filesystem)
boost_lexical_cast_add_test(try_lexical_convert "")
file(GLOB EXAMPLE_FILES "../example/*.cpp")
foreach (testsourcefile ${EXAMPLE_FILES})
get_filename_component(testname ${testsourcefile} NAME_WE)
boost_lexical_cast_add_test_impl(lexical_cast_example_${testname} ${testsourcefile} "Boost::variant;Boost::date_time")
endforeach()
+14 -7
View File
@@ -1,17 +1,19 @@
# Copyright (C) 2001-2003 Douglas Gregor
# Copyright (C) Antony Polukhin, 2011-2024
# Copyright Antony Polukhin, 2011-2026.
#
# 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)
#
require-b2 5.0.1 ;
import-search /boost/config/checks ;
import config : requires ;
import testing ;
import feature ;
import ../../config/checks/config : requires ;
project
: requirements
<library>/boost/lexical_cast//boost_lexical_cast
[ requires cxx11_rvalue_references cxx11_static_assert cxx11_template_aliases ]
<link>static
<toolset>gcc-4.7:<cxxflags>-ftrapv
@@ -29,6 +31,10 @@ project
# Not a lexical_cast related warning: boost/mpl/aux_/preprocessed/gcc/greater_equal.hpp:78:1: warning: empty macro arguments are a C99 feature [-Wc99-extensions]
# boost/mpl/iter_fold.hpp:45:1: warning: empty macro arguments are a C99 feature [-Wc99-extensions]
<toolset>clang:<cxxflags>-Wno-c99-extensions
<library>/boost/array//boost_array
<library>/boost/range//boost_range
<library>/boost/utility//boost_utility
;
# Thanks to Steven Watanabe for helping with <nowchar> feature
@@ -48,7 +54,8 @@ test-suite conversion
# Make sure that LexicalCast works the same way as some of the C++ Standard Libraries
[ run float_types_test.cpp : : : <define>BOOST_LEXICAL_CAST_DETAIL_TEST_ON_OLD
<toolset>msvc:<build>no # could have outdated behavior in some border cases
<toolset>msvc:<build>no # could have outdated behavior in some border cases
<target-os>darwin:<build>no # may have outdated behavior in some border cases
: float_types_non_opt
]
@@ -56,7 +63,7 @@ test-suite conversion
[ run containers_test.cpp : : : <toolset>gcc:<cxxflags>-Wno-long-long <toolset>clang:<cxxflags>-Wno-long-long ]
[ run empty_input_test.cpp ]
[ run pointers_test.cpp ]
[ compile typedefed_wchar_test.cpp : <toolset>msvc:<nowchar>on ]
[ compile typedefed_wchar_test.cpp : <toolset>msvc:<nowchar>on <library>/boost/date_time//boost_date_time ]
[ run typedefed_wchar_test_runtime.cpp : : : <toolset>msvc:<nowchar>on <toolset>msvc,<stdlib>stlport:<build>no ]
[ run no_locale_test.cpp : : : <define>BOOST_NO_STD_LOCALE <define>BOOST_LEXICAL_CAST_ASSUME_C_LOCALE ]
[ run no_exceptions_test.cpp : : : <exception-handling>off
@@ -73,14 +80,14 @@ test-suite conversion
[ run stream_traits_test.cpp ]
[ compile-fail to_pointer_test.cpp ]
[ compile-fail from_volatile.cpp ]
[ run filesystem_test.cpp ../../filesystem/build//boost_filesystem/<link>static ]
[ run filesystem_test.cpp /boost/filesystem//boost_filesystem : : : <toolset>gcc,<target-os>windows:<build>no ] # Boost.Atomic no longer supports MinGW
[ run try_lexical_convert.cpp ]
;
# Assuring that examples compile and run. Adding sources from `example` directory to the `conversion` test suite.
for local p in [ glob ../example/*.cpp ]
{
conversion += [ run $(p) ] ;
conversion += [ run $(p) : : : <library>/boost/variant//boost_variant <library>/boost/date_time//boost_date_time ] ;
}
+3 -3
View File
@@ -3,7 +3,7 @@
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Sergey Shandar 2005, Alexander Nasonov, 2007.
// Copyright Antony Polukhin, 2023-2024.
// Copyright Antony Polukhin, 2023-2026.
//
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
@@ -12,10 +12,10 @@
// Test abstract class. Bug 1358600:
// http://sf.net/tracker/?func=detail&aid=1358600&group_id=7586&atid=107586
#include <boost/lexical_cast.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/lexical_cast.hpp>
class A
{
public:
+1 -1
View File
@@ -2,7 +2,7 @@
# subject to the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#
# Copyright Antony Polukhin, 2016-2024.
# Copyright Antony Polukhin, 2016-2026.
#
# See https://svn.boost.org/trac/boost/wiki/TravisCoverals for description of this file
+10 -5
View File
@@ -2,18 +2,18 @@
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Antony Polukhin, 2012-2024.
// Copyright Antony Polukhin, 2012-2026.
//
// 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).
#include <boost/lexical_cast.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/array.hpp>
#include <boost/lexical_cast.hpp>
using namespace boost;
#if !defined(BOOST_NO_CXX11_CHAR16_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS) && !defined(_LIBCPP_VERSION) && !defined(BOOST_MSVC)
@@ -61,7 +61,7 @@ static void testing_template_array_output_on_spec_value(T val)
BOOST_TEST_THROWS(lexical_cast<sshort_arr_type>(val), boost::bad_lexical_cast);
}
#if !defined(BOOST_NO_STRINGSTREAM) && !defined(BOOST_NO_STD_WSTRING)
#if !defined(BOOST_NO_STRINGSTREAM) && !defined(BOOST_NO_STD_WSTRING) && !defined(_LIBCPP_VERSION)
typedef ArrayT<wchar_t, 300> warr_type;
typedef ArrayT<wchar_t, 3> wshort_arr_type;
std::wstring wethalon(L"100");
@@ -156,7 +156,7 @@ static void testing_template_array_output_on_char_value()
BOOST_TEST_THROWS(lexical_cast<sshort_arr_type>(val), boost::bad_lexical_cast);
}
#if !defined(BOOST_NO_STRINGSTREAM) && !defined(BOOST_NO_STD_WSTRING)
#if !defined(BOOST_NO_STRINGSTREAM) && !defined(BOOST_NO_STD_WSTRING) && !defined(_LIBCPP_VERSION)
typedef ArrayT<wchar_t, 4> warr_type;
typedef ArrayT<wchar_t, 3> wshort_arr_type;
std::wstring wethalon(L"100");
@@ -238,11 +238,13 @@ static void testing_template_array_output_on_char_value()
void testing_boost_array_output_conversion()
{
#ifndef _LIBCPP_VERSION
testing_template_array_output_on_char_value<boost::array>();
testing_template_array_output_on_spec_value<boost::array>(100);
testing_template_array_output_on_spec_value<boost::array>(static_cast<short>(100));
testing_template_array_output_on_spec_value<boost::array>(static_cast<unsigned short>(100));
testing_template_array_output_on_spec_value<boost::array>(static_cast<unsigned int>(100));
#endif
}
void testing_std_array_output_conversion()
@@ -344,7 +346,10 @@ static void testing_generic_array_input_conversion()
void testing_boost_array_input_conversion()
{
#ifndef _LIBCPP_VERSION
testing_generic_array_input_conversion<boost::array>();
#endif
BOOST_TEST(true);
}
void testing_std_array_input_conversion()
+80
View File
@@ -0,0 +1,80 @@
# Copyright (c) 2016-2025 Antony Polukhin
# Copyright (c) 2025-2026 Fedor Osetrov
# 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...4.0)
project(lexical_cast_subdir_test LANGUAGES CXX)
set(deps
# Library dependencies
config
container
core
throw_exception
# Test dependencies
algorithm
array
align
assert
atomic
bind
compat
concept_check
container_hash
conversion
date_time
describe
detail
exception
filesystem
function
function_types
functional
fusion
integer
intrusive
io
iterator
move
mp11
mpl
numeric/conversion
optional
predef
preprocessor
range
regex
scope
smart_ptr
static_assert
system
test
tokenizer
tuple
type_index
type_traits
typeof
unordered
utility
variant
variant2
winapi
)
foreach(dep IN LISTS deps)
add_subdirectory(../../../${dep} boostorg/${dep})
endforeach()
enable_testing()
add_subdirectory(../../ boostorg/lexical_cast)
if (BOOST_USE_MODULES)
add_executable(boost_lexical_cast_module_usage ../modules/usage_sample.cpp)
target_link_libraries(boost_lexical_cast_module_usage PRIVATE Boost::lexical_cast)
add_test(NAME boost_lexical_cast_module_usage COMMAND boost_lexical_cast_module_usage)
endif()
+3 -3
View File
@@ -2,17 +2,17 @@
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Antony Polukhin, 2011-2024.
// Copyright Antony Polukhin, 2011-2026.
//
// 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).
#include <boost/lexical_cast.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/container/string.hpp>
#include <boost/lexical_cast.hpp>
using namespace boost;
void testing_boost_containers_basic_string()
+5 -4
View File
@@ -2,21 +2,22 @@
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Antony Polukhin, 2011-2024.
// Copyright Antony Polukhin, 2011-2026.
//
// 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).
#include <boost/lexical_cast.hpp>
#include <boost/range/iterator_range.hpp>
#include "escape_struct.hpp"
#include <boost/core/lightweight_test.hpp>
#include <vector>
#include <boost/lexical_cast.hpp>
#include "escape_struct.hpp"
using namespace boost;
#if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_WSTRING)
+1 -1
View File
@@ -1,6 +1,6 @@
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Antony Polukhin, 2020.
// Copyright Antony Polukhin, 2020-2026.
//
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
+3 -3
View File
@@ -2,7 +2,7 @@
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Antony Polukhin, 2013-2024.
// Copyright Antony Polukhin, 2013-2026.
//
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
@@ -10,11 +10,11 @@
//
// Test lexical_cast usage with long filesystem::path. Bug 7704.
#include <boost/lexical_cast.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/lexical_cast.hpp>
void test_filesystem()
{
boost::filesystem::path p;
+18 -8
View File
@@ -2,23 +2,27 @@
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Antony Polukhin, 2011-2024.
// Copyright Antony Polukhin, 2011-2026.
//
// 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).
#include <sstream>
#include <type_traits>
#include <boost/cstdint.hpp>
#include <boost/core/lightweight_test.hpp>
#ifndef BOOST_LEXICAL_CAST_DETAIL_TEST_ON_OLD
#include <boost/lexical_cast/detail/type_traits.hpp>
#include <boost/lexical_cast.hpp>
#else
// Make sure that tests work the same way on non-optimized version
#include "lexical_cast_old.hpp"
#include <boost/lexical_cast/detail/type_traits.hpp>
#endif
#include <boost/cstdint.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/is_signed.hpp>
#ifndef BOOST_TEST_CLOSE_FRACTION
// Naiive, but works for most tests in this file
@@ -302,8 +306,8 @@ void test_float_typess_for_overflows()
BOOST_TEST_THROWS(lexical_cast<test_t>("1"+s_max_value), bad_lexical_cast);
BOOST_TEST_THROWS(lexical_cast<test_t>("9"+s_max_value), bad_lexical_cast);
#endif
if ( is_same<test_t,float>::value )
#if !(defined(_LIBCPP_VERSION) && defined(BOOST_LEXICAL_CAST_DETAIL_TEST_ON_OLD))
if ( std::is_same<test_t,float>::value )
{
BOOST_TEST_THROWS(lexical_cast<test_t>( (std::numeric_limits<double>::max)() ), bad_lexical_cast);
BOOST_TEST(
@@ -338,6 +342,7 @@ void test_float_typess_for_overflows()
<= (std::numeric_limits<long double>::min)() / 2 + std::numeric_limits<test_t>::epsilon()
);
}
#endif
}
#undef CHECK_CLOSE_ABS_DIFF
@@ -549,7 +554,7 @@ void test_conversion_integral_float()
BOOST_TEST_EQ(lexical_cast<Integral>(static_cast<Float>(8.0)), 8);
BOOST_TEST_EQ(lexical_cast<Integral>(static_cast<Float>(16.0)), 16);
if (boost::is_signed<Integral>::value) {
if (boost::detail::lcast::is_signed<Integral>::value) {
BOOST_TEST_EQ(lexical_cast<Integral>(static_cast<Float>(-1.0)), -1);
BOOST_TEST_EQ(lexical_cast<Integral>(static_cast<Float>(-8.0)), -8);
BOOST_TEST_EQ(lexical_cast<Integral>(static_cast<Float>(-16.0)), -16);
@@ -568,6 +573,11 @@ void test_conversion_integral_float()
BOOST_TEST_THROWS(lexical_cast<Integral>((std::numeric_limits<Float>::max)()), bad_lexical_cast);
BOOST_TEST_THROWS(lexical_cast<Integral>((std::numeric_limits<Float>::epsilon)()), bad_lexical_cast);
BOOST_TEST_THROWS(lexical_cast<Integral>((std::numeric_limits<Float>::lowest)()), bad_lexical_cast);
BOOST_TEST_THROWS(lexical_cast<Integral>(std::numeric_limits<Float>::quiet_NaN()), bad_lexical_cast);
BOOST_TEST_THROWS(lexical_cast<Integral>(-std::numeric_limits<Float>::quiet_NaN()), bad_lexical_cast);
BOOST_TEST_THROWS(lexical_cast<Integral>(std::numeric_limits<Float>::infinity()), bad_lexical_cast);
BOOST_TEST_THROWS(lexical_cast<Integral>(-std::numeric_limits<Float>::infinity()), bad_lexical_cast);
}
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright Antony Polukhin, 2013-2024.
// Copyright Antony Polukhin, 2013-2026.
//
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
+41 -6
View File
@@ -1,11 +1,9 @@
// Copyright Antony Polukhin, 2023-2024.
// Copyright Antony Polukhin, 2023-2026.
//
// 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).
#include <boost/lexical_cast.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/lexical_cast.hpp>
@@ -20,9 +18,46 @@ inline std::ostream& operator<<(std::ostream& os, const oops&) {
return os << 42;
}
int main () {
auto val = boost::lexical_cast<int>(oops{});
BOOST_TEST_EQ(val, 42);
struct oops2 {
operator double () const {
return 1.12;
}
};
inline std::ostream& operator<<(std::ostream& os, const oops2&) {
return os << 2;
}
struct Value {
explicit Value(double x) : x(x) {}
operator double() const {
return x;
}
double x;
};
int main() {
BOOST_TEST_EQ(boost::lexical_cast<int>(oops{}), 42);
BOOST_TEST_EQ(boost::lexical_cast<std::string>(oops{}), "42");
BOOST_TEST_EQ(boost::lexical_cast<double>(oops2{}), 2);
BOOST_TEST_EQ(boost::lexical_cast<std::string>(oops2{}), "2");
Value longer_that_1_digit(128);
BOOST_TEST_EQ(boost::lexical_cast<std::string>(longer_that_1_digit), "128");
// iostreams have default precision 6, see [basic.ios.cons]
const double precision_more_than_6_digits = 1.23456789123;
// At the moment we do not set the precision for types that use conversion
// operators for ostreaming, so the below test pass. We do not set precision
// for user provided `operator<<`, types with conversion operators follow
// the same design decision for now.
BOOST_TEST_NE(
boost::lexical_cast<std::string>(Value(precision_more_than_6_digits)),
boost::lexical_cast<std::string>(precision_more_than_6_digits)
);
return boost::report_errors();
}
+28 -4
View File
@@ -2,19 +2,20 @@
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Antony Polukhin, 2011-2024.
// Copyright Antony Polukhin, 2011-2026.
//
// 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).
#include <boost/lexical_cast.hpp>
#include <type_traits>
#include <boost/core/cmath.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/lexical_cast.hpp>
#if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_WSTRING)
#define BOOST_LCAST_NO_WCHAR_T
#endif
@@ -46,7 +47,7 @@ bool is_neg_nan(T value)
* It is a IA64 feature, or it is a boost::math feature, not a lexical_cast bug */
#if defined(__ia64__) || defined(_M_IA64)
return (boost::core::isnan)(value)
&& ( boost::is_same<T, long double >::value || (boost::core::signbit)(value) );
&& ( std::is_same<T, long double >::value || (boost::core::signbit)(value) );
#else
return (boost::core::isnan)(value) && (boost::core::signbit)(value);
#endif
@@ -208,11 +209,34 @@ void test_inf_nan_long_double()
BOOST_TEST(true);
}
template <class Integral>
void test_inf_nan_to_integral()
{
BOOST_TEST_THROWS(lexical_cast<Integral>(std::numeric_limits<float>::quiet_NaN()), boost::bad_lexical_cast);
BOOST_TEST_THROWS(lexical_cast<Integral>(-std::numeric_limits<float>::quiet_NaN()), boost::bad_lexical_cast);
BOOST_TEST_THROWS(lexical_cast<Integral>(std::numeric_limits<float>::infinity()), boost::bad_lexical_cast);
BOOST_TEST_THROWS(lexical_cast<Integral>(-std::numeric_limits<float>::infinity()), boost::bad_lexical_cast);
BOOST_TEST_THROWS(lexical_cast<Integral>(std::numeric_limits<double>::quiet_NaN()), boost::bad_lexical_cast);
BOOST_TEST_THROWS(lexical_cast<Integral>(-std::numeric_limits<double>::quiet_NaN()), boost::bad_lexical_cast);
BOOST_TEST_THROWS(lexical_cast<Integral>(std::numeric_limits<double>::infinity()), boost::bad_lexical_cast);
BOOST_TEST_THROWS(lexical_cast<Integral>(-std::numeric_limits<double>::infinity()), boost::bad_lexical_cast);
BOOST_TEST_THROWS(lexical_cast<Integral>(std::numeric_limits<long double>::quiet_NaN()), boost::bad_lexical_cast);
BOOST_TEST_THROWS(lexical_cast<Integral>(-std::numeric_limits<long double>::quiet_NaN()), boost::bad_lexical_cast);
BOOST_TEST_THROWS(lexical_cast<Integral>(std::numeric_limits<long double>::infinity()), boost::bad_lexical_cast);
BOOST_TEST_THROWS(lexical_cast<Integral>(-std::numeric_limits<long double>::infinity()), boost::bad_lexical_cast);
}
int main()
{
test_inf_nan_float();
test_inf_nan_double();
test_inf_nan_long_double();
test_inf_nan_to_integral<int>();
test_inf_nan_to_integral<bool>();
test_inf_nan_to_integral<short>();
return boost::report_errors();
}
+11 -7
View File
@@ -4,7 +4,7 @@
//
// Copyright Terje Sletteb and Kevlin Henney, 2005.
// Copyright Alexander Nasonov, 2006.
// Copyright Antony Polukhin, 2011-2024.
// Copyright Antony Polukhin, 2011-2026.
//
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
@@ -19,17 +19,20 @@
//
#define _SCL_SECURE_NO_WARNINGS
#include <boost/lexical_cast.hpp>
#include <boost/cstdint.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/lexical_cast/detail/type_traits.hpp>
#include <boost/type_traits/integral_promotion.hpp>
#include <boost/type_traits/make_unsigned.hpp>
#include <string>
#include <sstream>
#include <vector>
#include <memory>
#include <type_traits>
#include <boost/lexical_cast.hpp>
#if (defined(BOOST_HAS_LONG_LONG) || defined(BOOST_HAS_MS_INT64)) \
&& !(defined(BOOST_MSVC) && BOOST_MSVC < 1300)
@@ -40,7 +43,8 @@
#define BOOST_LCAST_NO_WCHAR_T
#endif
#if defined(BOOST_HAS_INT128) && !defined(BOOST_LEXICAL_CAST_TEST_NO_128_INTS)
// There's no typeinfo for unsigned __int128 in Xcode_15.0.1
#if defined(BOOST_HAS_INT128) && !defined(BOOST_LEXICAL_CAST_TEST_NO_128_INTS) && !defined(__APPLE__)
# define BOOST_LCAST_TEST_128 1
#endif
@@ -248,7 +252,7 @@ void test_conversion_from_string_to_integral(CharT)
}
typedef typename boost::integral_promotion<T>::type promoted;
if ( !(boost::is_same<T, promoted>::value) )
if ( !(std::is_same<T, promoted>::value) )
{
promoted prom = max_val;
s = to_str<CharT>(max_val);
@@ -563,7 +567,7 @@ template <typename SignedT>
void test_integral_conversions_on_min_max_impl()
{
typedef SignedT signed_t;
typedef typename boost::make_unsigned<signed_t>::type unsigned_t;
typedef typename boost::detail::lcast::make_unsigned<signed_t>::type unsigned_t;
typedef std::numeric_limits<signed_t> s_limits;
typedef std::numeric_limits<unsigned_t> uns_limits;
+5 -5
View File
@@ -2,19 +2,19 @@
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Antony Polukhin, 2012-2024.
// Copyright Antony Polukhin, 2012-2026.
//
// 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).
#include <boost/lexical_cast.hpp>
#include <boost/range/iterator_range.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/lexical_cast.hpp>
using namespace boost;
#if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_WSTRING)
@@ -136,7 +136,7 @@ void test_it_range_using_char(CharT* one, CharT* eleven)
#endif
BOOST_TEST_EQ(lexical_cast<class_with_user_defined_sream_operators>(crng2), 1);
#ifndef BOOST_LCAST_NO_WCHAR_T
#if !defined(BOOST_LCAST_NO_WCHAR_T) && !defined(_LIBCPP_VERSION)
BOOST_TEST(lexical_cast<std::wstring>(rng1) == L"1");
BOOST_TEST(lexical_cast<std::wstring>(crng1) == L"1");
BOOST_TEST(lexical_cast<std::wstring>(rng2) == L"1");
@@ -191,7 +191,7 @@ void test_signed_char_iterator_ranges()
void test_wchar_iterator_ranges()
{
#ifndef BOOST_LCAST_NO_WCHAR_T
#if !defined(BOOST_LCAST_NO_WCHAR_T) && !defined(_LIBCPP_VERSION)
typedef wchar_t test_char_type;
test_char_type data1[] = L"1";
test_char_type data2[] = L"11";
+8 -5
View File
@@ -1,6 +1,6 @@
// Copyright Kevlin Henney, 2000-2005.
// Copyright Alexander Nasonov, 2006-2010.
// Copyright Antony Polukhin, 2011-2024.
// Copyright Antony Polukhin, 2011-2026.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -32,10 +32,9 @@
#include <string>
#include <cstring>
#include <cstdio>
#include <type_traits>
#include <boost/limits.hpp>
#include <boost/type_traits/is_pointer.hpp>
#include <boost/detail/lcast_precision.hpp>
#include <boost/detail/workaround.hpp>
#include <boost/config/workaround.hpp>
#ifdef BOOST_NO_STRINGSTREAM
#include <strstream>
@@ -43,6 +42,10 @@
#include <sstream>
#endif
#if defined(BOOST_USE_MODULES)
#undef BOOST_USE_MODULES
#endif
#include <boost/lexical_cast/detail/lcast_precision.hpp>
#include <boost/lexical_cast/bad_lexical_cast.hpp>
#include <boost/lexical_cast/detail/widest_char.hpp>
@@ -115,7 +118,7 @@ namespace boost {
template<typename InputStreamable>
bool operator>>(InputStreamable &output)
{
return !is_pointer<InputStreamable>::value &&
return !std::is_pointer<InputStreamable>::value &&
stream >> output &&
stream.get() == traits_type::eof();
}
+13 -11
View File
@@ -4,7 +4,7 @@
//
// Copyright Terje Sletteb and Kevlin Henney, 2005.
// Copyright Alexander Nasonov, 2006.
// Copyright Antony Polukhin, 2011-2024.
// Copyright Antony Polukhin, 2011-2026.
//
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
@@ -19,8 +19,6 @@
//
#define _SCL_SECURE_NO_WARNINGS
#include <boost/lexical_cast.hpp>
#include <boost/cstdint.hpp>
#include <boost/core/lightweight_test.hpp>
@@ -31,6 +29,8 @@
#include <algorithm> // std::transform
#include <memory>
#include <boost/lexical_cast.hpp>
#if (defined(BOOST_HAS_LONG_LONG) || defined(BOOST_HAS_MS_INT64)) \
&& !(defined(BOOST_MSVC) && BOOST_MSVC < 1300)
#define LCAST_TEST_LONGLONG
@@ -523,21 +523,27 @@ void operators_overload_test()
}
#if !defined(BOOST_NO_CXX11_CHAR16_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS)
void test_char16_conversions()
{
// There's no std::ctype<char16_t> in Xcode_15.0.1
#if !defined(BOOST_NO_CXX11_CHAR16_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS) && !defined(__APPLE__)
BOOST_TEST(u"100" == lexical_cast<std::u16string>(u"100"));
#if !defined(_LIBCPP_VERSION) // libc++ also does not have std::ctype<char16_t>
BOOST_TEST(u"1" == lexical_cast<std::u16string>(u'1'));
}
#endif
#endif
}
#if !defined(BOOST_NO_CXX11_CHAR16_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS)
void test_char32_conversions()
{
// There's no std::ctype<char32_t> in Xcode_15.0.1
#if !defined(BOOST_NO_CXX11_CHAR32_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS) && !defined(__APPLE__)
BOOST_TEST(U"100" == lexical_cast<std::u32string>(U"100"));
#if !defined(_LIBCPP_VERSION) // libc++ also does not have std::ctype<char32_t>
BOOST_TEST(U"1" == lexical_cast<std::u32string>(U'1'));
}
#endif
#endif
}
void test_getting_pointer_to_function()
{
@@ -585,12 +591,8 @@ int main()
test_char_types_conversions();
operators_overload_test();
#if !defined(BOOST_NO_CXX11_CHAR16_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS)
test_char16_conversions();
#endif
#if !defined(BOOST_NO_CXX11_CHAR32_T) && !defined(BOOST_NO_CXX11_UNICODE_LITERALS)
test_char32_conversions();
#endif
test_getting_pointer_to_function();
return boost::report_errors();
+3 -3
View File
@@ -3,7 +3,7 @@
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Alexander Nasonov, 2006.
// Copyright Antony Polukhin, 2023-2024.
// Copyright Antony Polukhin, 2023-2026.
//
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
@@ -12,10 +12,10 @@
// Test round-tripping conversion FPT -> string -> FPT,
// where FPT is Floating Point Type.
#include <boost/lexical_cast.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/lexical_cast.hpp>
#if (defined(__CYGWIN__) || defined(__FreeBSD__) || defined(__NetBSD__) \
|| (defined(__hppa) && !defined(__OpenBSD__)) || (defined(__NO_LONG_DOUBLE_MATH) && (DBL_MANT_DIG != LDBL_MANT_DIG))) \
|| defined(__MINGW64__)
+6 -2
View File
@@ -2,7 +2,7 @@
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Antony Polukhin, 2012-2024.
// Copyright Antony Polukhin, 2012-2026.
//
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
@@ -16,12 +16,16 @@
#pragma warning(disable: 4097 4100 4121 4127 4146 4244 4245 4511 4512 4701 4800)
#endif
#include <boost/lexical_cast.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/range/iterator_range.hpp>
#include <cstdlib>
#if defined(BOOST_USE_MODULES)
#undef BOOST_USE_MODULES
#endif
#include <boost/lexical_cast.hpp>
#include "escape_struct.hpp"
#ifndef BOOST_NO_EXCEPTIONS
+3 -3
View File
@@ -2,14 +2,12 @@
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Antony Polukhin, 2012-2024.
// Copyright Antony Polukhin, 2012-2026.
//
// 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).
#include <boost/lexical_cast.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/range/iterator_range.hpp>
@@ -17,6 +15,8 @@
#include <vector>
#include <boost/lexical_cast.hpp>
using namespace boost;
// Testing compilation and some basic usage with BOOST_NO_STD_LOCALE
+3 -2
View File
@@ -3,7 +3,7 @@
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Alexander Nasonov, 2007.
// Copyright Antony Polukhin, 2023-2024.
// Copyright Antony Polukhin, 2023-2026.
//
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
@@ -11,11 +11,12 @@
//
// Test that Source can be non-copyable.
#include <boost/lexical_cast.hpp>
#include <boost/core/noncopyable.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/lexical_cast.hpp>
class Noncopyable : private boost::noncopyable
{
public:
+5 -3
View File
@@ -2,16 +2,18 @@
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Antony Polukhin, 2012-2024.
// Copyright Antony Polukhin, 2012-2026.
//
// 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).
#include <boost/lexical_cast.hpp>
#include <boost/core/lightweight_test.hpp>
#include <sstream>
#include <boost/lexical_cast.hpp>
#if defined(BOOST_NO_STRINGSTREAM)
typedef std::strstream ss_t;
#else
+12 -11
View File
@@ -2,17 +2,18 @@
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Antony Polukhin, 2011-2024.
// Copyright Antony Polukhin, 2011-2026.
//
// 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).
#include <boost/lexical_cast.hpp>
#include <boost/core/lightweight_test.hpp>
#include <iostream>
#include <type_traits>
#include <boost/lexical_cast.hpp>
///////////////////////// char streamable classes ///////////////////////////////////////////
@@ -28,12 +29,12 @@ std::istream& operator >> (std::istream& istr, const streamable_easy&) {
struct streamable_medium { enum ENU {value = 1}; };
template <class CharT>
typename boost::enable_if<boost::is_same<CharT, char>, std::basic_ostream<CharT>&>::type
typename std::enable_if<std::is_same<CharT, char>::value, std::basic_ostream<CharT>&>::type
operator << (std::basic_ostream<CharT>& ostr, const streamable_medium&) {
return ostr << streamable_medium::value;
}
template <class CharT>
typename boost::enable_if<boost::is_same<CharT, char>, std::basic_istream<CharT>&>::type
typename std::enable_if<std::is_same<CharT, char>::value, std::basic_istream<CharT>&>::type
operator >> (std::basic_istream<CharT>& istr, const streamable_medium&) {
int i; istr >> i; BOOST_TEST_EQ(i, streamable_medium::value);
return istr;
@@ -41,12 +42,12 @@ operator >> (std::basic_istream<CharT>& istr, const streamable_medium&) {
struct streamable_hard { enum ENU {value = 2}; };
template <class CharT, class TraitsT>
typename boost::enable_if<boost::is_same<CharT, char>, std::basic_ostream<CharT, TraitsT>&>::type
typename std::enable_if<std::is_same<CharT, char>::value, std::basic_ostream<CharT, TraitsT>&>::type
operator << (std::basic_ostream<CharT, TraitsT>& ostr, const streamable_hard&) {
return ostr << streamable_hard::value;
}
template <class CharT, class TraitsT>
typename boost::enable_if<boost::is_same<CharT, char>, std::basic_istream<CharT, TraitsT>&>::type
typename std::enable_if<std::is_same<CharT, char>::value, std::basic_istream<CharT, TraitsT>&>::type
operator >> (std::basic_istream<CharT, TraitsT>& istr, const streamable_hard&) {
int i; istr >> i; BOOST_TEST_EQ(i, streamable_hard::value);
return istr;
@@ -77,12 +78,12 @@ std::wistream& operator >> (std::wistream& istr, const wstreamable_easy&) {
struct wstreamable_medium { enum ENU {value = 5}; };
template <class CharT>
typename boost::enable_if<boost::is_same<CharT, wchar_t>, std::basic_ostream<CharT>& >::type
typename std::enable_if<std::is_same<CharT, wchar_t>::value, std::basic_ostream<CharT>& >::type
operator << (std::basic_ostream<CharT>& ostr, const wstreamable_medium&) {
return ostr << wstreamable_medium::value;
}
template <class CharT>
typename boost::enable_if<boost::is_same<CharT, wchar_t>, std::basic_istream<CharT>& >::type
typename std::enable_if<std::is_same<CharT, wchar_t>::value, std::basic_istream<CharT>& >::type
operator >> (std::basic_istream<CharT>& istr, const wstreamable_medium&) {
int i; istr >> i; BOOST_TEST_EQ(i, wstreamable_medium::value);
return istr;
@@ -90,12 +91,12 @@ operator >> (std::basic_istream<CharT>& istr, const wstreamable_medium&) {
struct wstreamable_hard { enum ENU {value = 6}; };
template <class CharT, class TraitsT>
typename boost::enable_if<boost::is_same<CharT, wchar_t>, std::basic_ostream<CharT, TraitsT>&>::type
typename std::enable_if<std::is_same<CharT, wchar_t>::value, std::basic_ostream<CharT, TraitsT>&>::type
operator << (std::basic_ostream<CharT, TraitsT>& ostr, const wstreamable_hard&) {
return ostr << wstreamable_hard::value;
}
template <class CharT, class TraitsT>
typename boost::enable_if<boost::is_same<CharT, wchar_t>, std::basic_istream<CharT, TraitsT>&>::type
typename std::enable_if<std::is_same<CharT, wchar_t>::value, std::basic_istream<CharT, TraitsT>&>::type
operator >> (std::basic_istream<CharT, TraitsT>& istr, const wstreamable_hard&) {
int i; istr >> i; BOOST_TEST_EQ(i, wstreamable_hard::value);
return istr;
+26 -21
View File
@@ -1,9 +1,12 @@
// Copyright Antony Polukhin, 2012-2024.
// Copyright Antony Polukhin, 2012-2026.
//
// 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).
#if defined(BOOST_USE_MODULES)
#undef BOOST_USE_MODULES
#endif
#include <boost/lexical_cast/detail/converter_lexical.hpp>
#include <boost/core/lightweight_test.hpp>
@@ -13,11 +16,13 @@
#include <boost/range/iterator_range.hpp>
#include <boost/utility/string_view.hpp>
#include <type_traits>
template <class T>
struct is_optimized_stream : boost::false_type {};
struct is_optimized_stream : std::false_type {};
template <class CharT, class Traits, std::size_t CharacterBufferSize>
struct is_optimized_stream< boost::detail::lcast::optimized_src_stream<CharT, Traits, CharacterBufferSize> > : boost::true_type {};
struct is_optimized_stream< boost::detail::lcast::optimized_src_stream<CharT, Traits, CharacterBufferSize> > : std::true_type {};
template <class Source, class Target>
static void assert_optimized_stream()
@@ -32,21 +37,21 @@ static void test_optimized_types_to_string_const()
{
namespace de = boost::detail;
typedef de::lexical_cast_stream_traits<T, std::string> trait_1;
BOOST_TEST((boost::is_same<typename trait_1::src_char_t, char>::value));
BOOST_TEST((boost::is_same<typename trait_1::target_char_t, char>::value));
BOOST_TEST((boost::is_same<typename trait_1::char_type, char>::value));
BOOST_TEST((std::is_same<typename trait_1::src_char_t, char>::value));
BOOST_TEST((std::is_same<typename trait_1::target_char_t, char>::value));
BOOST_TEST((std::is_same<typename trait_1::char_type, char>::value));
assert_optimized_stream<T, std::string>();
assert_optimized_stream<T, boost::container::string>();
typedef de::lexical_cast_stream_traits<const T, std::string> trait_2;
BOOST_TEST((boost::is_same<typename trait_2::src_char_t, char>::value));
BOOST_TEST((boost::is_same<typename trait_2::target_char_t, char>::value));
BOOST_TEST((boost::is_same<typename trait_2::char_type, char>::value));
BOOST_TEST((std::is_same<typename trait_2::src_char_t, char>::value));
BOOST_TEST((std::is_same<typename trait_2::target_char_t, char>::value));
BOOST_TEST((std::is_same<typename trait_2::char_type, char>::value));
typedef de::lexical_cast_stream_traits<T, std::wstring> trait_3;
BOOST_TEST((boost::is_same<typename trait_3::src_char_t, char>::value));
BOOST_TEST((boost::is_same<typename trait_3::target_char_t, wchar_t>::value));
BOOST_TEST((boost::is_same<typename trait_3::char_type, wchar_t>::value));
BOOST_TEST((std::is_same<typename trait_3::src_char_t, char>::value));
BOOST_TEST((std::is_same<typename trait_3::target_char_t, wchar_t>::value));
BOOST_TEST((std::is_same<typename trait_3::char_type, wchar_t>::value));
assert_optimized_stream<T, std::wstring>();
assert_optimized_stream<T, boost::container::wstring>();
}
@@ -59,20 +64,20 @@ static void test_optimized_types_to_string()
namespace de = boost::detail;
typedef de::lexical_cast_stream_traits<std::string, T> trait_4;
BOOST_TEST((boost::is_same<typename trait_4::src_char_t, char>::value));
BOOST_TEST((boost::is_same<typename trait_4::target_char_t, char>::value));
BOOST_TEST((boost::is_same<typename trait_4::char_type, char>::value));
BOOST_TEST((std::is_same<typename trait_4::src_char_t, char>::value));
BOOST_TEST((std::is_same<typename trait_4::target_char_t, char>::value));
BOOST_TEST((std::is_same<typename trait_4::char_type, char>::value));
assert_optimized_stream<std::string, T>();
typedef de::lexical_cast_stream_traits<const std::string, T> trait_5;
BOOST_TEST((boost::is_same<typename trait_5::src_char_t, char>::value));
BOOST_TEST((boost::is_same<typename trait_5::target_char_t, char>::value));
BOOST_TEST((boost::is_same<typename trait_5::char_type, char>::value));
BOOST_TEST((std::is_same<typename trait_5::src_char_t, char>::value));
BOOST_TEST((std::is_same<typename trait_5::target_char_t, char>::value));
BOOST_TEST((std::is_same<typename trait_5::char_type, char>::value));
typedef de::lexical_cast_stream_traits<const std::wstring, T> trait_6;
BOOST_TEST((boost::is_same<typename trait_6::src_char_t, wchar_t>::value));
BOOST_TEST((boost::is_same<typename trait_6::target_char_t, char>::value));
BOOST_TEST((boost::is_same<typename trait_6::char_type, wchar_t>::value));
BOOST_TEST((std::is_same<typename trait_6::src_char_t, wchar_t>::value));
BOOST_TEST((std::is_same<typename trait_6::target_char_t, char>::value));
BOOST_TEST((std::is_same<typename trait_6::char_type, wchar_t>::value));
}
+22 -10
View File
@@ -2,15 +2,13 @@
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Antony Polukhin, 2012-2024.
// Copyright Antony Polukhin, 2012-2026.
//
// 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).
#include <boost/lexical_cast.hpp>
#include <boost/utility/string_view.hpp>
#ifndef BOOST_NO_CXX17_HDR_STRING_VIEW
@@ -19,18 +17,32 @@
#include <boost/core/lightweight_test.hpp>
using namespace boost;
#include <boost/lexical_cast.hpp>
template <class StringView>
void test_string_view_conversion() {
using boost::lexical_cast;
StringView sw = "1";
BOOST_TEST_EQ(lexical_cast<std::string>(sw), "1");
BOOST_TEST_EQ(lexical_cast<int>(sw), 1);
sw = StringView("a\0b", 3);
BOOST_TEST_EQ(lexical_cast<std::string>(sw), std::string("a\0b", 3));
sw = StringView("a\0b", 4);
BOOST_TEST_EQ(lexical_cast<std::string>(sw), std::string("a\0b", 4));
sw = StringView("\0a\0", 3);
BOOST_TEST_EQ(lexical_cast<std::string>(sw), std::string("\0a\0", 3));
}
int main() {
boost::string_view bsw = "1";
BOOST_TEST_EQ(lexical_cast<std::string>(bsw), "1");
BOOST_TEST_EQ(lexical_cast<int>(bsw), 1);
test_string_view_conversion<boost::string_view>();
#ifndef BOOST_NO_CXX17_HDR_STRING_VIEW
std::string_view ssw = "42";
BOOST_TEST_EQ(lexical_cast<std::string>(ssw), "42");
BOOST_TEST_EQ(lexical_cast<int>(ssw), 42);
test_string_view_conversion<std::string_view>();
#endif
return boost::report_errors();
+1 -1
View File
@@ -2,7 +2,7 @@
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Antony Polukhin, 2013-2024.
// Copyright Antony Polukhin, 2013-2026.
//
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
+3 -3
View File
@@ -2,16 +2,16 @@
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Antony Polukhin, 2014-2024.
// Copyright Antony Polukhin, 2014-2026.
//
// 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).
#include <boost/lexical_cast/try_lexical_convert.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/lexical_cast/try_lexical_convert.hpp>
using namespace boost::conversion;
void try_uncommon_cases()
+1 -1
View File
@@ -2,7 +2,7 @@
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Antony Polukhin, 2011-2024.
// Copyright Antony Polukhin, 2011-2026.
//
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
+14 -1
View File
@@ -2,7 +2,7 @@
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Antony Polukhin, 2011-2024.
// Copyright Antony Polukhin, 2011-2026.
//
// Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
@@ -32,9 +32,22 @@ void test_typedefed_wchar_t_runtime()
test_typedefed_wchar_t(L'0');
}
void test_unsigned_short_to_wstring()
{
// Test case from https://github.com/boostorg/lexical_cast/issues/89
unsigned short number = 4550;
auto res1 = boost::lexical_cast<std::wstring>(number);
BOOST_TEST(res1 == L"4550");
auto res2 = boost::lexical_cast<std::string>(number);
BOOST_TEST_EQ(res2, "4550");
}
int main()
{
test_typedefed_wchar_t_runtime();
test_unsigned_short_to_wstring();
return boost::report_errors();
}
+3 -1
View File
@@ -12,12 +12,14 @@
// implementation has changed and it does not use stringstream for casts
// to integral types
#include <boost/lexical_cast.hpp>
#include <boost/cstdint.hpp>
#include <boost/core/lightweight_test.hpp>
#include <string>
#include <sstream>
#include <boost/lexical_cast.hpp>
#ifdef BOOST_MSVC
# pragma warning(disable: 4127) // conditional expression is constant
+7 -2
View File
@@ -2,15 +2,20 @@
//
// See http://www.boost.org for most recent version, including documentation.
//
// Copyright Antony Polukhin, 2011-2024.
// Copyright Antony Polukhin, 2011-2026.
//
// 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).
#include <boost/core/lightweight_test.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/core/lightweight_test.hpp>
#if defined(BOOST_USE_MODULES)
#undef BOOST_USE_MODULES
#endif
#include <boost/lexical_cast/detail/lcast_char_constants.hpp>
#if defined(BOOST_NO_STRINGSTREAM) || defined(BOOST_NO_STD_WSTRING)
#define BOOST_LCAST_NO_WCHAR_T