9 #ifndef LIBPMEMOBJ_CPP_VECTOR_HPP 10 #define LIBPMEMOBJ_CPP_VECTOR_HPP 16 #include <libpmemobj++/detail/temp_value.hpp> 23 #include <libpmemobj/base.h> 45 using size_type = std::size_t;
46 using difference_type = std::ptrdiff_t;
47 using reference = value_type &;
48 using const_reference =
const value_type &;
49 using pointer = value_type *;
50 using const_pointer =
const value_type *;
52 using const_iterator = const_pointer;
53 using reverse_iterator = std::reverse_iterator<iterator>;
54 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
58 using for_each_ptr_function =
59 std::function<void(persistent_ptr_base &)>;
63 vector(size_type count,
const value_type &value);
64 explicit vector(size_type count);
65 template <
typename InputIt,
66 typename std::enable_if<
68 InputIt>::type * =
nullptr>
69 vector(InputIt first, InputIt last);
72 vector(std::initializer_list<T> init);
73 vector(
const std::vector<T> &other);
82 void assign(size_type count,
const T &value);
83 template <
typename InputIt,
84 typename std::enable_if<
85 detail::is_input_iterator<InputIt>::value,
86 InputIt>::type * =
nullptr>
87 void assign(InputIt first, InputIt last);
88 void assign(std::initializer_list<T> ilist);
89 void assign(
const vector &other);
90 void assign(
vector &&other);
91 void assign(
const std::vector<T> &other);
97 reference
at(size_type n);
98 const_reference
at(size_type n)
const;
99 const_reference
const_at(size_type n)
const;
101 const_reference
operator[](size_type n)
const;
103 const_reference
front()
const;
104 const_reference
cfront()
const;
106 const_reference
back()
const;
107 const_reference
cback()
const;
109 const value_type *
data()
const noexcept;
110 const value_type *
cdata()
const noexcept;
114 const_iterator
begin()
const noexcept;
115 const_iterator
cbegin()
const noexcept;
117 const_iterator
end()
const noexcept;
118 const_iterator
cend()
const noexcept;
119 reverse_iterator
rbegin();
120 const_reverse_iterator
rbegin()
const noexcept;
121 const_reverse_iterator
crbegin()
const noexcept;
122 reverse_iterator
rend();
123 const_reverse_iterator
rend()
const noexcept;
124 const_reverse_iterator
crend()
const noexcept;
129 size_type snapshot_size);
135 constexpr
bool empty()
const noexcept;
136 size_type
size()
const noexcept;
137 constexpr size_type
max_size()
const noexcept;
138 void reserve(size_type capacity_new);
139 size_type
capacity()
const noexcept;
147 iterator insert(const_iterator pos, size_type count,
const T &value);
148 template <
typename InputIt,
149 typename std::enable_if<
150 detail::is_input_iterator<InputIt>::value,
151 InputIt>::type * =
nullptr>
153 iterator insert(const_iterator pos, std::initializer_list<T> ilist);
154 template <
class... Args>
156 template <
class... Args>
163 void resize(size_type count);
164 void resize(size_type count,
const value_type &value);
169 template <
typename P>
170 struct single_element_iterator {
171 using iterator_category = std::input_iterator_tag;
172 using value_type = P;
173 using difference_type = std::ptrdiff_t;
174 using pointer =
const P *;
175 using reference =
const P &;
180 single_element_iterator(
const P *ptr, std::size_t count = 0)
181 : ptr(ptr), count(count)
185 reference operator*()
195 single_element_iterator &
202 single_element_iterator
205 single_element_iterator tmp =
206 single_element_iterator(ptr, count);
212 operator-(
const single_element_iterator &rhs)
214 return count - rhs.count;
218 operator!=(
const single_element_iterator &rhs)
220 return ptr != rhs.ptr || count != rhs.count;
228 template <
typename... Args>
230 template <
typename InputIt,
231 typename std::enable_if<
232 detail::is_input_iterator<InputIt>::value,
233 InputIt>::type * =
nullptr>
237 template <
typename InputIt>
241 void shrink(size_type size_new);
243 template <
typename InputIt>
256 template <
typename T>
263 template <
typename T>
265 template <
typename T>
267 template <
typename T>
268 bool operator<(const vector<T> &lhs,
const vector<T> &rhs);
269 template <
typename T>
270 bool operator<=(const vector<T> &lhs,
const vector<T> &rhs);
271 template <
typename T>
273 template <
typename T>
280 template <
typename T>
282 template <
typename T>
284 template <
typename T>
285 bool operator<(const vector<T> &lhs,
const std::vector<T> &rhs);
286 template <
typename T>
287 bool operator<=(const vector<T> &lhs,
const std::vector<T> &rhs);
288 template <
typename T>
290 template <
typename T>
297 template <
typename T>
299 template <
typename T>
301 template <
typename T>
302 bool operator<(const std::vector<T> &lhs,
const vector<T> &rhs);
303 template <
typename T>
304 bool operator<=(const std::vector<T> &lhs,
const vector<T> &rhs);
305 template <
typename T>
307 template <
typename T>
319 template <
typename T>
348 template <
typename T>
377 template <
typename T>
411 template <
typename T>
412 template <
typename InputIt,
413 typename std::enable_if<detail::is_input_iterator<InputIt>::value,
422 alloc(static_cast<size_type>(std::distance(first, last)));
444 template <
typename T>
475 template <
typename T>
482 _capacity = other.capacity();
483 _size = other.size();
484 other._data =
nullptr;
485 other._capacity = other._size = 0;
505 template <
typename T>
529 template <
typename T>
546 template <
typename T>
565 template <
typename T>
569 assign(std::move(other));
583 template <
typename T>
587 assign(ilist.begin(), ilist.end());
604 template <
typename T>
629 template <
typename T>
635 transaction::run(pb, [&] {
636 if (count <= capacity()) {
643 size_type size_old = _size;
644 add_data_to_tx(0, size_old);
649 static_cast<size_type>(size_old)),
652 if (count > size_old) {
653 add_data_to_tx(size_old, count - size_old);
654 construct_at_end(count - size_old, value);
661 construct_at_end(count, value);
684 template <
typename T>
685 template <
typename InputIt,
686 typename std::enable_if<detail::is_input_iterator<InputIt>::value,
693 size_type size_new =
static_cast<size_type
>(std::distance(first, last));
695 transaction::run(pb, [&] {
696 if (size_new <= capacity()) {
703 size_type size_old = _size;
704 add_data_to_tx(0, size_old);
707 bool growing = size_new > size_old;
710 add_data_to_tx(size_old, size_new - size_old);
713 std::advance(mid, size_old);
716 iterator shrink_to = std::copy(first, mid, &_data[0]);
719 construct_at_end(mid, last);
721 shrink(static_cast<size_type>(std::distance(
727 construct_at_end(first, last);
747 template <
typename T>
751 assign(ilist.begin(), ilist.end());
765 template <
typename T>
784 template <
typename T>
793 transaction::run(pb, [&] {
797 _capacity = other._capacity;
800 other._data =
nullptr;
801 other._capacity = other._size = 0;
817 template <
typename T>
821 assign(other.cbegin(), other.cend());
831 template <
typename T>
853 template <
typename T>
854 typename vector<T>::reference
858 throw std::out_of_range(
"vector::at");
860 detail::conditional_add_to_tx(&_data[static_cast<difference_type>(n)],
861 1, POBJ_XADD_ASSUME_INITIALIZED);
863 return _data[
static_cast<difference_type
>(n)];
875 template <
typename T>
876 typename vector<T>::const_reference
880 throw std::out_of_range(
"vector::at");
882 return _data[
static_cast<difference_type
>(n)];
897 template <
typename T>
898 typename vector<T>::const_reference
902 throw std::out_of_range(
"vector::const_at");
904 return _data[
static_cast<difference_type
>(n)];
918 template <
typename T>
921 detail::conditional_add_to_tx(&_data[static_cast<difference_type>(n)],
922 1, POBJ_XADD_ASSUME_INITIALIZED);
924 return _data[
static_cast<difference_type
>(n)];
934 template <
typename T>
937 return _data[
static_cast<difference_type
>(n)];
948 template <
typename T>
949 typename vector<T>::reference
952 detail::conditional_add_to_tx(&_data[0], 1,
953 POBJ_XADD_ASSUME_INITIALIZED);
963 template <
typename T>
964 typename vector<T>::const_reference
977 template <
typename T>
978 typename vector<T>::const_reference
992 template <
typename T>
993 typename vector<T>::reference
996 detail::conditional_add_to_tx(
997 &_data[static_cast<difference_type>(size() - 1)], 1,
998 POBJ_XADD_ASSUME_INITIALIZED);
1000 return _data[
static_cast<difference_type
>(size() - 1)];
1008 template <
typename T>
1009 typename vector<T>::const_reference
1012 return _data[
static_cast<difference_type
>(size() - 1)];
1022 template <
typename T>
1023 typename vector<T>::const_reference
1026 return _data[
static_cast<difference_type
>(size() - 1)];
1038 template <
typename T>
1039 typename vector<T>::value_type *
1042 add_data_to_tx(0, _size);
1052 template <
typename T>
1053 const typename vector<T>::value_type *
1066 template <
typename T>
1067 const typename vector<T>::value_type *
1078 template <
typename T>
1090 template <
typename T>
1091 typename vector<T>::const_iterator
1094 return const_iterator(_data.get());
1104 template <
typename T>
1105 typename vector<T>::const_iterator
1108 return const_iterator(_data.get());
1116 template <
typename T>
1120 return iterator(_data.get() +
static_cast<std::ptrdiff_t
>(_size));
1128 template <
typename T>
1129 typename vector<T>::const_iterator
1132 return const_iterator(_data.get() +
static_cast<std::ptrdiff_t
>(_size));
1142 template <
typename T>
1143 typename vector<T>::const_iterator
1146 return const_iterator(_data.get() +
static_cast<std::ptrdiff_t
>(_size));
1154 template <
typename T>
1155 typename vector<T>::reverse_iterator
1158 return reverse_iterator(
end());
1166 template <
typename T>
1167 typename vector<T>::const_reverse_iterator
1170 return const_reverse_iterator(
cend());
1180 template <
typename T>
1181 typename vector<T>::const_reverse_iterator
1184 return const_reverse_iterator(
cend());
1193 template <
typename T>
1194 typename vector<T>::reverse_iterator
1197 return reverse_iterator(
begin());
1206 template <
typename T>
1207 typename vector<T>::const_reverse_iterator
1210 return const_reverse_iterator(
cbegin());
1221 template <
typename T>
1222 typename vector<T>::const_reverse_iterator
1225 return const_reverse_iterator(
cbegin());
1241 template <
typename T>
1245 if (start + n > size())
1246 throw std::out_of_range(
"vector::range");
1248 detail::conditional_add_to_tx(cdata() + start, n,
1249 POBJ_XADD_ASSUME_INITIALIZED);
1251 return {_data.get() + start, _data.get() + start + n};
1269 template <
typename T>
1273 if (start + n > size())
1274 throw std::out_of_range(
"vector::range");
1276 if (snapshot_size > n)
1280 _data.get() + start, n,
1283 _data.get() + start, n,
1298 template <
typename T>
1302 if (start + n > size())
1303 throw std::out_of_range(
"vector::range");
1305 return {const_iterator(cdata() + start),
1306 const_iterator(cdata() + start + n)};
1320 template <
typename T>
1324 if (start + n > size())
1325 throw std::out_of_range(
"vector::crange");
1327 return {const_iterator(cdata() + start),
1328 const_iterator(cdata() + start + n)};
1336 template <
typename T>
1346 template <
typename T>
1347 typename vector<T>::size_type
1357 template <
typename T>
1358 constexpr
typename vector<T>::size_type
1361 return PMEMOBJ_MAX_ALLOC_SIZE /
sizeof(value_type);
1382 template <
typename T>
1386 if (capacity_new <= _capacity)
1390 transaction::run(pb, [&] { realloc(capacity_new); });
1396 template <
typename T>
1397 typename vector<T>::size_type
1417 template <
typename T>
1421 size_type capacity_new = size();
1422 if (capacity() == capacity_new)
1426 transaction::run(pb, [&] { realloc(capacity_new); });
1437 template <
typename T>
1442 transaction::run(pb, [&] { shrink(0); });
1457 template <
typename T>
1461 if (_data ==
nullptr)
1465 transaction::run(pb, [&] { dealloc(); });
1492 template <
typename T>
1496 return insert(pos, 1, value);
1523 template <
typename T>
1529 size_type idx =
static_cast<size_type
>(std::distance(
cbegin(), pos));
1531 transaction::run(pb, [&] {
1532 internal_insert(idx, std::make_move_iterator(&value),
1533 std::make_move_iterator(&value + 1));
1536 return iterator(&_data[static_cast<difference_type>(idx)]);
1567 template <
typename T>
1573 size_type idx =
static_cast<size_type
>(std::distance(
cbegin(), pos));
1575 transaction::run(pb, [&] {
1577 idx, single_element_iterator<value_type>(&value, 0),
1578 single_element_iterator<value_type>(&value, count));
1581 return iterator(&_data[static_cast<difference_type>(idx)]);
1618 template <
typename T>
1619 template <
typename InputIt,
1620 typename std::enable_if<detail::is_input_iterator<InputIt>::value,
1627 size_type idx =
static_cast<size_type
>(std::distance(
cbegin(), pos));
1629 transaction::run(pb, [&] { internal_insert(idx, first, last); });
1631 return iterator(&_data[static_cast<difference_type>(idx)]);
1662 template <
typename T>
1666 return insert(pos, ilist.begin(), ilist.end());
1696 template <
typename T>
1697 template <
class... Args>
1703 size_type idx =
static_cast<size_type
>(std::distance(
cbegin(), pos));
1705 transaction::run(pb, [&] {
1711 detail::temp_value<value_type,
1712 noexcept(T(std::forward<Args>(args)...))>
1713 tmp(std::forward<Args>(args)...);
1715 auto &tmp_ref = tmp.get();
1717 internal_insert(idx, std::make_move_iterator(&tmp_ref),
1718 std::make_move_iterator(&tmp_ref + 1));
1721 return iterator(&_data[static_cast<difference_type>(idx)]);
1746 template <
typename T>
1747 template <
class... Args>
1748 typename vector<T>::reference
1758 transaction::run(pb, [&] {
1759 if (_size == _capacity) {
1760 realloc(get_recommended_capacity(_size + 1));
1762 add_data_to_tx(size(), 1);
1765 construct_at_end(1, std::forward<Args>(args)...);
1790 template <
typename T>
1794 return erase(pos, pos + 1);
1819 template <
typename T>
1823 size_type idx =
static_cast<size_type
>(
1824 std::distance(const_iterator(&_data[0]), first));
1825 size_type count =
static_cast<size_type
>(std::distance(first, last));
1828 return iterator(&_data[static_cast<difference_type>(idx)]);
1832 transaction::run(pb, [&] {
1833 if (!std::is_trivially_destructible<T>::value ||
1834 idx + count < _size)
1835 add_data_to_tx(idx, _size - idx);
1837 pointer move_begin =
1838 &_data[
static_cast<difference_type
>(idx + count)];
1839 pointer move_end = &_data[
static_cast<difference_type
>(size())];
1840 pointer dest = &_data[
static_cast<difference_type
>(idx)];
1842 std::move(move_begin, move_end, dest);
1847 return iterator(&_data[static_cast<difference_type>(idx)]);
1865 template <
typename T>
1869 emplace_back(value);
1888 template <
typename T>
1892 emplace_back(std::move(value));
1905 template <
typename T>
1913 transaction::run(pb, [&] { shrink(size() - 1); });
1932 template <
typename T>
1937 transaction::run(pb, [&] {
1941 if (_capacity < count)
1943 construct_at_end(count - _size);
1965 template <
typename T>
1969 if (_capacity == count)
1973 transaction::run(pb, [&] {
1977 if (_capacity < count)
1979 construct_at_end(count - _size, value);
1987 template <
typename T>
1992 transaction::run(pb, [&] {
1995 std::swap(this->_capacity, other._capacity);
2005 template <
typename T>
2029 template <
typename T>
2033 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
2034 assert(_data ==
nullptr);
2037 if (capacity_new > max_size())
2038 throw std::length_error(
"New capacity exceeds max size.");
2040 _capacity = capacity_new;
2042 if (capacity_new == 0)
2051 pmemobj_tx_alloc(
sizeof(value_type) * capacity_new,
2052 detail::type_num<value_type>());
2054 if (res ==
nullptr) {
2055 if (errno == ENOMEM)
2057 "Failed to allocate persistent memory object")
2058 .with_pmemobj_errormsg();
2061 "Failed to allocate persistent memory object")
2062 .with_pmemobj_errormsg();
2074 template <
typename T>
2078 if (
nullptr == pmemobj_pool_by_ptr(
this))
2089 template <
typename T>
2093 if (pmemobj_tx_stage() != TX_STAGE_WORK)
2095 "Function called out of transaction scope.");
2116 template <
typename T>
2117 template <
typename... Args>
2121 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
2122 assert(_capacity >= count + _size);
2124 pointer dest = _data.get() + size();
2125 const_pointer
end = dest + count;
2126 for (; dest !=
end; ++dest)
2127 detail::create<value_type, Args...>(
2128 dest, std::forward<Args>(args)...);
2154 template <
typename T>
2155 template <
typename InputIt,
2156 typename std::enable_if<detail::is_input_iterator<InputIt>::value,
2161 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
2162 difference_type range_size = std::distance(first, last);
2163 assert(range_size >= 0);
2164 assert(_capacity >= static_cast<size_type>(range_size) + _size);
2166 pointer dest = _data.get() + size();
2167 _size +=
static_cast<size_type
>(range_size);
2168 while (first != last)
2169 detail::create<value_type>(dest++, *first++);
2187 template <
typename T>
2191 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
2193 if (_data !=
nullptr) {
2195 if (pmemobj_tx_free(*_data.raw_ptr()) != 0)
2197 "failed to delete persistent memory object")
2198 .with_pmemobj_errormsg();
2211 template <
typename T>
2225 template <
typename T>
2229 while (first != last && d_last >=
cend())
2230 detail::create<value_type>(--d_last, std::move(*(--last)));
2233 std::move_backward(first, last, d_last);
2243 template <
typename T>
2244 template <
typename InputIt>
2248 auto count =
static_cast<size_type
>(std::distance(first, last));
2249 auto dest = _data.get() + idx;
2250 auto initialized_slots =
static_cast<size_type
>(
cend() - dest);
2254 dest = std::copy_n(first, (std::min)(initialized_slots, count),
2257 std::advance(first, (std::min)(initialized_slots, count));
2260 while (first != last)
2261 detail::create<value_type>(dest++, *first++);
2286 template <
typename T>
2287 template <
typename InputIt>
2291 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
2293 auto count =
static_cast<size_type
>(std::distance(first, last));
2295 if (_capacity >= size() + count) {
2297 &_data[
static_cast<difference_type
>(size() + count)];
2298 pointer
begin = &_data[
static_cast<difference_type
>(idx)];
2299 pointer
end = &_data[
static_cast<difference_type
>(size())];
2301 add_data_to_tx(idx, size() - idx + count);
2304 move_elements_backward(begin, end, dest);
2307 construct_or_assign(idx, first, last);
2313 add_data_to_tx(0, _size);
2315 auto old_data = _data;
2316 auto old_size = _size;
2317 pointer old_begin = &_data[0];
2318 pointer old_mid = &_data[
static_cast<difference_type
>(idx)];
2319 pointer old_end = &_data[
static_cast<difference_type
>(size())];
2322 _size = _capacity = 0;
2324 alloc(get_recommended_capacity(old_size + count));
2327 construct_at_end(std::make_move_iterator(old_begin),
2328 std::make_move_iterator(old_mid));
2331 construct_at_end(first, last);
2334 construct_at_end(std::make_move_iterator(old_mid),
2335 std::make_move_iterator(old_end));
2338 for (size_type i = 0; i < old_size; ++i)
2339 detail::destroy<value_type>(
2340 old_data[static_cast<difference_type>(i)]);
2341 if (pmemobj_tx_free(old_data.raw()) != 0)
2343 "failed to delete persistent memory object")
2344 .with_pmemobj_errormsg();
2365 template <
typename T>
2369 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
2375 add_data_to_tx(0, _size);
2377 auto old_data = _data;
2378 auto old_size = _size;
2379 pointer old_begin = &_data[0];
2380 pointer old_end = capacity_new < _size
2381 ? &_data[
static_cast<difference_type
>(capacity_new)]
2382 : &_data[static_cast<difference_type>(size())];
2385 _size = _capacity = 0;
2387 alloc(capacity_new);
2389 construct_at_end(std::make_move_iterator(old_begin),
2390 std::make_move_iterator(old_end));
2393 for (size_type i = 0; i < old_size; ++i)
2394 detail::destroy<value_type>(
2395 old_data[static_cast<difference_type>(i)]);
2396 if (pmemobj_tx_free(old_data.raw()) != 0)
2398 "failed to delete persistent memory object")
2399 .with_pmemobj_errormsg();
2408 template <
typename T>
2409 typename vector<T>::size_type
2431 template <
typename T>
2435 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
2436 assert(size_new <= _size);
2438 if (!std::is_trivially_destructible<T>::value)
2439 add_data_to_tx(size_new, _size - size_new);
2441 for (size_type i = size_new; i < _size; ++i)
2442 detail::destroy<value_type>(
2443 _data[static_cast<difference_type>(i)]);
2456 template <
typename T>
2460 assert(idx_first + num <= capacity());
2462 #if LIBPMEMOBJ_CPP_VG_MEMCHECK_ENABLED 2464 assert(VALGRIND_CHECK_MEM_IS_ADDRESSABLE(_data.get() + idx_first,
2465 num *
sizeof(T)) == 0);
2468 auto initialized_num = size() - idx_first;
2471 detail::conditional_add_to_tx(_data.get() + idx_first,
2472 (std::min)(initialized_num, num),
2473 POBJ_XADD_ASSUME_INITIALIZED);
2475 if (num > initialized_num) {
2477 detail::conditional_add_to_tx(_data.get() + size(),
2478 num - initialized_num,
2479 POBJ_XADD_NO_SNAPSHOT);
2494 template <
typename T>
2513 template <
typename T>
2517 return !(lhs == rhs);
2530 template <
typename T>
2534 return std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.
begin(),
2548 template <
typename T>
2552 return !(rhs < lhs);
2566 template <
typename T>
2583 template <
typename T>
2587 return !(lhs < rhs);
2601 template <
typename T>
2605 return lhs.
size() == rhs.size() &&
2606 std::equal(lhs.
begin(), lhs.
end(), rhs.begin());
2620 template <
typename T>
2624 return !(lhs == rhs);
2637 template <
typename T>
2639 operator<(const vector<T> &lhs,
const std::vector<T> &rhs)
2641 return std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.
begin(),
2655 template <
typename T>
2657 operator<=(const vector<T> &lhs,
const std::vector<T> &rhs)
2659 return !(std::lexicographical_compare(rhs.
begin(), rhs.
end(),
2660 lhs.begin(), lhs.end()));
2674 template <
typename T>
2678 return !(lhs <= rhs);
2691 template <
typename T>
2695 return !(lhs < rhs);
2709 template <
typename T>
2727 template <
typename T>
2731 return !(lhs == rhs);
2744 template <
typename T>
2761 template <
typename T>
2765 return !(rhs < lhs);
2779 template <
typename T>
2796 template <
typename T>
2800 return !(lhs < rhs);
2809 template <
typename T>
Custom transaction error class.
Definition: pexceptions.hpp:101
pmem::obj::array< T, N >::const_reverse_iterator crbegin(const pmem::obj::array< T, N > &a)
Non-member crbegin.
Definition: array.hpp:780
void shrink(size_type size_new)
Private helper function.
Definition: vector.hpp:2433
vector & operator=(const vector &other)
Copy assignment operator.
Definition: vector.hpp:548
void free_data()
Clears the content of a vector and frees all allocated persistent memory for data transactionally...
Definition: vector.hpp:1459
pmem::obj::array< T, N >::reverse_iterator rbegin(pmem::obj::array< T, N > &a)
Non-member rbegin.
Definition: array.hpp:840
bool operator==(const std::vector< T > &lhs, const vector< T > &rhs)
Comparison operator.
Definition: vector.hpp:2711
void move_elements_backward(pointer first, pointer last, pointer d_last)
Private helper function.
Definition: vector.hpp:2227
Persistent_ptr transactional allocation functions for objects.
void pop_back()
Removes the last element of the container transactionally.
Definition: vector.hpp:1907
slice< const_iterator > crange(size_type start, size_type n) const
Returns const slice.
Definition: vector.hpp:1322
size_type capacity() const noexcept
Definition: vector.hpp:1398
The non-template pool base class.
Definition: pool.hpp:46
void clear()
Clears the content of a vector transactionally.
Definition: vector.hpp:1439
Custom pool error class.
Definition: pexceptions.hpp:45
const_iterator cbegin() const noexcept
Returns const iterator to the beginning.
Definition: vector.hpp:1106
void construct_or_assign(size_type idx, InputIt first, InputIt last)
Private helper function.
Definition: vector.hpp:2246
void internal_insert(size_type idx, InputIt first, InputIt last)
Private helper function.
Definition: vector.hpp:2289
pmem::obj::slice - provides interface to access sequence of objects.
Definition: slice.hpp:27
reverse_iterator rbegin()
Returns a reverse iterator to the beginning.
Definition: vector.hpp:1156
const_reference cfront() const
Access the first element.
Definition: vector.hpp:979
pool_base get_pool() const
Private helper function.
Definition: vector.hpp:2213
bool operator>(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member greater than operator.
Definition: array.hpp:730
iterator begin()
Returns an iterator to the beginning.
Definition: vector.hpp:1080
pmem::obj::array< T, N >::const_iterator cend(const pmem::obj::array< T, N > &a)
Non-member cend.
Definition: array.hpp:770
C++ pmemobj transactions.
void construct_at_end(size_type count, Args &&... args)
Private helper function.
Definition: vector.hpp:2119
const_reverse_iterator crbegin() const noexcept
Returns a const reverse iterator to the beginning.
Definition: vector.hpp:1182
Convenience extensions for the resides on pmem property template.
reference operator[](size_type n)
Access element at specific index and add it to a transaction.
Definition: vector.hpp:919
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:536
void check_pmem()
Private helper function.
Definition: vector.hpp:2076
size_type get_recommended_capacity(size_type at_least) const
Private helper function.
Definition: vector.hpp:2410
Functions for destroying arrays.
Commonly used functionality.
~vector()
Destructor.
Definition: vector.hpp:832
size_type size() const noexcept
Definition: vector.hpp:1348
void shrink_to_fit()
Requests transactional removal of unused capacity.
Definition: vector.hpp:1419
Iterators for contiguous persistent containers.
constexpr bool empty() const noexcept
Checks whether the container is empty.
Definition: vector.hpp:1338
uint64_t next_pow_2(uint64_t v)
Round up to the next lowest power of 2.
Definition: common.hpp:182
slice< pointer > range(size_type start, size_type n)
Returns slice and snapshots requested range.
Definition: vector.hpp:1243
bool operator>=(const std::vector< T > &lhs, const vector< T > &rhs)
Comparison operator.
Definition: vector.hpp:2798
void check_tx_stage_work()
Private helper function.
Definition: vector.hpp:2091
pmem::obj::array< T, N >::iterator end(pmem::obj::array< T, N > &a)
Non-member end.
Definition: array.hpp:820
Non-const iterator which adds elements to a transaction in a bulk.
Definition: contiguous_iterator.hpp:191
persistent_ptr< T > operator-(persistent_ptr< T > const &lhs, std::ptrdiff_t s)
Subtraction operator for persistent pointers.
Definition: persistent_ptr.hpp:819
iterator erase(const_iterator pos)
Removes the element at pos.
Definition: vector.hpp:1792
void resize(size_type count)
Resizes the container to count elements transactionally.
Definition: vector.hpp:1934
reference front()
Access the first element and add this element to a transaction.
Definition: vector.hpp:950
void for_each_ptr(for_each_ptr_function func)
Iterates over all internal pointers and executes a callback function on each of them.
Definition: vector.hpp:2007
pool_base pool_by_vptr(const T *that)
Retrieve pool handle for the given pointer.
Definition: utils.hpp:32
pmem::obj::array< T, N >::reverse_iterator rend(pmem::obj::array< T, N > &a)
Non-member rend.
Definition: array.hpp:860
pmem::obj::array< T, N >::const_iterator cbegin(const pmem::obj::array< T, N > &a)
Non-member cbegin.
Definition: array.hpp:760
constexpr size_type max_size() const noexcept
Definition: vector.hpp:1359
Custom out of memory error class.
Definition: pexceptions.hpp:119
Default non-const iterator which adds element to a transaction on every access.
Definition: contiguous_iterator.hpp:330
bool operator>=(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member greater or equal operator.
Definition: array.hpp:740
bool operator!=(const std::vector< T > &lhs, const vector< T > &rhs)
Comparison operator.
Definition: vector.hpp:2729
void add_data_to_tx(size_type idx_first, size_type num)
Private helper function.
Definition: vector.hpp:2458
pmem::obj::vector - persistent container with std::vector compatible interface.
Definition: vector.hpp:41
pmem::obj::array< T, N >::const_reverse_iterator crend(const pmem::obj::array< T, N > &a)
Non-member crend.
Definition: array.hpp:790
const_iterator cend() const noexcept
Returns a const iterator to the end.
Definition: vector.hpp:1144
reference emplace_back(Args &&... args)
Appends a new element to the end of the container.
Definition: vector.hpp:1749
reverse_iterator rend()
Returns a reverse iterator to the end.
Definition: vector.hpp:1195
iterator emplace(const_iterator pos, Args &&... args)
Inserts a new element into the container directly before pos.
Definition: vector.hpp:1699
reference back()
Access the last element and add this element to a transaction.
Definition: vector.hpp:994
void alloc(size_type size)
Private helper function.
Definition: vector.hpp:2031
Persistent smart pointer.
void dealloc()
Private helper function.
Definition: vector.hpp:2189
Interface to access sequence of objects.
void reserve(size_type capacity_new)
Increases the capacity of the vector to capacity_new transactionally.
Definition: vector.hpp:1384
const_reverse_iterator crend() const noexcept
Returns a const reverse iterator to the beginning.
Definition: vector.hpp:1223
const_reference const_at(size_type n) const
Access element at specific index with bounds checking.
Definition: vector.hpp:899
const_reference cback() const
Access the last element.
Definition: vector.hpp:1024
p< T > & operator++(p< T > &pp)
Prefix increment operator overload.
Definition: pext.hpp:48
Custom transaction error class.
Definition: pexceptions.hpp:140
vector()
Default constructor.
Definition: vector.hpp:320
void push_back(const T &value)
Appends the given element value to the end of the container transactionally.
Definition: vector.hpp:1867
Custom transaction error class.
Definition: pexceptions.hpp:158
Persistent memory namespace.
Definition: allocation_flag.hpp:14
iterator insert(const_iterator pos, const T &value)
Inserts value before pos in the container transactionally.
Definition: vector.hpp:1494
iterator end()
Returns an iterator to past the end.
Definition: vector.hpp:1118
reference at(size_type n)
Access element at specific index with bounds checking and add it to a transaction.
Definition: vector.hpp:855
const value_type * cdata() const noexcept
Returns const raw pointer to the underlying data.
Definition: vector.hpp:1068
void swap(vector &other)
Exchanges the contents of the container with other transactionally.
Definition: vector.hpp:1989
bool operator==(standard_alloc_policy< T > const &, standard_alloc_policy< T2 > const &)
Determines if memory from another allocator can be deallocated from this one.
Definition: allocator.hpp:420
void realloc(size_type size)
Private helper function.
Definition: vector.hpp:2367
value_type * data()
Returns raw pointer to the underlying data and adds entire array to a transaction.
Definition: vector.hpp:1040
pmem::obj::array< T, N >::iterator begin(pmem::obj::array< T, N > &a)
Non-member begin.
Definition: array.hpp:800
void swap(vector< T > &lhs, vector< T > &rhs)
Swaps the contents of lhs and rhs.
Definition: vector.hpp:2811
bool operator>(const std::vector< T > &lhs, const vector< T > &rhs)
Comparison operator.
Definition: vector.hpp:2781