I have a small code as follows:
int main() {
double d;
const char* str = "26.50";
std::from_chars(str, str + strlen(str), d);
std::cout << d;
}
This code works as expected with libstdc++, but it fails with the following error in libc++ 12.0.0:
candidate template ignored: requirement '__or_<std::__or_<std::is_same<double, signed char>, std::is_same<double, short>, std::is_same<double, int>, std::is_same<double, long>, std::is_same<double, long long>>, std::__or_<std::is_same<double, unsigned char>, std::is_same<double, unsigned short>, std::is_same<double, unsigned int>, std::is_same<double, unsigned long>, std::is_same<double, unsigned long long>>, std::is_same<char, double>>::value' was not satisfied [with _Tp = double]
Is this a libc++ bug? or am I missing something? I should say that this code works if I change data type from double
to int
.
libc++
does not support it yet for floating point types.
std::to_chars
with floating point types seems to work since clang-16 (godbolt). According to cppreference, it is supported in libc++-14
.
std::from_chars
for floating point types is not implemented in libc++
as of now.
If you need to use these functions, you will need to link a different C++ standard library, e.g. libstdc++
.