Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 35 additions & 26 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
- 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
Expand All @@ -40,6 +41,7 @@ jobs:
- 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}}
Expand Down Expand Up @@ -74,43 +76,50 @@ 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;'


- name: Run modules tests without '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 ..
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: false
# if: ${{matrix.toolset == 'clang-19'}}
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 ..
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'}}
if: ${{matrix.toolset == 'gcc-14' || matrix.toolset == 'clang-19'}}
run: |
cd ../boost-root/
mkdir __build
cd __build
cmake -DBUILD_TESTING=1 -DBOOST_INCLUDE_LIBRARIES=lexical_cast -DCMAKE_CXX_COMPILER=g++-14 -DCMAKE_C_COMPILER=gcc-14 ..
cmake --build . --target tests
ctest --output-on-failure --no-tests=error
cd ..
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
Expand Down Expand Up @@ -187,7 +196,7 @@ 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

Expand All @@ -200,7 +209,7 @@ jobs:
cd ../boost-root/
mkdir __build
cd __build
cmake -DBUILD_TESTING=1 -DBOOST_INCLUDE_LIBRARIES=lexical_cast ..
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

Expand All @@ -219,7 +228,7 @@ jobs:
cmake --build .
ctest --no-tests=error -V

- name: Run modules tests wihtout 'import std;'
- name: Run modules tests without 'import std;'
if: ${{matrix.toolset == 'msvc-14.3'}}
shell: cmd
run: |
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if (BOOST_USE_MODULES)
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")
message(STATUS "`import std;` is not available")
endif()
set(__scope PUBLIC)
else()
Expand Down
3 changes: 2 additions & 1 deletion example/args_to_numbers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 6 additions & 4 deletions example/generic_stringize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
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 {
Expand All @@ -38,7 +44,6 @@ struct stringize_functor {
};

//` 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;
Expand All @@ -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") {
Expand Down
5 changes: 3 additions & 2 deletions example/small_examples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
// (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
Expand Down
6 changes: 5 additions & 1 deletion example/variant_to_long_double.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
98 changes: 58 additions & 40 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,64 +3,82 @@
# 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(BoostTest OPTIONAL RESULT_VARIABLE HAVE_BOOST_TEST)

if(NOT HAVE_BOOST_TEST)
return()
if(NOT TARGET tests)
add_custom_target(tests)
endif()

set(BOOST_TEST_LINK_LIBRARIES Boost::lexical_cast Boost::core)
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_test(TYPE run SOURCES lexical_cast_test.cpp LINK_LIBRARIES Boost::type_traits)
boost_test(TYPE run SOURCES loopback_test.cpp)
boost_test(TYPE run SOURCES abstract_test.cpp)
boost_test(TYPE run SOURCES noncopyable_test.cpp)
boost_test(TYPE run SOURCES vc8_bug_test.cpp)
boost_test(TYPE run SOURCES implicit_convert.cpp)
boost_test(TYPE run SOURCES wchars_test.cpp)
boost_test(TYPE run SOURCES float_types_test.cpp)
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_test(TYPE run SOURCES float_types_test.cpp COMPILE_DEFINITIONS BOOST_LEXICAL_CAST_DETAIL_TEST_ON_OLD NAME float_types_non_opt)
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_test(TYPE run SOURCES inf_nan_test.cpp)
boost_test(TYPE run SOURCES containers_test.cpp)
boost_test(TYPE run SOURCES empty_input_test.cpp LINK_LIBRARIES Boost::range)
boost_test(TYPE run SOURCES pointers_test.cpp)
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)
boost_test(TYPE compile SOURCES typedefed_wchar_test.cpp COMPILE_OPTIONS "/Zc:wchar_t-")
boost_test(TYPE run SOURCES typedefed_wchar_test_runtime.cpp COMPILE_OPTIONS "/Zc:wchar_t-")
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_test(TYPE run SOURCES no_locale_test.cpp
COMPILE_DEFINITIONS BOOST_NO_STD_LOCALE BOOST_LEXICAL_CAST_ASSUME_C_LOCALE
LINK_LIBRARIES Boost::range
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_test(TYPE run SOURCES no_exceptions_test.cpp
COMPILE_OPTIONS "-fno-exceptions"
COMPILE_DEFINITIONS
_HAS_EXCEPTIONS=0 # MSVC stdlib
_STLP_NO_EXCEPTIONS # STLPort
LINK_LIBRARIES Boost::range
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_test(TYPE run SOURCES iterator_range_test.cpp LINK_LIBRARIES Boost::range)
boost_test(TYPE run SOURCES string_view_test.cpp LINK_LIBRARIES Boost::utility)
boost_test(TYPE run SOURCES arrays_test.cpp LINK_LIBRARIES Boost::array)
boost_test(TYPE run SOURCES integral_types_test.cpp LINK_LIBRARIES Boost::type_traits)
boost_test(TYPE run SOURCES stream_detection_test.cpp)
boost_test(TYPE run SOURCES stream_traits_test.cpp LINK_LIBRARIES Boost::array Boost::range Boost::utility)
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_test(TYPE compile-fail SOURCES to_pointer_test.cpp)
boost_test(TYPE compile-fail SOURCES from_volatile.cpp)
boost_test(TYPE run SOURCES filesystem_test.cpp LINK_LIBRARIES Boost::filesystem)
boost_test(TYPE run SOURCES try_lexical_convert.cpp)
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})
boost_test(TYPE run SOURCES ${testsourcefile} LINK_LIBRARIES Boost::variant Boost::date_time)
get_filename_component(testname ${testsourcefile} NAME_WE)
boost_lexical_cast_add_test_impl(lexical_cast_example_${testname} ${testsourcefile} "Boost::variant;Boost::date_time")
endforeach()
4 changes: 2 additions & 2 deletions test/abstract_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 9 additions & 4 deletions test/arrays_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
// 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)
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
Loading
Loading