An implementation of <charconv> in C++11
This library is a C++11 compatible implementation of <charconv>
. The full documentation can be found here: https://www.boost.org/doc/libs/master/libs/charconv/doc/html/charconv.html
Build Status
Master | Develop | |
---|---|---|
Github Actions | ||
Drone | ||
Codecov | ||
Fuzzing |
How to build the library
B2
git clone https://github.com/boostorg/boost
cd boost
git submodule update --init
cd ..
./bootstrap
./b2 cxxstd=11
This sets up a complete boost development and allows the tests to be run. To install the development environment run:
sudo ./b2 install cxxstd=11
vcpkg
git clone https://github.com/boostorg/charconv
cd charconv
vcpkg install charconv --overlay-ports=ports/charconv
This will install charconv and all the required boost packages if they do not already exist.
Conan
git clone https://github.com/boostorg/charconv
conan create charconv/conan --build missing
This will build a boost_charconv package using your default profile and put it in the local Conan cache along with all direct and transitive dependencies. Since Charconv only depends on a few header-only Boost libraries, you can save some time by requesting header-only Boost:
conan create charconv/conan -o 'boost*:header_only=True' --build missing
Following one of those approaches you can use the package as usual. For
example, using a conanfile.txt
:
[requires]
boost_charconv/1.0.0
Synopsis
Charconv is a collection of parsing functions that are locale-independent, non-allocating, and non-throwing.
namespace boost { namespace charconv {
enum class chars_format : unsigned
{
scientific = 1 << 0,
fixed = 1 << 1,
hex = 1 << 2,
general = fixed | scientific
};
struct from_chars_result
{
const char* ptr;
std::errc ec;
friend constexpr bool operator==(const from_chars_result& lhs, const from_chars_result& rhs) noexcept
friend constexpr bool operator!=(const from_chars_result& lhs, const from_chars_result& rhs) noexcept
constexpr explicit operator bool() const noexcept
}
template <typename Integral>
BOOST_CXX14_CONSTEXPR from_chars_result from_chars(const char* first, const char* last, Integral& value, int base = 10) noexcept;
BOOST_CXX14_CONSTEXPR from_chars_result from_chars<bool>(const char* first, const char* last, bool& value, int base) = delete;
template <typename Real>
from_chars_result from_chars(const char* first, const char* last, Real& value, chars_format fmt = chars_format::general) noexcept;
template <typename Real>
from_chars_result from_chars_erange(const char* first, const char* last, Real& value, chars_format fmt = chars_format::general) noexcept;
struct to_chars_result
{
char* ptr;
std::errc ec;
friend constexpr bool operator==(const to_chars_result& lhs, const to_chars_result& rhs) noexcept;
friend constexpr bool operator!=(const to_chars_result& lhs, const to_chars_result& rhs) noexcept;
constexpr explicit operator bool() const noexcept
};
template <typename Integral>
BOOST_CHARCONV_CONSTEXPR to_chars_result to_chars(char* first, char* last, Integral value, int base = 10) noexcept;
template <typename Integral>
BOOST_CHARCONV_CONSTEXPR to_chars_result to_chars<bool>(char* first, char* last, Integral value, int base) noexcept = delete;
template <typename Real>
to_chars_result to_chars(char* first, char* last, Real value, chars_format fmt = chars_format::general, int precision) noexcept;
}} // Namespace boost::charconv
Notes
-
BOOST_CXX14_CONSTEXPR
is defined asconstexpr
when compiling with C++14 or newer. -
BOOST_CHARCONV_CONSTEXPR
is defined asconstexpr
when compiling with C++14 or newer, and the compiler has__builtin_is_constant_evaluated
-
For explanation of
from_chars_erange
see docs under heading: Usage notes for from_chars for floating point types
Examples
from_chars
const char* buffer = "42";
int v = 0;
from_chars_result r = boost::charconv::from_chars(buffer, buffer + std::strlen(buffer), v);
assert(r.ec == std::errc());
assert(r); // Equivalent to the above
assert(v == 42);
const char* buffer = "1.2345"
double v = 0;
auto r = boost::charconv::from_chars(buffer, buffer + std::strlen(buffer), v);
assert(r.ec == std::errc());
assert(v == 1.2345);
const char* buffer = "2a";
unsigned v = 0;
auto r = boost::charconv::from_chars(buffer, buffer + std::strlen(buffer), v, 16);
assert(r); // from_chars_result has operator bool()
assert(v == 42);
const char* buffer = "1.3a2bp-10";
double v = 0;
auto r = boost::charconv::from_chars(buffer, buffer + std::strlen(buffer), v, boost::charconv::chars_format::hex);
assert(r);
assert(v == 8.0427e-18);
to_chars
char buffer[64] {};
int v = 42;
to_chars_result r = boost::charconv::to_chars(buffer, buffer + sizeof(buffer), v);
assert(r.ec == std::errc());
assert(!strcmp(buffer, "42")); // strcmp returns 0 on match
char buffer[64] {};
double v = 1e300;
to_chars_result r = boost::charconv::to_chars(buffer, buffer + sizeof(buffer), v);
assert(r.ec == std::errc());
assert(!strcmp(buffer, "1e+300"));
char buffer[64] {};
int v = 42;
to_chars_result r = boost::charconv::to_chars(buffer, buffer + sizeof(buffer), v, 16);
assert(r); // to_chars_result has operator bool()
assert(!strcmp(buffer, "2a")); // strcmp returns 0 on match
version | 1.85.0 |
---|---|
license | BSL-1.0Boost Software License 1.0 |
repository | https://pkg.cppget.org/1/stable |
download | libboost-charconv-1.85.0.tar.gz |
sha256 | d2e86b5d88533bc3b55347a3b7b8d556c14e47d7a63aaa6cedc74f9a6ac31a3f |
project | boost |
---|---|
url | github.com/boostorg/charconv |
doc-url | www.boost.org/doc/libs/1_85_0/libs/charconv |
package-url | github.com/build2-packaging/boost |
boost-users@lists.boost.orgMailing list | |
package-email | packaging@build2.orgMailing list |
topics | C++Boost |
Depends (3)
libboost-assert == 1.85.0 | |
libboost-config == 1.85.0 | |
libboost-core == 1.85.0 |
Reviews
fail | 0 |
---|---|
pass | 1 |
Builds
toolchain | public-0.17.0 |
---|---|
target | aarch64-linux-gnu |
tgt config | linux_debian_12-gcc_14-ndebug_O3 |
timestamp | 2025-08-20 23:50:52 UTC (03:29:26 hours ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | aarch64-linux-gnu |
tgt config | linux_debian_12-gcc_14-static_O3 |
timestamp | 2025-08-20 23:50:20 UTC (03:29:59 hours ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | aarch64-linux-gnu |
tgt config | linux_debian_12-gcc_14 |
timestamp | 2025-08-20 23:49:48 UTC (03:30:31 hours ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | aarch64-linux-gnu |
tgt config | linux_debian_12-gcc_14-O3 |
timestamp | 2025-08-20 23:46:30 UTC (03:33:49 hours ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | aarch64-linux-gnu |
tgt config | linux_debian_12-clang_18_libc++-O3 |
timestamp | 2025-08-19 17:51:14 UTC (01 09:29:05 days ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | aarch64-linux-gnu |
tgt config | linux_debian_12-clang_18_libc++-static_O3 |
timestamp | 2025-08-19 17:50:41 UTC (01 09:29:38 days ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | aarch64-linux-gnu |
tgt config | linux_debian_12-clang_18 |
timestamp | 2025-08-19 17:50:08 UTC (01 09:30:10 days ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | aarch64-linux-gnu |
tgt config | linux_debian_12-clang_18_libc++ |
timestamp | 2025-08-19 17:49:28 UTC (01 09:30:51 days ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | aarch64-linux-gnu |
tgt config | linux_debian_12-clang_18-static_O3 |
timestamp | 2025-08-19 17:48:53 UTC (01 09:31:26 days ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | aarch64-linux-gnu |
tgt config | linux_debian_12-clang_18-O3 |
timestamp | 2025-08-19 17:48:49 UTC (01 09:31:30 days ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | x86_64-linux-gnu |
tgt config | linux_fedora_40-gcc_14-bindist |
timestamp | 2025-08-19 06:46:13 UTC (01 20:34:06 days ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | x86_64-microsoft-win32-msvc14.3 |
tgt config | windows_10-clang_18_llvm_msvc_17.10-O2 |
timestamp | 2025-08-19 00:38:14 UTC (02 02:42:05 days ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | x86_64-microsoft-win32-msvc14.3 |
tgt config | windows_10-clang_18_llvm_msvc_17.10-static_O2 |
timestamp | 2025-08-19 00:35:35 UTC (02 02:44:44 days ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | x86_64-microsoft-win32-msvc14.3 |
tgt config | windows_10-clang_18_llvm_msvc_17.10 |
timestamp | 2025-08-19 00:33:35 UTC (02 02:46:44 days ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | x86_64-w64-mingw32 |
tgt config | windows_10-gcc_13.2_mingw_w64-O2 |
timestamp | 2025-08-18 23:44:32 UTC (02 03:35:47 days ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | x86_64-w64-mingw32 |
tgt config | windows_10-gcc_13.2_mingw_w64-static_O2 |
timestamp | 2025-08-18 23:44:05 UTC (02 03:36:13 days ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | x86_64-w64-mingw32 |
tgt config | windows_10-gcc_13.2_mingw_w64 |
timestamp | 2025-08-18 23:42:45 UTC (02 03:37:34 days ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | x86_64-microsoft-win32-msvc14.3 |
tgt config | windows_10-msvc_17.10-static_O2 |
timestamp | 2025-08-18 23:39:28 UTC (02 03:40:51 days ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | x86_64-linux-gnu |
tgt config | linux_debian_12-gcc_12-bindist |
timestamp | 2025-08-18 23:37:55 UTC (02 03:42:24 days ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | x86_64-microsoft-win32-msvc14.3 |
tgt config | windows_10-msvc_17.10-O2 |
timestamp | 2025-08-18 23:35:21 UTC (02 03:44:58 days ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | x86_64-microsoft-win32-msvc14.3 |
tgt config | windows_10-msvc_17.10 |
timestamp | 2025-08-18 23:35:00 UTC (02 03:45:19 days ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | x86_64-microsoft-win32-msvc14.3 |
tgt config | windows_10-msvc_17.8-static_O2 |
timestamp | 2025-08-18 22:09:28 UTC (02 05:10:50 days ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | x86_64-microsoft-win32-msvc14.3 |
tgt config | windows_10-msvc_17.8 |
timestamp | 2025-08-18 22:08:45 UTC (02 05:11:34 days ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | x86_64-linux-gnu |
tgt config | linux_debian_12-gcc_14-static_O3 |
timestamp | 2025-08-18 22:08:10 UTC (02 05:12:09 days ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | x86_64-microsoft-win32-msvc14.3 |
tgt config | windows_10-msvc_17.8-O2 |
timestamp | 2025-08-18 22:06:14 UTC (02 05:14:05 days ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | x86_64-linux-gnu |
tgt config | linux_debian_12-gcc_14-ndebug_O3 |
timestamp | 2025-08-18 21:59:52 UTC (02 05:20:27 days ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | x86_64-linux-gnu |
tgt config | linux_debian_12-gcc_14-O3 |
timestamp | 2025-08-18 21:59:24 UTC (02 05:20:55 days ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | x86_64-linux-gnu |
tgt config | linux_debian_12-gcc_14 |
timestamp | 2025-08-18 21:54:52 UTC (02 05:25:27 days ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | x86_64-microsoft-win32-msvc14.3 |
tgt config | windows_10-clang_17_msvc_msvc_17.10 |
timestamp | 2025-08-18 21:54:41 UTC (02 05:25:38 days ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | x86_64-linux-gnu |
tgt config | linux_ubuntu_24.04-gcc_13-bindist |
timestamp | 2025-08-18 21:54:14 UTC (02 05:26:05 days ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | x86_64-freebsd13.3 |
tgt config | freebsd_13-clang_17 |
timestamp | 2025-08-18 21:28:44 UTC (02 05:51:34 days ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | x86_64-freebsd14.1 |
tgt config | freebsd_14-clang_18-static_O3 |
timestamp | 2025-08-18 21:25:13 UTC (02 05:55:06 days ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | x86_64-freebsd14.1 |
tgt config | freebsd_14-clang_18-O3 |
timestamp | 2025-08-18 21:24:26 UTC (02 05:55:53 days ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | x86_64-linux-gnu |
tgt config | linux_debian_12-clang_17_libc++ |
timestamp | 2025-08-18 21:22:26 UTC (02 05:57:53 days ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | x86_64-freebsd14.1 |
tgt config | freebsd_14-clang_18 |
timestamp | 2025-08-18 21:20:35 UTC (02 05:59:44 days ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | x86_64-linux-gnu |
tgt config | linux_debian_12-clang_17 |
timestamp | 2025-08-18 21:19:57 UTC (02 06:00:22 days ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | x86_64-linux-gnu |
tgt config | linux_debian_12-gcc_13.1 |
timestamp | 2025-08-18 21:18:52 UTC (02 06:01:27 days ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | aarch64-linux-gnu |
tgt config | linux_debian_12-clang_17_libc++ |
timestamp | 2025-08-18 09:02:14 UTC (02 18:18:05 days ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | aarch64-linux-gnu |
tgt config | linux_debian_12-gcc_13 |
timestamp | 2025-08-18 09:01:16 UTC (02 18:19:02 days ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | aarch64-linux-gnu |
tgt config | linux_debian_12-clang_17 |
timestamp | 2025-08-18 09:00:26 UTC (02 18:19:52 days ago) |
result | success | log | rebuild |
toolchain | public-0.17.0 |
---|---|
target | x86_64-linux-gnu |
tgt config | linux_debian_12-clang_18 |
result | unbuilt |
toolchain | public-0.17.0 |
---|---|
target | x86_64-linux-gnu |
tgt config | linux_debian_12-clang_18-O3 |
result | unbuilt |
toolchain | public-0.17.0 |
---|---|
target | x86_64-linux-gnu |
tgt config | linux_debian_12-clang_18-static_O3 |
result | unbuilt |
toolchain | public-0.17.0 |
---|---|
target | x86_64-linux-gnu |
tgt config | linux_debian_12-clang_18_libc++ |
result | unbuilt |
toolchain | public-0.17.0 |
---|---|
target | x86_64-linux-gnu |
tgt config | linux_debian_12-clang_18_libc++-O3 |
result | unbuilt |
toolchain | public-0.17.0 |
---|---|
target | x86_64-linux-gnu |
tgt config | linux_debian_12-clang_18_libc++-static_O3 |
result | unbuilt |
toolchain | public-0.17.0 |
---|---|
target | x86_64-linux-gnu |
tgt config | linux_fedora_39-gcc_13-bindist |
result | unbuilt |
toolchain | public-0.17.0 |
---|---|
target | x86_64-apple-darwin22.5.0 |
tgt config | macos_13-clang_15.0 |
result | unbuilt |
toolchain | public-0.17.0 |
---|---|
target | x86_64-apple-darwin23.5.0 |
tgt config | macos_14-clang_15.0 |
result | unbuilt |
toolchain | public-0.17.0 |
---|---|
target | x86_64-apple-darwin23.5.0 |
tgt config | macos_14-clang_15.0-O3 |
result | unbuilt |
toolchain | public-0.17.0 |
---|---|
target | x86_64-apple-darwin23.5.0 |
tgt config | macos_14-clang_15.0-static_O3 |
result | unbuilt |
target | x86_64-apple-darwin23.5.0 |
---|---|
tgt config | macos_14-gcc_14_homebrew |
result | excluded (https://github) |
target | x86_64-apple-darwin23.5.0 |
---|---|
tgt config | macos_14-gcc_14_homebrew-O3 |
result | excluded (https://github) |
target | x86_64-apple-darwin23.5.0 |
---|---|
tgt config | macos_14-gcc_14_homebrew-static_O3 |
result | excluded (https://github) |