PMDK C++ bindings
1.11
This is the C++ bindings documentation for PMDK's libpmemobj.
|
Go to the documentation of this file.
9 #ifndef LIBPMEMOBJ_CPP_ARRAY_HPP
10 #define LIBPMEMOBJ_CPP_ARRAY_HPP
22 #include <libpmemobj/base.h>
45 template <
typename T, std::
size_t N>
48 template <
typename Y, std::
size_t M>
49 struct standard_array_traits {
55 struct standard_array_traits<Y, 0> {
56 struct _alignment_struct {
60 struct alignas(_alignment_struct) type {
61 char _data[
sizeof(_alignment_struct)];
67 using pointer = value_type *;
68 using const_pointer =
const value_type *;
69 using reference = value_type &;
70 using const_reference =
const value_type &;
72 using const_iterator = const_pointer;
73 using size_type = std::size_t;
74 using difference_type = std::ptrdiff_t;
75 using reverse_iterator = std::reverse_iterator<iterator>;
76 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
81 typename standard_array_traits<T, N>::type _data;
124 detail::conditional_add_to_tx(
125 this, 1, POBJ_XADD_ASSUME_INITIALIZED);
155 detail::conditional_add_to_tx(
156 this, 1, POBJ_XADD_ASSUME_INITIALIZED);
157 detail::conditional_add_to_tx(
158 &other, 1, POBJ_XADD_ASSUME_INITIALIZED);
159 std::move(other._get_data(), other._get_data() +
size(),
177 throw std::out_of_range(
"array::at");
179 detail::conditional_add_to_tx(
_get_data() + n, 1,
180 POBJ_XADD_ASSUME_INITIALIZED);
191 at(size_type n)
const
194 throw std::out_of_range(
"array::at");
208 throw std::out_of_range(
"array::const_at");
222 detail::conditional_add_to_tx(
_get_data() + n, 1,
223 POBJ_XADD_ASSUME_INITIALIZED);
247 detail::conditional_add_to_tx(
this, 1,
248 POBJ_XADD_ASSUME_INITIALIZED);
357 const_reverse_iterator
360 return const_reverse_iterator(
cend());
366 const_reverse_iterator
369 return const_reverse_iterator(
cend());
375 const_reverse_iterator
378 return const_reverse_iterator(
cbegin());
384 const_reverse_iterator
387 return const_reverse_iterator(
cbegin());
399 detail::conditional_add_to_tx(
_get_data(), 1,
400 POBJ_XADD_ASSUME_INITIALIZED);
414 POBJ_XADD_ASSUME_INITIALIZED);
469 throw std::out_of_range(
"array::range");
471 detail::conditional_add_to_tx(
_get_data() + start, n,
472 POBJ_XADD_ASSUME_INITIALIZED);
494 range(size_type start, size_type n, size_type snapshot_size)
497 throw std::out_of_range(
"array::range");
499 if (snapshot_size > n)
522 range(size_type start, size_type n)
const
525 throw std::out_of_range(
"array::range");
527 return {const_iterator(
_get_data() + start),
528 const_iterator(
_get_data() + start + n)};
543 crange(size_type start, size_type n)
const
546 throw std::out_of_range(
"array::crange");
548 return {const_iterator(
_get_data() + start),
549 const_iterator(
_get_data() + start + n)};
592 detail::conditional_add_to_tx(
593 this, 1, POBJ_XADD_ASSUME_INITIALIZED);
605 template <std::
size_t Size = N>
606 typename std::enable_if<Size != 0>::type
619 detail::conditional_add_to_tx(
620 this, 1, POBJ_XADD_ASSUME_INITIALIZED);
621 detail::conditional_add_to_tx(
622 &other, 1, POBJ_XADD_ASSUME_INITIALIZED);
632 template <std::
size_t Size = N>
633 typename std::enable_if<Size == 0>::type
636 static_assert(!std::is_const<T>::value,
637 "cannot swap zero-sized array of type 'const T'");
644 template <std::
size_t Size = N>
645 typename std::enable_if<Size != 0, T *>::type
654 template <std::
size_t Size = N>
655 typename std::enable_if<Size != 0, const T *>::type
665 template <std::
size_t Size = N>
666 typename std::enable_if<Size == 0, T *>::type
669 return reinterpret_cast<T *
>(&this->_data);
675 template <std::
size_t Size = N>
676 typename std::enable_if<Size == 0, const T *>::type
679 return reinterpret_cast<const T *
>(&this->_data);
697 template <
typename T, std::
size_t N>
707 template <
typename T, std::
size_t N>
711 return !(lhs == rhs);
717 template <
typename T, std::
size_t N>
721 return std::lexicographical_compare(lhs.
cbegin(), lhs.
cend(),
728 template <
typename T, std::
size_t N>
738 template <
typename T, std::
size_t N>
748 template <
typename T, std::
size_t N>
758 template <
typename T, std::
size_t N>
759 typename pmem::obj::array<T, N>::const_iterator
768 template <
typename T, std::
size_t N>
769 typename pmem::obj::array<T, N>::const_iterator
778 template <
typename T, std::
size_t N>
779 typename pmem::obj::array<T, N>::const_reverse_iterator
788 template <
typename T, std::
size_t N>
789 typename pmem::obj::array<T, N>::const_reverse_iterator
798 template <
typename T, std::
size_t N>
808 template <
typename T, std::
size_t N>
809 typename pmem::obj::array<T, N>::const_iterator
818 template <
typename T, std::
size_t N>
828 template <
typename T, std::
size_t N>
829 typename pmem::obj::array<T, N>::const_iterator
838 template <
typename T, std::
size_t N>
839 typename pmem::obj::array<T, N>::reverse_iterator
848 template <
typename T, std::
size_t N>
849 typename pmem::obj::array<T, N>::const_reverse_iterator
858 template <
typename T, std::
size_t N>
859 typename pmem::obj::array<T, N>::reverse_iterator
868 template <
typename T, std::
size_t N>
869 typename pmem::obj::array<T, N>::const_reverse_iterator
878 template <
typename T,
size_t N>
888 template <
size_t I,
typename T,
size_t N>
893 "Index out of bounds in std::get<> (pmem::obj::array)");
900 template <
size_t I,
typename T,
size_t N>
905 "Index out of bounds in std::get<> (pmem::obj::array)");
906 return std::move(a.at(I));
912 template <
size_t I,
typename T,
size_t N>
917 "Index out of bounds in std::get<> (pmem::obj::array)");
924 template <
size_t I,
typename T,
size_t N>
929 "Index out of bounds in std::get<> (pmem::obj::array)");
930 return std::move(a.at(I));
const_reverse_iterator rbegin() const noexcept
Returns a const reverse iterator to the beginning.
Definition: array.hpp:358
const_reference operator[](size_type n) const
Access element at specific index.
Definition: array.hpp:232
constexpr size_type max_size() const noexcept
Returns the maximum size of the array.
Definition: array.hpp:565
const_reference back() const
Access the last element.
Definition: array.hpp:440
slice< const_iterator > range(size_type start, size_type n) const
Returns const slice.
Definition: array.hpp:522
reference operator[](size_type n)
Access element at specific index and add it to a transaction.
Definition: array.hpp:220
array(array &&)=default
Defaulted move constructor.
reference back()
Access the last element and add this element to a transaction.
Definition: array.hpp:411
Persistent memory namespace.
Definition: allocation_flag.hpp:15
slice< range_snapshotting_iterator > range(size_type start, size_type n, size_type snapshot_size)
Returns slice.
Definition: array.hpp:494
const T * cdata() const noexcept
Returns const raw pointer to the underlying data.
Definition: array.hpp:265
Commonly used functionality.
const_iterator cbegin() const noexcept
Returns const iterator to the beginning.
Definition: array.hpp:307
bool operator>(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member greater than operator.
Definition: array.hpp:730
const_reverse_iterator crbegin() const noexcept
Returns a const reverse iterator to the beginning.
Definition: array.hpp:367
const_iterator begin() const noexcept
Returns const iterator to the beginning.
Definition: array.hpp:298
std::enable_if< Size==0, T * >::type _get_data()
Support for zero sized array.
Definition: array.hpp:667
bool operator>=(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member greater or equal operator.
Definition: array.hpp:740
void fill(const_reference value)
Fills array with specified value inside internal transaction.
Definition: array.hpp:587
pool_base _get_pool() const
Check whether object is on pmem and return pool_base instance.
Definition: array.hpp:688
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
std::enable_if< Size !=0, T * >::type _get_data()
Support for non-zero sized array.
Definition: array.hpp:646
const_iterator cend() const noexcept
Returns a const iterator to the end.
Definition: array.hpp:325
array & operator=(const array &other)
Copy assignment operator - perform assignment from other pmem::obj::array.
Definition: array.hpp:112
Interface to access sequence of objects.
static void run(pool_base &pool, std::function< void()> tx, Locks &... locks)
Execute a closure-like transaction and lock locks.
Definition: transaction.hpp:406
const_reference at(size_type n) const
Access element at specific index.
Definition: array.hpp:191
const_reference cfront() const
Access the first element.
Definition: array.hpp:431
Default non-const iterator which adds element to a transaction on every access.
Definition: contiguous_iterator.hpp:331
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
const T * data() const noexcept
Returns const raw pointer to the underlying data.
Definition: array.hpp:256
std::enable_if< Size !=0 >::type swap(array &other)
Swaps content with other array's content inside internal transaction.
Definition: array.hpp:607
Iterators for contiguous persistent containers.
C++ pmemobj transactions.
iterator begin()
Returns an iterator to the beginning.
Definition: array.hpp:277
T * data()
Returns raw pointer to the underlying data and adds entire array to a transaction.
Definition: array.hpp:245
array & operator=(array &&other)
Move assignment operator - perform move assignment from other pmem::obj::array.
Definition: array.hpp:143
const_reference front() const
Access the first element.
Definition: array.hpp:422
bool operator<(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member less than operator.
Definition: array.hpp:719
constexpr bool empty() const noexcept
Checks whether array is empty.
Definition: array.hpp:574
reverse_iterator rbegin()
Returns a reverse iterator to the beginning.
Definition: array.hpp:337
reference at(size_type n)
Access element at specific index and add it to a transaction.
Definition: array.hpp:174
T & get(pmem::obj::array< T, N > &a)
Non-member get function.
Definition: array.hpp:890
const_reverse_iterator crend() const noexcept
Returns a const reverse iterator to the beginning.
Definition: array.hpp:385
pmem::obj::slice - provides interface to access sequence of objects.
Definition: slice.hpp:27
const_reference const_at(size_type n) const
Access element at specific index.
Definition: array.hpp:205
const_reference cback() const
Access the last element.
Definition: array.hpp:449
bool operator<=(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member less or equal operator.
Definition: array.hpp:750
const_iterator end() const noexcept
Returns a const iterator to the end.
Definition: array.hpp:316
pmem::obj::array - persistent container with std::array compatible interface.
Definition: array.hpp:46
Convenience extensions for the resides on pmem property template.
array()=default
Defaulted constructor.
slice< pointer > range(size_type start, size_type n)
Returns slice and snapshots requested range.
Definition: array.hpp:466
Non-const iterator which adds elements to a transaction in a bulk.
Definition: contiguous_iterator.hpp:192
std::enable_if< Size !=0, const T * >::type _get_data() const
Support for non-zero sized array.
Definition: array.hpp:656
slice< const_iterator > crange(size_type start, size_type n) const
Returns const slice.
Definition: array.hpp:543
pool_base pool_by_vptr(const T *that)
Retrieve pool handle for the given pointer.
Definition: utils.hpp:32
std::enable_if< Size==0, const T * >::type _get_data() const
Support for zero sized array.
Definition: array.hpp:677
const_reverse_iterator rend() const noexcept
Returns a const reverse iterator to the end.
Definition: array.hpp:376
The non-template pool base class.
Definition: pool.hpp:46
reverse_iterator rend()
Returns a reverse iterator to the end.
Definition: array.hpp:349
array(const array &)=default
Defaulted copy constructor.
Persistent smart pointer.
reference front()
Access the first element and add this element to a transaction.
Definition: array.hpp:397
iterator end()
Returns an iterator to the end.
Definition: array.hpp:289
std::enable_if< Size==0 >::type swap(array &other)
Swap for zero-sized array.
Definition: array.hpp:634
constexpr size_type size() const noexcept
Returns size of the array.
Definition: array.hpp:556