27 #ifndef MLN_CONVERT_FROM_TO_HH
28 # define MLN_CONVERT_FROM_TO_HH
40 # include <mln/convert/impl/all.hh>
41 # include <mln/convert/from_to.hxx>
43 # include <mln/metal/abort.hh>
44 # include <mln/metal/converts_to.hh>
45 # include <mln/metal/is.hh>
46 # include <mln/metal/is_a.hh>
48 # include <mln/value/cast.hh>
54 template <
typename E>
struct Object;
55 template <
typename E>
struct Value;
56 template <
typename E>
struct Site_Set;
57 template <
typename E>
struct Image;
62 template <
typename F,
typename T>
64 from_to(
const F& from, T&
to);
67 # ifndef MLN_INCLUDE_ONLY
75 template <
typename I,
typename S>
78 from_to_dispatch(
const Image<I>& from, Site_Set<S>&
to)
80 mlc_is(mln_trait_site_set_contents(S),
81 mln::trait::site_set::contents::dynamic)::check();
82 mln_precondition(exact(from).is_valid());
83 mln::convert::impl::from_image_to_site_set(from, to);
88 template <
typename S,
typename I>
91 from_to_dispatch(
const Site_Set<S>& from, Image<I>& to)
93 mlc_converts_to(mln_site(S), mln_site(I))::check();
94 mln_precondition(exact(from).is_valid());
95 mln::convert::impl::from_site_set_to_image(from, to);
100 template <
typename F,
typename T>
103 from_to_dispatch(
const Value<F>& from, Value<T>& to)
105 mln::convert::impl::from_value_to_value(from, to);
114 template <
typename F,
typename T>
117 from_to_dispatch(metal::true_,
118 const Object<F>& from, Object<T>& to)
120 exact(to) = exact(from);
125 template <
typename F,
typename T>
128 from_to_dispatch(metal::false_,
129 const Object<F>& from, Object<T>& to)
131 over_load::from_to_(exact(from), exact(to));
139 template <
typename F,
typename T>
142 from_to_dispatch(
const Object<F>& from, Object<T>& to)
144 typedef mlc_converts_to(F, T) F_converts_to_T;
145 internal::from_to_dispatch(F_converts_to_T(),
146 exact(from), exact(to));
155 template <typename F, typename T>
158 from_to_dispatch(metal::false_, const F& from,
159 metal::false_, T& to)
161 over_load::from_to_(from, to);
166 template <
typename F,
typename T>
169 from_to_dispatch(metal::true_,
const F& from,
170 metal::false_, T& to)
172 over_load::from_to_(exact(from), to);
177 template <
typename F,
typename T>
180 from_to_dispatch(metal::false_,
const F& from,
183 over_load::from_to_(from, exact(to));
187 template <
typename F,
typename T>
190 from_to_dispatch(metal::true_,
const F& from,
193 internal::from_to_dispatch(exact(from), exact(to));
206 template <
typename F,
typename T>
208 from_to_(
const Object<F>&, Object<T>&)
214 mlc_abort(F)::check();
219 template <
typename T>
222 from_to_(
const Object<T>& from, Object<T>& to)
224 exact(to) = exact(from);
229 template <
typename T>
232 from_to_(
const T& from, T& to)
239 template <
typename F,
typename T>
242 from_to_(
const F& from, T& to)
244 to = mln::value::cast<T>(from);
254 template <
typename F,
typename T>
257 from_to(
const F& from, T& to)
259 typedef mlc_is_a(F, Object) F_is_object;
260 typedef mlc_is_a(T, Object) T_is_object;
261 internal::from_to_dispatch(F_is_object(), from,
266 # endif // ! MLN_INCLUDE_ONLY
273 #endif // ! MLN_CONVERT_FROM_TO_HH