9 #ifndef LIBPMEMOBJ_CPP_VECTOR_HPP
10 #define LIBPMEMOBJ_CPP_VECTOR_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 =
63 vector(size_type count,
const value_type &value);
65 template <
typename InputIt,
66 typename std::enable_if<
68 InputIt>::type * =
nullptr>
72 vector(std::initializer_list<T> init);
82 void assign(size_type count,
const T &value);
83 template <
typename InputIt,
84 typename std::enable_if<
86 InputIt>::type * =
nullptr>
87 void assign(InputIt first, InputIt last);
88 void assign(std::initializer_list<T> ilist);
91 void assign(
const std::vector<T> &other);
97 reference
at(size_type n);
98 const_reference
at(size_type n)
const;
109 const value_type *
data() const noexcept;
110 const value_type *
cdata() const noexcept;
114 const_iterator
begin() const noexcept;
117 const_iterator
end() const noexcept;
118 const_iterator
cend() const noexcept;
120 const_reverse_iterator
rbegin() const noexcept;
121 const_reverse_iterator
crbegin() const noexcept;
123 const_reverse_iterator
rend() const noexcept;
124 const_reverse_iterator
crend() const noexcept;
129 size_type snapshot_size);
130 slice<const_iterator>
range(size_type start, size_type n) const;
135 constexpr
bool empty() const noexcept;
136 size_type
size() const noexcept;
148 template <typename InputIt,
149 typename std::enable_if<
150 detail::is_input_iterator<InputIt>::value,
151 InputIt>::type * =
nullptr>
154 template <class... Args>
156 template <class... Args>
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;
225 void alloc(size_type
size);
227 void check_tx_stage_work();
228 template <
typename... Args>
229 void construct_at_end(size_type count, Args &&... args);
230 template <
typename InputIt,
231 typename std::enable_if<
233 InputIt>::type * =
nullptr>
234 void construct_at_end(InputIt first, InputIt last);
237 template <
typename InputIt>
238 void internal_insert(size_type idx, InputIt first, InputIt last);
239 void realloc(size_type
size);
240 size_type get_recommended_capacity(size_type at_least)
const;
241 void shrink(size_type size_new);
242 void add_data_to_tx(size_type idx_first, size_type num);
243 template <
typename InputIt>
244 void construct_or_assign(size_type idx, InputIt first, InputIt last);
245 void move_elements_backward(pointer first, pointer last,
258 template <
typename T>
259 void swap(vector<T> &lhs, vector<T> &rhs);
265 template <
typename T>
266 bool operator==(
const vector<T> &lhs,
const vector<T> &rhs);
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>
272 bool operator<=(
const vector<T> &lhs,
const vector<T> &rhs);
273 template <
typename T>
274 bool operator>(
const vector<T> &lhs,
const vector<T> &rhs);
275 template <
typename T>
276 bool operator>=(
const vector<T> &lhs,
const vector<T> &rhs);
282 template <
typename T>
283 bool operator==(
const vector<T> &lhs,
const std::vector<T> &rhs);
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>
289 bool operator<=(
const vector<T> &lhs,
const std::vector<T> &rhs);
290 template <
typename T>
291 bool operator>(
const vector<T> &lhs,
const std::vector<T> &rhs);
292 template <
typename T>
293 bool operator>=(
const vector<T> &lhs,
const std::vector<T> &rhs);
299 template <
typename T>
300 bool operator==(
const std::vector<T> &lhs,
const vector<T> &rhs);
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>
306 bool operator<=(
const std::vector<T> &lhs,
const vector<T> &rhs);
307 template <
typename T>
308 bool operator>(
const std::vector<T> &lhs,
const vector<T> &rhs);
309 template <
typename T>
310 bool operator>=(
const std::vector<T> &lhs,
const vector<T> &rhs);
321 template <
typename T>
325 check_tx_stage_work();
350 template <
typename T>
354 check_tx_stage_work();
359 construct_at_end(count, value);
379 template <
typename T>
383 check_tx_stage_work();
388 construct_at_end(count);
413 template <
typename T>
414 template <
typename InputIt,
415 typename std::enable_if<detail::is_input_iterator<InputIt>::value,
420 check_tx_stage_work();
424 alloc(
static_cast<size_type
>(std::distance(first, last)));
425 construct_at_end(first, last);
446 template <
typename T>
450 check_tx_stage_work();
455 construct_at_end(other.
cbegin(), other.
cend());
477 template <
typename T>
481 check_tx_stage_work();
484 _capacity = other.capacity();
485 _size = other.size();
486 other._data =
nullptr;
487 other._capacity = other._size = 0;
507 template <
typename T>
509 :
vector(init.begin(), init.end())
531 template <
typename T>
533 :
vector(other.cbegin(), other.cend())
548 template <
typename T>
567 template <
typename T>
571 assign(std::move(other));
585 template <
typename T>
589 assign(ilist.begin(), ilist.end());
606 template <
typename T>
631 template <
typename T>
638 if (count <= capacity()) {
645 size_type size_old = _size;
646 add_data_to_tx(0, size_old);
651 static_cast<size_type
>(size_old)),
654 if (count > size_old) {
655 add_data_to_tx(size_old, count - size_old);
656 construct_at_end(count - size_old, value);
663 construct_at_end(count, value);
686 template <
typename T>
687 template <
typename InputIt,
688 typename std::enable_if<detail::is_input_iterator<InputIt>::value,
695 size_type size_new =
static_cast<size_type
>(std::distance(first, last));
698 if (size_new <= capacity()) {
705 size_type size_old = _size;
706 add_data_to_tx(0, size_old);
709 bool growing = size_new > size_old;
712 add_data_to_tx(size_old, size_new - size_old);
715 std::advance(mid, size_old);
718 iterator shrink_to = std::copy(first, mid, &_data[0]);
721 construct_at_end(mid, last);
723 shrink(
static_cast<size_type
>(std::distance(
729 construct_at_end(first, last);
749 template <
typename T>
753 assign(ilist.begin(), ilist.end());
767 template <
typename T>
786 template <
typename T>
799 _capacity = other._capacity;
802 other._data =
nullptr;
803 other._capacity = other._size = 0;
819 template <
typename T>
823 assign(other.cbegin(), other.cend());
833 template <
typename T>
855 template <
typename T>
856 typename vector<T>::reference
860 throw std::out_of_range(
"vector::at");
863 1, POBJ_XADD_ASSUME_INITIALIZED);
865 return _data[
static_cast<difference_type
>(n)];
877 template <
typename T>
878 typename vector<T>::const_reference
882 throw std::out_of_range(
"vector::at");
884 return _data[
static_cast<difference_type
>(n)];
899 template <
typename T>
900 typename vector<T>::const_reference
904 throw std::out_of_range(
"vector::const_at");
906 return _data[
static_cast<difference_type
>(n)];
920 template <
typename T>
924 1, POBJ_XADD_ASSUME_INITIALIZED);
926 return _data[
static_cast<difference_type
>(n)];
936 template <
typename T>
939 return _data[
static_cast<difference_type
>(n)];
950 template <
typename T>
951 typename vector<T>::reference
955 POBJ_XADD_ASSUME_INITIALIZED);
965 template <
typename T>
966 typename vector<T>::const_reference
979 template <
typename T>
980 typename vector<T>::const_reference
994 template <
typename T>
995 typename vector<T>::reference
999 &_data[
static_cast<difference_type
>(size() - 1)], 1,
1000 POBJ_XADD_ASSUME_INITIALIZED);
1002 return _data[
static_cast<difference_type
>(size() - 1)];
1010 template <
typename T>
1011 typename vector<T>::const_reference
1014 return _data[
static_cast<difference_type
>(size() - 1)];
1024 template <
typename T>
1025 typename vector<T>::const_reference
1028 return _data[
static_cast<difference_type
>(size() - 1)];
1040 template <
typename T>
1041 typename vector<T>::value_type *
1044 add_data_to_tx(0, _size);
1054 template <
typename T>
1055 const typename vector<T>::value_type *
1068 template <
typename T>
1069 const typename vector<T>::value_type *
1080 template <
typename T>
1092 template <
typename T>
1093 typename vector<T>::const_iterator
1096 return const_iterator(_data.get());
1106 template <
typename T>
1107 typename vector<T>::const_iterator
1110 return const_iterator(_data.get());
1118 template <
typename T>
1122 return iterator(_data.get() +
static_cast<std::ptrdiff_t
>(_size));
1130 template <
typename T>
1131 typename vector<T>::const_iterator
1134 return const_iterator(_data.get() +
static_cast<std::ptrdiff_t
>(_size));
1144 template <
typename T>
1145 typename vector<T>::const_iterator
1148 return const_iterator(_data.get() +
static_cast<std::ptrdiff_t
>(_size));
1156 template <
typename T>
1157 typename vector<T>::reverse_iterator
1160 return reverse_iterator(end());
1168 template <
typename T>
1169 typename vector<T>::const_reverse_iterator
1172 return const_reverse_iterator(cend());
1182 template <
typename T>
1183 typename vector<T>::const_reverse_iterator
1186 return const_reverse_iterator(cend());
1195 template <
typename T>
1196 typename vector<T>::reverse_iterator
1199 return reverse_iterator(begin());
1208 template <
typename T>
1209 typename vector<T>::const_reverse_iterator
1212 return const_reverse_iterator(cbegin());
1223 template <
typename T>
1224 typename vector<T>::const_reverse_iterator
1227 return const_reverse_iterator(cbegin());
1243 template <
typename T>
1247 if (start + n > size())
1248 throw std::out_of_range(
"vector::range");
1251 POBJ_XADD_ASSUME_INITIALIZED);
1253 return {_data.get() + start, _data.get() + start + n};
1271 template <
typename T>
1275 if (start + n > size())
1276 throw std::out_of_range(
"vector::range");
1278 if (snapshot_size > n)
1282 _data.get() + start, n,
1285 _data.get() + start, n,
1300 template <
typename T>
1304 if (start + n > size())
1305 throw std::out_of_range(
"vector::range");
1307 return {const_iterator(cdata() + start),
1308 const_iterator(cdata() + start + n)};
1322 template <
typename T>
1326 if (start + n > size())
1327 throw std::out_of_range(
"vector::crange");
1329 return {const_iterator(cdata() + start),
1330 const_iterator(cdata() + start + n)};
1338 template <
typename T>
1348 template <
typename T>
1349 typename vector<T>::size_type
1359 template <
typename T>
1360 constexpr
typename vector<T>::size_type
1363 return PMEMOBJ_MAX_ALLOC_SIZE /
sizeof(value_type);
1384 template <
typename T>
1388 if (capacity_new <= _capacity)
1398 template <
typename T>
1399 typename vector<T>::size_type
1419 template <
typename T>
1423 size_type capacity_new = size();
1424 if (capacity() == capacity_new)
1439 template <
typename T>
1459 template <
typename T>
1463 if (_data ==
nullptr)
1494 template <
typename T>
1498 return insert(pos, 1, value);
1525 template <
typename T>
1531 size_type idx =
static_cast<size_type
>(std::distance(cbegin(), pos));
1534 internal_insert(idx, std::make_move_iterator(&value),
1535 std::make_move_iterator(&value + 1));
1538 return iterator(&_data[
static_cast<difference_type
>(idx)]);
1569 template <
typename T>
1575 size_type idx =
static_cast<size_type
>(std::distance(cbegin(), pos));
1579 idx, single_element_iterator<value_type>(&value, 0),
1580 single_element_iterator<value_type>(&value, count));
1583 return iterator(_data.get() +
static_cast<difference_type
>(idx));
1620 template <
typename T>
1621 template <
typename InputIt,
1622 typename std::enable_if<detail::is_input_iterator<InputIt>::value,
1629 size_type idx =
static_cast<size_type
>(std::distance(cbegin(), pos));
1633 return iterator(&_data[
static_cast<difference_type
>(idx)]);
1664 template <
typename T>
1668 return insert(pos, ilist.begin(), ilist.end());
1698 template <
typename T>
1699 template <
class... Args>
1705 size_type idx =
static_cast<size_type
>(std::distance(cbegin(), pos));
1714 noexcept(T(std::forward<Args>(args)...))>
1715 tmp(std::forward<Args>(args)...);
1717 auto &tmp_ref = tmp.get();
1719 internal_insert(idx, std::make_move_iterator(&tmp_ref),
1720 std::make_move_iterator(&tmp_ref + 1));
1723 return iterator(&_data[
static_cast<difference_type
>(idx)]);
1748 template <
typename T>
1749 template <
class... Args>
1750 typename vector<T>::reference
1761 if (_size == _capacity) {
1762 realloc(get_recommended_capacity(_size + 1));
1764 add_data_to_tx(size(), 1);
1767 construct_at_end(1, std::forward<Args>(args)...);
1792 template <
typename T>
1796 return erase(pos, pos + 1);
1821 template <
typename T>
1825 size_type idx =
static_cast<size_type
>(
1826 std::distance(const_iterator(_data.get()), first));
1827 size_type count =
static_cast<size_type
>(std::distance(first, last));
1830 return iterator(&_data[
static_cast<difference_type
>(idx)]);
1835 if (!std::is_trivially_destructible<T>::value ||
1836 idx + count < _size)
1837 add_data_to_tx(idx, _size - idx);
1839 pointer move_begin =
1840 &_data[
static_cast<difference_type
>(idx + count)];
1841 pointer move_end = &_data[
static_cast<difference_type
>(size())];
1842 pointer dest = &_data[
static_cast<difference_type
>(idx)];
1844 std::move(move_begin, move_end, dest);
1849 return iterator(&_data[
static_cast<difference_type
>(idx)]);
1867 template <
typename T>
1871 emplace_back(value);
1890 template <
typename T>
1894 emplace_back(std::move(value));
1907 template <
typename T>
1934 template <
typename T>
1943 if (_capacity < count)
1945 construct_at_end(count - _size);
1967 template <
typename T>
1971 if (_capacity == count)
1979 if (_capacity < count)
1981 construct_at_end(count - _size, value);
1989 template <
typename T>
1995 std::swap(this->_data, other._data);
1996 std::swap(this->_size, other._size);
1997 std::swap(this->_capacity, other._capacity);
2007 template <
typename T>
2031 template <
typename T>
2035 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
2036 assert(_data ==
nullptr);
2039 if (capacity_new > max_size())
2040 throw std::length_error(
"New capacity exceeds max size.");
2042 _capacity = capacity_new;
2044 if (capacity_new == 0)
2053 pmemobj_tx_alloc(
sizeof(value_type) * capacity_new,
2054 detail::type_num<value_type>());
2056 if (res ==
nullptr) {
2057 const char *msg =
"Failed to allocate persistent memory object";
2058 if (errno == ENOMEM)
2074 template <
typename T>
2076 vector<T>::check_pmem()
2078 if (
nullptr == pmemobj_pool_by_ptr(
this))
2089 template <
typename T>
2091 vector<T>::check_tx_stage_work()
2093 if (pmemobj_tx_stage() != TX_STAGE_WORK)
2095 "Function called out of transaction scope.");
2116 template <
typename T>
2117 template <
typename... Args>
2119 vector<T>::construct_at_end(size_type count, Args &&... 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,
2159 vector<T>::construct_at_end(InputIt first, InputIt last)
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>
2189 vector<T>::dealloc()
2191 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
2193 if (_data !=
nullptr) {
2195 if (pmemobj_tx_free(*_data.raw_ptr()) != 0)
2198 "failed to delete persistent memory object");
2211 template <
typename T>
2213 vector<T>::get_pool()
const
2225 template <
typename T>
2227 vector<T>::move_elements_backward(pointer first, pointer last, pointer d_last)
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>
2246 vector<T>::construct_or_assign(size_type idx, InputIt first, InputIt last)
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>
2289 vector<T>::internal_insert(size_type idx, InputIt first, InputIt last)
2291 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
2293 auto count =
static_cast<size_type
>(std::distance(first, last));
2295 if (_capacity >= size() + count) {
2296 pointer dest = _data.get() +
2297 static_cast<difference_type
>(size() + count);
2298 pointer begin = _data.get() +
static_cast<difference_type
>(idx);
2300 _data.get() +
static_cast<difference_type
>(size());
2302 add_data_to_tx(idx, size() - idx + count);
2305 move_elements_backward(begin, end, dest);
2308 construct_or_assign(idx, first, last);
2314 add_data_to_tx(0, _size);
2316 auto old_data = _data;
2317 auto old_size = _size;
2318 pointer old_begin = _data.get();
2320 _data.get() +
static_cast<difference_type
>(idx);
2322 _data.get() +
static_cast<difference_type
>(size());
2325 _size = _capacity = 0;
2327 alloc(get_recommended_capacity(old_size + count));
2330 construct_at_end(std::make_move_iterator(old_begin),
2331 std::make_move_iterator(old_mid));
2334 construct_at_end(first, last);
2337 construct_at_end(std::make_move_iterator(old_mid),
2338 std::make_move_iterator(old_end));
2341 for (size_type i = 0; i < old_size; ++i)
2342 detail::destroy<value_type>(
2343 old_data[
static_cast<difference_type
>(i)]);
2344 if (pmemobj_tx_free(old_data.raw()) != 0)
2347 "failed to delete persistent memory object");
2369 template <
typename T>
2371 vector<T>::realloc(size_type capacity_new)
2373 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
2379 if (_data ==
nullptr)
2380 return alloc(capacity_new);
2386 add_data_to_tx(0, _size);
2388 auto old_data = _data;
2389 auto old_size = _size;
2390 pointer old_begin = _data.get();
2391 pointer old_end = capacity_new < _size
2392 ? &_data[
static_cast<difference_type
>(capacity_new)]
2393 : &_data[
static_cast<difference_type
>(size())];
2396 _size = _capacity = 0;
2398 alloc(capacity_new);
2400 construct_at_end(std::make_move_iterator(old_begin),
2401 std::make_move_iterator(old_end));
2404 for (size_type i = 0; i < old_size; ++i)
2405 detail::destroy<value_type>(
2406 old_data[
static_cast<difference_type
>(i)]);
2407 if (pmemobj_tx_free(old_data.raw()) != 0)
2410 "failed to delete persistent memory object");
2419 template <
typename T>
2420 typename vector<T>::size_type
2421 vector<T>::get_recommended_capacity(size_type at_least)
const
2442 template <
typename T>
2444 vector<T>::shrink(size_type size_new)
2446 assert(pmemobj_tx_stage() == TX_STAGE_WORK);
2447 assert(size_new <= _size);
2449 if (!std::is_trivially_destructible<T>::value)
2450 add_data_to_tx(size_new, _size - size_new);
2452 for (size_type i = size_new; i < _size; ++i)
2453 detail::destroy<value_type>(
2454 _data[
static_cast<difference_type
>(i)]);
2467 template <
typename T>
2469 vector<T>::add_data_to_tx(size_type idx_first, size_type num)
2471 assert(idx_first + num <= capacity());
2473 #if LIBPMEMOBJ_CPP_VG_MEMCHECK_ENABLED
2475 assert(VALGRIND_CHECK_MEM_IS_ADDRESSABLE(_data.get() + idx_first,
2476 num *
sizeof(T)) == 0);
2479 auto initialized_num = size() - idx_first;
2483 (std::min)(initialized_num, num),
2484 POBJ_XADD_ASSUME_INITIALIZED);
2486 if (num > initialized_num) {
2489 num - initialized_num,
2490 POBJ_XADD_NO_SNAPSHOT);
2506 template <
typename T>
2526 template <
typename T>
2530 return !(lhs == rhs);
2544 template <
typename T>
2548 return std::lexicographical_compare(lhs.
begin(), lhs.
end(), rhs.
begin(),
2563 template <
typename T>
2567 return !(rhs < lhs);
2582 template <
typename T>
2600 template <
typename T>
2604 return !(lhs < rhs);
2619 template <
typename T>
2623 return lhs.
size() == rhs.size() &&
2624 std::equal(lhs.
begin(), lhs.
end(), rhs.begin());
2639 template <
typename T>
2643 return !(lhs == rhs);
2657 template <
typename T>
2659 operator<(
const vector<T> &lhs,
const std::vector<T> &rhs)
2661 return std::lexicographical_compare(lhs.
begin(), lhs.
end(), rhs.begin(),
2676 template <
typename T>
2678 operator<=(
const vector<T> &lhs,
const std::vector<T> &rhs)
2680 return !(std::lexicographical_compare(rhs.begin(), rhs.end(),
2695 template <
typename T>
2699 return !(lhs <= rhs);
2713 template <
typename T>
2717 return !(lhs < rhs);
2732 template <
typename T>
2751 template <
typename T>
2755 return !(lhs == rhs);
2769 template <
typename T>
2771 operator<(
const std::vector<T> &lhs,
const vector<T> &rhs)
2787 template <
typename T>
2789 operator<=(
const std::vector<T> &lhs,
const vector<T> &rhs)
2791 return !(rhs < lhs);
2806 template <
typename T>
2824 template <
typename T>
2828 return !(lhs < rhs);
2838 template <
typename T>
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
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
Persistent container with std::vector compatible interface.
Definition: vector.hpp:41
const_reference front() const
Access the first element.
Definition: vector.hpp:967
reverse_iterator rend()
Returns a reverse iterator to the end.
Definition: vector.hpp:1197
const value_type * cdata() const noexcept
Returns const raw pointer to the underlying data.
Definition: vector.hpp:1070
bool operator>=(const std::vector< T > &lhs, const vector< T > &rhs)
Comparison operator.
Definition: vector.hpp:2826
const_reverse_iterator crend() const noexcept
Returns a const reverse iterator to the beginning.
Definition: vector.hpp:1225
const value_type * data() const noexcept
Returns const raw pointer to the underlying data.
Definition: vector.hpp:1056
vector(vector &&other)
Move constructor.
Definition: vector.hpp:478
void free_data()
Clears the content of a vector and frees all allocated persistent memory for data transactionally.
Definition: vector.hpp:1461
vector(const std::vector< T > &other)
Copy constructor.
Definition: vector.hpp:532
const_reference const_at(size_type n) const
Access element at specific index with bounds checking.
Definition: vector.hpp:901
size_type size() const noexcept
Definition: vector.hpp:1350
const_reference operator[](size_type n) const
Access element at specific index.
Definition: vector.hpp:937
vector & operator=(const std::vector< T > &other)
Copy assignment operator.
Definition: vector.hpp:608
slice< pointer > range(size_type start, size_type n)
Returns slice and snapshots requested range.
Definition: vector.hpp:1245
bool operator==(const vector< T > &lhs, const vector< T > &rhs)
Comparison operator.
Definition: vector.hpp:2508
void assign(InputIt first, InputIt last)
Replaces the contents with copies of those in the range [first, last) transactionally.
Definition: vector.hpp:691
const_reference at(size_type n) const
Access element at specific index with bounds checking.
Definition: vector.hpp:879
reference back()
Access the last element and add this element to a transaction.
Definition: vector.hpp:996
slice< const_iterator > crange(size_type start, size_type n) const
Returns const slice.
Definition: vector.hpp:1324
bool operator==(const vector< T > &lhs, const std::vector< T > &rhs)
Comparison operator.
Definition: vector.hpp:2621
bool operator!=(const std::vector< T > &lhs, const vector< T > &rhs)
Comparison operator.
Definition: vector.hpp:2753
bool operator>(const vector< T > &lhs, const vector< T > &rhs)
Comparison operator.
Definition: vector.hpp:2584
void assign(const std::vector< T > &other)
Copy assignment method.
Definition: vector.hpp:821
iterator begin()
Returns an iterator to the beginning.
Definition: vector.hpp:1082
bool operator!=(const vector< T > &lhs, const std::vector< T > &rhs)
Comparison operator.
Definition: vector.hpp:2641
void assign(vector &&other)
Move assignment method.
Definition: vector.hpp:788
void pop_back()
Removes the last element of the container transactionally.
Definition: vector.hpp:1909
vector(InputIt first, InputIt last)
Constructs the container with the contents of the range [first, last).
Definition: vector.hpp:417
reference operator[](size_type n)
Access element at specific index and add it to a transaction.
Definition: vector.hpp:921
reference front()
Access the first element and add this element to a transaction.
Definition: vector.hpp:952
vector(size_type count, const value_type &value)
Constructs the container with count copies of elements with value value.
Definition: vector.hpp:351
reference at(size_type n)
Access element at specific index with bounds checking and add it to a transaction.
Definition: vector.hpp:857
void resize(size_type count)
Resizes the container to count elements transactionally.
Definition: vector.hpp:1936
void swap(vector &other)
Exchanges the contents of the container with other transactionally.
Definition: vector.hpp:1991
const_reverse_iterator crbegin() const noexcept
Returns a const reverse iterator to the beginning.
Definition: vector.hpp:1184
bool operator>=(const vector< T > &lhs, const vector< T > &rhs)
Comparison operator.
Definition: vector.hpp:2602
iterator emplace(const_iterator pos, Args &&... args)
Inserts a new element into the container directly before pos.
Definition: vector.hpp:1701
void shrink_to_fit()
Requests transactional removal of unused capacity.
Definition: vector.hpp:1421
bool operator>=(const vector< T > &lhs, const std::vector< T > &rhs)
Comparison operator.
Definition: vector.hpp:2715
iterator erase(const_iterator pos)
Removes the element at pos.
Definition: vector.hpp:1794
const_reference cfront() const
Access the first element.
Definition: vector.hpp:981
reference emplace_back(Args &&... args)
Appends a new element to the end of the container.
Definition: vector.hpp:1751
const_reference cback() const
Access the last element.
Definition: vector.hpp:1026
void clear()
Clears the content of a vector transactionally.
Definition: vector.hpp:1441
iterator insert(const_iterator pos, const T &value)
Inserts value before pos in the container transactionally.
Definition: vector.hpp:1496
vector(const vector &other)
Copy constructor.
Definition: vector.hpp:447
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:2009
const_reference back() const
Access the last element.
Definition: vector.hpp:1012
vector(std::initializer_list< T > init)
Constructs the container with the contents of the initializer list init.
Definition: vector.hpp:508
void assign(const vector &other)
Copy assignment method.
Definition: vector.hpp:769
reverse_iterator rbegin()
Returns a reverse iterator to the beginning.
Definition: vector.hpp:1158
vector & operator=(vector &&other)
Move assignment operator.
Definition: vector.hpp:569
vector()
Default constructor.
Definition: vector.hpp:322
~vector()
Destructor.
Definition: vector.hpp:834
vector & operator=(std::initializer_list< T > ilist)
Replaces the contents with those identified by initializer list ilist transactionally.
Definition: vector.hpp:587
size_type capacity() const noexcept
Definition: vector.hpp:1400
void reserve(size_type capacity_new)
Increases the capacity of the vector to capacity_new transactionally.
Definition: vector.hpp:1386
void assign(std::initializer_list< T > ilist)
Replaces the contents with the elements from the initializer list ilist transactionally.
Definition: vector.hpp:751
bool operator>(const vector< T > &lhs, const std::vector< T > &rhs)
Comparison operator.
Definition: vector.hpp:2697
bool operator>(const std::vector< T > &lhs, const vector< T > &rhs)
Comparison operator.
Definition: vector.hpp:2808
value_type * data()
Returns raw pointer to the underlying data and adds entire array to a transaction.
Definition: vector.hpp:1042
constexpr bool empty() const noexcept
Checks whether the container is empty.
Definition: vector.hpp:1340
bool operator==(const std::vector< T > &lhs, const vector< T > &rhs)
Comparison operator.
Definition: vector.hpp:2734
void swap(vector< T > &lhs, vector< T > &rhs)
Swaps the contents of lhs and rhs.
Definition: vector.hpp:2840
const_iterator cbegin() const noexcept
Returns const iterator to the beginning.
Definition: vector.hpp:1108
bool operator!=(const vector< T > &lhs, const vector< T > &rhs)
Comparison operator.
Definition: vector.hpp:2528
constexpr size_type max_size() const noexcept
Definition: vector.hpp:1361
void push_back(const T &value)
Appends the given element value to the end of the container transactionally.
Definition: vector.hpp:1869
const_iterator cend() const noexcept
Returns a const iterator to the end.
Definition: vector.hpp:1146
iterator end()
Returns an iterator to past the end.
Definition: vector.hpp:1120
vector & operator=(const vector &other)
Copy assignment operator.
Definition: vector.hpp:550
vector(size_type count)
Constructs the container with count copies of T default constructed values.
Definition: vector.hpp:380
Custom pool error class.
Definition: pexceptions.hpp:84
Custom transaction error class.
Definition: pexceptions.hpp:132
Custom transaction error class.
Definition: pexceptions.hpp:156
Custom out of memory error class.
Definition: pexceptions.hpp:144
Custom transaction error class.
Definition: pexceptions.hpp:167
Commonly used functionality.
Iterators for contiguous persistent containers.
Functions for lifetime management.
persistent_ptr transactional allocation functions for objects.
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
ExcT exception_with_errormsg(Args &&... args)
Generic error message decorator for pmemobj-based exceptions.
Definition: pexceptions.hpp:69
uint64_t next_pow_2(uint64_t v)
Round up to the next lowest power of 2.
Definition: common.hpp:213
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.
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
Template class for caching objects based on constructor's variadic template arguments and LIBPMEMOBJ_...
Definition: temp_value.hpp:35
template class for caching objects.
C++ pmemobj transactions.