Skip to content
Closed
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
390 changes: 389 additions & 1 deletion .github/workflows/ci.yml

Large diffs are not rendered by default.

29 changes: 26 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,40 @@
# Distributed under the Boost Software License, Version 1.0.
# https://www.boost.org/LICENSE_1_0.txt

cmake_minimum_required(VERSION 3.8...3.20)
cmake_minimum_required(VERSION 3.8...3.31)

project(boost_charconv VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)

# We can't make source files conditionally module units.
# In module builds, use cc files that include their respective cpp, plus the module infrastructure
if (BOOST_USE_MODULES)
set(SOURCE_SUFFIX "cc")
else()
set(SOURCE_SUFFIX "cpp")
endif()

add_library(boost_charconv
src/from_chars.cpp
src/to_chars.cpp
src/from_chars.${SOURCE_SUFFIX}
src/to_chars.${SOURCE_SUFFIX}
)

add_library(Boost::charconv ALIAS boost_charconv)

if (BOOST_USE_MODULES)
target_sources(boost_charconv
PUBLIC FILE_SET CXX_MODULES BASE_DIRS modules FILES
modules/boost_charconv.cppm
modules/boost_charconv_interface.cppm
PRIVATE FILE_SET helpers TYPE CXX_MODULES BASE_DIRS src FILES
src/helpers.cppm
)

# Enable and propagate C++23, import std, and the modules macro
target_compile_features(boost_charconv PUBLIC cxx_std_23)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried this with C++20 instead of 23? I know officially import std and import std.compat are C++23, but all of the compiler implementors have said they'll allow it at 20.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think there's a use to it? My understanding was that using C++20 over C++23 is about being able to use older compilers that might not support C++23. Such compilers won't have proper module implementations, likely, since modules are quite behind everything else.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Standards like MISRA are pinned to language standards not toolchains. Theoretically someone could have a modern compiler but be stuck at C++20. Probably best to have someone in the real world complain before changing it.

set_target_properties(boost_charconv PROPERTIES CXX_MODULE_STD 1)
target_compile_definitions(boost_charconv PUBLIC BOOST_USE_MODULES)
endif()

target_include_directories(boost_charconv PUBLIC include)


Expand Down
17 changes: 16 additions & 1 deletion include/boost/charconv/chars_format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,24 @@
#ifndef BOOST_CHARCONV_CHARS_FORMAT_HPP
#define BOOST_CHARCONV_CHARS_FORMAT_HPP

#if defined(BOOST_USE_MODULES) && !defined(BOOST_CHARCONV_INTERFACE_UNIT)

#ifndef BOOST_IN_MODULE_PURVIEW
import boost.charconv;
#ifndef BOOST_CHARCONV_CONSTEXPR
#define BOOST_CHARCONV_CONSTEXPR constexpr
#endif
#endif

#else

#include <boost/charconv/config.hpp>

namespace boost { namespace charconv {

// Floating-point format for primitive numerical conversion
// chars_format is a bitmask type (16.3.3.3.3)
enum class chars_format : unsigned
BOOST_CHARCONV_MODULE_EXPORT enum class chars_format : unsigned
{
scientific = 1 << 0,
fixed = 1 << 1,
Expand All @@ -19,4 +32,6 @@ enum class chars_format : unsigned

}} // Namespaces

#endif // defined(BOOST_USE_MODULES) && !defined(BOOST_CHARCONV_INTERFACE_UNIT)

#endif // BOOST_CHARCONV_CHARS_FORMAT_HPP
14 changes: 13 additions & 1 deletion include/boost/charconv/config.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Make the header safe to include from libraries supporting modules
#if defined(BOOST_IN_MODULE_PURVIEW) && !defined(BOOST_CHARCONV_CONFIG_HPP_INCLUDED)
# error "Please #include <boost/charconv/config.hpp> in your module global fragment"
#endif

#ifndef BOOST_CHARCONV_CONFIG_HPP_INCLUDED
#define BOOST_CHARCONV_CONFIG_HPP_INCLUDED

Expand All @@ -7,7 +12,7 @@
// https://www.boost.org/LICENSE_1_0.txt

#include <boost/config.hpp>
#include <climits>
#include <boost/config/std/climits.hpp>

// This header implements separate compilation features as described in
// http://www.boost.org/more/separate_compilation.html
Expand Down Expand Up @@ -36,4 +41,11 @@

#endif

// Modules
#ifdef BOOST_USE_MODULES
# define BOOST_CHARCONV_MODULE_EXPORT export
#else
# define BOOST_CHARCONV_MODULE_EXPORT
#endif

#endif // BOOST_CHARCONV_CONFIG_HPP_INCLUDED
6 changes: 5 additions & 1 deletion include/boost/charconv/detail/apply_sign.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
#ifndef BOOST_CHARCONV_DETAIL_APPLY_SIGN_HPP
#define BOOST_CHARCONV_DETAIL_APPLY_SIGN_HPP

#if !defined(BOOST_USE_MODULES) || defined(BOOST_CHARCONV_INTERFACE_UNIT)

#include <boost/config.hpp>
#include <boost/charconv/detail/emulated128.hpp>
#include <boost/charconv/detail/type_traits.hpp>
#include <type_traits>
#include <boost/config/std/type_traits.hpp>

// We are purposefully converting values here
#ifdef BOOST_MSVC
Expand Down Expand Up @@ -47,4 +49,6 @@ constexpr Unsigned_Integer apply_sign(Unsigned_Integer val) noexcept
# pragma clang diagnostic pop
#endif

#endif // !defined(BOOST_USE_MODULES) || !defined(BOOST_CHARCONV_INTERFACE_UNIT)

#endif // BOOST_CHARCONV_DETAIL_APPLY_SIGN_HPP
23 changes: 9 additions & 14 deletions include/boost/charconv/detail/bit_layouts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
#ifndef BOOST_CHARCONV_DETAIL_BIT_LAYOUTS_HPP
#define BOOST_CHARCONV_DETAIL_BIT_LAYOUTS_HPP

#if !defined(BOOST_USE_MODULES) || defined(BOOST_CHARCONV_INTERFACE_UNIT)

#include <boost/charconv/detail/config.hpp>
#include <boost/charconv/detail/emulated128.hpp>
#include <cstdint>
#include <cfloat>
#include <boost/config/std/cstdint.hpp>
#include <boost/config/std/cfloat.hpp>

// Layouts of floating point types as specified by IEEE 754
// See page 23 of IEEE 754-2008
Expand Down Expand Up @@ -56,7 +58,7 @@ struct ieee754_binary64
};

// 80 bit long double (e.g. x86-64)
#if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
#if BOOST_CHARCONV_LDBL_BITS == 80

struct IEEEl2bits
{
Expand All @@ -83,10 +85,8 @@ struct ieee754_binary80
static constexpr int decimal_digits = 18;
};

#define BOOST_CHARCONV_LDBL_BITS 80

// 128 bit long double (e.g. s390x, ppcle64)
#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
#elif BOOST_CHARCONV_LDBL_BITS == 128

struct IEEEl2bits
{
Expand All @@ -103,10 +103,8 @@ struct IEEEl2bits
#endif
};

#define BOOST_CHARCONV_LDBL_BITS 128

// 64 bit long double (double == long double on ARM)
#elif LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
#elif BOOST_CHARCONV_LDBL_BITS == 64

struct IEEEl2bits
{
Expand All @@ -123,11 +121,6 @@ struct IEEEl2bits
#endif
};

#define BOOST_CHARCONV_LDBL_BITS 64

#else // Unsupported long double representation
# define BOOST_CHARCONV_UNSUPPORTED_LONG_DOUBLE
# define BOOST_CHARCONV_LDBL_BITS -1
#endif

struct IEEEbinary128
Expand Down Expand Up @@ -157,4 +150,6 @@ struct ieee754_binary128

}}} // Namespaces

#endif // !defined(BOOST_USE_MODULES) || !defined(BOOST_CHARCONV_INTERFACE_UNIT)

#endif // BOOST_CHARCONV_DETAIL_BIT_LAYOUTS_HPP
6 changes: 5 additions & 1 deletion include/boost/charconv/detail/buffer_sizing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
#ifndef BOOST_CHARCONV_DETAIL_BUFFER_SIZING_HPP
#define BOOST_CHARCONV_DETAIL_BUFFER_SIZING_HPP

#if !defined(BOOST_USE_MODULES) || defined(BOOST_CHARCONV_INTERNAL_PARTITION_UNIT)

#include <boost/charconv/detail/config.hpp>
#include <boost/charconv/detail/integer_search_trees.hpp>
#include <type_traits>
#include <boost/config/std/type_traits.hpp>

namespace boost {
namespace charconv {
Expand Down Expand Up @@ -69,4 +71,6 @@ inline int total_buffer_length(int real_precision, Int exp, bool signed_value)
} //namespace charconv
} //namespace boost

#endif // !defined(BOOST_USE_MODULES) || defined(BOOST_CHARCONV_INTERFACE_UNIT)

#endif //BOOST_CHARCONV_DETAIL_BUFFER_SIZING_HPP
10 changes: 7 additions & 3 deletions include/boost/charconv/detail/compute_float32.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
#ifndef BOOST_CHARCONV_DETAIL_COMPUTE_FLOAT32_HPP
#define BOOST_CHARCONV_DETAIL_COMPUTE_FLOAT32_HPP

#if !defined(BOOST_USE_MODULES) || defined(BOOST_CHARCONV_INTERNAL_PARTITION_UNIT)

#include <boost/charconv/detail/compute_float64.hpp>
#include <limits>
#include <cstdint>
#include <cmath>
#include <boost/config/std/limits.hpp>
#include <boost/config/std/cstdint.hpp>
#include <boost/config/std/cmath.hpp>

namespace boost { namespace charconv { namespace detail {

Expand Down Expand Up @@ -52,4 +54,6 @@ inline float compute_float32(std::int64_t power, std::uint64_t i, bool negative,

}}} // Namespaces

#endif // !defined(BOOST_USE_MODULES) || defined(BOOST_CHARCONV_INTERFACE_UNIT)

#endif // BOOST_CHARCONV_DETAIL_COMPUTE_FLOAT32_HPP
14 changes: 9 additions & 5 deletions include/boost/charconv/detail/compute_float64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@
#ifndef BOOST_CHARCONV_DETAIL_COMPUTE_FLOAT64_HPP
#define BOOST_CHARCONV_DETAIL_COMPUTE_FLOAT64_HPP

#if !defined(BOOST_USE_MODULES) || defined(BOOST_CHARCONV_INTERNAL_PARTITION_UNIT)

#include <boost/charconv/detail/config.hpp>
#include <boost/charconv/detail/significand_tables.hpp>
#include <boost/charconv/detail/emulated128.hpp>
#include <boost/core/bit.hpp>
#include <cstdint>
#include <cfloat>
#include <cstring>
#include <cmath>
#include <boost/config/std/cstdint.hpp>
#include <boost/config/std/cfloat.hpp>
#include <boost/config/std/cstring.hpp>
#include <boost/config/std/cmath.hpp>

namespace boost { namespace charconv { namespace detail {

static constexpr double powers_of_ten[] = {
BOOST_INLINE_CONSTEXPR double powers_of_ten[] = {
1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11,
1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19, 1e20, 1e21, 1e22
};
Expand Down Expand Up @@ -198,4 +200,6 @@ inline double compute_float64(std::int64_t power, std::uint64_t i, bool negative

}}} // Namespaces

#endif // !defined(BOOST_USE_MODULES) || defined(BOOST_CHARCONV_INTERFACE_UNIT)

#endif // BOOST_CHARCONV_DETAIL_COMPUTE_FLOAT64_HPP
24 changes: 14 additions & 10 deletions include/boost/charconv/detail/compute_float80.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,30 @@
#ifndef BOOST_CHARCONV_DETAIL_COMPUTE_FLOAT80_HPP
#define BOOST_CHARCONV_DETAIL_COMPUTE_FLOAT80_HPP

#if !defined(BOOST_USE_MODULES) || defined(BOOST_CHARCONV_INTERNAL_PARTITION_UNIT)

#include <boost/charconv/detail/config.hpp>
#include <boost/charconv/detail/emulated128.hpp>
#include <boost/charconv/detail/bit_layouts.hpp>
#include <system_error>
#include <type_traits>
#include <limits>
#include <cstdint>
#include <cmath>
#include <climits>
#include <cfloat>
#include <boost/config/std/system_error.hpp>
#include <boost/config/std/type_traits.hpp>
#include <boost/config/std/limits.hpp>
#include <boost/config/std/cstdint.hpp>
#include <boost/config/std/cmath.hpp>
#include <boost/config/std/climits.hpp>
#include <boost/config/std/cfloat.hpp>

#ifdef BOOST_CHARCONV_DEBUG_FLOAT128
#include <iostream>
#include <iomanip>
#include <boost/config/std/iostream.hpp>
#include <boost/config/std/iomanip.hpp>
#include <boost/charconv/detail/to_chars_integer_impl.hpp>
#endif

namespace boost { namespace charconv { namespace detail {

#if BOOST_CHARCONV_LDBL_BITS > 64

static constexpr long double powers_of_ten_ld[] = {
BOOST_INLINE_CONSTEXPR long double powers_of_ten_ld[] = {
1e0L, 1e1L, 1e2L, 1e3L, 1e4L, 1e5L, 1e6L,
1e7L, 1e8L, 1e9L, 1e10L, 1e11L, 1e12L, 1e13L,
1e14L, 1e15L, 1e16L, 1e17L, 1e18L, 1e19L, 1e20L,
Expand Down Expand Up @@ -111,4 +113,6 @@ inline ResultType compute_float80(std::int64_t q, Unsigned_Integer w, bool negat

}}} // Namespaces

#endif // !defined(BOOST_USE_MODULES) || defined(BOOST_CHARCONV_INTERFACE_UNIT)

#endif // BOOST_CHARCONV_DETAIL_COMPUTE_FLOAT80_HPP
30 changes: 28 additions & 2 deletions include/boost/charconv/detail/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,39 @@
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

// Make this header safe to include in our purview
#if defined(BOOST_IN_MODULE_PURVIEW) && !defined(BOOST_CHARCONV_DETAIL_CONFIG_HPP)
# error "Please #include <boost/charconv/detail/config.hpp> in your module global fragment"
#endif

#ifndef BOOST_CHARCONV_DETAIL_CONFIG_HPP
#define BOOST_CHARCONV_DETAIL_CONFIG_HPP

#include <boost/config.hpp>
#include <type_traits>
#include <boost/config/std/type_traits.hpp>
#include <cfloat>

// Long double characteristics

// 80 bit long double (e.g. x86-64)
#if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
# define BOOST_CHARCONV_LDBL_BITS 80

// 128 bit long double (e.g. s390x, ppcle64)
#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
# define BOOST_CHARCONV_LDBL_BITS 128

// 64 bit long double (double == long double on ARM)
#elif LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
# define BOOST_CHARCONV_LDBL_BITS 64

// Unsupported long double representation
#else
# define BOOST_CHARCONV_UNSUPPORTED_LONG_DOUBLE
# define BOOST_CHARCONV_LDBL_BITS -1

#endif // long double feature detection

#include <boost/assert.hpp>
#define BOOST_CHARCONV_ASSERT(expr) BOOST_ASSERT(expr)
#define BOOST_CHARCONV_ASSERT_MSG(expr, msg) BOOST_ASSERT_MSG(expr, msg)
Expand Down Expand Up @@ -169,7 +195,7 @@ static_assert((BOOST_CHARCONV_ENDIAN_BIG_BYTE || BOOST_CHARCONV_ENDIAN_LITTLE_BY
// All of these types are optional so check for each of them individually
#if (defined(_MSVC_LANG) && _MSVC_LANG > 202002L) || __cplusplus > 202002L
# if __has_include(<stdfloat>)
# include <stdfloat>
# include <boost/config/std/stdfloat.hpp>
# endif
#endif
#ifdef __STDCPP_FLOAT16_T__
Expand Down
12 changes: 8 additions & 4 deletions include/boost/charconv/detail/dragonbox/dragonbox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#ifndef BOOST_CHARCONV_DETAIL_DRAGONBOX_HPP
#define BOOST_CHARCONV_DETAIL_DRAGONBOX_HPP

#if !defined(BOOST_USE_MODULES) || defined(BOOST_CHARCONV_INTERNAL_PARTITION_UNIT)

#include <boost/charconv/detail/config.hpp>
#include <boost/charconv/detail/dragonbox/dragonbox_common.hpp>
#include <boost/charconv/detail/bit_layouts.hpp>
Expand All @@ -30,10 +32,10 @@
#include <boost/charconv/detail/to_chars_result.hpp>
#include <boost/charconv/chars_format.hpp>
#include <boost/core/bit.hpp>
#include <type_traits>
#include <limits>
#include <cstdint>
#include <cstring>
#include <boost/config/std/type_traits.hpp>
#include <boost/config/std/limits.hpp>
#include <boost/config/std/cstdint.hpp>
#include <boost/config/std/cstring.hpp>

#ifdef BOOST_MSVC
# pragma warning(push)
Expand Down Expand Up @@ -2749,4 +2751,6 @@ to_chars_result dragonbox_to_chars(Float x, char* first, char* last, chars_forma
# pragma warning(pop)
#endif

#endif // !defined(BOOST_USE_MODULES) || defined(BOOST_CHARCONV_INTERFACE_UNIT)

#endif // BOOST_CHARCONV_DETAIL_DRAGONBOX_HPP
Loading
Loading