Visual Computing Library
Loading...
Searching...
No Matches
array.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2025 *
6 * Visual Computing Lab *
7 * ISTI - Italian National Research Council *
8 * *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the Mozilla Public License Version 2.0 as published *
13 * by the Mozilla Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * Mozilla Public License Version 2.0 *
20 * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21 ****************************************************************************/
22
23#ifndef VCL_CONCEPTS_SPACE_ARRAY_H
24#define VCL_CONCEPTS_SPACE_ARRAY_H
25
26#include <vclib/concepts/const_correctness.h>
27#include <vclib/concepts/iterators.h>
28#include <vclib/concepts/ranges/range.h>
29
30#include <vclib/types.h>
31
32#include <vector>
33
34namespace vcl {
35
44template<typename T>
45concept ArrayConcept = requires (
46 T&& obj,
47 typename RemoveRef<T>::ValueType v,
48 typename RemoveRef<T>::Pointer ptr,
49 typename RemoveRef<T>::ConstPointer cPtr,
50 std::vector<typename RemoveRef<T>::ValueType> vecV,
51 const std::vector<typename RemoveRef<T>::ValueType>& cVecVR) {
52 // inner types
53 typename RemoveRef<T>::ValueType;
54 typename RemoveRef<T>::Scalar;
55 typename RemoveRef<T>::ConstReference;
56 typename RemoveRef<T>::Reference;
57 typename RemoveRef<T>::ConstPointer;
58 typename RemoveRef<T>::Pointer;
59 typename RemoveRef<T>::ConstIterator;
60 typename RemoveRef<T>::Iterator;
61
62 obj.DIM;
63
64 RemoveRef<T>();
65
66 { obj.size(std::size_t()) } -> std::integral;
67 { obj.empty() } -> std::convertible_to<bool>;
68
69 { obj.data() } -> std::convertible_to<decltype(cPtr)>;
70
71 { obj.stdVector() } -> std::convertible_to<decltype(cVecVR)>;
72
73 obj.subArray(uint());
74
75 { obj.begin() } -> InputIterator<decltype(v)>;
76 { obj.end() } -> InputIterator<decltype(v)>;
77
78 requires InputRange<T, decltype(v)>;
79
80 // non const requirements
81 requires IsConst<T> || requires {
82 { obj.data() } -> std::same_as<decltype(ptr)>;
83
84 { obj.stdVector() } -> std::same_as<decltype(vecV)>;
85
86 { obj.fill(v) } -> std::same_as<void>;
87 { obj.clear() } -> std::same_as<void>;
88
89 { obj.begin() } -> OutputIterator<decltype(v)>;
90 { obj.end() } -> OutputIterator<decltype(v)>;
91
92 requires OutputRange<T, decltype(v)>;
93 };
94};
95
104template<typename T>
106 ArrayConcept<T> && requires (
107 T&& obj,
108 std::size_t n,
109 typename RemoveRef<T>::Reference ref,
110 typename RemoveRef<T>::ConstReference cRef,
111 typename RemoveRef<T>::Pointer ptr,
112 typename RemoveRef<T>::ConstPointer cPtr) {
113 requires RemoveRef<T>::DIM == 2;
114
115 RemoveRef<T>(n, n);
116
117 { obj.rows() } -> std::integral;
118 { obj.cols() } -> std::integral;
119 { obj.sizeX() } -> std::integral;
120 { obj.sizeY() } -> std::integral;
121
122 { obj.operator()(n, n) } -> std::convertible_to<decltype(cRef)>;
123
124 { obj.data(n) } -> std::convertible_to<decltype(cPtr)>;
125
126 // non const requirements
127 requires IsConst<T> || requires {
128 { obj.operator()(n, n) } -> std::same_as<decltype(ref)>;
129
130 { obj.data(n) } -> std::same_as<decltype(ptr)>;
131
132 { obj.resize(n, n) } -> std::same_as<void>;
133 { obj.conservativeResize(n, n) } -> std::same_as<void>;
134 };
135 };
136
145template<typename T>
147 ArrayConcept<T> && requires (
148 T&& obj,
149 std::size_t n,
150 typename RemoveRef<T>::Reference ref,
151 typename RemoveRef<T>::ConstReference cRef,
152 typename RemoveRef<T>::Pointer ptr,
153 typename RemoveRef<T>::ConstPointer cPtr) {
154 requires RemoveRef<T>::DIM == 3;
155
156 RemoveRef<T>(n, n, n);
157
158 { obj.sizeX() } -> std::integral;
159 { obj.sizeY() } -> std::integral;
160 { obj.sizeZ() } -> std::integral;
161
162 { obj.operator()(n, n, n) } -> std::convertible_to<decltype(cRef)>;
163
164 { obj.data(n) } -> std::convertible_to<decltype(cPtr)>;
165
166 { obj.data(n, n) } -> std::convertible_to<decltype(cPtr)>;
167
168 // non const requirements
169 requires IsConst<T> || requires {
170 { obj.operator()(n, n, n) } -> std::same_as<decltype(ref)>;
171 { obj.data(n) } -> std::same_as<decltype(ptr)>;
172 { obj.data(n, n) } -> std::same_as<decltype(ptr)>;
173 { obj.resize(n, n, n) } -> std::same_as<void>;
174 { obj.conservativeResize(n, n, n) } -> std::same_as<void>;
175 };
176 };
177
186template<typename T>
188 ArrayConcept<T> && requires (
189 T&& obj,
190 std::size_t n,
191 typename RemoveRef<T>::Reference ref,
192 typename RemoveRef<T>::ConstReference cRef,
193 typename RemoveRef<T>::Pointer ptr,
194 typename RemoveRef<T>::ConstPointer cPtr) {
195 requires RemoveRef<T>::DIM == 4;
196
197 RemoveRef<T>(n, n, n, n);
198
199 { obj.sizeX() } -> std::integral;
200 { obj.sizeY() } -> std::integral;
201 { obj.sizeZ() } -> std::integral;
202 { obj.sizeW() } -> std::integral;
203
204 { obj.operator()(n, n, n, n) } -> std::convertible_to<decltype(cRef)>;
205
206 { obj.data(n) } -> std::convertible_to<decltype(cPtr)>;
207 { obj.data(n, n) } -> std::convertible_to<decltype(cPtr)>;
208 { obj.data(n, n, n) } -> std::convertible_to<decltype(cPtr)>;
209
210 // non const requirements
211 requires IsConst<T> || requires {
212 { obj.operator()(n, n, n, n) } -> std::same_as<decltype(ref)>;
213
214 { obj.data(n) } -> std::same_as<decltype(ptr)>;
215 { obj.data(n, n) } -> std::same_as<decltype(ptr)>;
216 { obj.data(n, n, n) } -> std::same_as<decltype(ptr)>;
217
218 { obj.resize(n, n, n, n) } -> std::same_as<void>;
219 { obj.conservativeResize(n, n, n, n) } -> std::same_as<void>;
220 };
221 };
222
223} // namespace vcl
224
225#endif // VCL_CONCEPTS_SPACE_ARRAY_H
A concept representing a 2-dimensional array.
Definition array.h:105
A concept representing a 3-dimensional array.
Definition array.h:146
A concept representing a 4-dimensional array.
Definition array.h:187
A concept representing a N-dimensional array.
Definition array.h:45
The InputIterator concept is satisfied if T is an input iterator that implements the operator* return...
Definition iterators.h:46
Utility concept that is evaluated true the Range R is an Input Range and has a value_type that is con...
Definition range.h:89
The IsConst concept is satisfied if T satisfies one of the following conditions:
Definition const_correctness.h:43
The OutputIterator concept is satisfied if T is an output iterator that implements the operator* retu...
Definition iterators.h:60
Utility concept that is evaluated true the Range R is an Output Range and has a value_type that is T.
Definition range.h:113