10#ifndef XTENSOR_BUFFER_ADAPTOR_HPP
11#define XTENSOR_BUFFER_ADAPTOR_HPP
19#include <xtl/xclosure.hpp>
21#include "xstorage.hpp"
22#include "xtensor_config.hpp"
37 template <
class CP,
class O = no_ownership,
class A = std::allocator<std::remove_po
inter_t<std::remove_reference_t<CP>>>>
46 template <
class CP,
class A>
52 using allocator_type = A;
53 using destructor_type = allocator_type;
54 using allocator_traits = std::allocator_traits<allocator_type>;
55 using value_type =
typename allocator_traits::value_type;
56 using reference = std::conditional_t<
57 std::is_const<std::remove_pointer_t<std::remove_reference_t<CP>>>::value,
60 using const_reference =
const value_type&;
61 using pointer = std::conditional_t<
62 std::is_const<std::remove_pointer_t<std::remove_reference_t<CP>>>::value,
63 typename allocator_traits::const_pointer,
64 typename allocator_traits::pointer>;
65 using const_pointer =
typename allocator_traits::const_pointer;
66 using size_type =
typename allocator_traits::size_type;
67 using difference_type =
typename allocator_traits::difference_type;
72 xbuffer_storage(
P&& data, size_type size,
const allocator_type&
alloc = allocator_type());
75 void resize(size_type size);
83 void reset_data(
P&& data, size_type size)
noexcept;
92 class xbuffer_smart_pointer
97 using destructor_type =
D;
98 using value_type = std::remove_const_t<std::remove_pointer_t<std::remove_reference_t<CP>>>;
99 using allocator_type = std::allocator<value_type>;
100 using allocator_traits = std::allocator_traits<allocator_type>;
101 using reference = std::conditional_t<
102 std::is_const<std::remove_pointer_t<std::remove_reference_t<CP>>>::value,
105 using const_reference =
const value_type&;
106 using pointer = std::conditional_t<
107 std::is_const<std::remove_pointer_t<std::remove_reference_t<CP>>>::value,
108 typename allocator_traits::const_pointer,
109 typename allocator_traits::pointer>;
110 using const_pointer =
typename allocator_traits::const_pointer;
111 using size_type =
typename allocator_traits::size_type;
112 using difference_type =
typename allocator_traits::difference_type;
114 xbuffer_smart_pointer();
116 template <
class P,
class DT>
120 void resize(size_type size);
134 destructor_type m_destruct;
138 class xbuffer_owner_storage
143 using allocator_type = A;
144 using destructor_type = allocator_type;
145 using allocator_traits = std::allocator_traits<allocator_type>;
146 using value_type =
typename allocator_traits::value_type;
147 using reference = std::conditional_t<
148 std::is_const<std::remove_pointer_t<std::remove_reference_t<CP>>>::value,
151 using const_reference =
const value_type&;
152 using pointer = std::conditional_t<
153 std::is_const<std::remove_pointer_t<std::remove_reference_t<CP>>>::value,
154 typename allocator_traits::const_pointer,
155 typename allocator_traits::pointer>;
156 using const_pointer =
typename allocator_traits::const_pointer;
157 using size_type =
typename allocator_traits::size_type;
158 using difference_type =
typename allocator_traits::difference_type;
160 xbuffer_owner_storage() =
default;
163 xbuffer_owner_storage(
P&& data, size_type size,
const allocator_type&
alloc = allocator_type());
165 ~xbuffer_owner_storage();
167 xbuffer_owner_storage(
const self_type&) =
delete;
168 self_type& operator=(
const self_type&);
170 xbuffer_owner_storage(self_type&&);
171 self_type& operator=(self_type&&);
174 void resize(size_type size);
184 void reset_data(
P&& data, size_type size,
const allocator_type&
alloc = allocator_type())
noexcept;
191 allocator_type m_allocator;
204 using msvc2015_void_t =
typename msvc2015_void<T>::type;
206 template <
class E,
class =
void>
207 struct is_lambda_type : std::false_type
213 struct is_lambda_type<E, msvc2015_void_t<decltype(&E::operator())>> : std::true_type
223 template <
class CP,
class A,
class O>
224 struct get_buffer_storage
226 using type = xtl::mpl::eval_if_t<
228 self_type<xbuffer_smart_pointer<CP, A>>,
229 self_type<xbuffer_storage<CP, A>>>;
232 template <
class CP,
class A>
233 struct get_buffer_storage<CP, A, acquire_ownership>
235 using type = xbuffer_owner_storage<CP, A>;
238 template <
class CP,
class T>
239 struct get_buffer_storage<CP, std::shared_ptr<T>, no_ownership>
241 using type = xbuffer_smart_pointer<CP, std::shared_ptr<T>>;
244 template <
class CP,
class T>
245 struct get_buffer_storage<CP, std::unique_ptr<T>, no_ownership>
247 using type = xbuffer_smart_pointer<CP, std::unique_ptr<T>>;
250 template <
class CP,
class A,
class O>
251 using buffer_storage_t =
typename get_buffer_storage<CP, A, O>::type;
269 using value_type =
typename inner_types::value_type;
270 using reference =
typename inner_types::reference;
271 using const_reference =
typename inner_types::const_reference;
272 using pointer =
typename inner_types::pointer;
273 using const_pointer =
typename inner_types::const_pointer;
274 using size_type =
typename inner_types::size_type;
275 using difference_type =
typename inner_types::difference_type;
276 using iterator =
typename inner_types::iterator;
277 using const_iterator =
typename inner_types::const_iterator;
278 using reverse_iterator =
typename inner_types::reverse_iterator;
279 using const_reverse_iterator =
typename inner_types::const_reverse_iterator;
280 using index_type =
typename inner_types::index_type;
282 bool empty()
const noexcept;
284 reference operator[](size_type
i);
285 const_reference operator[](size_type
i)
const;
288 const_reference front()
const;
291 const_reference back()
const;
293 iterator begin()
noexcept;
294 iterator end()
noexcept;
296 const_iterator begin()
const noexcept;
297 const_iterator end()
const noexcept;
298 const_iterator cbegin()
const noexcept;
299 const_iterator cend()
const noexcept;
301 reverse_iterator rbegin()
noexcept;
302 reverse_iterator rend()
noexcept;
304 const_reverse_iterator rbegin()
const noexcept;
305 const_reverse_iterator rend()
const noexcept;
306 const_reverse_iterator crbegin()
const noexcept;
307 const_reverse_iterator crend()
const noexcept;
346 template <
class CP,
class O,
class A>
349 using base_type = detail::buffer_storage_t<CP, A, O>;
350 using value_type =
typename base_type::value_type;
351 using reference =
typename base_type::reference;
352 using const_reference =
typename base_type::const_reference;
353 using pointer =
typename base_type::pointer;
354 using const_pointer =
typename base_type::const_pointer;
355 using size_type =
typename base_type::size_type;
356 using difference_type =
typename base_type::difference_type;
357 using iterator = pointer;
358 using const_iterator = const_pointer;
359 using reverse_iterator = std::reverse_iterator<iterator>;
360 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
361 using index_type = size_type;
364 template <
class CP,
class O,
class A>
371 using base_type = detail::buffer_storage_t<CP, A, O>;
373 using allocator_type =
typename base_type::allocator_type;
374 using destructor_type =
typename base_type::destructor_type;
375 using value_type =
typename buffer_base_type::value_type;
376 using reference =
typename buffer_base_type::reference;
377 using const_reference =
typename buffer_base_type::const_reference;
378 using pointer =
typename buffer_base_type::pointer;
379 using const_pointer =
typename buffer_base_type::const_pointer;
380 using size_type =
typename buffer_base_type::size_type;
381 using difference_type =
typename buffer_base_type::difference_type;
382 using iterator =
typename buffer_base_type::iterator;
383 using const_iterator =
typename buffer_base_type::const_iterator;
384 using reverse_iterator =
typename buffer_base_type::reverse_iterator;
385 using const_reverse_iterator =
typename buffer_base_type::const_reverse_iterator;
390 using base_type::base_type;
402 using base_type::data;
403 using base_type::reset_data;
404 using base_type::resize;
405 using base_type::size;
406 using base_type::swap;
409 template <
class CP,
class O,
class A>
416 template <
class I,
class CI>
419 template <
class I,
class CI>
422 using traits = std::iterator_traits<I>;
423 using const_traits = std::iterator_traits<CI>;
425 using value_type = std::common_type_t<typename traits::value_type, typename const_traits::value_type>;
426 using reference =
typename traits::reference;
427 using const_reference =
typename const_traits::reference;
428 using pointer =
typename traits::pointer;
429 using const_pointer =
typename const_traits::pointer;
430 using difference_type = std::common_type_t<typename traits::difference_type, typename const_traits::difference_type>;
431 using size_type = std::make_unsigned_t<difference_type>;
435 using reverse_iterator = std::reverse_iterator<iterator>;
436 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
437 using index_type = difference_type;
440 template <
class I,
class CI>
447 using value_type =
typename base_type::value_type;
448 using allocator_type = std::allocator<value_type>;
449 using size_type =
typename base_type::size_type;
450 using iterator =
typename base_type::iterator;
451 using const_iterator =
typename base_type::const_iterator;
468 size_type size()
const noexcept;
469 void resize(size_type size);
471 iterator data()
noexcept;
472 const_iterator data()
const noexcept;
483 template <
class I,
class CI>
486 template <
class I,
class CI>
495 template <
class C,
class IG>
498 template <
class C,
class IG>
501 using iterator =
typename IG::iterator;
502 using const_iterator =
typename IG::const_iterator;
503 using reverse_iterator = std::reverse_iterator<iterator>;
504 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
506 using traits = std::iterator_traits<iterator>;
507 using const_traits = std::iterator_traits<const_iterator>;
509 using value_type = std::common_type_t<typename traits::value_type, typename const_traits::value_type>;
510 using reference =
typename traits::reference;
511 using const_reference =
typename const_traits::reference;
512 using pointer =
typename traits::pointer;
513 using const_pointer =
typename const_traits::pointer;
514 using difference_type = std::common_type_t<typename traits::difference_type, typename const_traits::difference_type>;
515 using size_type = std::make_unsigned_t<difference_type>;
516 using index_type = difference_type;
519 template <
class C,
class IG>
526 using value_type =
typename base_type::value_type;
527 using allocator_type = std::allocator<value_type>;
528 using size_type =
typename base_type::size_type;
529 using iterator =
typename base_type::iterator;
530 using const_iterator =
typename base_type::const_iterator;
546 size_type size()
const noexcept;
547 void resize(size_type size);
549 iterator data()
noexcept;
550 const_iterator data()
const noexcept;
556 void init_iterators();
560 const_iterator m_cit;
564 template <
class C,
class IG>
567 template <
class C,
class IG>
577 template <
class C,
class IG>
590 template <
class CP,
class O,
class A>
596 template <
class I,
class CI>
602 template <
class C,
class IG>
617 template <
class CP,
class A>
618 inline xbuffer_storage<CP, A>::xbuffer_storage()
624 template <
class CP,
class A>
626 inline xbuffer_storage<CP, A>::xbuffer_storage(P&& data, size_type size,
const allocator_type&)
627 : p_data(std::forward<P>(data))
632 template <
class CP,
class A>
633 inline auto xbuffer_storage<CP, A>::size() const noexcept -> size_type
638 template <
class CP,
class A>
639 inline void xbuffer_storage<CP, A>::resize(size_type size)
643 XTENSOR_THROW(std::runtime_error,
"xbuffer_storage not resizable");
647 template <
class CP,
class A>
648 inline auto xbuffer_storage<CP, A>::data() noexcept -> pointer
653 template <
class CP,
class A>
654 inline auto xbuffer_storage<CP, A>::data() const noexcept -> const_pointer
659 template <
class CP,
class A>
660 inline void xbuffer_storage<CP, A>::swap(self_type& rhs)
noexcept
663 swap(p_data, rhs.p_data);
664 swap(m_size, rhs.m_size);
667 template <
class CP,
class A>
669 inline void xbuffer_storage<CP, A>::reset_data(P&& data, size_type size)
noexcept
671 p_data = std::forward<P>(data);
682 template <
class CP,
class A>
684 inline xbuffer_owner_storage<CP, A>::xbuffer_owner_storage(P&& data, size_type size,
const allocator_type& alloc)
685 : m_data(std::forward<P>(data))
687 , m_moved_from(false)
692 template <
class CP,
class A>
693 inline xbuffer_owner_storage<CP, A>::~xbuffer_owner_storage()
697 safe_destroy_deallocate(m_allocator, m_data.get(), m_size);
702 template <
class CP,
class A>
703 inline auto xbuffer_owner_storage<CP, A>::operator=(
const self_type& rhs) -> self_type&
708 allocator_type al = std::allocator_traits<allocator_type>::select_on_container_copy_construction(
711 pointer tmp = safe_init_allocate(al, rhs.m_size);
712 if (xtrivially_default_constructible<value_type>::value)
714 std::uninitialized_copy(rhs.m_data.get(), rhs.m_data.get() + rhs.m_size, tmp);
718 std::copy(rhs.m_data.get(), rhs.m_data.get() + rhs.m_size, tmp);
720 swap(m_data.get(), tmp);
721 swap(m_allocator, al);
722 safe_destroy_deallocate(al, tmp, m_size);
728 template <
class CP,
class A>
729 inline xbuffer_owner_storage<CP, A>::xbuffer_owner_storage(self_type&& rhs)
730 : m_data(std::move(rhs.m_data))
731 , m_size(std::move(rhs.m_size))
732 , m_moved_from(std::move(rhs.m_moved_from))
733 , m_allocator(std::move(rhs.m_allocator))
735 rhs.m_moved_from =
true;
739 template <
class CP,
class A>
740 inline auto xbuffer_owner_storage<CP, A>::operator=(self_type&& rhs) -> self_type&
746 template <
class CP,
class A>
747 inline auto xbuffer_owner_storage<CP, A>::size() const noexcept -> size_type
752 template <
class CP,
class A>
753 void xbuffer_owner_storage<CP, A>::resize(size_type size)
758 pointer tmp = safe_init_allocate(m_allocator, size);
759 swap(m_data.get(), tmp);
761 safe_destroy_deallocate(m_allocator, tmp, size);
765 template <
class CP,
class A>
766 inline auto xbuffer_owner_storage<CP, A>::data() noexcept -> pointer
771 template <
class CP,
class A>
772 inline auto xbuffer_owner_storage<CP, A>::data() const noexcept -> const_pointer
777 template <
class CP,
class A>
778 inline auto xbuffer_owner_storage<CP, A>::get_allocator() const noexcept -> allocator_type
780 return allocator_type(m_allocator);
783 template <
class CP,
class A>
784 inline void xbuffer_owner_storage<CP, A>::swap(self_type& rhs)
noexcept
787 swap(m_data, rhs.m_data);
788 swap(m_size, rhs.m_size);
789 swap(m_allocator, rhs.m_allocator);
792 template <
class CP,
class A>
795 xbuffer_owner_storage<CP, A>::reset_data(P&& data, size_type size,
const allocator_type& alloc)
noexcept
797 xbuffer_owner_storage<CP, A> tmp(std::forward<P>(data), size, alloc);
808 template <
class CP,
class D>
809 template <
class P,
class DT>
810 xbuffer_smart_pointer<CP, D>::xbuffer_smart_pointer(P&& data_ptr, size_type size, DT&& destruct)
813 , m_destruct(std::forward<DT>(destruct))
817 template <
class CP,
class D>
818 auto xbuffer_smart_pointer<CP, D>::size() const noexcept -> size_type
823 template <
class CP,
class D>
824 void xbuffer_smart_pointer<CP, D>::resize(size_type size)
828 XTENSOR_THROW(std::runtime_error,
"xbuffer_storage not resizeable");
832 template <
class CP,
class D>
833 auto xbuffer_smart_pointer<CP, D>::data() noexcept -> pointer
838 template <
class CP,
class D>
839 auto xbuffer_smart_pointer<CP, D>::data() const noexcept -> const_pointer
844 template <
class CP,
class D>
845 void xbuffer_smart_pointer<CP, D>::swap(self_type& rhs)
noexcept
848 swap(p_data, rhs.p_data);
849 swap(m_size, rhs.m_size);
850 swap(m_destruct, rhs.m_destruct);
853 template <
class CP,
class D>
854 template <
class P,
class DT>
855 void xbuffer_smart_pointer<CP, D>::reset_data(P&& data, size_type size, DT&& destruct)
noexcept
857 p_data = std::forward<P>(data);
859 m_destruct = destruct;
868 inline bool xbuffer_adaptor_base<D>::empty() const noexcept
870 return derived_cast().size() == size_type(0);
874 inline auto xbuffer_adaptor_base<D>::operator[](size_type i) -> reference
876 return derived_cast().data()[
static_cast<index_type
>(i)];
880 inline auto xbuffer_adaptor_base<D>::operator[](size_type i)
const -> const_reference
882 return derived_cast().data()[
static_cast<index_type
>(i)];
886 inline auto xbuffer_adaptor_base<D>::front() -> reference
888 return this->operator[](0);
892 inline auto xbuffer_adaptor_base<D>::front() const -> const_reference
894 return this->operator[](0);
898 inline auto xbuffer_adaptor_base<D>::back() -> reference
900 return this->operator[](derived_cast().size() - 1);
904 inline auto xbuffer_adaptor_base<D>::back() const -> const_reference
906 return this->operator[](derived_cast().size() - 1);
910 inline auto xbuffer_adaptor_base<D>::begin() noexcept -> iterator
912 return derived_cast().data();
916 inline auto xbuffer_adaptor_base<D>::end() noexcept -> iterator
918 return derived_cast().data() +
static_cast<index_type
>(derived_cast().size());
922 inline auto xbuffer_adaptor_base<D>::begin() const noexcept -> const_iterator
924 return derived_cast().data();
928 inline auto xbuffer_adaptor_base<D>::end() const noexcept -> const_iterator
930 return derived_cast().data() +
static_cast<index_type
>(derived_cast().size());
934 inline auto xbuffer_adaptor_base<D>::cbegin() const noexcept -> const_iterator
940 inline auto xbuffer_adaptor_base<D>::cend() const noexcept -> const_iterator
946 inline auto xbuffer_adaptor_base<D>::rbegin() noexcept -> reverse_iterator
948 return reverse_iterator(end());
952 inline auto xbuffer_adaptor_base<D>::rend() noexcept -> reverse_iterator
954 return reverse_iterator(begin());
958 inline auto xbuffer_adaptor_base<D>::rbegin() const noexcept -> const_reverse_iterator
960 return const_reverse_iterator(end());
964 inline auto xbuffer_adaptor_base<D>::rend() const noexcept -> const_reverse_iterator
966 return const_reverse_iterator(begin());
970 inline auto xbuffer_adaptor_base<D>::crbegin() const noexcept -> const_reverse_iterator
976 inline auto xbuffer_adaptor_base<D>::crend() const noexcept -> const_reverse_iterator
982 inline auto xbuffer_adaptor_base<D>::derived_cast() noexcept -> derived_type&
984 return *
static_cast<derived_type*
>(
this);
988 inline auto xbuffer_adaptor_base<D>::derived_cast() const noexcept -> const derived_type&
990 return *
static_cast<const derived_type*
>(
this);
994 inline bool operator==(
const xbuffer_adaptor_base<D>& lhs,
const xbuffer_adaptor_base<D>& rhs)
996 return lhs.derived_cast().size() == rhs.derived_cast().size()
997 && std::equal(lhs.begin(), lhs.end(), rhs.begin());
1001 inline bool operator!=(
const xbuffer_adaptor_base<D>& lhs,
const xbuffer_adaptor_base<D>& rhs)
1003 return !(lhs == rhs);
1007 inline bool operator<(
const xbuffer_adaptor_base<D>& lhs,
const xbuffer_adaptor_base<D>& rhs)
1009 return std::lexicographical_compare(
1014 std::less<typename D::value_type>()
1019 inline bool operator<=(
const xbuffer_adaptor_base<D>& lhs,
const xbuffer_adaptor_base<D>& rhs)
1021 return std::lexicographical_compare(
1026 std::less_equal<typename D::value_type>()
1031 inline bool operator>(
const xbuffer_adaptor_base<D>& lhs,
const xbuffer_adaptor_base<D>& rhs)
1033 return std::lexicographical_compare(
1038 std::greater<typename D::value_type>()
1043 inline bool operator>=(
const xbuffer_adaptor_base<D>& lhs,
const xbuffer_adaptor_base<D>& rhs)
1045 return std::lexicographical_compare(
1050 std::greater_equal<typename D::value_type>()
1058 template <
class CP,
class O,
class A>
1059 inline auto xbuffer_adaptor<CP, O, A>::operator=(temporary_type&& tmp) -> self_type&
1061 base_type::resize(tmp.size());
1062 std::copy(tmp.cbegin(), tmp.cend(), this->begin());
1066 template <
class CP,
class O,
class A>
1067 inline void swap(xbuffer_adaptor<CP, O, A>& lhs, xbuffer_adaptor<CP, O, A>& rhs)
noexcept
1076 template <
class I,
class CI>
1077 inline xiterator_adaptor<I, CI>::xiterator_adaptor(I it, CI cit, size_type size)
1084 template <
class I,
class CI>
1085 inline auto xiterator_adaptor<I, CI>::operator=(
const temporary_type& rhs) -> self_type&
1088 std::copy(rhs.cbegin(), rhs.cend(), m_it);
1092 template <
class I,
class CI>
1093 inline auto xiterator_adaptor<I, CI>::operator=(temporary_type&& rhs) -> self_type&
1095 return (*
this = rhs);
1098 template <
class I,
class CI>
1099 inline auto xiterator_adaptor<I, CI>::size() const noexcept -> size_type
1104 template <
class I,
class CI>
1105 inline void xiterator_adaptor<I, CI>::resize(size_type size)
1109 XTENSOR_THROW(std::runtime_error,
"xiterator_adaptor not resizeable");
1113 template <
class I,
class CI>
1114 inline auto xiterator_adaptor<I, CI>::data() noexcept -> iterator
1119 template <
class I,
class CI>
1120 inline auto xiterator_adaptor<I, CI>::data() const noexcept -> const_iterator
1125 template <
class I,
class CI>
1126 inline void xiterator_adaptor<I, CI>::swap(self_type& rhs)
noexcept
1129 swap(m_it, rhs.m_it);
1130 swap(m_cit, rhs.m_cit);
1131 swap(m_size, rhs.m_size);
1134 template <
class I,
class CI>
1135 inline void swap(xiterator_adaptor<I, CI>& lhs, xiterator_adaptor<I, CI>& rhs)
noexcept
1144 template <
class C,
class IG>
1145 inline xiterator_owner_adaptor<C, IG>::xiterator_owner_adaptor(C&& c)
1146 : m_container(std::move(c))
1151 template <
class C,
class IG>
1152 inline xiterator_owner_adaptor<C, IG>::xiterator_owner_adaptor(
const self_type& rhs)
1153 : m_container(rhs.m_container)
1158 template <
class C,
class IG>
1159 inline xiterator_owner_adaptor<C, IG>& xiterator_owner_adaptor<C, IG>::operator=(
const self_type& rhs)
1161 m_container = rhs.m_container;
1165 template <
class C,
class IG>
1166 inline xiterator_owner_adaptor<C, IG>::xiterator_owner_adaptor(self_type&& rhs)
1167 : m_container(std::move(rhs.m_container))
1172 template <
class C,
class IG>
1173 inline xiterator_owner_adaptor<C, IG>& xiterator_owner_adaptor<C, IG>::operator=(self_type&& rhs)
1175 m_container = std::move(rhs.m_container);
1179 template <
class C,
class IG>
1180 inline xiterator_owner_adaptor<C, IG>& xiterator_owner_adaptor<C, IG>::operator=(
const temporary_type& rhs)
1183 std::copy(rhs.cbegin(), rhs.cend(), m_it);
1187 template <
class C,
class IG>
1188 inline xiterator_owner_adaptor<C, IG>& xiterator_owner_adaptor<C, IG>::operator=(temporary_type&& rhs)
1190 return (*
this = rhs);
1193 template <
class C,
class IG>
1194 inline auto xiterator_owner_adaptor<C, IG>::size() const noexcept -> size_type
1199 template <
class C,
class IG>
1200 inline void xiterator_owner_adaptor<C, IG>::resize(size_type size)
1204 XTENSOR_THROW(std::runtime_error,
"xiterator_owner_adaptor not resizeable");
1208 template <
class C,
class IG>
1209 inline auto xiterator_owner_adaptor<C, IG>::data() noexcept -> iterator
1214 template <
class C,
class IG>
1215 inline auto xiterator_owner_adaptor<C, IG>::data() const noexcept -> const_iterator
1220 template <
class C,
class IG>
1221 inline void xiterator_owner_adaptor<C, IG>::swap(self_type& rhs)
noexcept
1224 swap(m_container, rhs.m_container);
1226 rhs.init_iterators();
1229 template <
class C,
class IG>
1230 inline void xiterator_owner_adaptor<C, IG>::init_iterators()
1232 m_it = IG::begin(m_container);
1233 m_cit = IG::cbegin(m_container);
1234 m_size = IG::size(m_container);
1237 template <
class C,
class IG>
1238 inline void swap(xiterator_owner_adaptor<C, IG>& lhs, xiterator_owner_adaptor<C, IG>& rhs)
noexcept
1249 template <class C, class IG, bool = std::is_lvalue_reference<C>::value>
1250 struct xiterator_adaptor_builder
1252 using iterator =
decltype(IG::begin(std::declval<C>()));
1253 using const_iterator =
decltype(IG::cbegin(std::declval<C>()));
1254 using type = xiterator_adaptor<iterator, const_iterator>;
1256 inline static type build(C& c)
1258 return type(IG::begin(c), IG::cbegin(c), IG::size(c));
1262 template <
class C,
class IG>
1263 struct xiterator_adaptor_builder<C, IG, false>
1265 using type = xiterator_owner_adaptor<C, IG>;
1267 inline static type build(C&& c)
1269 return type(std::move(c));
1274 template <
class C,
class IG>
1275 inline auto make_xiterator_adaptor(C&& container, IG)
1277 using builder_type = detail::xiterator_adaptor_builder<C, IG>;
1278 return builder_type::build(std::forward<C>(container));
standard mathematical functions for xexpressions
bool operator==(const xaxis_iterator< CT > &lhs, const xaxis_iterator< CT > &rhs)
Checks equality of the iterators.
bool operator!=(const xaxis_iterator< CT > &lhs, const xaxis_iterator< CT > &rhs)
Checks inequality of the iterators.
xarray< T, L > empty(const S &shape)
Create a xcontainer (xarray, xtensor or xtensor_fixed) with uninitialized values of with value_type T...