PMDK C++ bindings
1.5.2
This is the C++ bindings documentation for PMDK's libpmemobj.
|
Go to the documentation of this file.
38 #ifndef LIBPMEMOBJ_CPP_ARRAY_HPP
39 #define LIBPMEMOBJ_CPP_ARRAY_HPP
49 #include <libpmemobj.h>
57 namespace experimental
73 template <
typename T, std::
size_t N>
76 template <
typename Y, std::
size_t M>
77 struct standard_array_traits {
83 struct standard_array_traits<Y, 0> {
84 struct _alignment_struct {
88 struct alignas(_alignment_struct) type {
89 char _data[
sizeof(_alignment_struct)];
95 using pointer = value_type *;
96 using const_pointer =
const value_type *;
97 using reference = value_type &;
98 using const_reference =
const value_type &;
101 using size_type = std::size_t;
102 using difference_type = std::ptrdiff_t;
103 using reverse_iterator = std::reverse_iterator<iterator>;
104 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
107 typename standard_array_traits<T, N>::type _data;
133 detail::conditional_add_to_tx(
this);
148 detail::conditional_add_to_tx(
this);
150 std::copy(other.cbegin(), other.cend(),
_get_data());
165 throw std::out_of_range(
"array::at");
167 detail::conditional_add_to_tx(
_get_data() + n);
178 at(size_type n)
const
181 throw std::out_of_range(
"array::at");
195 detail::conditional_add_to_tx(
_get_data() + n);
219 detail::conditional_add_to_tx(
this);
319 const_reverse_iterator
322 return const_reverse_iterator(
cend());
328 const_reverse_iterator
331 return const_reverse_iterator(
cend());
337 const_reverse_iterator
340 return const_reverse_iterator(
cbegin());
346 const_reverse_iterator
349 return const_reverse_iterator(
cbegin());
361 detail::conditional_add_to_tx(
_get_data());
414 size_type snapshot_size = std::numeric_limits<size_type>::max())
417 throw std::out_of_range(
"array::range");
419 if (snapshot_size > n)
442 range(size_type start, size_type n)
const
445 throw std::out_of_range(
"array::range");
463 crange(size_type start, size_type n)
const
466 throw std::out_of_range(
"array::crange");
509 detail::conditional_add_to_tx(
this);
520 template <std::
size_t Size = N>
521 typename std::enable_if<Size != 0>::type
524 detail::conditional_add_to_tx(
this);
525 detail::conditional_add_to_tx(&other);
534 template <std::
size_t Size = N>
535 typename std::enable_if<Size == 0>::type
538 static_assert(!std::is_const<T>::value,
539 "cannot swap zero-sized array of type 'const T'");
546 template <std::
size_t Size = N>
547 typename std::enable_if<Size != 0, T *>::type
556 template <std::
size_t Size = N>
557 typename std::enable_if<Size != 0, const T *>::type
567 template <std::
size_t Size = N>
568 typename std::enable_if<Size == 0, T *>::type
571 return reinterpret_cast<T *
>(&this->_data);
577 template <std::
size_t Size = N>
578 typename std::enable_if<Size == 0, const T *>::type
581 return reinterpret_cast<const T *
>(&this->_data);
588 template <
typename T, std::
size_t N>
598 template <
typename T, std::
size_t N>
602 return !(lhs == rhs);
608 template <
typename T, std::
size_t N>
612 return std::lexicographical_compare(lhs.
cbegin(), lhs.
cend(),
619 template <
typename T, std::
size_t N>
629 template <
typename T, std::
size_t N>
639 template <
typename T, std::
size_t N>
649 template <
typename T, std::
size_t N>
659 template <
typename T, std::
size_t N>
669 template <
typename T, std::
size_t N>
670 typename pmem::obj::experimental::array<T, N>::const_reverse_iterator
679 template <
typename T, std::
size_t N>
680 typename pmem::obj::experimental::array<T, N>::const_reverse_iterator
689 template <
typename T, std::
size_t N>
699 template <
typename T, std::
size_t N>
709 template <
typename T, std::
size_t N>
710 typename pmem::obj::experimental::array<T, N>::reverse_iterator
719 template <
typename T, std::
size_t N>
720 typename pmem::obj::experimental::array<T, N>::reverse_iterator
729 template <
typename T,
size_t N>
740 template <
size_t I,
typename T,
size_t N>
745 "Index out of bounds in std::get<> (pmem::obj::array)");
752 template <
size_t I,
typename T,
size_t N>
757 "Index out of bounds in std::get<> (pmem::obj::array)");
758 return std::move(a.at(I));
764 template <
size_t I,
typename T,
size_t N>
769 "Index out of bounds in std::get<> (pmem::obj::array)");
776 template <
size_t I,
typename T,
size_t N>
781 "Index out of bounds in std::get<> (pmem::obj::array)");
782 return std::move(a.at(I));
array(array &&)=default
Defaulted move constructor.
std::enable_if< Size !=0 >::type swap(array &other)
Swaps content with other array's content.
Definition: array.hpp:522
reference operator[](size_type n)
Access element at specific index and add it to a transaction.
Definition: array.hpp:193
iterator end()
Returns an iterator to the end.
Definition: array.hpp:251
T * data()
Returns raw pointer to the underlying data and adds entire array to a transaction.
Definition: array.hpp:217
T & get(pmem::obj::experimental::array< T, N > &a)
Non-member get function.
Definition: array.hpp:742
std::enable_if< Size==0 >::type swap(array &other)
Swap for zero-sized array.
Definition: array.hpp:536
array & operator=(array &&other)
Move assignment operator - adds 'this' to a transaction.
Definition: array.hpp:146
array()=default
Defaulted constructor.
const_iterator cend() const noexcept
Returns a const iterator to the end.
Definition: array.hpp:287
slice< const_iterator > crange(size_type start, size_type n) const
Returns const slice.
Definition: array.hpp:463
void fill(const_reference value)
Adds entire array to a transaction and fills array with specified value.
Definition: array.hpp:507
Commonly used functionality.
constexpr bool empty() const noexcept
Checks whether array is empty.
Definition: array.hpp:494
const_reference operator[](size_type n) const
Access element at specific index.
Definition: array.hpp:204
constexpr size_type size() const noexcept
Returns size of the array.
Definition: array.hpp:476
iterator begin()
Returns an iterator to the beginning.
Definition: array.hpp:239
constexpr size_type max_size() const noexcept
Returns the maximum size of the array.
Definition: array.hpp:485
array(const array &)=default
Defaulted copy constructor.
const_reverse_iterator rbegin() const noexcept
Returns a const reverse iterator to the beginning.
Definition: array.hpp:320
const_reference back() const
Access the last element.
Definition: array.hpp:391
const T * data() const noexcept
Returns const raw pointer to the underlying data.
Definition: array.hpp:227
reverse_iterator rbegin()
Returns a reverse iterator to the beginning.
Definition: array.hpp:299
slice< const_iterator > range(size_type start, size_type n) const
Returns const slice.
Definition: array.hpp:442
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:522
const_reverse_iterator rend() const noexcept
Returns a const reverse iterator to the end.
Definition: array.hpp:338
pmem::obj::experimental::slice - provides interface to access sequence of objects.
Definition: slice.hpp:58
Iterface to access sequence of objects.
const_iterator begin() const noexcept
Returns const iterator to the beginning.
Definition: array.hpp:260
std::enable_if< Size !=0, const T * >::type _get_data() const
Support for non-zero sized array.
Definition: array.hpp:558
const_iterator end() const noexcept
Returns a const iterator to the end.
Definition: array.hpp:278
std::enable_if< Size==0, T * >::type _get_data()
Support for zero sized array.
Definition: array.hpp:569
reverse_iterator rend()
Returns a reverse iterator to the end.
Definition: array.hpp:311
Const iterator.
Definition: contiguous_iterator.hpp:491
Iterators for pmem::obj::array.
const_reference at(size_type n) const
Access element at specific index.
Definition: array.hpp:178
const_reference front() const
Access the first element.
Definition: array.hpp:382
bool operator>(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member greater than operator.
Definition: array.hpp:621
array & operator=(const array &other)
Copy assignment operator - adds 'this' to a transaction.
Definition: array.hpp:131
reference at(size_type n)
Access element at specific index and add it to a transaction.
Definition: array.hpp:162
Non-const iterator which adds elements to a transaction in a bulk.
Definition: contiguous_iterator.hpp:296
std::enable_if< Size !=0, T * >::type _get_data()
Support for non-zero sized array.
Definition: array.hpp:548
const_reverse_iterator crbegin() const noexcept
Returns a const reverse iterator to the beginning.
Definition: array.hpp:329
bool operator<(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member less than operator.
Definition: array.hpp:610
reference back()
Access the last element and add this element to a transaction.
Definition: array.hpp:372
const_iterator cbegin() const noexcept
Returns const iterator to the beginning.
Definition: array.hpp:269
std::enable_if< Size==0, const T * >::type _get_data() const
Support for zero sized array.
Definition: array.hpp:579
Convenience extensions for the resides on pmem property template.
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:406
pmem::obj::experimental::array - EXPERIMENTAL persistent container with std::array compatible interfa...
Definition: array.hpp:74
bool operator<=(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member less or equal operator.
Definition: array.hpp:641
reference front()
Access the first element and add this element to a transaction.
Definition: array.hpp:359
const_reverse_iterator crend() const noexcept
Returns a const reverse iterator to the beginning.
Definition: array.hpp:347
bool operator>=(const array< T, N > &lhs, const array< T, N > &rhs)
Non-member greater or equal operator.
Definition: array.hpp:631
Persistent smart pointer.
slice< range_snapshotting_iterator< T > > range(size_type start, size_type n, size_type snapshot_size=std::numeric_limits< size_type >::max())
Returns slice.
Definition: array.hpp:413
Default non-const iterator which adds element to a transaction on every access.
Definition: contiguous_iterator.hpp:426