27 #ifndef MLN_FUN_I2V_ARRAY_HH
28 # define MLN_FUN_I2V_ARRAY_HH
36 # include <mln/core/concept/function.hh>
37 # include <mln/util/array.hh>
38 # include <mln/metal/equal.hh>
39 # include <mln/tag/init.hh>
41 # include <mln/fun/internal/selector.hh>
49 template <
typename T>
class array;
54 template <
typename T>
class array;
86 array(
unsigned n,
const T& val);
93 array(
const std::vector<T>& from);
105 void resize(
unsigned n,
const T& val);
111 unsigned size()
const;
119 void init_(
unsigned n);
131 template <
typename T>
137 template <
typename T1,
typename T2>
152 template <
typename T>
158 template <
typename T,
typename U>
166 # ifndef MLN_INCLUDE_ONLY
173 template <
typename T1,
typename T2>
174 void init_(tag::function_t,
175 fun::i2v::array<T1>& f,
176 const fun::i2v::array<T2>& model)
178 f.init_(model.size());
190 template <
typename T>
196 template <
typename T>
203 template <
typename T>
205 array<T>::array(
unsigned n,
const T& val)
210 template <
typename T>
212 array<T>::array(
const util::array<T>& from)
213 : v_(from.std_vector())
218 template <
typename T>
220 array<T>::array(
const std::vector<T>& from)
226 template <
typename T>
229 array<T>::reserve(
unsigned n)
234 template <
typename T>
242 template <
typename T>
245 array<T>::append(
const T& val)
250 template <
typename T>
258 template <
typename T>
261 array<T>::size()
const
266 template <
typename T>
268 typename array<T>::result
269 array<T>::operator()(
unsigned i)
const
271 mln_precondition(i < v_.size());
275 template <
typename T>
277 typename array<T>::mutable_result
278 array<T>::operator()(
unsigned i)
280 mln_precondition(i < v_.size());
284 template <
typename T>
287 array<T>::init_(
unsigned n)
292 template <
typename T>
294 const std::vector<T>&
295 array<T>::std_vector()
const
303 template <
typename T>
308 const unsigned n = a.size();
309 for (
unsigned i = 0; i < n; ++i)
322 template <
typename T1,
typename T2>
324 from_to_(
const array<T1>& from, util::array<T2>& to)
326 to.resize(from.size());
328 for (
unsigned i = 0; i < from.size(); ++i)
329 to[i] = convert::to<T2>(from(i));
337 template <
typename T>
339 fun::i2v::array<T> array(
unsigned n,
const T& t)
341 fun::i2v::array<T> tmp(n, t);
350 template <
typename T>
358 template <
typename T,
typename U>
363 to.
resize(from.nelements());
364 for (
unsigned i = 0; i < from.size(); ++i)
365 to(i) = mln::convert::to<U>(from[i]);
370 # endif // ! MLN_INCLUDE_ONLY
372 #endif // ! MLN_FUN_I2V_ARRAY_HH