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>;
60 template <
typename Iterator>
63 using size_type = std::size_t;
64 using iterator = Iterator;
65 using reverse_iterator = std::reverse_iterator<iterator>;
66 using reference =
typename std::iterator_traits<iterator>::reference;
79 std::is_pointer<Iterator>::value ||
80 (detail::has_indexing<Iterator>::value &&
81 detail::has_pre_decrement<Iterator>::value &&
82 detail::has_subtraction<Iterator>::value),
83 "Iterator should support: operator[], operator-(), operator--()");
85 if (it_end - it_begin < 0)
86 throw std::out_of_range(
"pmem::obj::slice");
128 return reverse_iterator(it_end);
141 return reverse_iterator(it_begin);
156 throw std::out_of_range(
"pmem::obj::slice");
158 return it_begin[
static_cast<typename std::iterator_traits<
159 Iterator
>::difference_type>(idx)];
173 return it_begin[
static_cast<typename std::iterator_traits<
174 Iterator
>::difference_type>(idx)];
185 return static_cast<size_type
>(it_end - it_begin);
189 iterator it_begin, it_end;
Provides interface to access sequence of objects.
Definition: slice.hpp:61
slice & operator=(const slice &other) noexcept=default
Defaulted assignment operator.
iterator begin() const noexcept
Definition: slice.hpp:103
reverse_iterator rbegin() const noexcept
Returns a reverse_iterator to the last element in the range.
Definition: slice.hpp:126
iterator end() const noexcept
Definition: slice.hpp:112
slice(const slice &other) noexcept=default
Defaulted copy constructor.
reverse_iterator rend() const noexcept
Returns a reverse_iterator to the first element in the range.
Definition: slice.hpp:139
size_type size() const
Returns total number of elements within slice's range.
Definition: slice.hpp:183
reference at(size_type idx)
Access operator for a single element of slice.
Definition: slice.hpp:153
reference operator[](size_type idx)
Subscript operator, providing access to a single element of the slice.
Definition: slice.hpp:171
slice(Iterator begin, Iterator end)
Constructor taking two iterators, which define a range.
Definition: slice.hpp:76
Persistent memory namespace.
Definition: allocation_flag.hpp:15
Commonly used SFINAE helpers.