9 #ifndef LIBPMEMOBJ_CPP_SLICE_HPP
10 #define LIBPMEMOBJ_CPP_SLICE_HPP
14 #include <type_traits>
23 template <
typename Iterator>
25 decltype(std::declval<Iterator>() - std::declval<Iterator>());
26 template <
typename Iterator>
27 using has_subtraction = supports<Iterator, subtraction>;
29 template <
typename Iterator>
30 using pre_decrement = decltype(std::declval<Iterator>().
operator--());
31 template <
typename Iterator>
32 using has_pre_decrement = supports<Iterator, pre_decrement>;
34 template <
typename Iterator>
35 using indexing = decltype(std::declval<Iterator>().
operator[](
37 typename std::iterator_traits<Iterator>::difference_type>()));
38 template <
typename Iterator>
39 using has_indexing = supports<Iterator, indexing>;
49 template <
typename Iterator>
52 using size_type = std::size_t;
53 using iterator = Iterator;
54 using reverse_iterator = std::reverse_iterator<iterator>;
55 using reference =
typename std::iterator_traits<iterator>::reference;
66 std::is_pointer<Iterator>::value ||
67 (detail::has_indexing<Iterator>::value &&
68 detail::has_pre_decrement<Iterator>::value &&
69 detail::has_subtraction<Iterator>::value),
70 "Iterator should support: operator[], operator-(), operator--()");
72 if (it_end - it_begin < 0)
73 throw std::out_of_range(
"pmem::obj::slice");
110 return reverse_iterator(it_begin);
119 return reverse_iterator(it_end);
131 throw std::out_of_range(
"pmem::obj::slice");
133 return it_begin[
static_cast<typename std::iterator_traits<
134 Iterator
>::difference_type>(idx)];
143 return it_begin[
static_cast<typename std::iterator_traits<
144 Iterator
>::difference_type>(idx)];
150 return static_cast<size_type
>(it_end - it_begin);
154 iterator it_begin, it_end;
pmem::obj::slice - provides interface to access sequence of objects.
Definition: slice.hpp:50
slice & operator=(const slice &other) noexcept=default
Defaulted assignment operator.
iterator begin() const noexcept
Returns iterator to the beginning of the range.
Definition: slice.hpp:90
reverse_iterator rbegin() const noexcept
Returns reverse iterator to the beginning.
Definition: slice.hpp:117
iterator end() const noexcept
Returns iterator to the end of the range.
Definition: slice.hpp:99
slice(const slice &other) noexcept=default
Defaulted copy constructor.
reverse_iterator rend() const noexcept
Returns reverse iterator to the end.
Definition: slice.hpp:108
reference at(size_type idx)
Element access operator.
Definition: slice.hpp:128
reference operator[](size_type idx)
Element access operator.
Definition: slice.hpp:141
slice(Iterator begin, Iterator end)
Constructor taking two iterators (iterators should support: operator[], operator-(),...
Definition: slice.hpp:63
Persistent memory namespace.
Definition: allocation_flag.hpp:15
Commonly used SFINAE helpers.