28#include <system_error>
33#if !defined(__cpp_lib_string_view) || (__cpp_lib_string_view < 202403L)
39inline std::string operator+(
const std::string& lhs, std::string_view rhs) {
return lhs + std::string(rhs); }
42inline std::string operator+(std::string_view lhs,
const std::string& rhs) {
return std::string(lhs) + rhs; }
47using hack_string_view::operator+;
52inline bool iequals(std::string_view a, std::string_view b)
54 return a.size() == b.size() && std::equal(a.begin(), a.end(), b.begin(), [](
unsigned char ca,
unsigned char cb) {
55 return std::tolower(ca) == std::tolower(cb);
82 if constexpr (std::is_arithmetic_v<T>)
85 auto [ptr, ec] = std::from_chars(s.data(), s.data() + s.size(), result);
86 if (ec != std::errc())
throw std::runtime_error(
"from_string: conversion failed for arithmetic type");
89 else if constexpr (std::is_constructible_v<T, std::string>)
91 return T{std::string(s)};
93 else if constexpr (has_stream_extractor_v<T>)
95 std::istringstream iss{std::string(s)};
98 throw std::runtime_error(
"from_string: conversion failed for non-arithmetic type using stream extraction");
103 static_assert(dependent_false_v<T>,
"from_string: No conversion available for type T");
Definition string_util.hpp:36
bool iequals(std::string_view a, std::string_view b)
Definition string_util.hpp:52
constexpr bool has_stream_extractor_v
Definition string_util.hpp:70
constexpr bool dependent_false_v
Definition string_util.hpp:73
T from_string(std::string_view s)
Definition string_util.hpp:80