11#ifndef SEQAN_STD_CHARCONV_SHIM
12#define SEQAN_STD_CHARCONV_SHIM
17#if defined(__APPLE__) && defined(_LIBCPP_VERSION)
18# ifdef _LIBCPP___CHARCONV_FROM_CHARS_FLOATING_POINT_H
19# warning This file needs to be included before any <charconv> include.
21# if __has_include(<__configuration/availability.h>)
22# include <__configuration/availability.h>
23# undef _LIBCPP_AVAILABILITY_FROM_CHARS_FLOATING_POINT
24# define _LIBCPP_AVAILABILITY_FROM_CHARS_FLOATING_POINT
25# undef _LIBCPP_AVAILABILITY_HAS_FROM_CHARS_FLOATING_POINT
26# define _LIBCPP_AVAILABILITY_HAS_FROM_CHARS_FLOATING_POINT
51#if __cpp_lib_to_chars < 201611
56namespace seqan3::contrib::charconv_float
58using ::std::chars_format;
59using ::std::from_chars_result;
60using ::std::to_chars_result;
65template <std::
floating_po
int value_type>
66inline to_chars_result to_chars_floating_point(
char * first,
char * last, value_type value)
noexcept
68 assert(first !=
nullptr);
69 assert(last !=
nullptr);
76 return {last, std::errc::value_too_large};
86template <std::
floating_po
int value_type>
87inline from_chars_result from_chars_floating_point(
char const * first,
90 chars_format fmt = chars_format::general)
noexcept
100 return {last, std::errc::invalid_argument};
103 constexpr ptrdiff_t buffer_size = 100;
104 char buffer[buffer_size];
106 if (fmt != chars_format::general)
108 bool exponent_is_present{
false};
109 for (
auto it = first; it != last; ++it)
111 if (*it ==
'e' || *it ==
'E')
113 exponent_is_present =
true;
118 if (fmt == chars_format::scientific && !exponent_is_present)
119 return {last, std::errc::invalid_argument};
121 if (fmt == chars_format::fixed && exponent_is_present)
122 return {last, std::errc::invalid_argument};
132 if ((*last !=
'\0') || fmt == chars_format::hex)
142 if (fmt == chars_format::hex)
150 buffer[std::min<ptrdiff_t>(buffer_size -
offset, last - first)] =
'\0';
156 start =
const_cast<char *
>(first);
161 if constexpr (std::same_as<std::remove_reference_t<value_type>,
float>)
163 tmp =
strtof(start, &end);
165 if constexpr (std::same_as<std::remove_reference_t<value_type>,
double>)
167 tmp =
strtod(start, &end);
169 if constexpr (std::same_as<std::remove_reference_t<value_type>,
long double>)
174 last = first + (
end - start);
178 return {last, std::errc::result_out_of_range};
180 else if (tmp == 0 && end == start)
182 return {last, std::errc::invalid_argument};
192namespace seqan3::contrib::charconv_float
201template <std::
floating_po
int floating_po
int_type>
202inline to_chars_result
to_chars(
char * first,
char * last, floating_point_type value)
noexcept
204 return to_chars_floating_point(first, last, value);
266template <std::
floating_po
int floating_po
int_type>
267inline from_chars_result
from_chars(
char const * first,
269 floating_point_type & value,
270 chars_format fmt = chars_format::general)
noexcept
272 return from_chars_floating_point(first, last, value, fmt);
280using ::seqan3::contrib::charconv_float::from_chars;
281using ::seqan3::contrib::charconv_float::to_chars;
@ offset
Sequence (seqan3::field::seq) relative start position (0-based), unsigned value.
SeqAn specific customisations in the standard namespace.