9 #ifndef LIBPMEMOBJ_CPP_STRING_VIEW 10 #define LIBPMEMOBJ_CPP_STRING_VIEW 15 #if __cpp_lib_string_view 16 #include <string_view> 25 #if __cpp_lib_string_view 27 template <
typename CharT,
typename Traits = std::
char_traits<CharT>>
28 using basic_string_view = std::basic_string_view<CharT, Traits>;
29 using string_view = std::string_view;
30 using wstring_view = std::basic_string_view<wchar_t>;
31 using u16string_view = std::basic_string_view<char16_t>;
32 using u32string_view = std::basic_string_view<char32_t>;
42 template <
typename CharT,
typename Traits = std::
char_traits<CharT>>
43 class basic_string_view {
46 using traits_type = Traits;
47 using value_type = CharT;
48 using size_type = std::size_t;
49 using difference_type = std::ptrdiff_t;
50 using reference = value_type &;
51 using const_reference =
const value_type &;
52 using pointer = value_type *;
53 using const_pointer =
const value_type *;
62 operator=(
const basic_string_view &rhs) noexcept =
default;
64 const CharT *
data()
const noexcept;
65 size_type
size()
const noexcept;
67 const CharT &
operator[](size_type
p)
const noexcept;
69 int compare(
const basic_string_view &other)
const noexcept;
72 const value_type *data_;
83 template <
typename CharT,
typename Traits>
85 : data_(
nullptr), size_(0)
96 template <
typename CharT,
typename Traits>
99 : data_(data), size_(size)
108 template <
typename CharT,
typename Traits>
110 const std::basic_string<CharT, Traits> &s)
111 : data_(s.c_str()), size_(s.
size())
122 template <
typename CharT,
typename Traits>
124 : data_(data), size_(Traits::length(data))
135 template <
typename CharT,
typename Traits>
148 template <
typename CharT,
typename Traits>
149 inline typename basic_string_view<CharT, Traits>::size_type
160 template <
typename CharT,
typename Traits>
175 template <
typename CharT,
typename Traits>
180 int ret = Traits::compare(
data(), other.data(),
181 (std::min)(
size(), other.size()));
184 if (
size() < other.size())
186 if (
size() > other.size())
194 template <
class CharT,
class Traits>
int compare(const basic_string_view &other) const noexcept
Compares this string_view with other.
Definition: string_view.hpp:177
size_type size() const noexcept
Returns count of characters stored in this pmem::obj::string_view data.
Definition: string_view.hpp:150
basic_string_view() noexcept
Default constructor with empty data.
Definition: string_view.hpp:84
const CharT * data() const noexcept
Returns pointer to data stored in this pmem::obj::string_view.
Definition: string_view.hpp:137
const CharT & operator[](size_type p) const noexcept
Returns reference to a character at position.
Definition: string_view.hpp:161
Resides on pmem class.
Definition: p.hpp:35
Our partial std::string_view implementation.
Definition: string_view.hpp:43
Persistent memory namespace.
Definition: allocation_flag.hpp:14
bool operator==(standard_alloc_policy< T > const &, standard_alloc_policy< T2 > const &)
Determines if memory from another allocator can be deallocated from this one.
Definition: allocator.hpp:420