00001 #ifndef NMWR_GB_FUNCTION_ADAPTER_H
00002 #define NMWR_GB_FUNCTION_ADAPTER_H
00003
00004
00005
00006
00007 #include "Utility/pre-post-conditions.h"
00008
00044 template<class F>
00045 class unary_fct_ref {
00046 private:
00047 const F* f;
00048 public:
00049 typedef typename F::argument_type argument_type;
00050 typedef typename F::result_type result_type;
00051
00052 unary_fct_ref() : f(0) {}
00053 unary_fct_ref(const F& ff) : f(&ff) {}
00054
00055 result_type operator()(const argument_type& x) const {
00056 REQUIRE((f != 0), "No function!\n",1);
00057 return (*f)(x);
00058 }
00059 };
00060
00064 template<class F>
00065 inline unary_fct_ref<F> make_unary_fct_ref(const F& f)
00066 { return unary_fct_ref<F>(f); }
00067
00068
00079 template<class M1, class M2>
00080 class unary_map_composition {
00081 private:
00082 M1 const* m1;
00083 M2 const* m2;
00084
00085 public:
00086 typedef typename M2::argument_type argument_type;
00087 typedef typename M1::result_type result_type;
00088 typedef typename M2::domain_type domain_type;
00089 typedef typename M1::range_type range_type;
00090
00092 unary_map_composition(M1 const& mm1,M2 const& mm2) : m1(&mm1), m2(&mm2) {}
00093
00095 result_type operator()(argument_type const& x) const { return (*m1)((*m2)(x));}
00096
00102 domain_type const& domain() const { return m2->domain();}
00103
00105 range_type const& range() const { return m1->range();}
00106 };
00107
00108
00112 template<class M1, class M2>
00113 inline
00114 unary_map_composition<M1,M2>
00115 compose_map( M1 const& m1, M2 const& m2)
00116 { return unary_map_composition<M1,M2>(m1,m2);}
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134 #endif
00135