20 #ifndef BEAST_MODULE_CORE_TEXT_LEXICALCAST_H_INCLUDED
21 #define BEAST_MODULE_CORE_TEXT_LEXICALCAST_H_INCLUDED
40 template <
class Out,
class In>
49 template <
class Arithmetic = In>
57 template <
class Enumeration = In>
74 std::is_integral_v<Out>,
75 "beast::LexicalCast can only be used with integral types");
77 template <
class Integral = Out>
79 std::is_integral_v<Integral> && !std::is_same_v<Integral, bool>,
83 auto first = in.data();
84 auto last = in.data() + in.size();
86 if (first != last && *first ==
'+')
91 return ret.ec ==
std::errc() && ret.ptr == last;
99 return std::tolower(static_cast<unsigned char>(c));
102 if (in ==
"1" || in ==
"true")
108 if (in ==
"0" || in ==
"false")
162 template <
class Out,
class In>
175 template <
class Out,
class In>
190 template <
class Out,
class In>
std::enable_if_t< std::is_integral_v< Integral > &&!std::is_same_v< Integral, bool >, bool > operator()(Integral &out, std::string const &in) const
Out lexicalCast(In in, Out defaultValue=Out())
Convert from one type to another.
std::enable_if_t< std::is_arithmetic_v< Arithmetic >, bool > operator()(std::string &out, Arithmetic in)
Thrown when a conversion is not possible with LexicalCast.
bool operator()(Out &out, char *in) const
Out lexicalCastThrow(In in)
Convert from one type to another, throw on error.
bool operator()(Out &out, char const *in) const
bool operator()(bool &out, std::string in) const
bool lexicalCastChecked(Out &out, In in)
Intelligently convert from one type to another.
std::enable_if_t< std::is_enum_v< Enumeration >, bool > operator()(std::string &out, Enumeration in)