00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 #ifndef MLN_FUN_P2V_TERNARY_HH
00027 # define MLN_FUN_P2V_TERNARY_HH
00028 
00034 # include <mln/fun/internal/selector.hh>
00035 
00036 
00037 namespace mln
00038 {
00039 
00040   namespace fun
00041   {
00042 
00043     namespace p2v
00044     {
00045 
00046       template <typename P, typename T, typename F>
00047       struct ternary_
00048         : fun::internal::selector_from_result_<mln_result(T), ternary_<P,T,F> >::ret
00049       {
00050         typedef mln_result(T) result;
00051 
00052         ternary_(const Function_v2b<P>& f_pred,
00053                  const Function_v2v<T>& f_true,
00054                  const Function_v2v<F>& f_false);
00055 
00056         template <typename Pt>
00057         result operator()(const Pt& p) const;
00058 
00059       protected:
00060         const P f_pred_;
00061         const T f_true_;
00062         const F f_false_;
00063       };
00064     
00065     
00066       template <typename P, typename T, typename F>
00067       ternary_<P, T, F>
00068       ternary(const Function_v2b<P>& f_pred,
00069               const Function_v2v<T>& f_true,
00070               const Function_v2v<F>& f_false);
00071     
00072 
00073 # ifndef MLN_INCLUDE_ONLY
00074 
00075       template <typename P, typename T, typename F>
00076       inline
00077       ternary_<P,T,F>::ternary_(const Function_v2b<P>& f_pred,
00078                                 const Function_v2v<T>& f_true,
00079                                 const Function_v2v<F>& f_false)
00080         : f_pred_(exact(f_pred)),
00081           f_true_(exact(f_true)),
00082           f_false_(exact(f_false))
00083       {
00084       }
00085 
00086       template <typename P, typename T, typename F>
00087       template <typename Pt>
00088       inline
00089       mln_result(T)
00090         ternary_<P,T,F>::operator()(const Pt& p) const
00091       {
00092         return f_pred_(p) ? f_true_(p) : f_false_(p);
00093       }
00094 
00095 
00096       template <typename P, typename T, typename F>
00097       inline
00098       ternary_<P, T, F>
00099       ternary(const Function_v2b<P>& f_pred,
00100               const Function_v2v<T>& f_true,
00101               const Function_v2v<F>& f_false)
00102       {
00103         ternary_<P, T, F> tmp(exact(f_pred),
00104                               exact(f_true),
00105                               exact(f_false));
00106         return tmp;
00107       }
00108 
00109 # endif // ! MLN_INCLUDE_ONLY
00110 
00111     } 
00112 
00113   } 
00114 
00115 } 
00116 
00117 
00118 #endif // ! MLN_FUN_P2V_TERNARY_HH