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>
590 operator==(
const array<T, N> &lhs,
const array<T, N> &rhs)
592 return std::equal(lhs.cbegin(), lhs.cend(), rhs.cbegin());
598 template <
typename T, std::
size_t N>
600 operator!=(
const array<T, N> &lhs,
const array<T, N> &rhs)
602 return !(lhs == rhs);
608 template <
typename T, std::
size_t N>
610 operator<(const array<T, N> &lhs,
const array<T, N> &rhs)
612 return std::lexicographical_compare(lhs.cbegin(), lhs.cend(),
613 rhs.cbegin(), rhs.cend());
619 template <
typename T, std::
size_t N>
621 operator>(
const array<T, N> &lhs,
const array<T, N> &rhs)
629 template <
typename T, std::
size_t N>
631 operator>=(
const array<T, N> &lhs,
const array<T, N> &rhs)
639 template <
typename T, std::
size_t N>
641 operator<=(const array<T, N> &lhs,
const array<T, N> &rhs)
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));
Non-const iterator which adds elements to a transaction in a bulk.
Definition: contiguous_iterator.hpp:294
constexpr bool empty() const noexcept
Checks wheter array is empty.
Definition: array.hpp:494
std::enable_if< Size!=0, const T * >::type _get_data() const
Support for non-zero sized array.
Definition: array.hpp:558
std::enable_if< Size!=0 >::type swap(array &other)
Swaps content with other array's content.
Definition: array.hpp:522
const_reverse_iterator crbegin() const noexcept
Returns a const reverse iterator to the beginning.
Definition: array.hpp:329
slice< const_iterator > range(size_type start, size_type n) const
Returns const slice.
Definition: array.hpp:442
Default non-const iterator which adds element to a transaction on every access.
Definition: contiguous_iterator.hpp:420
const_reference back() const
Access the last element.
Definition: array.hpp:391
const_iterator cbegin() const noexcept
Returns const iterator to the beginning.
Definition: array.hpp:269
void fill(const_reference value)
Adds entire array to a transaction and fills array with specified value.
Definition: array.hpp:507
iterator end()
Returns an iterator to the end.
Definition: array.hpp:251
const_iterator begin() const noexcept
Returns const iterator to the beginning.
Definition: array.hpp:260
array & operator=(const array &other)
Copy assignment operator - adds 'this' to a transaction.
Definition: array.hpp:131
iterator begin()
Returns an iterator to the beginning.
Definition: array.hpp:239
const_reference front() const
Access the first element.
Definition: array.hpp:382
std::enable_if< Size!=0, T * >::type _get_data()
Support for non-zero sized array.
Definition: array.hpp:548
reverse_iterator rend()
Returns a reverse iterator to the end.
Definition: array.hpp:311
reference back()
Access the last element and add this element to a transaction.
Definition: array.hpp:372
Convenience extensions for the resides on pmem property template.
Commonly used functionality.
Iterators for pmem::obj::array.
pmem::obj::experimental::array - EXPERIMENTAL persistent container with std::array compatible interfa...
Definition: array.hpp:74
reference operator[](size_type n)
Access element at specific index and add it to a transaction.
Definition: array.hpp:193
T * data()
Returns raw pointer to the underlying data and adds entire array to a transaction.
Definition: array.hpp:217
constexpr size_type max_size() const noexcept
Returns the maximum size of the array.
Definition: array.hpp:485
array()=default
Defaulted constructor.
const_reverse_iterator rbegin() const noexcept
Returns a const reverse iterator to the beginning.
Definition: array.hpp:320
std::enable_if< Size==0, T * >::type _get_data()
Support for zero sized array.
Definition: array.hpp:569
pmem::obj::experimental::slice - provides interface to access sequence of objects.
Definition: slice.hpp:58
reverse_iterator rbegin()
Returns a reverse iterator to the beginning.
Definition: array.hpp:299
const_reverse_iterator rend() const noexcept
Returns a const reverse iterator to the end.
Definition: array.hpp:338
std::enable_if< Size==0, const T * >::type _get_data() const
Support for zero sized array.
Definition: array.hpp:579
const_iterator end() const noexcept
Returns a const iterator to the end.
Definition: array.hpp:278
const T * data() const noexcept
Returns const raw pointer to the underlying data.
Definition: array.hpp:227
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
slice< range_snapshotting_iterator< T > > range(size_type start, size_type n, size_type snapshot_size=std::numeric_limits< size_type >::max())
Adds requested range to a transaction and returns slice.
Definition: array.hpp:413
std::enable_if< Size==0 >::type swap(array &other)
Swap for zero-sized array.
Definition: array.hpp:536
Const iterator.
Definition: contiguous_iterator.hpp:208
const_reference at(size_type n) const
Access element at specific index.
Definition: array.hpp:178
Persistent smart pointer.
Iterface to access sequence of objects.
reference at(size_type n)
Access element at specific index and add it to a transaction.
Definition: array.hpp:162
const_reference operator[](size_type n) const
Access element at specific index.
Definition: array.hpp:204
const_reverse_iterator crend() const noexcept
Returns a const reverse iterator to the beginning.
Definition: array.hpp:347
constexpr size_type size() const noexcept
Returns size of the array.
Definition: array.hpp:476
array & operator=(array &&other)
Move assignment operator - adds 'this' to a transaction.
Definition: array.hpp:146
reference front()
Access the first element and add this element to a transaction.
Definition: array.hpp:359