Fix converations.

This commit is contained in:
Aleksandr Orefkov 2025-11-24 15:46:16 +03:00
parent 6905c9bb76
commit fa55aa5f46
1 changed files with 30 additions and 27 deletions

View File

@ -690,7 +690,8 @@ public:
* @en @brief Convert to std::string_view. * @en @brief Convert to std::string_view.
* @return std::string_view. * @return std::string_view.
*/ */
std::string_view to_sv() const noexcept { template<typename=int> requires is_one_of_std_char_v<K>
std::basic_string_view<K> to_sv() const noexcept {
return {_str(), _len()}; return {_str(), _len()};
} }
/*! /*!
@ -699,7 +700,8 @@ public:
* @en @brief Convert to std::string. * @en @brief Convert to std::string.
* @return std::string. * @return std::string.
*/ */
std::string to_string() const noexcept { template<typename=int> requires is_one_of_std_char_v<K>
std::basic_string<K> to_string() const noexcept {
return {_str(), _len()}; return {_str(), _len()};
} }
/*! /*!
@ -5682,22 +5684,32 @@ consteval simple_str_nt<K> select_str(simple_str_nt<u8s> s8, simple_str_nt<uws>
#define uni_string(K, p) select_str<K>(p, L##p, u##p, U##p) #define uni_string(K, p) select_str<K>(p, L##p, u##p, U##p)
template<typename K> requires (is_one_of_std_char_v<K>) template<typename K>
struct expr_real { struct expr_real {
using symb_type = K; using symb_type = K;
mutable K buf[40]; mutable std::conditional_t<is_one_of_std_char_v<K>, K, u8s> buf[40];
mutable size_t l; mutable size_t l;
double v; double v;
expr_real(double d) : v(d) {} expr_real(double d) : v(d) {}
expr_real(float d) : v(d) {} expr_real(float d) : v(d) {}
size_t length() const noexcept { size_t length() const noexcept {
printf_selector::snprintf(buf, 40, uni_string(K, "%.16g").str, v); if constexpr (is_one_of_std_char_v<K>) {
l = (size_t)ch_traits<K>::length(buf); printf_selector::snprintf(buf, 40, uni_string(K, "%.16g").str, v);
l = (size_t)ch_traits<K>::length(buf);
} else {
l = std::snprintf(buf, sizeof(buf), "%.16g", v);
}
return l; return l;
} }
K* place(K* ptr) const noexcept { K* place(K* ptr) const noexcept {
ch_traits<K>::copy(ptr, buf, l); if constexpr (is_one_of_std_char_v<K>) {
ch_traits<K>::copy(ptr, buf, l);
} else {
for (size_t i = 0; i < l; i++) {
ptr[i] = buf[i];
}
}
return ptr + l; return ptr + l;
} }
}; };
@ -5714,7 +5726,7 @@ struct expr_real {
* @details The number is converted to a string representation via sprintf("%.16g"). * @details The number is converted to a string representation via sprintf("%.16g").
*/ */
template<StrExpr A, typename R> template<StrExpr A, typename R>
requires(is_one_of_std_char_v<typename A::symb_type> && (std::is_same_v<R, double> || std::is_same_v<R, float>)) requires(std::is_same_v<R, double> || std::is_same_v<R, float>)
inline constexpr auto operator+(const A& a, R s) { inline constexpr auto operator+(const A& a, R s) {
return strexprjoin_c<A, expr_real<typename A::symb_type>>{a, s}; return strexprjoin_c<A, expr_real<typename A::symb_type>>{a, s};
} }
@ -6818,15 +6830,6 @@ public:
return erase(toStoreType(key)); return erase(toStoreType(key));
} }
bool lookup(const K* txt, T& val) const {
auto it = find(e_s(txt));
if (it != hash_t::end()) {
val = it->second;
return true;
}
return false;
}
bool lookup(simple_str<K> txt, T& val) const { bool lookup(simple_str<K> txt, T& val) const {
auto it = find(txt); auto it = find(txt);
if (it != hash_t::end()) { if (it != hash_t::end()) {