26 #ifndef MLN_FUN_I2V_ARRAY_HH
27 # define MLN_FUN_I2V_ARRAY_HH
35 # include <mln/core/concept/function.hh>
36 # include <mln/util/array.hh>
37 # include <mln/metal/equal.hh>
38 # include <mln/tag/init.hh>
40 # include <mln/fun/internal/selector.hh>
48 template <
typename T>
class array;
63 from_to_(
const util::array<T>& from, fun::i2v::array<T>&
to);
65 template <
typename T,
typename U>
68 from_to_(
const util::array<T>& from, fun::i2v::array<U>&
to);
73 from_to_(
const std::vector<T>& from, fun::i2v::array<T>&
to);
75 template <
typename T,
typename U>
78 from_to_(
const std::vector<T>& from, fun::i2v::array<U>&
to);
94 :
public fun::internal::selector_from_result_<T, array<T> >::ret
101 typedef typename std::vector<T>::reference mutable_result;
112 array(
unsigned n,
const T& val);
116 array(
const util::array<T>& from);
119 array(
const std::vector<T>& from);
124 void reserve(
unsigned n);
130 void resize(
unsigned n,
const T& val);
133 void append(
const T& val);
136 unsigned size()
const;
139 result operator()(
unsigned i)
const;
141 mutable_result operator()(
unsigned i);
144 void init_(
unsigned n);
147 const std::vector<T>& std_vector()
const;
156 template <
typename T>
167 # ifndef MLN_INCLUDE_ONLY
171 template <
typename T1,
typename T2>
172 void init_(tag::function_t,
173 fun::i2v::array<T1>& f,
174 const fun::i2v::array<T2>& model)
176 f.init_(model.size());
188 template <
typename T>
191 from_to_(
const util::array<T>& from, fun::i2v::array<T>&
to)
193 to = fun::i2v::array<T>(from);
196 template <
typename T,
typename U>
199 from_to_(
const util::array<T>& from, fun::i2v::array<U>&
to)
201 to.resize(from.nelements());
202 for (
unsigned i = 0; i < from.nelements(); ++i)
203 to(i) = convert::to<U>(from[i]);
206 template <
typename T>
209 from_to_(
const std::vector<T>& from, fun::i2v::array<T>& to)
211 to = fun::i2v::array<T>(from);
214 template <
typename T,
typename U>
217 from_to_(
const std::vector<T>& from, fun::i2v::array<U>& to)
219 to.resize(from.nelements());
220 for (
unsigned i = 0; i < from.size(); ++i)
221 to(i) = convert::to<U>(from[i]);
239 template <
typename T>
245 template <
typename T>
247 array<T>::array(
unsigned n)
252 template <
typename T>
254 array<T>::array(
unsigned n,
const T& val)
259 template <
typename T>
261 array<T>::array(
const util::array<T>& from)
262 : v_(from.std_vector())
267 template <
typename T>
269 array<T>::array(
const std::vector<T>& from)
275 template <
typename T>
278 array<T>::reserve(
unsigned n)
283 template <
typename T>
286 array<T>::resize(
unsigned n)
291 template <
typename T>
294 array<T>::append(
const T& val)
299 template <
typename T>
302 array<T>::resize(
unsigned n,
const T& val)
307 template <
typename T>
310 array<T>::size()
const
315 template <
typename T>
317 typename array<T>::result
318 array<T>::operator()(
unsigned i)
const
320 mln_precondition(i < v_.size());
324 template <
typename T>
326 typename array<T>::mutable_result
327 array<T>::operator()(
unsigned i)
329 mln_precondition(i < v_.size());
333 template <
typename T>
336 array<T>::init_(
unsigned n)
341 template <
typename T>
343 const std::vector<T>&
344 array<T>::std_vector()
const
352 template <
typename T>
353 std::ostream& operator<<(std::ostream& ostr,
357 const unsigned n = a.size();
358 for (
unsigned i = 0; i < n; ++i)
374 template <
typename T>
376 fun::i2v::array<T> array(
unsigned n,
const T& t)
378 fun::i2v::array<T> tmp(n, t);
382 # endif // ! MLN_INCLUDE_ONLY
387 #endif // ! MLN_FUN_I2V_ARRAY_HH