1 #ifndef C4_STD_SPAN_HPP_
2 #define C4_STD_SPAN_HPP_
6 #ifndef C4CORE_SINGLE_HEADER
7 #include "c4/language.hpp"
11 #if (C4_CPP >= 20) || defined(__DOXYGEN__)
13 #ifndef C4CORE_SINGLE_HEADER
22 template<
class T>
struct is_string;
23 template<
class T>
struct is_writeable_string;
26 template<>
struct is_string<std::span<const char>> :
public std::true_type {};
27 template<>
struct is_string<const std::span<const char>> :
public std::true_type {};
30 template<>
struct is_string<std::span<char>> :
public std::true_type {};
31 template<>
struct is_string<const std::span<char>> :
public std::true_type {};
62 C4_ALWAYS_INLINE
bool operator<= (c4::csubstr ss, std::span<char> s) {
return ss.compare(s.data(), s.size()) <= 0; }
63 C4_ALWAYS_INLINE
bool operator< (c4::csubstr ss, std::span<char> s) {
return ss.compare(s.data(), s.size()) < 0; }
67 C4_ALWAYS_INLINE
bool operator<= (std::span<char> s,
c4::csubstr ss) {
return ss.
compare(s.data(), s.size()) >= 0; }
68 C4_ALWAYS_INLINE
bool operator< (std::span<char> s,
c4::csubstr ss) {
return ss.
compare(s.data(), s.size()) > 0; }
77 C4_ALWAYS_INLINE
bool operator<= (c4::csubstr ss, std::span<const char> s) {
return ss.compare(s.data(), s.size()) <= 0; }
78 C4_ALWAYS_INLINE
bool operator< (c4::csubstr ss, std::span<const char> s) {
return ss.compare(s.data(), s.size()) < 0; }
82 C4_ALWAYS_INLINE
bool operator<= (std::span<const char> s,
c4::csubstr ss) {
return ss.
compare(s.data(), s.size()) >= 0; }
83 C4_ALWAYS_INLINE
bool operator< (std::span<const char> s,
c4::csubstr ss) {
return ss.
compare(s.data(), s.size()) > 0; }
94 size_t len = buf.
len < sz ? buf.
len : sz;
102 size_t sz = s.size();
103 size_t len = buf.
len < sz ? buf.
len : sz;
111 if(buf.
len <= s->size())
113 substr(s->data(), buf.
len).copy_from(buf);
114 *s = s->first(buf.
len);
122 #endif // SPAN_AVAILABLE
124 #endif // C4_STD_SPAN_HPP_
bool operator!=(const char c, basic_substring< C > const that) noexcept
a traits class to mark a type as a writeable string type, meaning c4::to_substr() can be used directl...
substr to_substr(char(&s)[N]) noexcept
bool from_chars(csubstr buf, uint8_t *v) noexcept
bool operator>=(const char c, basic_substring< C > const that) noexcept
bool operator>(const char c, basic_substring< C > const that) noexcept
a traits class to mark a type as a string type, meaning c4::to_csubstr() can be used directly instead...
int compare(C const c) const noexcept
csubstr to_csubstr(const char(&s)[N]) noexcept
basic_substring< char > substr
a mutable string view
basic_substring< const char > csubstr
an immutable string view
auto copy_from(ro_substr that) -> typename std::enable_if< !std::is_const< U >::value, void >::type
copy a string to this substr, starting at 0
size_t len
the length of the substring
size_t to_chars(substr buf, uint8_t v) noexcept
bool operator==(const char c, basic_substring< C > const that) noexcept