38 #ifndef LIBPMEMOBJ_CPP_BASIC_STRING_HPP 39 #define LIBPMEMOBJ_CPP_BASIC_STRING_HPP 62 namespace experimental
71 template <
typename CharT,
typename Traits = std::
char_traits<CharT>>
75 using traits_type = Traits;
76 using value_type = CharT;
77 using size_type = std::size_t;
78 using difference_type = std::ptrdiff_t;
79 using reference = value_type &;
80 using const_reference =
const value_type &;
81 using pointer = value_type *;
82 using const_pointer =
const value_type *;
84 using const_iterator = const_pointer;
85 using reverse_iterator = std::reverse_iterator<iterator>;
86 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
89 static constexpr size_type sso_capacity = (32 - 8) /
sizeof(CharT) - 1;
95 size_type count = npos);
96 basic_string(
const std::basic_string<CharT> &other, size_type pos,
97 size_type count = npos);
102 typename Enable =
typename std::enable_if<
126 size_type count = npos);
128 size_type pos, size_type count = npos);
131 template <
typename InputIt,
139 reference
at(size_type n);
140 const_reference
at(size_type n)
const;
141 const_reference
const_at(size_type n)
const;
143 const_reference
operator[](size_type n)
const;
145 const CharT &
front()
const;
146 const CharT &
cfront()
const;
148 const CharT &
back()
const;
149 const CharT &
cback()
const;
151 const CharT *data()
const noexcept;
152 const CharT *
cdata()
const noexcept;
153 const CharT *
c_str()
const noexcept;
157 const_iterator
begin()
const noexcept;
158 const_iterator
cbegin()
const noexcept;
160 const_iterator
end()
const noexcept;
161 const_iterator
cend()
const noexcept;
162 reverse_iterator
rbegin();
163 const_reverse_iterator
rbegin()
const noexcept;
164 const_reverse_iterator
crbegin()
const noexcept;
165 reverse_iterator
rend();
166 const_reverse_iterator
rend()
const noexcept;
167 const_reverse_iterator
crend()
const noexcept;
170 bool empty()
const noexcept;
171 size_type
size()
const noexcept;
172 size_type
length()
const noexcept;
173 size_type
max_size()
const noexcept;
174 size_type
capacity()
const noexcept;
175 void resize(size_type count, CharT ch);
177 void reserve(size_type new_cap = 0);
186 template <
typename T,
187 typename Enable =
typename std::enable_if<
188 std::is_convertible<T, size_type>::value>::type>
190 template <
typename T,
191 typename Enable =
typename std::enable_if<
192 !std::is_convertible<T, size_type>::value>::type>
198 size_type count = npos);
201 template <
typename InputIt,
208 int compare(
const std::basic_string<CharT> &other)
const;
209 int compare(size_type pos, size_type count,
211 int compare(size_type pos, size_type count,
212 const std::basic_string<CharT> &other)
const;
214 size_type pos2, size_type count2 = npos)
const;
215 int compare(size_type pos1, size_type count1,
216 const std::basic_string<CharT> &other, size_type pos2,
217 size_type count2 = npos)
const;
218 int compare(
const CharT *s)
const;
219 int compare(size_type pos, size_type count,
const CharT *s)
const;
220 int compare(size_type pos, size_type count1,
const CharT *s,
221 size_type count2)
const;
224 static const size_type npos = static_cast<size_type>(-1);
268 static constexpr size_type _sso_mask = 1ULL
269 << (std::numeric_limits<size_type>::digits - 1);
272 bool is_sso_used()
const;
276 typename Enable =
typename std::enable_if<
278 size_type
get_size(InputIt first, InputIt last)
const;
279 size_type
get_size(size_type count, value_type ch)
const;
281 template <
typename... Args>
282 pointer
replace(Args &&... args);
283 template <
typename... Args>
288 typename Enable =
typename std::enable_if<
295 typename Enable =
typename std::enable_if<
322 template <
typename CharT,
typename Traits>
328 initialize(0U, value_type(
'\0'));
345 template <
typename CharT,
typename Traits>
351 initialize(count, ch);
371 template <
typename CharT,
typename Traits>
373 size_type pos, size_type count)
377 if (pos > other.
size())
378 throw std::out_of_range(
"Index out of range.");
380 if (count == npos || pos + count > other.
size())
381 count = other.
size() - pos;
383 auto first = static_cast<difference_type>(pos);
384 auto last = first + static_cast<difference_type>(count);
387 initialize(other.
cbegin() + first, other.
cbegin() + last);
408 template <
typename CharT,
typename Traits>
410 size_type pos, size_type count)
414 if (pos > other.size())
415 throw std::out_of_range(
"Index out of range.");
417 if (count == npos || pos + count > other.size())
418 count = other.size() - pos;
420 auto first = static_cast<difference_type>(pos);
421 auto last = first + static_cast<difference_type>(count);
424 initialize(other.cbegin() + first, other.cbegin() + last);
442 template <
typename CharT,
typename Traits>
448 initialize(s, s + count);
464 template <
typename CharT,
typename Traits>
469 auto length = traits_type::length(s);
472 initialize(s, s + length);
491 template <
typename CharT,
typename Traits>
492 template <
typename InputIt,
typename Enable>
495 auto len = std::distance(first, last);
500 allocate(static_cast<size_type>(len));
501 initialize(first, last);
518 template <
typename CharT,
typename Traits>
523 allocate(other.
size());
542 template <
typename CharT,
typename Traits>
562 template <
typename CharT,
typename Traits>
567 allocate(other.size());
568 initialize(std::move(other));
570 if (other.is_sso_used())
571 other.initialize(0U, value_type(
'\0'));
588 template <
typename CharT,
typename Traits>
593 allocate(ilist.size());
594 initialize(ilist.begin(), ilist.end());
602 template <
typename CharT,
typename Traits>
606 detail::destroy<non_sso_type>(non_sso.data);
618 template <
typename CharT,
typename Traits>
622 return assign(other);
635 template <
typename CharT,
typename Traits>
639 return assign(other);
651 template <
typename CharT,
typename Traits>
655 return assign(std::move(other));
666 template <
typename CharT,
typename Traits>
681 template <
typename CharT,
typename Traits>
685 return assign(1, ch);
697 template <
typename CharT,
typename Traits>
701 return assign(ilist);
714 template <
typename CharT,
typename Traits>
718 auto pop = get_pool();
734 template <
typename CharT,
typename Traits>
741 auto pop = get_pool();
758 template <
typename CharT,
typename Traits>
762 return assign(other.cbegin(), other.cend());
777 template <
typename CharT,
typename Traits>
782 if (pos > other.
size())
783 throw std::out_of_range(
"Index out of range.");
785 if (count == npos || pos + count > other.
size())
786 count = other.
size() - pos;
788 auto pop = get_pool();
789 auto first = static_cast<difference_type>(pos);
790 auto last = first + static_cast<difference_type>(count);
813 template <
typename CharT,
typename Traits>
816 size_type pos, size_type count)
818 if (pos > other.size())
819 throw std::out_of_range(
"Index out of range.");
821 if (count == npos || pos + count > other.size())
822 count = other.
size() - pos;
824 return assign(other.c_str() + pos, count);
837 template <
typename CharT,
typename Traits>
841 auto pop = get_pool();
856 template <
typename CharT,
typename Traits>
860 auto pop = get_pool();
862 auto length = traits_type::length(s);
880 template <
typename CharT,
typename Traits>
881 template <
typename InputIt,
typename Enable>
885 auto pop = get_pool();
901 template <
typename CharT,
typename Traits>
908 auto pop = get_pool();
911 replace(std::move(other));
913 if (other.is_sso_used())
914 other.initialize(0U, value_type(
'\0'));
929 template <
typename CharT,
typename Traits>
933 return assign(ilist.begin(), ilist.end());
941 template <
typename CharT,
typename Traits>
945 return is_sso_used() ?
iterator(&*sso.data.begin())
954 template <
typename CharT,
typename Traits>
955 typename basic_string<CharT, Traits>::const_iterator
966 template <
typename CharT,
typename Traits>
967 typename basic_string<CharT, Traits>::const_iterator
970 return is_sso_used() ? const_iterator(&*sso.data.cbegin())
971 : const_iterator(&*non_sso.data.cbegin());
979 template <
typename CharT,
typename Traits>
983 return begin() + static_cast<difference_type>(size());
992 template <
typename CharT,
typename Traits>
993 typename basic_string<CharT, Traits>::const_iterator
996 return cbegin() + static_cast<difference_type>(size());
1005 template <
typename CharT,
typename Traits>
1006 typename basic_string<CharT, Traits>::const_iterator
1009 return cbegin() + static_cast<difference_type>(size());
1018 template <
typename CharT,
typename Traits>
1019 typename basic_string<CharT, Traits>::reverse_iterator
1022 return reverse_iterator(
end());
1031 template <
typename CharT,
typename Traits>
1032 typename basic_string<CharT, Traits>::const_reverse_iterator
1044 template <
typename CharT,
typename Traits>
1045 typename basic_string<CharT, Traits>::const_reverse_iterator
1048 return const_reverse_iterator(
cend());
1057 template <
typename CharT,
typename Traits>
1058 typename basic_string<CharT, Traits>::reverse_iterator
1061 return reverse_iterator(
begin());
1070 template <
typename CharT,
typename Traits>
1071 typename basic_string<CharT, Traits>::const_reverse_iterator
1083 template <
typename CharT,
typename Traits>
1084 typename basic_string<CharT, Traits>::const_reverse_iterator
1087 return const_reverse_iterator(
cbegin());
1103 template <
typename CharT,
typename Traits>
1104 typename basic_string<CharT, Traits>::reference
1108 throw std::out_of_range(
"string::at");
1110 return is_sso_used() ? sso.data[n] : non_sso.data[n];
1123 template <
typename CharT,
typename Traits>
1124 typename basic_string<CharT, Traits>::const_reference
1143 template <
typename CharT,
typename Traits>
1144 typename basic_string<CharT, Traits>::const_reference
1148 throw std::out_of_range(
"string::const_at");
1150 return is_sso_used()
1151 ? static_cast<const sso_type &>(sso.data)[n]
1152 : static_cast<const non_sso_type &>(non_sso.data)[n];
1166 template <
typename CharT,
typename Traits>
1170 return is_sso_used() ? sso.data[n] : non_sso.data[n];
1180 template <
typename CharT,
typename Traits>
1181 typename basic_string<CharT, Traits>::const_reference
1184 return is_sso_used() ? sso.data[n] : non_sso.data[n];
1196 template <
typename CharT,
typename Traits>
1208 template <
typename CharT,
typename Traits>
1223 template <
typename CharT,
typename Traits>
1227 return static_cast<const basic_string &>(*
this)[0];
1239 template <
typename CharT,
typename Traits>
1243 return (*
this)[size() - 1];
1251 template <
typename CharT,
typename Traits>
1266 template <
typename CharT,
typename Traits>
1270 return static_cast<const basic_string &>(*
this)[size() - 1];
1276 template <
typename CharT,
typename Traits>
1277 typename basic_string<CharT, Traits>::size_type
1281 return get_sso_size();
1282 else if (non_sso.data.size() == 0)
1285 return non_sso.data.size() - 1;
1294 template <
typename CharT,
typename Traits>
1298 return is_sso_used() ? sso.
data.
range(0, get_sso_size() + 1).begin()
1299 : non_sso.data.data();
1320 template <
typename CharT,
typename Traits>
1321 basic_string<CharT, Traits> &
1327 throw std::out_of_range(
"Index exceeds size.");
1329 count = (std::min)(count, sz - index);
1331 auto pop = get_pool();
1333 auto first =
begin() + static_cast<difference_type>(index);
1334 auto last = first + static_cast<difference_type>(count);
1336 if (is_sso_used()) {
1338 auto move_len = sz - index - count;
1340 auto dest = sso.data.range(index, move_len + 1).begin();
1342 traits_type::move(dest, &*last, move_len);
1344 auto new_size = sz - count;
1345 set_sso_size(new_size);
1346 sso.data[new_size] = value_type(
'\0');
1349 non_sso.data.erase(first, last);
1371 template <
typename CharT,
typename Traits>
1375 return erase(pos, pos + 1);
1396 template <
typename CharT,
typename Traits>
1401 static_cast<size_type>(std::distance(
cbegin(), first));
1402 size_type len = static_cast<size_type>(std::distance(first, last));
1406 return begin() + static_cast<difference_type>(index);
1428 template <
typename CharT,
typename Traits>
1433 auto new_size = sz + count;
1435 if (new_size > max_size())
1436 throw std::length_error(
"Size exceeds max size.");
1438 if (is_sso_used()) {
1439 auto pop = get_pool();
1442 if (new_size > sso_capacity) {
1443 sso_to_large(new_size);
1445 non_sso.data.insert(
1446 non_sso.data.cbegin() +
1447 static_cast<difference_type>(
1465 sso.data.range(sz, count + 1).begin();
1466 traits_type::assign(dest, count, ch);
1468 set_sso_size(new_size);
1469 sso.data[new_size] = value_type(
'\0');
1473 non_sso.data.insert(non_sso.data.cbegin() +
1474 static_cast<difference_type>(sz),
1499 template <
typename CharT,
typename Traits>
1503 return append(str.
data(), str.
size());
1531 template <
typename CharT,
typename Traits>
1536 auto sz = str.
size();
1539 throw std::out_of_range(
"Index out of range.");
1541 count = (std::min)(count, sz - pos);
1543 append(str.
data() + pos, count);
1567 template <
typename CharT,
typename Traits>
1571 return append(s, s + count);
1593 template <
typename CharT,
typename Traits>
1597 return append(s, traits_type::length(s));
1621 template <
typename CharT,
typename Traits>
1622 template <
typename InputIt,
typename Enable>
1627 auto count = static_cast<size_type>(std::distance(first, last));
1628 auto new_size = sz + count;
1630 if (new_size > max_size())
1631 throw std::length_error(
"Size exceeds max size.");
1633 if (is_sso_used()) {
1634 auto pop = get_pool();
1637 if (new_size > sso_capacity) {
1646 std::vector<value_type> str(first, last);
1648 sso_to_large(new_size);
1649 non_sso.data.insert(
1650 non_sso.data.cbegin() +
1651 static_cast<difference_type>(
1653 str.begin(), str.end());
1663 sso.data.range(sz, count + 1).begin();
1664 std::copy(first, last, dest);
1666 set_sso_size(new_size);
1667 sso.data[new_size] = value_type(
'\0');
1671 non_sso.data.insert(non_sso.data.cbegin() +
1672 static_cast<difference_type>(sz),
1697 template <
typename CharT,
typename Traits>
1701 return append(ilist.begin(), ilist.end());
1721 template <
typename CharT,
typename Traits>
1724 const CharT *s, size_type count2)
const 1727 throw std::out_of_range(
"Index out of range.");
1729 if (count1 > size() - pos)
1730 count1 = size() - pos;
1732 auto ret = traits_type::compare(cdata() + pos, s,
1733 std::min<size_type>(count1, count2));
1738 if (count1 < count2)
1740 else if (count1 == count2)
1754 template <
typename CharT,
typename Traits>
1758 return compare(0, size(), other.
cdata(), other.
size());
1769 template <
typename CharT,
typename Traits>
1772 const std::basic_string<CharT> &other)
const 1774 return compare(0, size(), other.data(), other.size());
1790 template <
typename CharT,
typename Traits>
1795 return compare(pos, count, other.
cdata(), other.
size());
1812 template <
typename CharT,
typename Traits>
1815 size_type pos, size_type count,
1816 const std::basic_string<CharT> &other)
const 1818 return compare(pos, count, other.data(), other.size());
1839 template <
typename CharT,
typename Traits>
1843 size_type count2)
const 1845 if (pos2 > other.
size())
1846 throw std::out_of_range(
"Index out of range.");
1848 if (count2 > other.
size() - pos2)
1849 count2 = other.
size() - pos2;
1851 return compare(pos1, count1, other.
cdata() + pos2, count2);
1872 template <
typename CharT,
typename Traits>
1875 const std::basic_string<CharT> &other,
1876 size_type pos2, size_type count2)
const 1878 if (pos2 > other.size())
1879 throw std::out_of_range(
"Index out of range.");
1881 if (count2 > other.size() - pos2)
1882 count2 = other.size() - pos2;
1884 return compare(pos1, count1, other.data() + pos2, count2);
1895 template <
typename CharT,
typename Traits>
1899 return compare(0, size(), s, traits_type::length(s));
1915 template <
typename CharT,
typename Traits>
1918 const CharT *s)
const 1920 return compare(pos, count, s, traits_type::length(s));
1926 template <
typename CharT,
typename Traits>
1930 return is_sso_used() ? sso.data.cdata() : non_sso.data.cdata();
1936 template <
typename CharT,
typename Traits>
1946 template <
typename CharT,
typename Traits>
1956 template <
typename CharT,
typename Traits>
1957 typename basic_string<CharT, Traits>::size_type
1966 template <
typename CharT,
typename Traits>
1967 typename basic_string<CharT, Traits>::size_type
1970 return PMEMOBJ_MAX_ALLOC_SIZE /
sizeof(CharT) - 1;
1977 template <
typename CharT,
typename Traits>
1978 typename basic_string<CharT, Traits>::size_type
1981 return is_sso_used() ? sso_capacity : non_sso.data.capacity() - 1;
2002 template <
typename CharT,
typename Traits>
2006 if (count > max_size())
2007 throw std::length_error(
"Count exceeds max size.");
2011 auto pop = get_pool();
2015 append(count - sz, ch);
2016 }
else if (is_sso_used()) {
2017 set_sso_size(count);
2018 sso.data[count] = value_type(
'\0');
2020 non_sso.data.resize(count + 1, ch);
2021 non_sso.data.back() = value_type(
'\0');
2043 template <
typename CharT,
typename Traits>
2047 resize(count, CharT());
2068 template <
typename CharT,
typename Traits>
2072 if (new_cap > max_size())
2073 throw std::length_error(
"New capacity exceeds max size.");
2075 if (new_cap < capacity() || new_cap <= sso_capacity)
2078 if (is_sso_used()) {
2079 auto pop = get_pool();
2083 non_sso.data.reserve(new_cap + 1);
2099 template <
typename CharT,
typename Traits>
2106 if (size() <= sso_capacity) {
2107 auto pop = get_pool();
2111 non_sso.data.shrink_to_fit();
2124 template <
typename CharT,
typename Traits>
2134 template <
typename CharT,
typename Traits>
2141 template <
typename CharT,
typename Traits>
2145 return sso._size & _sso_mask;
2148 template <
typename CharT,
typename Traits>
2150 basic_string<CharT, Traits>::destroy_data()
2152 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
2154 if (is_sso_used()) {
2158 non_sso.data.free_data();
2159 detail::destroy<decltype(non_sso.data)>(non_sso.data);
2169 template <
typename CharT,
typename Traits>
2170 template <
typename InputIt,
typename Enable>
2171 typename basic_string<CharT, Traits>::size_type
2174 return static_cast<size_type>(std::distance(first, last));
2183 template <
typename CharT,
typename Traits>
2184 typename basic_string<CharT, Traits>::size_type
2196 template <
typename CharT,
typename Traits>
2197 typename basic_string<CharT, Traits>::size_type
2200 return other.
size();
2210 template <
typename CharT,
typename Traits>
2211 template <
typename... Args>
2212 typename basic_string<CharT, Traits>::pointer
2215 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
2217 auto new_size = get_size(std::forward<Args>(args)...);
2220 if (!is_sso_used() && new_size <= capacity())
2221 return assign_large_data(std::forward<Args>(args)...);
2226 return initialize(std::forward<Args>(args)...);
2240 template <
typename CharT,
typename Traits>
2241 template <
typename... Args>
2242 typename basic_string<CharT, Traits>::pointer
2245 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
2247 auto size = get_size(std::forward<Args>(args)...);
2249 if (is_sso_used()) {
2251 return assign_sso_data(std::forward<Args>(args)...);
2253 return assign_large_data(std::forward<Args>(args)...);
2266 template <
typename CharT,
typename Traits>
2270 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
2272 if (capacity <= sso_capacity) {
2282 if (!is_sso_used()) {
2283 detail::conditional_add_to_tx(&non_sso.data);
2284 detail::create<decltype(non_sso.data)>(&non_sso.data);
2285 non_sso.data.reserve(capacity +
sizeof(
'\0'));
2292 template <
typename CharT,
typename Traits>
2293 template <
typename InputIt,
typename Enable>
2294 typename basic_string<CharT, Traits>::pointer
2297 auto size = static_cast<size_type>(std::distance(first, last));
2299 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
2300 assert(size <= sso_capacity);
2302 auto dest = sso.data.range(0, size + 1).begin();
2303 std::copy(first, last, dest);
2305 dest[size] = value_type(
'\0');
2313 template <
typename CharT,
typename Traits>
2314 typename basic_string<CharT, Traits>::pointer
2317 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
2318 assert(count <= sso_capacity);
2320 auto dest = sso.data.range(0, count + 1).begin();
2321 traits_type::assign(dest, count, ch);
2323 dest[count] = value_type(
'\0');
2331 template <
typename CharT,
typename Traits>
2332 typename basic_string<CharT, Traits>::pointer
2335 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
2337 return assign_sso_data(other.cbegin(), other.cend());
2344 template <
typename CharT,
typename Traits>
2345 template <
typename InputIt,
typename Enable>
2346 typename basic_string<CharT, Traits>::pointer
2349 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
2351 auto size = static_cast<size_type>(std::distance(first, last));
2353 non_sso.data.reserve(size + 1);
2354 non_sso.data.assign(first, last);
2355 non_sso.data.push_back(value_type(
'\0'));
2357 return non_sso.data.data();
2364 template <
typename CharT,
typename Traits>
2365 typename basic_string<CharT, Traits>::pointer
2368 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
2370 non_sso.data.reserve(count + 1);
2371 non_sso.data.assign(count, ch);
2372 non_sso.data.push_back(value_type(
'\0'));
2374 return non_sso.data.data();
2381 template <
typename CharT,
typename Traits>
2382 typename basic_string<CharT, Traits>::pointer
2385 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
2387 if (other.is_sso_used())
2388 return assign_large_data(other.cbegin(), other.cend());
2390 non_sso.data = std::move(other.non_sso.data);
2392 return non_sso.data.data();
2398 template <
typename CharT,
typename Traits>
2402 auto pop = pmemobj_pool_by_ptr(
this);
2403 assert(pop !=
nullptr);
2411 template <
typename CharT,
typename Traits>
2415 if (pmemobj_pool_by_ptr(
this) ==
nullptr)
2422 template <
typename CharT,
typename Traits>
2426 if (pmemobj_tx_stage() != TX_STAGE_WORK)
2434 template <
typename CharT,
typename Traits>
2439 check_tx_stage_work();
2445 template <
typename CharT,
typename Traits>
2452 #if LIBPMEMOBJ_CPP_VG_MEMCHECK_ENABLED 2453 VALGRIND_MAKE_MEM_DEFINED(&sso.data,
sizeof(sso.data));
2461 template <
typename CharT,
typename Traits>
2462 typename basic_string<CharT, Traits>::size_type
2465 return sso._size & ~_sso_mask;
2471 template <
typename CharT,
typename Traits>
2477 sso._size |= (size_type)(_sso_mask);
2483 template <
typename CharT,
typename Traits>
2487 sso._size &= ~_sso_mask;
2493 template <
typename CharT,
typename Traits>
2497 sso._size = new_size | _sso_mask;
2511 template <
typename CharT,
typename Traits>
2515 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
2516 assert(new_capacity > sso_capacity);
2522 tmp[sz] = value_type(
'\0');
2525 allocate(new_capacity);
2527 auto begin = tmp.cbegin();
2532 assert(!is_sso_used());
2544 template <
typename CharT,
typename Traits>
2548 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
2552 assert(sz <= sso_capacity);
2556 tmp[sz] = value_type(
'\0');
2561 auto begin = tmp.cbegin();
2566 assert(is_sso_used());
2573 template <
typename CharT,
typename Traits>
2574 template <
typename T,
typename Enable>
2578 return erase(static_cast<size_type>(param));
2585 template <
typename CharT,
typename Traits>
2586 template <
typename T,
typename Enable>
2590 return erase(static_cast<const_iterator>(param));
2596 template <
class CharT,
class Traits>
2607 template <
class CharT,
class Traits>
2618 template <
class CharT,
class Traits>
2629 template <
class CharT,
class Traits>
2640 template <
class CharT,
class Traits>
2651 template <
class CharT,
class Traits>
2662 template <
class CharT,
class Traits>
2672 template <
class CharT,
class Traits>
2682 template <
class CharT,
class Traits>
2692 template <
class CharT,
class Traits>
2702 template <
class CharT,
class Traits>
2712 template <
class CharT,
class Traits>
2722 template <
class CharT,
class Traits>
2732 template <
class CharT,
class Traits>
2742 template <
class CharT,
class Traits>
2752 template <
class CharT,
class Traits>
2762 template <
class CharT,
class Traits>
2772 template <
class CharT,
class Traits>
2782 template <
class CharT,
class Traits>
2793 template <
class CharT,
class Traits>
2804 template <
class CharT,
class Traits>
2815 template <
class CharT,
class Traits>
2826 template <
class CharT,
class Traits>
2837 template <
class CharT,
class Traits>
2848 template <
class CharT,
class Traits>
2851 const std::basic_string<CharT, Traits> &rhs)
2859 template <
class CharT,
class Traits>
2862 const std::basic_string<CharT, Traits> &rhs)
2870 template <
class CharT,
class Traits>
2873 const std::basic_string<CharT, Traits> &rhs)
2881 template <
class CharT,
class Traits>
2884 const std::basic_string<CharT, Traits> &rhs)
2892 template <
class CharT,
class Traits>
2895 const std::basic_string<CharT, Traits> &rhs)
2903 template <
class CharT,
class Traits>
2906 const std::basic_string<CharT, Traits> &rhs)
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:400
void reserve(size_type new_cap=0)
Increase the capacity of the string to new_cap transactionally.
Definition: basic_string.hpp:2070
pmem::obj::experimental::string - EXPERIMENTAL persistent container with std::basic_string compatible...
Definition: basic_string.hpp:72
basic_string & assign(size_type count, CharT ch)
Replace the contents with count copies of character ch transactionally.
Definition: basic_string.hpp:716
size_type size() const noexcept
Definition: basic_string.hpp:1278
bool operator>=(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member greater or equal operator.
Definition: array.hpp:757
sso_type data
Definition: basic_string.hpp:256
pmem::obj::experimental::array< T, N >::const_iterator cend(const pmem::obj::experimental::array< T, N > &a)
Non-member cend.
Definition: array.hpp:787
void large_to_sso()
Resize large string to sso string of size() size.
Definition: basic_string.hpp:2546
Default non-const iterator which adds element to a transaction on every access.
Definition: contiguous_iterator.hpp:360
void check_tx_stage_work() const
Definition: basic_string.hpp:2424
const_reverse_iterator crend() const noexcept
Return a const reverse iterator to the end.
Definition: basic_string.hpp:1085
size_type capacity() const noexcept
Definition: basic_string.hpp:1979
const_iterator cbegin() const noexcept
Return const iterator to the beginning.
Definition: basic_string.hpp:968
void disable_sso()
Disable sso string.
Definition: basic_string.hpp:2485
The non-template pool base class.
Definition: pool.hpp:67
pmem::obj::experimental::array< T, N >::iterator begin(pmem::obj::experimental::array< T, N > &a)
Non-member begin.
Definition: array.hpp:817
CharT & front()
Access first element and snapshot it if there is an active transaction.
Definition: basic_string.hpp:1198
pmem::obj::experimental::array< T, N >::const_reverse_iterator crbegin(const pmem::obj::experimental::array< T, N > &a)
Non-member crbegin.
Definition: array.hpp:797
size_type get_sso_size() const
Return size of sso string.
Definition: basic_string.hpp:2463
Custom pool error class.
Definition: pexceptions.hpp:53
pointer initialize(Args &&... args)
Generic function which initializes memory based on provided parameters - forwards parameters to initi...
Definition: basic_string.hpp:2243
void sso_to_large(size_t new_capacity)
Resize sso string to large string.
Definition: basic_string.hpp:2513
const CharT * c_str() const noexcept
Definition: basic_string.hpp:1948
pmem::obj::experimental::array< T, N >::const_reverse_iterator crend(const pmem::obj::experimental::array< T, N > &a)
Non-member crend.
Definition: array.hpp:807
size_type length() const noexcept
Definition: basic_string.hpp:1958
basic_string()
Default constructor.
Definition: basic_string.hpp:323
void allocate(size_type capacity)
Allocate storage for container of capacity bytes.
Definition: basic_string.hpp:2268
const CharT * cdata() const noexcept
Definition: basic_string.hpp:1928
C++ pmemobj transactions.
Convenience extensions for the resides on pmem property template.
reverse_iterator rend()
Return a reverse iterator to the end.
Definition: basic_string.hpp:1059
~basic_string()
Destructor.
Definition: basic_string.hpp:603
Functions for destroying arrays.
basic_string & erase(size_type index=0, size_type count=npos)
Remove characters from string starting at index transactionally.
Definition: basic_string.hpp:1322
void enable_sso()
Enable sso string.
Definition: basic_string.hpp:2473
Commonly used functionality.
void shrink_to_fit()
Remove unused capacity transactionally.
Definition: basic_string.hpp:2101
Iterators for pmem::obj::array.
void check_pmem() const
Definition: basic_string.hpp:2413
iterator end()
Return an iterator to past the end.
Definition: basic_string.hpp:981
void check_pmem_tx() const
Definition: basic_string.hpp:2436
T * data()
Returns raw pointer to the underlying data and adds entire array to a transaction.
Definition: array.hpp:265
pointer assign_large_data(InputIt first, InputIt last)
Initialize non_sso.data - call constructor of non_sso.data.
Definition: basic_string.hpp:2347
bool empty() const noexcept
Definition: basic_string.hpp:2136
reference operator[](size_type n)
Access element at specific index and snapshot it if there is an active transaction.
Definition: basic_string.hpp:1168
Array container with std::array compatible interface.
slice< pointer > range(size_type start, size_type n)
Returns slice and snapshots requested range.
Definition: array.hpp:483
void clear()
Remove all characters from the string transactionally.
Definition: basic_string.hpp:2126
Custom transaction error class.
Definition: pexceptions.hpp:63
CharT & back()
Access last element and snapshot it if there is an active transaction.
Definition: basic_string.hpp:1241
size_type get_size(InputIt first, InputIt last) const
Overload of generic get_size method used to calculate size based on provided parameters.
Definition: basic_string.hpp:2172
basic_string & operator=(const basic_string &other)
Copy assignment operator.
Definition: basic_string.hpp:620
const_reference const_at(size_type n) const
Access element at specific index with bounds checking.
Definition: basic_string.hpp:1145
basic_string & append(size_type count, CharT ch)
Append count copies of character ch to the string transactionally.
Definition: basic_string.hpp:1430
void resize(size_type count, CharT ch)
Resize the string to count characters transactionally.
Definition: basic_string.hpp:2004
pmem::obj::experimental::array< T, N >::iterator end(pmem::obj::experimental::array< T, N > &a)
Non-member end.
Definition: array.hpp:837
void set_sso_size(size_type new_size)
Set size for sso.
Definition: basic_string.hpp:2495
const CharT & cback() const
Access last element.
Definition: basic_string.hpp:1268
const CharT & cfront() const
Access first element.
Definition: basic_string.hpp:1225
bool operator<=(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member less or equal operator.
Definition: array.hpp:767
Vector container with std::vector compatible interface.
int compare(const basic_string &other) const
Compares this string to other.
Definition: basic_string.hpp:1756
Persistent smart pointer.
bool operator>(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member greater than operator.
Definition: array.hpp:747
Iterface to access sequence of objects.
reverse_iterator rbegin()
Return a reverse iterator to the beginning.
Definition: basic_string.hpp:1020
size_type max_size() const noexcept
Definition: basic_string.hpp:1968
const_reverse_iterator crbegin() const noexcept
Return a const reverse iterator to the beginning.
Definition: basic_string.hpp:1046
bool operator<(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member less than operator.
Definition: array.hpp:736
pointer replace(Args &&... args)
Generic function which replaces current content based on provided parameters.
Definition: basic_string.hpp:2213
bool operator!=(const allocator< T, P, Tr > &lhs, const OtherAllocator &rhs)
Determines if memory from another allocator can be deallocated from this one.
Definition: allocator.hpp:516
pmem::obj::experimental::array< T, N >::const_iterator cbegin(const pmem::obj::experimental::array< T, N > &a)
Non-member cbegin.
Definition: array.hpp:777
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:1105
void snapshot_sso() const
Snapshot sso data.
Definition: basic_string.hpp:2447
pointer assign_sso_data(InputIt first, InputIt last)
Initialize sso data.
Definition: basic_string.hpp:2295
pool_base get_pool() const
Return pool_base instance and assert that object is on pmem.
Definition: basic_string.hpp:2400
iterator begin()
Return an iterator to the beginning.
Definition: basic_string.hpp:943
static void run(pool_base &pool, std::function< void()> tx, Locks &... locks)
Execute a closure-like transaction and lock locks.
Definition: transaction.hpp:398
const_iterator cend() const noexcept
Return const iterator to past the end.
Definition: basic_string.hpp:1007