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;