/usr/include/xtensor/xaxis_iterator.hpp is in xtensor-dev 0.10.11-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | /***************************************************************************
* Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/
#ifndef XAXIS_ITERATOR_HPP
#define XAXIS_ITERATOR_HPP
#include "xview.hpp"
namespace xt
{
/******************
* xaxis_iterator *
******************/
template <class CT>
class xaxis_iterator
{
public:
using self_type = xaxis_iterator<CT>;
using xexpression_type = std::decay_t<CT>;
using size_type = typename xexpression_type::size_type;
using difference_type = typename xexpression_type::difference_type;
using value_type = xview<CT, size_type>;
using reference = std::remove_reference_t<apply_cv_t<CT, value_type>>;
using pointer = std::nullptr_t;
using iterator_category = std::forward_iterator_tag;
xaxis_iterator();
template <class CTA>
xaxis_iterator(CTA&& e, size_type index);
self_type& operator++();
self_type operator++(int);
reference operator*() const;
pointer operator->() const;
bool equal(const self_type& rhs) const;
private:
using storing_type = ptr_closure_t<CT>;
mutable storing_type p_expression;
size_type m_index;
template <class T>
std::enable_if_t<std::is_pointer<T>::value, std::add_lvalue_reference_t<std::remove_pointer_t<T>>>
deref(T val) const;
template <class T>
std::enable_if_t<!std::is_pointer<T>::value, T>
deref(T& val) const;
template <class T, class CTA>
std::enable_if_t<std::is_pointer<T>::value, T>
get_storage_init(CTA&& e) const;
template <class T, class CTA>
std::enable_if_t<!std::is_pointer<T>::value, T>
get_storage_init(CTA&& e) const;
};
template <class CT>
bool operator==(const xaxis_iterator<CT>& lhs, const xaxis_iterator<CT>& rhs);
template <class CT>
bool operator!=(const xaxis_iterator<CT>& lhs, const xaxis_iterator<CT>& rhs);
template <class E>
auto axis_begin(E&& e);
template <class E>
auto axis_end(E&& e);
/*********************************
* xaxis_iterator implementation *
*********************************/
template <class CT>
template <class T>
inline std::enable_if_t<std::is_pointer<T>::value, std::add_lvalue_reference_t<std::remove_pointer_t<T>>>
xaxis_iterator<CT>::deref(T val) const
{
return *val;
}
template <class CT>
template <class T>
inline std::enable_if_t<!std::is_pointer<T>::value, T>
xaxis_iterator<CT>::deref(T& val) const
{
return val;
}
template <class CT>
template <class T, class CTA>
inline std::enable_if_t<std::is_pointer<T>::value, T>
xaxis_iterator<CT>::get_storage_init(CTA&& e) const
{
return &e;
}
template <class CT>
template <class T, class CTA>
inline std::enable_if_t<!std::is_pointer<T>::value, T>
xaxis_iterator<CT>::get_storage_init(CTA&& e) const
{
return e;
}
template <class CT>
inline xaxis_iterator<CT>::xaxis_iterator()
: p_expression(nullptr), m_index(0)
{
}
template <class CT>
template <class CTA>
inline xaxis_iterator<CT>::xaxis_iterator(CTA&& e, size_type index)
: p_expression(get_storage_init<storing_type>(std::forward<CTA>(e))), m_index(index)
{
}
template <class CT>
inline auto xaxis_iterator<CT>::operator++() -> self_type&
{
++m_index;
return *this;
}
template <class CT>
inline auto xaxis_iterator<CT>::operator++(int) -> self_type
{
self_type tmp(*this);
++(*this);
return tmp;
}
template <class CT>
inline auto xaxis_iterator<CT>::operator*() const -> reference
{
return view(deref(p_expression), size_type(m_index));
}
template <class CT>
inline auto xaxis_iterator<CT>::operator->() const -> pointer
{
return nullptr;
}
template <class CT>
inline bool xaxis_iterator<CT>::equal(const self_type& rhs) const
{
return p_expression == rhs.p_expression && m_index == rhs.m_index;
}
template <class CT>
inline bool operator==(const xaxis_iterator<CT>& lhs, const xaxis_iterator<CT>& rhs)
{
return lhs.equal(rhs);
}
template <class CT>
inline bool operator!=(const xaxis_iterator<CT>& lhs, const xaxis_iterator<CT>& rhs)
{
return !(lhs == rhs);
}
template <class E>
inline auto axis_begin(E&& e)
{
using return_type = xaxis_iterator<closure_t<E>>;
using size_type = typename std::decay_t<E>::size_type;
return return_type(std::forward<E>(e), size_type(0));
}
template <class E>
inline auto axis_end(E&& e)
{
using return_type = xaxis_iterator<closure_t<E>>;
using size_type = typename std::decay_t<E>::size_type;
return return_type(std::forward<E>(e), size_type(e.shape()[0]));
}
}
#endif
|