29 class xconst_accessible
33 using derived_type = D;
35 using reference =
typename inner_types::reference;
36 using const_reference =
typename inner_types::const_reference;
37 using size_type =
typename inner_types::size_type;
39 size_type
size() const noexcept;
41 size_type
shape(size_type index) const;
43 template <class... Args>
44 const_reference at(Args... args) const;
47 disable_integral_t<S, const_reference> operator[](const S& index) const;
49 const_reference operator[](std::initializer_list<I> index) const;
50 const_reference operator[](size_type i) const;
52 template <class... Args>
53 const_reference periodic(Args... args) const;
55 template <class... Args>
59 const_reference
back() const;
63 xconst_accessible() = default;
64 ~xconst_accessible() = default;
66 xconst_accessible(const xconst_accessible&) = default;
67 xconst_accessible& operator=(const xconst_accessible&) = default;
69 xconst_accessible(xconst_accessible&&) = default;
70 xconst_accessible& operator=(xconst_accessible&&) = default;
74 const derived_type& derived_cast() const noexcept;
87 class xaccessible : public xconst_accessible<D>
91 using base_type = xconst_accessible<D>;
92 using derived_type =
typename base_type::derived_type;
93 using reference =
typename base_type::reference;
94 using size_type =
typename base_type::size_type;
96 template <
class... Args>
97 reference at(Args... args);
100 disable_integral_t<S, reference> operator[](
const S& index);
102 reference operator[](std::initializer_list<I> index);
103 reference operator[](size_type i);
105 template <
class... Args>
106 reference periodic(Args... args);
112 using base_type::operator[];
115 using base_type::periodic;
119 xaccessible() =
default;
120 ~xaccessible() =
default;
122 xaccessible(
const xaccessible&) =
default;
123 xaccessible& operator=(
const xaccessible&) =
default;
125 xaccessible(xaccessible&&) =
default;
126 xaccessible& operator=(xaccessible&&) =
default;
130 derived_type& derived_cast() noexcept;
141 inline auto xconst_accessible<D>::
size() const noexcept -> size_type
143 return compute_size(derived_cast().
shape());
152 return derived_cast().shape().size();
161 return derived_cast().shape()[index];
174 template <
class... Args>
175 inline auto xconst_accessible<D>::at(Args... args)
const -> const_reference
177 check_access(derived_cast().
shape(), args...);
178 return derived_cast().operator()(args...);
189 inline auto xconst_accessible<D>::operator[](
const S& index)
const
190 -> disable_integral_t<S, const_reference>
192 return derived_cast().element(index.cbegin(), index.cend());
197 inline auto xconst_accessible<D>::operator[](std::initializer_list<I> index)
const -> const_reference
199 return derived_cast().element(index.begin(), index.end());
203 inline auto xconst_accessible<D>::operator[](size_type i)
const -> const_reference
205 return derived_cast().operator()(i);
216 template <
class... Args>
217 inline auto xconst_accessible<D>::periodic(Args... args)
const -> const_reference
220 return derived_cast()(
static_cast<size_type
>(args)...);
229 return *derived_cast().begin();
238 return *std::prev(derived_cast().end());
247 template <
class... Args>
250 return check_in_bounds(derived_cast().
shape(), args...);
254 inline auto xconst_accessible<D>::derived_cast() const noexcept -> const derived_type&
256 return *
static_cast<const derived_type*
>(
this);
273 template <
class... Args>
274 inline auto xaccessible<D>::at(Args... args) -> reference
276 check_access(derived_cast().
shape(), args...);
277 return derived_cast().operator()(args...);
288 inline auto xaccessible<D>::operator[](
const S& index) -> disable_integral_t<S, reference>
290 return derived_cast().element(index.cbegin(), index.cend());
295 inline auto xaccessible<D>::operator[](std::initializer_list<I> index) -> reference
297 return derived_cast().element(index.begin(), index.end());
301 inline auto xaccessible<D>::operator[](size_type i) -> reference
303 return derived_cast().operator()(i);
314 template <
class... Args>
315 inline auto xaccessible<D>::periodic(Args... args) -> reference
318 return derived_cast()(args...);
327 return *derived_cast().begin();
336 return *std::prev(derived_cast().end());
340 inline auto xaccessible<D>::derived_cast() noexcept -> derived_type&
342 return *
static_cast<derived_type*
>(
this);