boostorg / lexical_cast Goto Github PK
View Code? Open in Web Editor NEWGeneral literal text conversions, such as an int represented as a string, or vice versa
Home Page: https://boost.org/libs/lexical_cast
General literal text conversions, such as an int represented as a string, or vice versa
Home Page: https://boost.org/libs/lexical_cast
Attempting to convert a string containing a number that is too big for an int
but fits into unsigned
throws a bad_lexical_cast
, as expected. However, attempting to convert a string with a negative number to unsigned
succeeds, although it should also throw.
See example here: http://coliru.stacked-crooked.com/a/73d91c38e5eaa3da
Why Boost lexical_cast does not work with boost::container::string instead of std::string?
Lexical cast of boost::filesystem::path to std::string as in
#include <iostream>
#include <boost/filesystem.hpp>
#include <boost/lexical_cast.hpp>
int main() {
boost::filesystem::path p("hello");
std::cout << boost::lexical_cast<std::string>(p) << "\n";
}
with -fsanitize=undefined
for gcc 6.2.0 brings the following usan message
/usr/include/boost/lexical_cast/detail/converter_lexical_streams.hpp:235:43: runtime error: downcast of address 0x7ffc173273a8 which does not point to an object of type 'basic_unlockedbuf'
0x7ffc173273a8: note: object is of type 'std::__cxx11::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >'
c1 7f 00 00 e8 da 6e af c1 7f 00 00 21 ec b1 f9 71 55 00 00 21 ec b1 f9 71 55 00 00 21 ec b1 f9
^~~~~~~~~~~~~~~~~~~~~~~
vptr for 'std::__cxx11::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >'
When parsing a negative integer, clang triggers an USAN error, test case is simply:
#include <boost/lexical_cast.hpp>
int main()
{
return boost::lexical_cast<int>("-6575543");
}
Compile with clang++ -fsanitize=undefined,integer
and you get:
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior boost/lexical_cast/detail/converter_lexical_streams.hpp:554:51 in
This one looks like a real error to me - the code is subtracting two unsigned values, the first of which is zero. A better solution might be to assign the unsigned value to the signed result and then negate, though this would have to account for the INT_MIN special case.
Found while investigating boostorg/multiprecision#313
I find a workaround for llvm.15723 in lexical_cast_test.cpp:https://github.com/boostorg/lexical_cast/blob/a9f296115967335aaa9f4a4cadfd900f131a60d1/test/lexical_cast_test.cpp
#ifndef _LIBCPP_VERSION
// libc++ had a bug in implementation of stream conversions for values that must be represented as infinity.
// http://llvm.org/bugs/show_bug.cgi?id=15723#c4
BOOST_CHECK_THROW(lexical_cast<test_t>(s_max_value+"1"), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<test_t>(s_max_value+"9"), bad_lexical_cast);
// VC9 can fail the following tests on floats and doubles when using stingstream...
BOOST_CHECK_THROW(lexical_cast<test_t>("1"+s_max_value), bad_lexical_cast);
BOOST_CHECK_THROW(lexical_cast<test_t>("9"+s_max_value), bad_lexical_cast);
#endif
This compiler bug is marked as fixed: http://llvm.org/bugs/show_bug.cgi?id=15723
Shall the workaround be removed?
C++ supports a few other number formats (for integers) as literals
It would be ideal if lexical_cast matches these.
I haven't been able to figure out if this is a real issue or not, but it is super-annoying as it prevents running the multiprecision tests with -fsanitize=memory.
If I compile:
#include <boost/lexical_cast.hpp>
int main()
{
std::string s("3.14");
float f = boost::lexical_cast<float>(s);
}
With clang++ -fsanitize=memory
then I see:
==11560==WARNING: MemorySanitizer: use-of-uninitialized-value
#0 0x49b367 in bool boost::detail::lexical_ostream_limited_src<char, std::char_traits<char> >::shr_using_base_class<float>(float&) /home/jzm/boost/libs/multiprecision/test/../../../boost/lexical_cast/detail/converter_lexical_streams.hpp:594:17
#1 0x49a4bc in bool boost::detail::lexical_ostream_limited_src<char, std::char_traits<char> >::float_types_converter_internal<float>(float&) /home/jzm/boost/libs/multiprecision/test/../../../boost/lexical_cast/detail/converter_lexical_streams.hpp:744:43
#2 0x499eb1 in boost::detail::lexical_ostream_limited_src<char, std::char_traits<char> >::operator>>(float&) /home/jzm/boost/libs/multiprecision/test/../../../boost/lexical_cast/detail/converter_lexical_streams.hpp:769:53
#3 0x499219 in boost::detail::lexical_converter_impl<float, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::try_convert(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, float&) /home/jzm/boost/libs/multiprecision/test/../../../boost/lexical_cast/detail/converter_lexical.hpp:485:26
#4 0x498e39 in bool boost::conversion::detail::try_lexical_convert<float, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, float&) /home/jzm/boost/libs/multiprecision/test/../../../boost/lexical_cast/try_lexical_convert.hpp:201:20
#5 0x498c35 in float boost::lexical_cast<float, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /home/jzm/boost/libs/multiprecision/test/../../../boost/lexical_cast.hpp:41:14
#6 0x4989ea in main /home/jzm/t.cpp:6:14
#7 0x7fa75f7d11e2 in __libc_start_main /build/glibc-5mDdLG/glibc-2.30/csu/../csu/libc-start.c:308:16
#8 0x41d4bd in _start (/home/jzm/boost/libs/multiprecision/test/a.out+0x41d4bd)
SUMMARY: MemorySanitizer: use-of-uninitialized-value /home/jzm/boost/libs/multiprecision/test/../../../boost/lexical_cast/detail/converter_lexical_streams.hpp:594:17 in bool boost::detail::lexical_ostream_limited_src<char, std::char_traits<char> >::shr_using_base_class<float>(float&)
Found during use of boost.program_options: A lexical_cast
of an unquoted string to bfs::path
(and probably to std::path
) stops on the first whitespace making the result invalid.
Reproducer:
std::cout << boost::lexical_castboost::filesystem::path("/home/my user");
Outputs: /home/my
Expected: /home/my user
Reason is the usage of the stream operators which stop on first whitespace
Possible solution: path
supports construction from string. So if a ctor from string exists, use that.
There are a variety of errors reported when running tests for macOS. See: https://github.com/boostorg/lexical_cast/actions/runs/8215553720/job/22469141219?pr=75
In my system, I've installed boost in /opt/local
from git tag 1.57. Formally there wasn't any /opt/local/include/boost
there, it was clean.
Given the following building/installation procedure
./bootstrap.sh --prefix=/opt/local --with-toolset=clang --with-icu=/usr/local/opt/icu4c
./b2 -q -j 4 --prefix="/opt/local" --build-dir="/opt/src/.build" toolset=clang variant=release optimization=speed cxxflags="-std=c++11 -stdlib=libc++" linkflags="-stdlib=libc++" install
lexical_cast.hpp
is copied to /opt/local/include/boost/lexical_cast.hpp
, but there isn't a /opt/local/include/boost/lexical_cast
directory containing bad_lexical_cast.hpp
, etc. It's in the source directory, but it was not copied on installation.
I believe it's because of some recent header spliting refactoring.
This code fails to compile at least since Boost 1.64
https://godbolt.org/z/Mfr4KPKbx
When source is nteger type, the failure arises when target is the same non-volatile type, without volatile. Only unsigned char
works, but this seems reasonable since it is treated as pure char
internally.
https://godbolt.org/z/dnKbWE99q
#include <boost/lexical_cast.hpp>
template <typename Int>
void foo() {
volatile Int v{};
boost::lexical_cast<Int>(v);
}
void test() {
foo<signed char>();
foo<signed int>(); // fails
foo<signed short>(); // fails
foo<signed long>(); // fails
foo<signed long long>(); // fails
foo<unsigned char>();
foo<unsigned int>(); // fails
foo<unsigned short>(); // fails
foo<unsigned long>(); // fails
foo<unsigned long long>(); // fails
}
Error:
d:\boost_1_80_0\msvc-14.3-64\boost\lexical_cast\bad_lexical_cast.hpp(54,60): error C3646: 'BOOST_OVERRIDE': unknown override specifier
My temp fix:
#ifndef BOOST_OVERRIDE
#define BOOST_OVERRIDE override
#endif
See here:
./boost/lexical_cast/bad_lexical_cast.hpp:59:9: error: function 'boost::bad_lexical_cast::~bad_lexical_cast()' defaulted on its first declaration must not have an exception-specification
./boost/lexical_cast/bad_lexical_cast.hpp:61:9: error: function 'boost::bad_lexical_cast::bad_lexical_cast(const boost::bad_lexical_cast&)' defaulted on its first declaration must not have an exception-specification
./boost/lexical_cast/bad_lexical_cast.hpp:62:27: error: function 'boost::bad_lexical_cast& boost::bad_lexical_cast::operator=(const boost::bad_lexical_cast&)' defaulted on its first declaration must not have an exception-specification
The compiler does not support noexcept
specification for defaulted functions.
This is caused by #59.
lexical_cast always throws std::bad_cast exception while converting values of type std::basic_string<char, ci_char_traits> (where ci_char_traits is derived from std::char_traits) to double on Linux. It works on windows though(i.e. throws boost::bad_lexcial_cast exception for bad values, and returns double for valid values). It also works on Linux with boost 1.57. I noticed there has been a change in lexical_cast implementation that causes this issue now. std::bad_cast exception is thrown here because locale associated with the stream does not has std::num_get<char, std::istreambuf_iterator<char, ci_char_traits> > > facet as shown in the stack trace below. It works with std::string (std::basic_string<char, std::char_traits) > ) because locale has std::num_get<char, std::istreambuf_iterator<char, std::char_traits> > facet.
#0 cxxabiv1::cxa_throw (obj=0x60b0c0, tinfo=0x60a3f0 <_ZTISt8bad_cast@@GLIBCXX_3.4>,
dest=0x2aaaaab092e0 <std::bad_cast::~bad_cast()>) at ../../../../gcc-4.8.1/libstdc++-v3/libsupc++/eh_throw.cc:71
#1 0x00002aaaaab5fb62 in std::throw_bad_cast ()
at ../../../../../gcc-4.8.1/libstdc++-v3/src/c++11/functexcept.cc:56
#2 0x00000000004051bc in std::check_facet<std::num_get<char, std::istreambuf_iterator<char, ci_char_traits> > > (f=0x0) at /xxxx/xxxx/xxxx/gcc-4.8.1/include/c++/4.8.1/bits/basic_ios.h:49 #3 0x0000000000404b3f in std::basic_istream<char, ci_char_traits>::_M_extract<double> (this=0x7fffffffe000,
v=@0x7fffffffe228: 0) at /xxxx/xxxx/xxxx/gcc-4.8.1/include/c++/4.8.1/bits/istream.tcc:95
#4 0x0000000000404397 in std::basic_istream<char, ci_char_traits>::operator>> (this=0x7fffffffe000,
f=@0x7fffffffe228: 0) at /xxxx/xxxx/xxxx/gcc-4.8.1/include/c++/4.8.1/istream:219
#5 0x0000000000403b84 in boost::detail::lexical_ostream_limited_src<char, ci_char_traits>::shr_using_base_class<double> (this=0x7fffffffe1a0, output=@0x7fffffffe228: 0)
at /xxxx/xxxx/xxxx/include/boost/lexical_cast/detail/converter_lexical_streams.hpp:600
#6 0x0000000000403503 in boost::detail::lexical_ostream_limited_src<char, ci_char_traits>::float_types_converter_internal<double> (this=0x7fffffffe1a0, output=@0x7fffffffe228: 0)
at /xxxx/xxxx/xxxx/include/boost/lexical_cast/detail/converter_lexical_streams.hpp:744
#7 0x0000000000403145 in boost::detail::lexical_ostream_limited_src<char, ci_char_traits>::operator>> (
this=0x7fffffffe1a0, output=@0x7fffffffe228: 0) at /xxxx/xxxx/xxxx/include/boost/lexical_cast/detail/converter_lexical_streams.hpp:770
#8 0x0000000000402cce in boost::detail::lexical_converter_impl<double, std::basic_string<char, ci_char_traits, std::allocator<char> > >::try_convert (arg=..., result=@0x7fffffffe228: 0)
at /xxxx/xxxx/xxxx/include/boost/lexical_cast/detail/converter_lexical.hpp:485
#9 0x0000000000402a32 in boost::conversion::detail::try_lexical_convert<double, std::basic_string<char, ci_char_traits, std::allocator<char> > > (arg=..., result=@0x7fffffffe228: 0)
at /xxxx/xxxx/xxxx/include/boost/lexical_cast/try_lexical_convert.hpp:196
#10 0x00000000004027be in boost::lexical_cast<double, std::basic_string<char, ci_char_traits, std::allocator<char> > > (arg=...) at /xxxx/xxxx/xxxx/include/boost/lexical_cast.hpp:41 #11 0x0000000000401d7f in lexicalcast (mystr=...) at lexicalcast_test.cpp:14 #12 0x0000000000401f0d in main () at lexicalcast_test.cpp:39
Issue from trac https://svn.boost.org/trac10/ticket/13366
boost::filesystem::path is being deserialized to the first whitespace occurrence.
I'm using Boost 1.68. I compiled it using NDK r17b. I used the following user-config.jam
. Note I did all of this on Windows using Command Prompt.
import os ;
local toolchain_arm = "C:/android/ndk-standalone/r17b-arm" ;
using clang : android_arm : "$(toolchain_arm)/bin/clang++.cmd"
:
<archiver>"$(toolchain_arm)/bin/arm-linux-androideabi-ar.exe"
<ranlib>"$(toolchain_arm)/bin/arm-linux-androideabi-ranlib.exe"
;
I created the standalone toolchains for the NDK using this command:
make_standalone_toolchain.py --arch arm --api 15 --stl libc++ --install-dir C:/android/ndk-standalone/r17b-arm
And I built boost using this command:
.\tools\build\b2 -j8 --without-python --without-test toolset=clang-android_arm variant=release target-os=android threading=multi threadapi=pthread link=static runtime-link=shared cxxstd=14 architecture=arm address-model=32 binary-format=elf abi=aapcs stage
When I run my native code on Android, which uses this version of boost, I get a SIGSEGV with this callstack:
<unknown> 0x0000000000000000
boost::exception_detail::refcount_ptr<boost::exception_detail::error_info_container>::release() exception.hpp:86
boost::exception_detail::refcount_ptr<boost::exception_detail::error_info_container>::~refcount_ptr() exception.hpp:42
boost::exception::~exception() exception.hpp:306
boost::exception_detail::error_info_injector<boost::bad_lexical_cast>::~error_info_injector() exception.hpp:360
void boost::throw_exception<boost::bad_lexical_cast>(boost::bad_lexical_cast const&) throw_exception.hpp:69
void boost::conversion::detail::throw_bad_cast<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> >, unsigned int>() bad_lexical_cast.hpp:92
unsigned int boost::lexical_cast<unsigned int, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > >(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&) lexical_cast.hpp:42
The code using lexical_cast is doing, basically:
boost::lexical_cast<unsigned>("");
This causes a bad_lexical_cast
to be thrown; but in the middle of throwing that exception, the segfault happens. I don't have any further analysis to share, and I'm not even certain what the root cause is. Does the information I provided offer any hints? I'm not sure if this is a bug, and I'm not sure if the lexical cast repo is the best place to ask the question since boost.exception shows up in the call stack too.
The following code will print "4948.4948" instead of expected "10.10" (This are ascii codes of the symbols instead of values):
std::wstring wstr(L"10.10");
typedef boost::split_iterator<std::wstring::iterator> wsplit_iter_t;
wsplit_iter_t wdot_iter = boost::make_split_iterator( wstr, boost::first_finder(L "."));
std::cout<<boost::lexical_cast<unsigned>(*wdot_iter++)<<'.'<<boost::lexical_cast<unsigned>(*wdot_iter++);
Issue on trac: https://svn.boost.org/trac10/ticket/8261
Environment:
VS 2017 + Windows Server 2016
One test from boost libraries failed to run after boost submodule throw_exception updated from 50c34d to 514355 boost/throw_exception@a40a714. Could you please take a look?
Reproduce steps:.
ErrorMessage:
testing.capture-output ..\out\x64rel\boost\bin.v2\libs\lexical_cast\test\lexical_cast_no_exceptions_test.test\msvc-14.1\release\link-static\threading-multi\lexical_cast_no_exceptions_test.run
====== BEGIN OUTPUT ======
Running 1 test case...
unknown location(0): fatal error: in "lexical_cast. Testing with BOOST_NO_EXCEPTIONS/test_exceptions_off": breakpoint encountered
*** 1 failure is detected in the test module "Master Test Suite"
EXIT STATUS: 201
====== END OUTPUT ======
set status=0
if %status% NEQ 0 (
echo Skipping test execution due to testing.execute=off
exit 0
)
"..\out\x64rel\boost\bin.v2\libs\lexical_cast\test\lexical_cast_no_exceptions_test.test\msvc-14.1\release\link-static\threading-multi\lexical_cast_no_exceptions_test.exe" > "..\out\x64rel\boost\bin.v2\libs\lexical_cast\test\lexical_cast_no_exceptions_test.test\msvc-14.1\release\link-static\threading-multi\lexical_cast_no_exceptions_test.output" 2>&1
set status=%ERRORLEVEL%
echo. >> "..\out\x64rel\boost\bin.v2\libs\lexical_cast\test\lexical_cast_no_exceptions_test.test\msvc-14.1\release\link-static\threading-multi\lexical_cast_no_exceptions_test.output"
echo EXIT STATUS: %status% >> "..\out\x64rel\boost\bin.v2\libs\lexical_cast\test\lexical_cast_no_exceptions_test.test\msvc-14.1\release\link-static\threading-multi\lexical_cast_no_exceptions_test.output"
if %status% EQU 0 (
copy "..\out\x64rel\boost\bin.v2\libs\lexical_cast\test\lexical_cast_no_exceptions_test.test\msvc-14.1\release\link-static\threading-multi\lexical_cast_no_exceptions_test.output" "..\out\x64rel\boost\bin.v2\libs\lexical_cast\test\lexical_cast_no_exceptions_test.test\msvc-14.1\release\link-static\threading-multi\lexical_cast_no_exceptions_test.run"
)
set verbose=0
if %status% NEQ 0 (
set verbose=1
)
if %verbose% EQU 1 (
echo ====== BEGIN OUTPUT ======
type "..\out\x64rel\boost\bin.v2\libs\lexical_cast\test\lexical_cast_no_exceptions_test.test\msvc-14.1\release\link-static\threading-multi\lexical_cast_no_exceptions_test.output"
echo ====== END OUTPUT ======
)
exit %status%
...failed testing.capture-output
As per title; lexical_cast
has specializations for string types, but not for string view types. Reported on the C++ Slack.
Using boost library 1_76_0 the following C++ program throws an exception.
#include
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/lexical_cast.hpp>
using namespace std;
using namespace boost::multiprecision;
int main()
{
int128_t r_number;
string reverse_number = "08";
r_number = boost::lexical_cast<int128_t>(reverse_number);
cout << r_number;
}
other strings i.e "02", "03" etc convert successfully.
I solved my problem by removing leading zeros prior to conversion.
math depends on lexical_cast in a number of places, however lexical_cast depends on math:
include/boost/lexical_cast/detail/inf_nan.hpp:#include <boost/math/special_functions/sign.hpp>
include/boost/lexical_cast/detail/inf_nan.hpp:#include <boost/math/special_functions/fpclassify.hpp>
Direct dependency cycles should be avoided to prepare boost for a future where each repository releases independently.
Warning when Boost 1.72 is built with GCC 7.5 with -Wsuggest-override
added to cxxflags
:
./boost/lexical_cast/bad_lexical_cast.hpp:54:29: warning: ‘virtual const char* boost::bad_lexical_cast::what() const’ can be marked override [-Wsuggest-override]
BOOST_OVERRIDE
was introduced in boostorg/config@ffe4e0f.
I would like to make use of lexical_cast into a caller provided buffer, to avoid memory allocation. The documentation implies that conversion into boost::array<char, ...>
targets will be null terminated but it is not stated explicitly.
Even so, is there a way to convert to a non-null terminated buffer, and receive the size of the converted result? I would like to avoid a call to char_traits::length.
clang-tidy reports (while checking the code that uses boost::lexical_cast
) a virtual function is called in the default constructor of class template boost::detail::basic_pointerbuf
. (Function setbuf()
is declared virtual in base class.) This might be an indication of a bug. If not, I would recommend using a different construct that avoids confusion, for instance declaring the function override final
in newer versions of C++, or providing another function with different name but with the same semantics as the overriding setbuf()
.
Here's the link to the offending call: https://github.com/boostorg/lexical_cast/blob/develop/include/boost/detail/basic_pointerbuf.hpp#L42
In case of forcing bool
value to be something other than 0
or 1
, lexical_cast
won't throw any error. But the result is out of bool
domain. This is where error might happen in case of re converting the converted value back to bool
. For more detail check boost::lexical_cast wrong output
In our project, we use a function to convert and convert back some bool value to std::string
and vise versa. When we are casting the value back to bool
, we face bad_lexical_cast
error. since the project is huge, we can't find out the rule breaking part but we hope some changes in boost will be helping us.
I'm using old ARMCC 4.1 compiler with vendor provided standard C++ library :(
My cmath / math.h do not have C++11/C99 floating point functions.
I did not see any mention about requiring C++11 now or before
"C:\devtools\boost\boost/core/cmath.hpp", line 141: Error: #135: namespace "std" has no member "isfinite"
using std::isfinite;
^
"C:\devtools\boost\boost/core/cmath.hpp", line 142: Error: #135: namespace "std" has no member "isnan"
using std::isnan;
^
"C:\devtools\boost\boost/core/cmath.hpp", line 143: Error: #135: namespace "std" has no member "isinf"
using std::isinf;
^
"C:\devtools\boost\boost/core/cmath.hpp", line 144: Error: #135: namespace "std" has no member "isnormal"
using std::isnormal;
^
"C:\devtools\boost\boost/core/cmath.hpp", line 145: Error: #135: namespace "std" has no member "fpclassify"
using std::fpclassify;
^
"C:\devtools\boost\boost/core/cmath.hpp", line 147: Error: #20: identifier "FP_ZERO" is undefined
int const fp_zero = FP_ZERO;
^
"C:\devtools\boost\boost/core/cmath.hpp", line 148: Error: #20: identifier "FP_SUBNORMAL" is undefined
int const fp_subnormal = FP_SUBNORMAL;
^
"C:\devtools\boost\boost/core/cmath.hpp", line 149: Error: #20: identifier "FP_NORMAL" is undefined
int const fp_normal = FP_NORMAL;
^
"C:\devtools\boost\boost/core/cmath.hpp", line 150: Error: #20: identifier "FP_INFINITE" is undefined
int const fp_infinite = FP_INFINITE;
^
"C:\devtools\boost\boost/core/cmath.hpp", line 151: Error: #20: identifier "FP_NAN" is undefined
int const fp_nan = FP_NAN;
^
"C:\devtools\boost\boost/core/cmath.hpp", line 153: Error: #135: namespace "std" has no member "signbit"
using std::signbit;
^
"C:\devtools\boost\boost/core/cmath.hpp", line 161: Error: #135: namespace "std" has no member "copysign"
return std::copysign( x, y );
^
"C:\devtools\boost\boost/lexical_cast/detail/inf_nan.hpp", line 108: Error: #135: namespace "boost::core" has no member "isnan"
if (boost::core::isnan(value)) {
^
"C:\devtools\boost\boost/lexical_cast/detail/inf_nan.hpp", line 109: Error: #135: namespace "boost::core" has no member "signbit"
if (boost::core::signbit(value)) {
^
"C:\devtools\boost\boost/lexical_cast/detail/inf_nan.hpp", line 117: Error: #135: namespace "boost::core" has no member "isinf"
} else if (boost::core::isinf(value)) {
^
"C:\devtools\boost\boost/lexical_cast/detail/inf_nan.hpp", line 118: Error: #135: namespace "boost::core" has no member "signbit"
if (boost::core::signbit(value)) {
^
I'm referring to this line:
I have an enum class, for which I defined a simple ostream operator:
std::ostream& operator<<(std::ostream& os, const FileExists& e) {
os << enumName(e);
return os;
}
Using an ostream directly works fine, e.g.
std::ostrstream s;
s << FileExists::FAIL;
However, boost::lexical_cast fails:
boost::lexical_cast<std::string>(FileExists::FAIL);
The error is useless: cannot bind ‘std::basic_ostream’ lvalue to ‘std::basic_ostream&&’
However, it's easy enough to reproduce:
template <typename T>
bool willFail(T& e) {
std::ostrstream s;
return !(s << e).fail();
}
The error is now pretty obvious: invalid initialization of non-const reference of type ‘FileExists&’ from an rvalue of type ‘FileExists’.
Making shl_input_streamable
take a const reference would fix this, but I'm not sure if it breaks anything else.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.