9 #ifndef LIBPMEMOBJ_CPP_BASIC_STRING_HPP
10 #define LIBPMEMOBJ_CPP_BASIC_STRING_HPP
47 template <
typename CharT,
typename Traits = std::
char_traits<CharT>>
51 using traits_type = Traits;
52 using value_type = CharT;
53 using size_type = std::size_t;
54 using difference_type = std::ptrdiff_t;
55 using reference = value_type &;
56 using const_reference =
const value_type &;
57 using pointer = value_type *;
58 using const_pointer =
const value_type *;
60 using const_iterator = const_pointer;
61 using reverse_iterator = std::reverse_iterator<iterator>;
62 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
65 using for_each_ptr_function =
69 static constexpr size_type sso_capacity = (32 - 8) /
sizeof(CharT) - 1;
75 size_type count = npos);
76 basic_string(
const std::basic_string<CharT> &other, size_type pos,
77 size_type count = npos);
82 typename Enable =
typename std::enable_if<
91 typename Enable =
typename std::enable_if<
92 std::is_convertible<
const T &,
94 CharT, Traits>>::value &&
95 !std::is_convertible<const T &, const CharT *>::value>>
98 typename Enable =
typename std::enable_if<std::is_convertible<
115 typename Enable =
typename std::enable_if<
116 std::is_convertible<
const T &,
118 CharT, Traits>>::value &&
119 !std::is_convertible<const T &, const CharT *>::value>>
127 size_type count = npos);
129 size_type pos, size_type count = npos);
132 template <
typename InputIt,
140 reference
at(size_type n);
141 const_reference
at(size_type n)
const;
142 const_reference
const_at(size_type n)
const;
144 const_reference
operator[](size_type n)
const;
146 const CharT &
front()
const;
147 const CharT &
cfront()
const;
149 const CharT &
back()
const;
150 const CharT &
cback()
const;
152 const CharT *
data()
const noexcept;
153 const CharT *
cdata()
const noexcept;
154 const CharT *
c_str()
const noexcept;
160 size_type snapshot_size);
166 const_iterator
begin()
const noexcept;
167 const_iterator
cbegin()
const noexcept;
169 const_iterator
end()
const noexcept;
170 const_iterator
cend()
const noexcept;
171 reverse_iterator
rbegin();
172 const_reverse_iterator
rbegin()
const noexcept;
173 const_reverse_iterator
crbegin()
const noexcept;
174 reverse_iterator
rend();
175 const_reverse_iterator
rend()
const noexcept;
176 const_reverse_iterator
crend()
const noexcept;
179 bool empty()
const noexcept;
180 size_type
size()
const noexcept;
181 size_type
length()
const noexcept;
182 size_type
max_size()
const noexcept;
183 size_type
capacity()
const noexcept;
184 void resize(size_type count, CharT ch);
186 void reserve(size_type new_cap = 0);
196 template <
typename T,
197 typename Enable =
typename std::enable_if<
198 std::is_convertible<T, size_type>::value>::type>
200 template <
typename T,
201 typename Enable =
typename std::enable_if<
202 !std::is_convertible<T, size_type>::value>::type>
209 size_type count = npos);
212 template <
typename InputIt,
228 size_type index2, size_type count = npos);
231 template <
typename InputIt,
235 iterator insert(const_iterator pos, std::initializer_list<CharT> ilist);
236 template <
typename T,
237 typename Enable =
typename std::enable_if<
238 std::is_convertible<T, size_type>::value>::type>
240 template <
typename T,
241 typename Enable =
typename std::enable_if<
242 !std::is_convertible<T, size_type>::value>::type>
251 size_type count2 = npos);
252 template <
typename InputIt,
256 InputIt first2, InputIt last2);
258 const CharT *s, size_type count2);
262 size_type count2, CharT ch);
264 size_type count2, CharT ch);
269 std::initializer_list<CharT> ilist);
271 size_type
copy(CharT *s, size_type count, size_type index = 0)
const;
274 int compare(
const std::basic_string<CharT> &other)
const;
275 int compare(size_type pos, size_type count,
277 int compare(size_type pos, size_type count,
278 const std::basic_string<CharT> &other)
const;
280 size_type pos2, size_type count2 = npos)
const;
281 int compare(size_type pos1, size_type count1,
282 const std::basic_string<CharT> &other, size_type pos2,
283 size_type count2 = npos)
const;
284 int compare(
const CharT *s)
const;
285 int compare(size_type pos, size_type count,
const CharT *s)
const;
286 int compare(size_type pos, size_type count1,
const CharT *s,
287 size_type count2)
const;
292 size_type
find(
const CharT *s, size_type pos, size_type count)
const;
293 size_type
find(
const CharT *s, size_type pos = 0)
const;
294 size_type
find(CharT ch, size_type pos = 0)
const noexcept;
297 size_type
rfind(
const CharT *s, size_type pos, size_type count)
const;
298 size_type
rfind(
const CharT *s, size_type pos = npos)
const;
299 size_type
rfind(CharT ch, size_type pos = npos)
const noexcept;
301 size_type pos = 0)
const noexcept;
303 size_type count)
const;
304 size_type
find_first_of(
const CharT *s, size_type pos = 0)
const;
305 size_type
find_first_of(CharT ch, size_type pos = 0)
const noexcept;
307 size_type pos = 0)
const noexcept;
309 size_type count)
const;
313 size_type pos = npos)
const noexcept;
315 size_type count)
const;
316 size_type
find_last_of(
const CharT *s, size_type pos = npos)
const;
317 size_type
find_last_of(CharT ch, size_type pos = npos)
const noexcept;
319 size_type pos = npos)
const noexcept;
321 size_type count)
const;
331 static const size_type npos =
static_cast<size_type
>(-1);
375 static constexpr size_type _sso_mask = 1ULL
376 << (std::numeric_limits<size_type>::digits - 1);
379 bool is_sso_used()
const;
383 typename Enable =
typename std::enable_if<
385 size_type get_size(InputIt first, InputIt last)
const;
386 size_type get_size(size_type count, value_type ch)
const;
388 template <
typename... Args>
389 pointer replace_content(Args &&... args);
390 template <
typename... Args>
391 pointer initialize(Args &&... args);
395 typename Enable =
typename std::enable_if<
397 pointer assign_sso_data(InputIt first, InputIt last);
398 pointer assign_sso_data(size_type count, value_type ch);
402 typename Enable =
typename std::enable_if<
404 pointer assign_large_data(InputIt first, InputIt last);
405 pointer assign_large_data(size_type count, value_type ch);
407 void check_pmem()
const;
408 void check_tx_stage_work()
const;
409 void check_pmem_tx()
const;
410 void add_sso_to_tx(size_type first, size_type num)
const;
411 size_type get_sso_size()
const;
414 void set_sso_size(size_type new_size);
415 void sso_to_large(
size_t new_capacity);
420 non_sso_data()
const;
433 template <
typename CharT,
typename Traits>
440 initialize(0U, value_type(
'\0'));
457 template <
typename CharT,
typename Traits>
464 initialize(count, ch);
484 template <
typename CharT,
typename Traits>
486 size_type pos, size_type count)
491 if (pos > other.
size())
492 throw std::out_of_range(
"Index out of range.");
494 if (count == npos || pos + count > other.
size())
495 count = other.
size() - pos;
497 auto first =
static_cast<difference_type
>(pos);
498 auto last = first +
static_cast<difference_type
>(count);
501 initialize(other.
cbegin() + first, other.
cbegin() + last);
522 template <
typename CharT,
typename Traits>
524 size_type pos, size_type count)
544 template <
typename CharT,
typename Traits>
551 initialize(s, s + count);
567 template <
typename CharT,
typename Traits>
573 auto length = traits_type::length(s);
576 initialize(s, s + length);
595 template <
typename CharT,
typename Traits>
596 template <
typename InputIt,
typename Enable>
599 auto len = std::distance(first, last);
605 allocate(
static_cast<size_type
>(len));
606 initialize(first, last);
623 template <
typename CharT,
typename Traits>
629 allocate(other.
size());
648 template <
typename CharT,
typename Traits>
668 template <
typename CharT,
typename Traits>
674 move_data(std::move(other));
691 template <
typename CharT,
typename Traits>
697 allocate(ilist.size());
698 initialize(ilist.begin(), ilist.end());
716 template <
typename CharT,
typename Traits>
717 template <
class T,
typename Enable>
746 template <
typename CharT,
typename Traits>
747 template <
class T,
typename Enable>
757 throw std::out_of_range(
"Index out of range.");
759 if (n == npos || pos + n > sv.
size())
763 auto last = first + n;
766 initialize(sv.
data() + first, sv.
data() + last);
772 template <
typename CharT,
typename Traits>
791 template <
typename CharT,
typename Traits>
795 return assign(other);
808 template <
typename CharT,
typename Traits>
812 return assign(other);
824 template <
typename CharT,
typename Traits>
828 return assign(std::move(other));
839 template <
typename CharT,
typename Traits>
854 template <
typename CharT,
typename Traits>
858 return assign(1, ch);
870 template <
typename CharT,
typename Traits>
874 return assign(ilist);
886 template <
typename CharT,
typename Traits>
887 template <
class T,
typename Enable>
892 return assign(sv.
data(), sv.
size());
905 template <
typename CharT,
typename Traits>
909 auto pop = get_pool();
925 template <
typename CharT,
typename Traits>
932 auto pop = get_pool();
935 pop, [&] { replace_content(other.
cbegin(), other.
cend()); });
950 template <
typename CharT,
typename Traits>
954 return assign(other.cbegin(), other.cend());
969 template <
typename CharT,
typename Traits>
974 if (pos > other.
size())
975 throw std::out_of_range(
"Index out of range.");
977 if (count == npos || pos + count > other.
size())
978 count = other.
size() - pos;
980 auto pop = get_pool();
981 auto first =
static_cast<difference_type
>(pos);
982 auto last = first +
static_cast<difference_type
>(count);
985 replace_content(other.
cbegin() + first, other.
cbegin() + last);
1005 template <
typename CharT,
typename Traits>
1008 size_type pos, size_type count)
1010 if (pos > other.size())
1011 throw std::out_of_range(
"Index out of range.");
1013 if (count == npos || pos + count > other.size())
1014 count = other.size() - pos;
1016 return assign(other.c_str() + pos, count);
1029 template <
typename CharT,
typename Traits>
1033 auto pop = get_pool();
1048 template <
typename CharT,
typename Traits>
1052 auto pop = get_pool();
1054 auto length = traits_type::length(s);
1072 template <
typename CharT,
typename Traits>
1073 template <
typename InputIt,
typename Enable>
1077 auto pop = get_pool();
1093 template <
typename CharT,
typename Traits>
1100 auto pop = get_pool();
1104 move_data(std::move(other));
1119 template <
typename CharT,
typename Traits>
1123 return assign(ilist.begin(), ilist.end());
1133 template <
typename CharT,
typename Traits>
1137 if (!is_sso_used()) {
1138 non_sso._data.for_each_ptr(func);
1147 template <
typename CharT,
typename Traits>
1151 return is_sso_used() ?
iterator(&*sso_data().begin())
1152 :
iterator(&*non_sso_data().begin());
1160 template <
typename CharT,
typename Traits>
1161 typename basic_string<CharT, Traits>::const_iterator
1172 template <
typename CharT,
typename Traits>
1173 typename basic_string<CharT, Traits>::const_iterator
1176 return is_sso_used() ? const_iterator(&*sso_data().cbegin())
1177 : const_iterator(&*non_sso_data().cbegin());
1185 template <
typename CharT,
typename Traits>
1189 return begin() +
static_cast<difference_type
>(size());
1198 template <
typename CharT,
typename Traits>
1199 typename basic_string<CharT, Traits>::const_iterator
1202 return cbegin() +
static_cast<difference_type
>(size());
1211 template <
typename CharT,
typename Traits>
1212 typename basic_string<CharT, Traits>::const_iterator
1215 return cbegin() +
static_cast<difference_type
>(size());
1224 template <
typename CharT,
typename Traits>
1225 typename basic_string<CharT, Traits>::reverse_iterator
1228 return reverse_iterator(end());
1237 template <
typename CharT,
typename Traits>
1238 typename basic_string<CharT, Traits>::const_reverse_iterator
1250 template <
typename CharT,
typename Traits>
1251 typename basic_string<CharT, Traits>::const_reverse_iterator
1254 return const_reverse_iterator(cend());
1263 template <
typename CharT,
typename Traits>
1264 typename basic_string<CharT, Traits>::reverse_iterator
1267 return reverse_iterator(begin());
1276 template <
typename CharT,
typename Traits>
1277 typename basic_string<CharT, Traits>::const_reverse_iterator
1289 template <
typename CharT,
typename Traits>
1290 typename basic_string<CharT, Traits>::const_reverse_iterator
1293 return const_reverse_iterator(cbegin());
1309 template <
typename CharT,
typename Traits>
1310 typename basic_string<CharT, Traits>::reference
1314 throw std::out_of_range(
"string::at");
1316 return is_sso_used() ? sso_data()[n] : non_sso_data()[n];
1329 template <
typename CharT,
typename Traits>
1330 typename basic_string<CharT, Traits>::const_reference
1349 template <
typename CharT,
typename Traits>
1350 typename basic_string<CharT, Traits>::const_reference
1354 throw std::out_of_range(
"string::const_at");
1356 return is_sso_used()
1357 ?
static_cast<const sso_type &
>(sso_data())[n]
1358 :
static_cast<const non_sso_type &
>(non_sso_data())[n];
1372 template <
typename CharT,
typename Traits>
1373 typename basic_string<CharT, Traits>::reference
1376 return is_sso_used() ? sso_data()[n] : non_sso_data()[n];
1386 template <
typename CharT,
typename Traits>
1387 typename basic_string<CharT, Traits>::const_reference
1390 return is_sso_used() ? sso_data()[n] : non_sso_data()[n];
1406 template <
typename CharT,
typename Traits>
1410 if (start + n > size())
1411 throw std::out_of_range(
"basic_string::range");
1413 return is_sso_used() ? sso_data().range(start, n)
1414 : non_sso_data().range(start, n);
1433 template <
typename CharT,
typename Traits>
1436 size_type snapshot_size)
1438 if (start + n > size())
1439 throw std::out_of_range(
"basic_string::range");
1441 if (snapshot_size > n)
1444 return is_sso_used() ? sso_data().range(start, n, snapshot_size)
1445 : non_sso_data().range(start, n, snapshot_size);
1459 template <
typename CharT,
typename Traits>
1463 return crange(start, n);
1477 template <
typename CharT,
typename Traits>
1481 if (start + n > size())
1482 throw std::out_of_range(
"basic_string::range");
1484 return {const_iterator(cdata() + start),
1485 const_iterator(cdata() + start + n)};
1497 template <
typename CharT,
typename Traits>
1509 template <
typename CharT,
typename Traits>
1524 template <
typename CharT,
typename Traits>
1540 template <
typename CharT,
typename Traits>
1544 return (*
this)[size() - 1];
1552 template <
typename CharT,
typename Traits>
1567 template <
typename CharT,
typename Traits>
1571 return static_cast<const basic_string &
>(*this)[size() - 1];
1577 template <
typename CharT,
typename Traits>
1578 typename basic_string<CharT, Traits>::size_type
1582 return get_sso_size();
1583 else if (non_sso_data().size() == 0)
1586 return non_sso_data().size() - 1;
1595 template <
typename CharT,
typename Traits>
1599 return is_sso_used() ? sso_data().range(0, get_sso_size() + 1).begin()
1600 : non_sso_data().data();
1621 template <
typename CharT,
typename Traits>
1628 throw std::out_of_range(
"Index exceeds size.");
1630 count = (std::min)(count, sz - index);
1632 auto pop = get_pool();
1634 auto first = begin() +
static_cast<difference_type
>(index);
1635 auto last = first +
static_cast<difference_type
>(count);
1637 if (is_sso_used()) {
1639 auto move_len = sz - index - count;
1640 auto new_size = sz - count;
1644 sso_data().range(index, move_len + 1);
1645 traits_type::move(range.begin(), &*last,
1648 assert(range.end() - 1 ==
1649 &sso_data()._data[index + move_len]);
1652 sso_data()[index + move_len] = value_type(
'\0');
1653 set_sso_size(new_size);
1656 non_sso_data().erase(first, last);
1678 template <
typename CharT,
typename Traits>
1682 return erase(pos, pos + 1);
1703 template <
typename CharT,
typename Traits>
1708 static_cast<size_type
>(std::distance(cbegin(), first));
1709 size_type len =
static_cast<size_type
>(std::distance(first, last));
1713 return begin() +
static_cast<difference_type
>(index);
1726 template <
typename CharT,
typename Traits>
1730 erase(size() - 1, 1);
1752 template <
typename CharT,
typename Traits>
1757 auto new_size = sz + count;
1759 if (new_size > max_size())
1760 throw std::length_error(
"Size exceeds max size.");
1762 if (is_sso_used()) {
1763 auto pop = get_pool();
1766 if (new_size > sso_capacity) {
1767 sso_to_large(new_size);
1769 non_sso_data().insert(
1770 non_sso_data().cbegin() +
1771 static_cast<difference_type
>(
1775 add_sso_to_tx(sz, count + 1);
1776 traits_type::assign(&sso_data()._data[sz],
1779 assert(new_size == sz + count);
1780 set_sso_size(new_size);
1781 sso_data()._data[new_size] = value_type(
'\0');
1785 non_sso_data().insert(non_sso_data().cbegin() +
1786 static_cast<difference_type
>(sz),
1811 template <
typename CharT,
typename Traits>
1815 return append(str.
data(), str.
size());
1843 template <
typename CharT,
typename Traits>
1848 auto sz = str.
size();
1851 throw std::out_of_range(
"Index out of range.");
1853 count = (std::min)(count, sz - pos);
1855 append(str.
data() + pos, count);
1879 template <
typename CharT,
typename Traits>
1883 return append(s, s + count);
1905 template <
typename CharT,
typename Traits>
1909 return append(s, traits_type::length(s));
1933 template <
typename CharT,
typename Traits>
1934 template <
typename InputIt,
typename Enable>
1939 auto count =
static_cast<size_type
>(std::distance(first, last));
1940 auto new_size = sz + count;
1942 if (new_size > max_size())
1943 throw std::length_error(
"Size exceeds max size.");
1945 if (is_sso_used()) {
1946 auto pop = get_pool();
1949 if (new_size > sso_capacity) {
1958 std::vector<value_type> str(first, last);
1960 sso_to_large(new_size);
1961 non_sso_data().insert(
1962 non_sso_data().cbegin() +
1963 static_cast<difference_type
>(
1965 str.begin(), str.end());
1967 add_sso_to_tx(sz, count + 1);
1968 std::copy(first, last, &sso_data()._data[sz]);
1970 assert(new_size == sz + count);
1971 set_sso_size(new_size);
1972 sso_data()._data[new_size] = value_type(
'\0');
1976 non_sso_data().insert(non_sso_data().cbegin() +
1977 static_cast<difference_type
>(sz),
2002 template <
typename CharT,
typename Traits>
2006 return append(ilist.begin(), ilist.end());
2025 template <
typename CharT,
typename Traits>
2029 append(
static_cast<size_type
>(1), ch);
2050 template <
typename CharT,
typename Traits>
2076 template <
typename CharT,
typename Traits>
2099 template <
typename CharT,
typename Traits>
2126 template <
typename CharT,
typename Traits>
2130 return append(ilist);
2154 template <
typename CharT,
typename Traits>
2159 throw std::out_of_range(
"Index out of range.");
2161 auto pos = cbegin() +
static_cast<difference_type
>(index);
2163 insert(pos, count, ch);
2189 template <
typename CharT,
typename Traits>
2193 return insert(index, s, traits_type::length(s));
2217 template <
typename CharT,
typename Traits>
2223 throw std::out_of_range(
"Index out of range.");
2225 auto pos = cbegin() +
static_cast<difference_type
>(index);
2227 insert(pos, s, s + count);
2252 template <
typename CharT,
typename Traits>
2256 return insert(index, str.
data(), str.
size());
2281 template <
typename CharT,
typename Traits>
2284 size_type index2, size_type count)
2286 auto sz = str.
size();
2288 if (index1 > size() || index2 > sz)
2289 throw std::out_of_range(
"Index out of range.");
2291 count = (std::min)(count, sz - index2);
2293 return insert(index1, str.
data() + index2, count);
2318 template <
typename CharT,
typename Traits>
2322 return insert(pos, 1, ch);
2349 template <
typename CharT,
typename Traits>
2356 if (sz + count > max_size())
2357 throw std::length_error(
"Count exceeds max size.");
2359 auto new_size = sz + count;
2361 auto pop = get_pool();
2363 auto index =
static_cast<size_type
>(std::distance(cbegin(), pos));
2366 if (is_sso_used() && new_size <= sso_capacity) {
2367 auto len = sz - index;
2369 add_sso_to_tx(index, len + count + 1);
2371 traits_type::move(&sso_data()._data[index + count],
2372 &sso_data()._data[index], len);
2373 traits_type::assign(&sso_data()._data[index], count,
2376 assert(new_size == index + len + count);
2377 set_sso_size(new_size);
2378 sso_data()._data[new_size] = value_type(
'\0');
2381 sso_to_large(new_size);
2383 non_sso_data().insert(
2384 non_sso_data().begin() +
2385 static_cast<difference_type
>(index),
2390 return iterator(&data()[
static_cast<difference_type
>(index)]);
2417 template <
typename CharT,
typename Traits>
2418 template <
typename InputIt,
typename Enable>
2425 auto count =
static_cast<size_type
>(std::distance(first, last));
2427 if (sz + count > max_size())
2428 throw std::length_error(
"Count exceeds max size.");
2430 auto pop = get_pool();
2432 auto new_size = sz + count;
2434 auto index =
static_cast<size_type
>(std::distance(cbegin(), pos));
2437 if (is_sso_used() && new_size <= sso_capacity) {
2438 auto len = sz - index;
2440 add_sso_to_tx(index, len + count + 1);
2442 traits_type::move(&sso_data()._data[index + count],
2443 &sso_data()._data[index], len);
2444 std::copy(first, last, &sso_data()._data[index]);
2446 assert(new_size == index + len + count);
2447 set_sso_size(new_size);
2448 sso_data()._data[new_size] = value_type(
'\0');
2450 if (is_sso_used()) {
2459 std::vector<value_type> str(first, last);
2461 sso_to_large(new_size);
2462 non_sso_data().insert(
2463 non_sso_data().begin() +
2464 static_cast<difference_type
>(
2466 str.begin(), str.end());
2468 non_sso_data().insert(
2469 non_sso_data().begin() +
2470 static_cast<difference_type
>(
2477 return iterator(&data()[
static_cast<difference_type
>(index)]);
2503 template <
typename CharT,
typename Traits>
2506 std::initializer_list<CharT> ilist)
2508 return insert(pos, ilist.begin(), ilist.end());
2533 template <
typename CharT,
typename Traits>
2538 return replace(index, count, str.
data(), str.
size());
2561 template <
typename CharT,
typename Traits>
2566 return replace(first, last, str.
data(), str.
data() + str.
size());
2595 template <
typename CharT,
typename Traits>
2601 auto sz = str.
size();
2604 throw std::out_of_range(
"Index out of range.");
2606 count2 = (std::min)(count2, sz - index2);
2608 return replace(index, count, str.
data() + index2, count2);
2636 template <
typename CharT,
typename Traits>
2637 template <
typename InputIt,
typename Enable>
2640 InputIt first2, InputIt last2)
2643 auto index =
static_cast<size_type
>(std::distance(cbegin(), first));
2644 auto count =
static_cast<size_type
>(std::distance(first, last));
2645 auto count2 =
static_cast<size_type
>(std::distance(first2, last2));
2647 count = (std::min)(count, sz - index);
2649 if (sz - count + count2 > max_size())
2650 throw std::length_error(
"Count exceeds max size.");
2652 auto new_size = sz - count + count2;
2654 auto pop = get_pool();
2657 if (is_sso_used() && new_size <= sso_capacity) {
2658 add_sso_to_tx(index, new_size - index + 1);
2660 assert(count2 < new_size + 1);
2661 traits_type::move(&sso_data()._data[index + count2],
2662 &sso_data()._data[index + count],
2663 sz - index - count);
2664 std::copy(first2, last2, &sso_data()._data[index]);
2666 set_sso_size(new_size);
2667 sso_data()._data[new_size] = value_type(
'\0');
2677 std::vector<value_type> str(first2, last2);
2679 if (is_sso_used()) {
2680 sso_to_large(new_size);
2684 begin() +
static_cast<difference_type
>(index);
2685 auto end = beg +
static_cast<difference_type
>(count);
2686 non_sso_data().erase(beg, end);
2687 non_sso_data().insert(beg, str.begin(), str.end());
2690 if (!is_sso_used() && new_size <= sso_capacity)
2719 template <
typename CharT,
typename Traits>
2722 const CharT *s, size_type count2)
2724 return replace(first, last, s, s + count2);
2750 template <
typename CharT,
typename Traits>
2753 const CharT *s, size_type count2)
2756 throw std::out_of_range(
"Index out of range.");
2758 auto first = cbegin() +
static_cast<difference_type
>(index);
2759 auto last = first +
static_cast<difference_type
>(count);
2761 return replace(first, last, s, s + count2);
2787 template <
typename CharT,
typename Traits>
2792 return replace(index, count, s, traits_type::length(s));
2818 template <
typename CharT,
typename Traits>
2821 size_type count2, CharT ch)
2824 throw std::out_of_range(
"Index out of range.");
2826 auto first = cbegin() +
static_cast<difference_type
>(index);
2827 auto last = first +
static_cast<difference_type
>(count);
2829 return replace(first, last, count2, ch);
2854 template <
typename CharT,
typename Traits>
2857 size_type count2, CharT ch)
2860 auto index =
static_cast<size_type
>(std::distance(cbegin(), first));
2861 auto count =
static_cast<size_type
>(std::distance(first, last));
2863 count = (std::min)(count, sz - index);
2865 if (sz - count + count2 > max_size())
2866 throw std::length_error(
"Count exceeds max size.");
2868 auto new_size = sz - count + count2;
2870 auto pop = get_pool();
2873 if (is_sso_used() && new_size <= sso_capacity) {
2874 add_sso_to_tx(index, new_size - index + 1);
2876 assert(count2 < new_size + 1);
2877 traits_type::move(&sso_data()._data[index + count2],
2878 &sso_data()._data[index + count],
2879 sz - index - count);
2880 traits_type::assign(&sso_data()._data[index], count2,
2883 set_sso_size(new_size);
2884 sso_data()._data[new_size] = value_type(
'\0');
2886 if (is_sso_used()) {
2887 sso_to_large(new_size);
2891 begin() +
static_cast<difference_type
>(index);
2892 auto end = beg +
static_cast<difference_type
>(count);
2893 non_sso_data().erase(beg, end);
2894 non_sso_data().insert(beg, count2, ch);
2897 if (!is_sso_used() && new_size <= sso_capacity)
2925 template <
typename CharT,
typename Traits>
2930 return replace(first, last, s, traits_type::length(s));
2955 template <
typename CharT,
typename Traits>
2958 std::initializer_list<CharT> ilist)
2960 return replace(first, last, ilist.begin(), ilist.end());
2976 template <
typename CharT,
typename Traits>
2977 typename basic_string<CharT, Traits>::size_type
2979 size_type index)
const
2984 throw std::out_of_range(
"Index out of range.");
2986 auto len = (std::min)(count, sz - index);
2988 traits_type::copy(s, data() + index, len);
3010 template <
typename CharT,
typename Traits>
3013 const CharT *s, size_type count2)
const
3016 throw std::out_of_range(
"Index out of range.");
3018 if (count1 > size() - pos)
3019 count1 = size() - pos;
3021 auto ret = traits_type::compare(cdata() + pos, s,
3022 std::min<size_type>(count1, count2));
3027 if (count1 < count2)
3029 else if (count1 == count2)
3044 template <
typename CharT,
typename Traits>
3045 typename basic_string<CharT, Traits>::size_type
3049 return find(str.data(), pos, str.size());
3063 template <
typename CharT,
typename Traits>
3064 typename basic_string<CharT, Traits>::size_type
3066 size_type count)
const
3081 template <
typename CharT,
typename Traits>
3082 typename basic_string<CharT, Traits>::size_type
3085 return find(s, pos, traits_type::length(s));
3097 template <
typename CharT,
typename Traits>
3098 typename basic_string<CharT, Traits>::size_type
3101 return find(&ch, pos, 1);
3114 template <
typename CharT,
typename Traits>
3115 typename basic_string<CharT, Traits>::size_type
3119 return rfind(str.cdata(), pos, str.size());
3138 template <
typename CharT,
typename Traits>
3139 typename basic_string<CharT, Traits>::size_type
3141 size_type count)
const
3158 template <
typename CharT,
typename Traits>
3159 typename basic_string<CharT, Traits>::size_type
3162 return rfind(s, pos, traits_type::length(s));
3176 template <
typename CharT,
typename Traits>
3177 typename basic_string<CharT, Traits>::size_type
3180 return rfind(&ch, pos, 1);
3192 template <
typename CharT,
typename Traits>
3193 typename basic_string<CharT, Traits>::size_type
3195 size_type pos)
const noexcept
3197 return find_first_of(str.cdata(), pos, str.size());
3213 template <
typename CharT,
typename Traits>
3214 typename basic_string<CharT, Traits>::size_type
3216 size_type count)
const
3234 template <
typename CharT,
typename Traits>
3235 typename basic_string<CharT, Traits>::size_type
3238 return find_first_of(s, pos, traits_type::length(s));
3250 template <
typename CharT,
typename Traits>
3251 typename basic_string<CharT, Traits>::size_type
3255 return find(ch, pos);
3267 template <
typename CharT,
typename Traits>
3268 typename basic_string<CharT, Traits>::size_type
3270 size_type pos)
const noexcept
3272 return find_first_not_of(str.cdata(), pos, str.size());
3288 template <
typename CharT,
typename Traits>
3289 typename basic_string<CharT, Traits>::size_type
3291 size_type count)
const
3309 template <
typename CharT,
typename Traits>
3310 typename basic_string<CharT, Traits>::size_type
3312 size_type pos)
const
3314 return find_first_not_of(s, pos, traits_type::length(s));
3326 template <
typename CharT,
typename Traits>
3327 typename basic_string<CharT, Traits>::size_type
3331 return find_first_not_of(&ch, pos, 1);
3343 template <
typename CharT,
typename Traits>
3344 typename basic_string<CharT, Traits>::size_type
3346 size_type pos)
const noexcept
3348 return find_last_of(str.cdata(), pos, str.size());
3364 template <
typename CharT,
typename Traits>
3365 typename basic_string<CharT, Traits>::size_type
3367 size_type count)
const
3385 template <
typename CharT,
typename Traits>
3386 typename basic_string<CharT, Traits>::size_type
3389 return find_last_of(s, pos, traits_type::length(s));
3401 template <
typename CharT,
typename Traits>
3402 typename basic_string<CharT, Traits>::size_type
3406 return rfind(ch, pos);
3418 template <
typename CharT,
typename Traits>
3419 typename basic_string<CharT, Traits>::size_type
3421 size_type pos)
const noexcept
3423 return find_last_not_of(str.cdata(), pos, str.size());
3439 template <
typename CharT,
typename Traits>
3440 typename basic_string<CharT, Traits>::size_type
3442 size_type count)
const
3460 template <
typename CharT,
typename Traits>
3461 typename basic_string<CharT, Traits>::size_type
3463 size_type pos)
const
3465 return find_last_not_of(s, pos, traits_type::length(s));
3477 template <
typename CharT,
typename Traits>
3478 typename basic_string<CharT, Traits>::size_type
3482 return find_last_not_of(&ch, pos, 1);
3493 template <
typename CharT,
typename Traits>
3497 return compare(0, size(), other.
cdata(), other.
size());
3508 template <
typename CharT,
typename Traits>
3511 const std::basic_string<CharT> &other)
const
3513 return compare(0, size(), other.data(), other.size());
3529 template <
typename CharT,
typename Traits>
3534 return compare(pos, count, other.
cdata(), other.
size());
3551 template <
typename CharT,
typename Traits>
3554 size_type pos, size_type count,
3555 const std::basic_string<CharT> &other)
const
3557 return compare(pos, count, other.data(), other.size());
3578 template <
typename CharT,
typename Traits>
3582 size_type count2)
const
3584 if (pos2 > other.
size())
3585 throw std::out_of_range(
"Index out of range.");
3587 if (count2 > other.
size() - pos2)
3588 count2 = other.
size() - pos2;
3590 return compare(pos1, count1, other.
cdata() + pos2, count2);
3611 template <
typename CharT,
typename Traits>
3614 const std::basic_string<CharT> &other,
3615 size_type pos2, size_type count2)
const
3617 if (pos2 > other.size())
3618 throw std::out_of_range(
"Index out of range.");
3620 if (count2 > other.size() - pos2)
3621 count2 = other.size() - pos2;
3623 return compare(pos1, count1, other.data() + pos2, count2);
3634 template <
typename CharT,
typename Traits>
3638 return compare(0, size(), s, traits_type::length(s));
3654 template <
typename CharT,
typename Traits>
3657 const CharT *s)
const
3659 return compare(pos, count, s, traits_type::length(s));
3665 template <
typename CharT,
typename Traits>
3669 return is_sso_used() ? sso_data().cdata() : non_sso_data().cdata();
3675 template <
typename CharT,
typename Traits>
3685 template <
typename CharT,
typename Traits>
3695 template <
typename CharT,
typename Traits>
3696 typename basic_string<CharT, Traits>::size_type
3705 template <
typename CharT,
typename Traits>
3706 typename basic_string<CharT, Traits>::size_type
3709 return PMEMOBJ_MAX_ALLOC_SIZE /
sizeof(CharT) - 1;
3716 template <
typename CharT,
typename Traits>
3717 typename basic_string<CharT, Traits>::size_type
3720 return is_sso_used() ? sso_capacity : non_sso_data().capacity() - 1;
3742 template <
typename CharT,
typename Traits>
3746 if (count > max_size())
3747 throw std::length_error(
"Count exceeds max size.");
3751 auto pop = get_pool();
3755 append(count - sz, ch);
3756 }
else if (is_sso_used()) {
3757 set_sso_size(count);
3758 sso_data()[count] = value_type(
'\0');
3760 non_sso_data().resize(count + 1, ch);
3761 non_sso_data().back() = value_type(
'\0');
3784 template <
typename CharT,
typename Traits>
3788 resize(count, CharT());
3811 template <
typename CharT,
typename Traits>
3815 if (new_cap > max_size())
3816 throw std::length_error(
"New capacity exceeds max size.");
3818 if (new_cap < capacity() || new_cap <= sso_capacity)
3821 if (is_sso_used()) {
3822 auto pop = get_pool();
3826 non_sso_data().reserve(new_cap + 1);
3843 template <
typename CharT,
typename Traits>
3850 if (size() <= sso_capacity) {
3851 auto pop = get_pool();
3855 non_sso_data().shrink_to_fit();
3868 template <
typename CharT,
typename Traits>
3872 erase(begin(), end());
3887 template <
typename CharT,
typename Traits>
3891 auto pop = get_pool();
3894 if (is_sso_used()) {
3895 add_sso_to_tx(0, get_sso_size() + 1);
3899 non_sso_data().free_data();
3900 detail::destroy<non_sso_type>(non_sso_data());
3909 template <
typename CharT,
typename Traits>
3916 template <
typename CharT,
typename Traits>
3920 return (sso._size & _sso_mask) != 0;
3923 template <
typename CharT,
typename Traits>
3925 basic_string<CharT, Traits>::destroy_data()
3927 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
3929 if (is_sso_used()) {
3930 add_sso_to_tx(0, get_sso_size() + 1);
3933 non_sso_data().free_data();
3934 detail::destroy<non_sso_type>(non_sso_data());
3944 template <
typename CharT,
typename Traits>
3945 template <
typename InputIt,
typename Enable>
3946 typename basic_string<CharT, Traits>::size_type
3947 basic_string<CharT, Traits>::get_size(InputIt first, InputIt last)
const
3949 return static_cast<size_type
>(std::distance(first, last));
3958 template <
typename CharT,
typename Traits>
3959 typename basic_string<CharT, Traits>::size_type
3960 basic_string<CharT, Traits>::get_size(size_type count, value_type ch)
const
3971 template <
typename CharT,
typename Traits>
3972 typename basic_string<CharT, Traits>::size_type
3973 basic_string<CharT, Traits>::get_size(
const basic_string &other)
const
3975 return other.size();
3984 template <
typename CharT,
typename Traits>
3985 template <
typename... Args>
3986 typename basic_string<CharT, Traits>::pointer
3987 basic_string<CharT, Traits>::replace_content(Args &&... args)
3989 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
3991 auto new_size = get_size(std::forward<Args>(args)...);
3994 if (!is_sso_used() && new_size <= capacity())
3995 return assign_large_data(std::forward<Args>(args)...);
4000 return initialize(std::forward<Args>(args)...);
4013 template <
typename CharT,
typename Traits>
4014 template <
typename... Args>
4015 typename basic_string<CharT, Traits>::pointer
4016 basic_string<CharT, Traits>::initialize(Args &&... args)
4018 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
4020 if (is_sso_used()) {
4021 return assign_sso_data(std::forward<Args>(args)...);
4023 return assign_large_data(std::forward<Args>(args)...);
4036 template <
typename CharT,
typename Traits>
4038 basic_string<CharT, Traits>::allocate(size_type n)
4040 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
4042 if (n <= sso_capacity) {
4052 if (!is_sso_used()) {
4054 POBJ_XADD_NO_SNAPSHOT);
4055 detail::create<non_sso_type>(&non_sso_data());
4056 non_sso_data().reserve(n + 1);
4063 template <
typename CharT,
typename Traits>
4064 template <
typename InputIt,
typename Enable>
4065 typename basic_string<CharT, Traits>::pointer
4066 basic_string<CharT, Traits>::assign_sso_data(InputIt first, InputIt last)
4068 auto size =
static_cast<size_type
>(std::distance(first, last));
4070 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
4071 assert(size <= sso_capacity);
4073 add_sso_to_tx(0, size + 1);
4074 std::copy(first, last, &sso_data()._data[0]);
4076 sso_data()._data[size] = value_type(
'\0');
4080 return &sso_data()[0];
4086 template <
typename CharT,
typename Traits>
4087 typename basic_string<CharT, Traits>::pointer
4088 basic_string<CharT, Traits>::assign_sso_data(size_type count, value_type ch)
4090 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
4091 assert(count <= sso_capacity);
4093 add_sso_to_tx(0, count + 1);
4094 traits_type::assign(&sso_data()._data[0], count, ch);
4096 sso_data()._data[count] = value_type(
'\0');
4098 set_sso_size(count);
4100 return &sso_data()[0];
4107 template <
typename CharT,
typename Traits>
4108 template <
typename InputIt,
typename Enable>
4109 typename basic_string<CharT, Traits>::pointer
4110 basic_string<CharT, Traits>::assign_large_data(InputIt first, InputIt last)
4112 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
4114 auto size =
static_cast<size_type
>(std::distance(first, last));
4116 non_sso_data().reserve(size + 1);
4117 non_sso_data().assign(first, last);
4118 non_sso_data().push_back(value_type(
'\0'));
4120 return non_sso_data().data();
4127 template <
typename CharT,
typename Traits>
4128 typename basic_string<CharT, Traits>::pointer
4129 basic_string<CharT, Traits>::assign_large_data(size_type count, value_type ch)
4131 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
4133 non_sso_data().reserve(count + 1);
4134 non_sso_data().assign(count, ch);
4135 non_sso_data().push_back(value_type(
'\0'));
4137 return non_sso_data().data();
4144 template <
typename CharT,
typename Traits>
4145 typename basic_string<CharT, Traits>::pointer
4146 basic_string<CharT, Traits>::move_data(basic_string &&other)
4148 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
4150 typename basic_string::pointer ptr;
4152 if (other.size() <= sso_capacity) {
4154 ptr = assign_sso_data(other.cbegin(), other.cend());
4158 POBJ_XADD_NO_SNAPSHOT);
4159 detail::create<non_sso_type>(&non_sso_data());
4161 assert(!other.is_sso_used());
4162 non_sso_data() = std::move(other.non_sso_data());
4164 ptr = non_sso_data().data();
4167 if (other.is_sso_used())
4168 other.initialize(0U, value_type(
'\0'));
4176 template <
typename CharT,
typename Traits>
4182 if (is_sso_used() && other.is_sso_used()) {
4183 sso_data().swap(other.sso_data());
4184 pmem::obj::swap(sso._size, other.sso._size);
4185 }
else if (!is_sso_used() && !other.is_sso_used()) {
4186 non_sso_data().swap(other.non_sso_data());
4188 basic_string *_short, *_long;
4189 if (size() > other.size()) {
4197 std::basic_string<CharT, Traits> tmp(_short->c_str(),
4208 template <
typename CharT,
typename Traits>
4217 template <
typename CharT,
typename Traits>
4227 template <
typename CharT,
typename Traits>
4229 basic_string<CharT, Traits>::check_pmem()
const
4231 if (pmemobj_pool_by_ptr(
this) ==
nullptr)
4238 template <
typename CharT,
typename Traits>
4240 basic_string<CharT, Traits>::check_tx_stage_work()
const
4242 if (pmemobj_tx_stage() != TX_STAGE_WORK)
4244 "Call made out of transaction scope.");
4251 template <
typename CharT,
typename Traits>
4253 basic_string<CharT, Traits>::check_pmem_tx()
const
4256 check_tx_stage_work();
4262 template <
typename CharT,
typename Traits>
4264 basic_string<CharT, Traits>::add_sso_to_tx(size_type idx_first,
4265 size_type num)
const
4267 assert(idx_first + num <= sso_capacity + 1);
4268 assert(is_sso_used());
4270 auto initialized_num = get_sso_size() + 1 - idx_first;
4274 (std::min)(initialized_num, num));
4276 if (num > initialized_num) {
4279 &sso_data()._data[0] + get_sso_size() + 1,
4280 num - initialized_num, POBJ_XADD_NO_SNAPSHOT);
4287 template <
typename CharT,
typename Traits>
4288 typename basic_string<CharT, Traits>::size_type
4289 basic_string<CharT, Traits>::get_sso_size()
const
4291 return sso._size & ~_sso_mask;
4297 template <
typename CharT,
typename Traits>
4299 basic_string<CharT, Traits>::enable_sso()
4303 sso._size |= (size_type)(_sso_mask);
4309 template <
typename CharT,
typename Traits>
4311 basic_string<CharT, Traits>::disable_sso()
4313 sso._size &= ~_sso_mask;
4319 template <
typename CharT,
typename Traits>
4321 basic_string<CharT, Traits>::set_sso_size(size_type new_size)
4323 sso._size = new_size | _sso_mask;
4337 template <
typename CharT,
typename Traits>
4339 basic_string<CharT, Traits>::sso_to_large(
size_t new_capacity)
4341 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
4342 assert(new_capacity > sso_capacity);
4343 assert(is_sso_used());
4348 std::copy(cbegin(), cend(), tmp.data());
4349 tmp[sz] = value_type(
'\0');
4352 allocate(new_capacity);
4354 auto begin = tmp.cbegin();
4355 auto end = begin + sz;
4357 initialize(begin, end);
4359 assert(!is_sso_used());
4371 template <
typename CharT,
typename Traits>
4373 basic_string<CharT, Traits>::large_to_sso()
4375 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
4376 assert(!is_sso_used());
4380 assert(sz <= sso_capacity);
4383 std::copy(cbegin(), cbegin() + sz, tmp.data());
4384 tmp[sz] = value_type(
'\0');
4389 auto begin = tmp.cbegin();
4390 auto end = begin + sz;
4392 initialize(begin, end);
4394 assert(is_sso_used());
4397 template <
typename CharT,
typename Traits>
4398 typename basic_string<CharT, Traits>::non_sso_type &
4399 basic_string<CharT, Traits>::non_sso_data()
4401 assert(!is_sso_used());
4402 return non_sso._data;
4405 template <
typename CharT,
typename Traits>
4406 typename basic_string<CharT, Traits>::sso_type &
4407 basic_string<CharT, Traits>::sso_data()
4409 assert(is_sso_used());
4413 template <
typename CharT,
typename Traits>
4414 const typename basic_string<CharT, Traits>::non_sso_type &
4415 basic_string<CharT, Traits>::non_sso_data()
const
4417 assert(!is_sso_used());
4418 return non_sso._data;
4421 template <
typename CharT,
typename Traits>
4422 const typename basic_string<CharT, Traits>::sso_type &
4423 basic_string<CharT, Traits>::sso_data()
const
4425 assert(is_sso_used());
4433 template <
typename CharT,
typename Traits>
4434 template <
typename T,
typename Enable>
4435 basic_string<CharT, Traits> &
4438 return erase(
static_cast<size_type
>(param));
4445 template <
typename CharT,
typename Traits>
4446 template <
typename T,
typename Enable>
4450 return erase(
static_cast<const_iterator
>(param));
4458 template <
typename CharT,
typename Traits>
4459 template <
typename T,
typename Enable>
4463 return insert(
static_cast<size_type
>(param), count, ch);
4471 template <
typename CharT,
typename Traits>
4472 template <
typename T,
typename Enable>
4476 return insert(
static_cast<const_iterator
>(param), count, ch);
4483 template <
class CharT,
class Traits>
4495 template <
class CharT,
class Traits>
4507 template <
class CharT,
class Traits>
4519 template <
class CharT,
class Traits>
4531 template <
class CharT,
class Traits>
4543 template <
class CharT,
class Traits>
4555 template <
class CharT,
class Traits>
4566 template <
class CharT,
class Traits>
4577 template <
class CharT,
class Traits>
4588 template <
class CharT,
class Traits>
4599 template <
class CharT,
class Traits>
4610 template <
class CharT,
class Traits>
4621 template <
class CharT,
class Traits>
4632 template <
class CharT,
class Traits>
4643 template <
class CharT,
class Traits>
4654 template <
class CharT,
class Traits>
4665 template <
class CharT,
class Traits>
4676 template <
class CharT,
class Traits>
4687 template <
class CharT,
class Traits>
4699 template <
class CharT,
class Traits>
4711 template <
class CharT,
class Traits>
4713 operator<(
const std::basic_string<CharT, Traits> &lhs,
4723 template <
class CharT,
class Traits>
4725 operator<=(
const std::basic_string<CharT, Traits> &lhs,
4735 template <
class CharT,
class Traits>
4747 template <
class CharT,
class Traits>
4759 template <
class CharT,
class Traits>
4762 const std::basic_string<CharT, Traits> &rhs)
4771 template <
class CharT,
class Traits>
4774 const std::basic_string<CharT, Traits> &rhs)
4783 template <
class CharT,
class Traits>
4786 const std::basic_string<CharT, Traits> &rhs)
4795 template <
class CharT,
class Traits>
4798 const std::basic_string<CharT, Traits> &rhs)
4807 template <
class CharT,
class Traits>
4810 const std::basic_string<CharT, Traits> &rhs)
4819 template <
class CharT,
class Traits>
4822 const std::basic_string<CharT, Traits> &rhs)
4831 template <
class CharT,
class Traits>
4835 return lhs.
swap(rhs);
Array container with std::array compatible interface.
Our partial std::string_view implementation.
Definition: string_view.hpp:48
constexpr size_type size() const noexcept
Returns count of characters stored in this pmem::obj::string_view data.
Definition: string_view.hpp:397
size_type find(basic_string_view str, size_type pos=0) const noexcept
Finds the first substring equal to str.
Definition: string_view.hpp:521
size_type find_first_not_of(basic_string_view str, size_type pos=0) const noexcept
Finds the first character equal to none of the characters in str.
Definition: string_view.hpp:775
size_type find_last_not_of(basic_string_view str, size_type pos=npos) const noexcept
Finds the last character equal to none of the characters in str.
Definition: string_view.hpp:950
size_type find_last_of(basic_string_view str, size_type pos=npos) const noexcept
Finds the last character equal to any of the characters in str.
Definition: string_view.hpp:860
size_type rfind(basic_string_view str, size_type pos=npos) const noexcept
Finds the last substring equal to str.
Definition: string_view.hpp:609
size_type find_first_of(basic_string_view str, size_type pos=0) const noexcept
Finds the first character equal to any of the characters in str.
Definition: string_view.hpp:694
constexpr const CharT * data() const noexcept
Returns pointer to data stored in this pmem::obj::string_view.
Definition: string_view.hpp:359
Persistent string container with std::basic_string compatible interface.
Definition: basic_string.hpp:48
void for_each_ptr(for_each_ptr_function func)
Iterates over all internal pointers and executes a callback function on each of them.
Definition: basic_string.hpp:1135
void resize(size_type count, CharT ch)
Resize the string to count characters transactionally.
Definition: basic_string.hpp:3744
bool operator>(const basic_string< CharT, Traits > &lhs, const std::basic_string< CharT, Traits > &rhs)
Non-member greater than operator.
Definition: basic_string.hpp:4809
void clear()
Remove all characters from the string transactionally.
Definition: basic_string.hpp:3870
bool operator==(const std::basic_string< CharT, Traits > &lhs, const basic_string< CharT, Traits > &rhs)
Non-member equal operator.
Definition: basic_string.hpp:4689
reverse_iterator rbegin()
Return a reverse iterator to the beginning.
Definition: basic_string.hpp:1226
size_type find_first_not_of(const basic_string &str, size_type pos=0) const noexcept
Finds the first character equal to none of the characters in str.
Definition: basic_string.hpp:3269
slice< pointer > range(size_type p, size_type count)
Returns slice and snapshots requested range.
Definition: basic_string.hpp:1408
const_iterator cbegin() const noexcept
Return const iterator to the beginning.
Definition: basic_string.hpp:1174
iterator begin()
Return an iterator to the beginning.
Definition: basic_string.hpp:1149
bool empty() const noexcept
Definition: basic_string.hpp:3911
basic_string & erase(size_type index=0, size_type count=npos)
Remove characters from string starting at index transactionally.
Definition: basic_string.hpp:1623
const_reverse_iterator crbegin() const noexcept
Return a const reverse iterator to the beginning.
Definition: basic_string.hpp:1252
void shrink_to_fit()
Remove unused capacity transactionally.
Definition: basic_string.hpp:3845
bool operator>=(const basic_string< CharT, Traits > &lhs, const CharT *rhs)
Non-member greater or equal operator.
Definition: basic_string.hpp:4678
reference at(size_type n)
Access element at specific index with bounds checking and snapshot it if there is an active transacti...
Definition: basic_string.hpp:1311
basic_string & append(size_type count, CharT ch)
Append count copies of character ch to the string transactionally.
Definition: basic_string.hpp:1754
void push_back(CharT ch)
Append character ch at the end of the string transactionally.
Definition: basic_string.hpp:2027
void swap(basic_string &other)
Swap the content of persistent strings.
Definition: basic_string.hpp:4178
bool operator>=(const CharT *lhs, const basic_string< CharT, Traits > &rhs)
Non-member greater or equal operator.
Definition: basic_string.hpp:4612
void pop_back()
Remove the last character from the string transactionally.
Definition: basic_string.hpp:1728
iterator end()
Return an iterator to past the end.
Definition: basic_string.hpp:1187
bool operator!=(const basic_string< CharT, Traits > &lhs, const std::basic_string< CharT, Traits > &rhs)
Non-member not equal operator.
Definition: basic_string.hpp:4773
size_type length() const noexcept
Definition: basic_string.hpp:3697
bool operator!=(const basic_string< CharT, Traits > &lhs, const CharT *rhs)
Non-member not equal operator.
Definition: basic_string.hpp:4634
size_type copy(CharT *s, size_type count, size_type index=0) const
Copy [index, index + count) substring of *this to C-style string.
Definition: basic_string.hpp:2978
CharT * data()
Definition: basic_string.hpp:1597
size_type size() const noexcept
Definition: basic_string.hpp:1579
void swap(basic_string< CharT, Traits > &lhs, basic_string< CharT, Traits > &rhs)
Swap the content of persistent strings.
Definition: basic_string.hpp:4833
basic_string & insert(size_type index, size_type count, CharT ch)
Insert count copies of ch character at index transactionally.
Definition: basic_string.hpp:2156
int compare(const basic_string &other) const
Compares this string to other.
Definition: basic_string.hpp:3495
reference operator[](size_type n)
Access element at specific index and snapshot it if there is an active transaction.
Definition: basic_string.hpp:1374
void reserve(size_type new_cap=0)
Increase the capacity of the string to new_cap transactionally.
Definition: basic_string.hpp:3813
reverse_iterator rend()
Return a reverse iterator to the end.
Definition: basic_string.hpp:1265
bool operator==(const CharT *lhs, const basic_string< CharT, Traits > &rhs)
Non-member equal operator.
Definition: basic_string.hpp:4557
bool operator==(const basic_string< CharT, Traits > &lhs, const CharT *rhs)
Non-member equal operator.
Definition: basic_string.hpp:4623
basic_string & replace(size_type index, size_type count, const basic_string &str)
Replace range [index, index + count) with the content of str string transactionally.
Definition: basic_string.hpp:2535
basic_string & assign(size_type count, CharT ch)
Replace the contents with count copies of character ch transactionally.
Definition: basic_string.hpp:907
void free_data()
Clears the content of a string and frees all allocated persistent memory for data transactionally.
Definition: basic_string.hpp:3889
bool operator!=(const std::basic_string< CharT, Traits > &lhs, const basic_string< CharT, Traits > &rhs)
Non-member not equal operator.
Definition: basic_string.hpp:4701
const_iterator cend() const noexcept
Return const iterator to past the end.
Definition: basic_string.hpp:1213
size_type find_last_of(const basic_string &str, size_type pos=npos) const noexcept
Finds the last character equal to any of the characters in str.
Definition: basic_string.hpp:3345
bool operator>=(const std::basic_string< CharT, Traits > &lhs, const basic_string< CharT, Traits > &rhs)
Non-member greater or equal operator.
Definition: basic_string.hpp:4749
basic_string()
Default constructor.
Definition: basic_string.hpp:434
size_type rfind(const basic_string &str, size_type pos=npos) const noexcept
Finds the last substring equal to str.
Definition: basic_string.hpp:3116
bool operator>(const basic_string< CharT, Traits > &lhs, const basic_string< CharT, Traits > &rhs)
Non-member greater than operator.
Definition: basic_string.hpp:4533
const CharT & cfront() const
Access first element.
Definition: basic_string.hpp:1526
const CharT * cdata() const noexcept
Definition: basic_string.hpp:3667
~basic_string()
Destructor.
Definition: basic_string.hpp:773
basic_string & operator+=(const basic_string &str)
Append string str transactionally.
Definition: basic_string.hpp:2052
bool operator>(const std::basic_string< CharT, Traits > &lhs, const basic_string< CharT, Traits > &rhs)
Non-member greater than operator.
Definition: basic_string.hpp:4737
bool operator>=(const basic_string< CharT, Traits > &lhs, const basic_string< CharT, Traits > &rhs)
Non-member greater or equal operator.
Definition: basic_string.hpp:4545
const CharT & cback() const
Access last element.
Definition: basic_string.hpp:1569
size_type max_size() const noexcept
Definition: basic_string.hpp:3707
bool operator>=(const basic_string< CharT, Traits > &lhs, const std::basic_string< CharT, Traits > &rhs)
Non-member greater or equal operator.
Definition: basic_string.hpp:4821
bool operator!=(const CharT *lhs, const basic_string< CharT, Traits > &rhs)
Non-member not equal operator.
Definition: basic_string.hpp:4568
size_type find_first_of(const basic_string &str, size_type pos=0) const noexcept
Finds the first character equal to any of the characters in str.
Definition: basic_string.hpp:3194
size_type find_last_not_of(const basic_string &str, size_type pos=npos) const noexcept
Finds the last character equal to none of the characters in str.
Definition: basic_string.hpp:3420
CharT & back()
Access last element and snapshot it if there is an active transaction.
Definition: basic_string.hpp:1542
const_reverse_iterator crend() const noexcept
Return a const reverse iterator to the end.
Definition: basic_string.hpp:1291
CharT & front()
Access first element and snapshot it if there is an active transaction.
Definition: basic_string.hpp:1499
size_type find(const basic_string &str, size_type pos=0) const noexcept
Finds the first substring equal str.
Definition: basic_string.hpp:3046
const_reference const_at(size_type n) const
Access element at specific index with bounds checking.
Definition: basic_string.hpp:1351
const CharT * c_str() const noexcept
Definition: basic_string.hpp:3687
bool operator==(const basic_string< CharT, Traits > &lhs, const std::basic_string< CharT, Traits > &rhs)
Non-member equal operator.
Definition: basic_string.hpp:4761
bool operator>(const basic_string< CharT, Traits > &lhs, const CharT *rhs)
Non-member greater than operator.
Definition: basic_string.hpp:4667
bool operator>(const CharT *lhs, const basic_string< CharT, Traits > &rhs)
Non-member greater than operator.
Definition: basic_string.hpp:4601
size_type capacity() const noexcept
Definition: basic_string.hpp:3718
bool operator!=(const basic_string< CharT, Traits > &lhs, const basic_string< CharT, Traits > &rhs)
Non-member not equal operator.
Definition: basic_string.hpp:4497
slice< const_iterator > crange(size_type start, size_type n) const
Returns const slice.
Definition: basic_string.hpp:1479
bool operator==(const basic_string< CharT, Traits > &lhs, const basic_string< CharT, Traits > &rhs)
Non-member equal operator.
Definition: basic_string.hpp:4485
basic_string & operator=(const basic_string &other)
Copy assignment operator.
Definition: basic_string.hpp:793
static void run(obj::pool_base &pool, std::function< void()> tx, Locks &... locks)
Execute a closure-like transaction and lock locks.
Definition: transaction.hpp:810
Resides on pmem class.
Definition: p.hpp:36
Persistent_ptr base (non-template) class.
Definition: persistent_ptr_base.hpp:42
The non-template pool base class.
Definition: pool.hpp:51
Provides interface to access sequence of objects.
Definition: slice.hpp:61
Custom pool error class.
Definition: pexceptions.hpp:84
Custom transaction error class.
Definition: pexceptions.hpp:167
Commonly used functionality.
Iterators for contiguous persistent containers.
Functions for lifetime management.
void conditional_add_to_tx(const T *that, std::size_t count=1, uint64_t flags=0)
Conditionally add 'count' objects to a transaction.
Definition: common.hpp:176
pool_base pool_by_vptr(const T *that)
Retrieve pool handle for the given pointer.
Definition: utils.hpp:32
Persistent memory namespace.
Definition: allocation_flag.hpp:15
Persistent smart pointer.
Convenience extensions for the resides on pmem property template.
Interface to access sequence of objects.
Our partial std::string_view implementation.
Default non-const iterator which adds element to a transaction on every access.
Definition: contiguous_iterator.hpp:331
Non-const iterator which adds elements to a transaction in a bulk.
Definition: contiguous_iterator.hpp:192
C++ pmemobj transactions.
Vector container with std::vector compatible interface.