mirror of
https://github.com/boostorg/lexical_cast.git
synced 2026-01-19 04:22:08 +00:00
Implement initial version of C++20 module boost.lexical_cast (#84)
This commit is contained in:
61
.github/workflows/ci.yml
vendored
61
.github/workflows/ci.yml
vendored
@@ -37,6 +37,10 @@ jobs:
|
||||
- toolset: clang
|
||||
cxxstd: "11,14,17,20"
|
||||
os: macos-13
|
||||
- toolset: clang-19
|
||||
cxxstd: "20,23"
|
||||
os: ubuntu-24.04
|
||||
install: clang-19 llvm-19 libclang-rt-19-dev libc++-19-dev libc++abi-19-dev clang-tools-19
|
||||
|
||||
runs-on: ${{matrix.os}}
|
||||
|
||||
@@ -70,6 +74,32 @@ jobs:
|
||||
python tools/boostdep/depinst/depinst.py --include benchmark --include example --include examples --include tools --git_args "--depth 10 --jobs 3" $LIBRARY
|
||||
./bootstrap.sh
|
||||
./b2 -j4 variant=debug tools/inspect
|
||||
- name: Run modules tests wihtout 'import std;'
|
||||
|
||||
|
||||
if: ${{matrix.toolset == 'clang-19'}}
|
||||
run: |
|
||||
cd ../boost-root/libs/lexical_cast
|
||||
mkdir build_module
|
||||
cd build_module
|
||||
cmake -DBOOST_USE_MODULES=1 -GNinja -DCMAKE_CXX_COMPILER=clang++-19 ../test/cmake_subdir_test/
|
||||
cmake --build .
|
||||
ctest -V
|
||||
cd ..
|
||||
rm -rf build_module
|
||||
|
||||
- name: Run modules tests
|
||||
if: false
|
||||
# if: ${{matrix.toolset == 'clang-19'}}
|
||||
run: |
|
||||
cd ../boost-root/libs/lexical_cast
|
||||
mkdir build_module
|
||||
cd build_module
|
||||
cmake -DBUILD_TESTING=1 -DBOOST_USE_MODULES=1 -DCMAKE_CXX_COMPILER=clang++-19 -DCMAKE_CXX_FLAGS=-stdlib=libc++ -DCMAKE_EXE_LINKER_FLAGS=-stdlib=libc++ -DCMAKE_CXX_STANDARD=23 -DCMAKE_EXPERIMENTAL_CXX_IMPORT_STD=0e5b6991-d74f-4b3d-a41c-cf096e0b2508 -G Ninja ../test/cmake_subdir_test/
|
||||
cmake --build .
|
||||
ctest -V
|
||||
cd ..
|
||||
rm -rf build_module
|
||||
|
||||
- name: Run CMake tests
|
||||
if: ${{matrix.toolset == 'gcc-14'}}
|
||||
@@ -173,8 +203,35 @@ jobs:
|
||||
cmake -DBUILD_TESTING=1 -DBOOST_INCLUDE_LIBRARIES=lexical_cast ..
|
||||
cmake --build . --target tests --config Debug
|
||||
ctest --output-on-failure --no-tests=error -C Debug
|
||||
cd ..
|
||||
rm -rf __build
|
||||
|
||||
- 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 wihtout '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
|
||||
|
||||
@@ -3,23 +3,43 @@
|
||||
# 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 awailable")
|
||||
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::throw_exception
|
||||
)
|
||||
|
||||
add_library(Boost::lexical_cast ALIAS boost_lexical_cast)
|
||||
|
||||
if(BUILD_TESTING)
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
|
||||
@@ -233,8 +233,45 @@ limitation of compiler options that you use.
|
||||
|
||||
[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`
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
22
include/boost/lexical_cast/detail/config.hpp
Normal file
22
include/boost/lexical_cast/detail/config.hpp
Normal file
@@ -0,0 +1,22 @@
|
||||
// Copyright Antony Polukhin, 2021-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_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
|
||||
@@ -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,15 +32,11 @@
|
||||
#define BOOST_LCAST_NO_WCHAR_T
|
||||
#endif
|
||||
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <boost/limits.hpp>
|
||||
#include <boost/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/type_traits.hpp>
|
||||
|
||||
#include <array>
|
||||
|
||||
@@ -43,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 {
|
||||
@@ -479,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
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -33,9 +37,8 @@
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <type_traits>
|
||||
|
||||
#include <boost/limits.hpp>
|
||||
#include <boost/detail/lcast_precision.hpp>
|
||||
#include <boost/lexical_cast/detail/type_traits.hpp>
|
||||
#include <boost/config/workaround.hpp>
|
||||
#include <boost/core/snprintf.hpp>
|
||||
|
||||
@@ -58,21 +61,28 @@
|
||||
#include <sstream>
|
||||
#endif
|
||||
|
||||
#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>
|
||||
#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 <boost/lexical_cast/detail/lcast_precision.hpp>
|
||||
#include <boost/lexical_cast/detail/type_traits.hpp>
|
||||
|
||||
// Forward declarations
|
||||
namespace boost {
|
||||
template<class T, std::size_t N>
|
||||
@@ -747,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
|
||||
|
||||
|
||||
@@ -18,6 +18,11 @@
|
||||
#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
|
||||
@@ -26,6 +31,9 @@
|
||||
#include <type_traits>
|
||||
#include <boost/core/cmath.hpp>
|
||||
#include <boost/limits.hpp>
|
||||
|
||||
#endif // #ifndef BOOST_LEXICAL_CAST_INTERFACE_UNIT
|
||||
|
||||
#include <boost/lexical_cast/detail/type_traits.hpp>
|
||||
|
||||
namespace boost { namespace detail {
|
||||
@@ -176,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
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -32,6 +37,7 @@
|
||||
#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
|
||||
|
||||
|
||||
@@ -18,13 +18,20 @@
|
||||
#ifndef BOOST_LEXICAL_CAST_DETAIL_IS_CHARACTER_HPP
|
||||
#define BOOST_LEXICAL_CAST_DETAIL_IS_CHARACTER_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#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>
|
||||
|
||||
#endif // #ifndef BOOST_LEXICAL_CAST_INTERFACE_UNIT
|
||||
|
||||
namespace boost { namespace detail {
|
||||
|
||||
// returns true, if T is one of the character types
|
||||
@@ -47,5 +54,7 @@ using is_character = std::integral_constant<
|
||||
|
||||
}}
|
||||
|
||||
#endif // #if !defined(BOOST_USE_MODULES) || defined(BOOST_LEXICAL_CAST_INTERFACE_UNIT)
|
||||
|
||||
#endif // BOOST_LEXICAL_CAST_DETAIL_IS_CHARACTER_HPP
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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,11 +8,21 @@
|
||||
#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>
|
||||
#endif // #ifndef BOOST_LEXICAL_CAST_INTERFACE_UNIT
|
||||
|
||||
namespace boost { namespace detail {
|
||||
|
||||
@@ -79,5 +89,7 @@ inline void lcast_set_precision(std::ios_base& stream, Source*, Target*)
|
||||
|
||||
}}
|
||||
|
||||
#endif // #if !defined(BOOST_USE_MODULES) || defined(BOOST_LEXICAL_CAST_INTERFACE_UNIT)
|
||||
|
||||
#endif // BOOST_DETAIL_LCAST_PRECISION_HPP_INCLUDED
|
||||
|
||||
@@ -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
|
||||
@@ -49,6 +54,9 @@
|
||||
|
||||
#include <boost/lexical_cast/detail/lcast_char_constants.hpp>
|
||||
#include <boost/core/noncopyable.hpp>
|
||||
#endif // #ifndef BOOST_LEXICAL_CAST_INTERFACE_UNIT
|
||||
|
||||
#include <boost/lexical_cast/detail/lcast_char_constants.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
@@ -294,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
|
||||
|
||||
|
||||
@@ -18,13 +18,19 @@
|
||||
#ifndef BOOST_LEXICAL_CAST_DETAIL_WIDEST_CHAR_HPP
|
||||
#define BOOST_LEXICAL_CAST_DETAIL_WIDEST_CHAR_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#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>
|
||||
|
||||
#endif // #ifndef BOOST_LEXICAL_CAST_INTERFACE_UNIT
|
||||
|
||||
namespace boost { namespace detail {
|
||||
|
||||
@@ -37,5 +43,7 @@ using widest_char = std::conditional<
|
||||
|
||||
}} // namespace boost::detail
|
||||
|
||||
#endif // #if !defined(BOOST_USE_MODULES) || defined(BOOST_LEXICAL_CAST_INTERFACE_UNIT)
|
||||
|
||||
#endif // BOOST_LEXICAL_CAST_DETAIL_WIDEST_CHAR_HPP
|
||||
|
||||
|
||||
@@ -18,13 +18,19 @@
|
||||
#ifndef BOOST_LEXICAL_CAST_TRY_LEXICAL_CONVERT_HPP
|
||||
#define BOOST_LEXICAL_CAST_TRY_LEXICAL_CONVERT_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#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>
|
||||
#endif
|
||||
|
||||
#include <boost/lexical_cast/detail/buffer_view.hpp>
|
||||
#include <boost/lexical_cast/detail/is_character.hpp>
|
||||
#include <boost/lexical_cast/detail/converter_numeric.hpp>
|
||||
@@ -45,6 +51,8 @@ namespace boost {
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -78,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
modules/boost_lexical_cast.cppm
Normal file
57
modules/boost_lexical_cast.cppm
Normal 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
modules/usage_sample.cpp
Normal file
16
modules/usage_sample.cpp
Normal 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");
|
||||
}
|
||||
//]
|
||||
|
||||
53
test/cmake_subdir_test/CMakeLists.txt
Normal file
53
test/cmake_subdir_test/CMakeLists.txt
Normal file
@@ -0,0 +1,53 @@
|
||||
# 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
|
||||
|
||||
cmake_minimum_required(VERSION 3.5...4.0)
|
||||
|
||||
project(lexical_cast_subdir_test LANGUAGES CXX)
|
||||
|
||||
add_subdirectory(../../../assert boostorg/assert)
|
||||
add_subdirectory(../../../core boostorg/core)
|
||||
add_subdirectory(../../../config boostorg/config)
|
||||
add_subdirectory(../../../container boostorg/container)
|
||||
add_subdirectory(../../../container_hash boostorg/container_hash)
|
||||
add_subdirectory(../../../detail boostorg/detail)
|
||||
add_subdirectory(../../../intrusive boostorg/intrusive)
|
||||
add_subdirectory(../../../move boostorg/move)
|
||||
add_subdirectory(../../../static_assert boostorg/static_assert)
|
||||
add_subdirectory(../../../throw_exception boostorg/throw_exception)
|
||||
add_subdirectory(../../../type_traits boostorg/type_traits)
|
||||
|
||||
add_subdirectory(../../ boostorg/lexical_cast)
|
||||
|
||||
enable_testing()
|
||||
|
||||
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()
|
||||
|
||||
list(APPEND RUN_TESTS_SOURCES
|
||||
lexical_cast_test.cpp
|
||||
loopback_test.cpp
|
||||
abstract_test.cpp
|
||||
noncopyable_test.cpp
|
||||
vc8_bug_test.cpp
|
||||
implicit_convert.cpp
|
||||
float_types_test.cpp
|
||||
inf_nan_test.cpp
|
||||
containers_test.cpp
|
||||
pointers_test.cpp
|
||||
integral_types_test.cpp
|
||||
stream_detection_test.cpp
|
||||
try_lexical_convert.cpp
|
||||
)
|
||||
|
||||
foreach (testsourcefile ${RUN_TESTS_SOURCES})
|
||||
get_filename_component(testname ${testsourcefile} NAME_WLE)
|
||||
add_executable(${PROJECT_NAME}_${testname} ../${testsourcefile})
|
||||
target_link_libraries(${PROJECT_NAME}_${testname} Boost::lexical_cast Boost::type_traits Boost::core)
|
||||
add_test(NAME ${PROJECT_NAME}_${testname} COMMAND ${PROJECT_NAME}_${testname})
|
||||
endforeach()
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "lexical_cast_old.hpp"
|
||||
#endif
|
||||
|
||||
#include <sstream>
|
||||
#include <type_traits>
|
||||
|
||||
#include <boost/cstdint.hpp>
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
#include <boost/type_traits/integral_promotion.hpp>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
#include <cstdio>
|
||||
#include <type_traits>
|
||||
#include <boost/limits.hpp>
|
||||
#include <boost/detail/lcast_precision.hpp>
|
||||
#include <boost/config/workaround.hpp>
|
||||
|
||||
#ifdef BOOST_NO_STRINGSTREAM
|
||||
@@ -43,6 +42,7 @@
|
||||
#include <sstream>
|
||||
#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>
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#if defined(BOOST_NO_STRINGSTREAM)
|
||||
typedef std::strstream ss_t;
|
||||
#else
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
# pragma warning(disable: 4127) // conditional expression is constant
|
||||
|
||||
Reference in New Issue
Block a user