1010#define LIBPMEMOBJ_CPP_STRING_VIEW
1111
1212#include < algorithm>
13- #include < cassert >
13+ #include < limits >
1414#include < stdexcept>
1515#include < string>
1616
@@ -38,8 +38,8 @@ using u32string_view = std::basic_string_view<char32_t>;
3838/* *
3939 * Our partial std::string_view implementation.
4040 *
41- * If C++17's std::string_view implementation is not available, this one is
42- * used to avoid unnecessary string copying.
41+ * If C++17's std::string_view implementation is not available, this one
42+ * is used to avoid unnecessary string copying.
4343 */
4444template <typename CharT, typename Traits = std::char_traits<CharT>>
4545class basic_string_view {
@@ -67,6 +67,8 @@ class basic_string_view {
6767 constexpr const CharT *data () const noexcept ;
6868 constexpr size_type size () const noexcept ;
6969 constexpr size_type length () const noexcept ;
70+ constexpr bool empty () const noexcept ;
71+ constexpr size_type max_size () const noexcept ;
7072
7173 const CharT &at (size_type pos) const ;
7274 constexpr const CharT &operator [](size_type pos) const noexcept ;
@@ -135,8 +137,8 @@ constexpr inline basic_string_view<CharT, Traits>::basic_string_view(
135137}
136138
137139/* *
138- * Returns pointer to data stored in this pmem::obj::string_view. It may not
139- * contain the terminating null character.
140+ * Returns pointer to data stored in this pmem::obj::string_view. It may
141+ *not contain the terminating null character.
140142 *
141143 * @return pointer to C-like string (char *), it may not end with null
142144 * character.
@@ -149,7 +151,8 @@ basic_string_view<CharT, Traits>::data() const noexcept
149151}
150152
151153/* *
152- * Returns count of characters stored in this pmem::obj::string_view data.
154+ * Returns count of characters stored in this pmem::obj::string_view
155+ * data.
153156 *
154157 * @return the number of CharT elements in the view.
155158 */
@@ -160,6 +163,31 @@ basic_string_view<CharT, Traits>::size() const noexcept
160163 return size_;
161164}
162165
166+ /* *
167+ * Returns that view is empty or not.
168+ *
169+ * @return true when size() == 0.
170+ */
171+ template <typename CharT, typename Traits>
172+ constexpr inline bool
173+ basic_string_view<CharT, Traits>::empty() const noexcept
174+ {
175+ return size () == 0 ;
176+ }
177+
178+ /* *
179+ * Returns the largest possible number of char-like objects that can be
180+ * referred to by a basic_string_view.
181+ *
182+ * @return maximum number of characters.
183+ */
184+ template <typename CharT, typename Traits>
185+ constexpr inline typename basic_string_view<CharT, Traits>::size_type
186+ basic_string_view<CharT, Traits>::max_size() const noexcept
187+ {
188+ return (std::numeric_limits<size_type>::max)();
189+ }
190+
163191/* *
164192 * Returns count of characters stored in this pmem::obj::string_view data.
165193 *
0 commit comments