38 #ifndef LIBPMEMOBJ_CPP_SLICE_HPP 39 #define LIBPMEMOBJ_CPP_SLICE_HPP 43 #include <type_traits> 51 namespace experimental
58 template <
typename Iterator>
61 using size_type = std::size_t;
62 using iterator = Iterator;
63 using reverse_iterator = std::reverse_iterator<iterator>;
64 using reference =
typename std::iterator_traits<iterator>::reference;
74 std::is_same<
typename std::iterator_traits<
75 iterator>::iterator_category,
76 std::random_access_iterator_tag>::value,
77 "Iterator should have RandomAccessIterator tag");
79 if (it_end < it_begin)
80 throw std::out_of_range(
"pmem::obj::slice");
117 return reverse_iterator(it_begin);
126 return reverse_iterator(it_end);
138 throw std::out_of_range(
"pmem::obj::slice");
140 return it_begin[
static_cast<typename std::iterator_traits<
141 Iterator
>::difference_type>(idx)];
150 return it_begin[
static_cast<typename std::iterator_traits<
151 Iterator
>::difference_type>(idx)];
157 return static_cast<size_type>(it_end - it_begin);
161 iterator it_begin, it_end;
reverse_iterator rend() const noexcept
Returns reverse iterator to the end.
Definition: slice.hpp:115
iterator end() const noexcept
Returns iterator to the end of the range.
Definition: slice.hpp:106
slice & operator=(const slice &other) noexcept=default
Defaulted assignment operator.
slice(Iterator begin, Iterator end)
Constructor taking two RandomAccess iterators which define a range.
Definition: slice.hpp:71
iterator begin() const noexcept
Returns iterator to the beginning of the range.
Definition: slice.hpp:97
pmem::obj::experimental::slice - provides interface to access sequence of objects.
Definition: slice.hpp:59
reference operator[](size_type idx)
Element access operator.
Definition: slice.hpp:148
reverse_iterator rbegin() const noexcept
Returns reverse iterator to the beginning.
Definition: slice.hpp:124
reference at(size_type idx)
Element access operator.
Definition: slice.hpp:135