00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __MAP_ONE_HH
00018 # define __MAP_ONE_HH
00019
00020 #include "../strategies.hh"
00021
00022 namespace aurelia {
00023
00026 template <typename S>
00027 struct map_one_strategy {
00028 private:
00029 S s;
00030
00031 public:
00032 map_one_strategy(const S& s): s(s) {}
00033 map_one_strategy(const map_one_strategy& other): s(other.s) {}
00034
00035 template <typename Pool>
00036 untyped_term<Pool> operator()(const untyped_term<Pool>& t) const {
00037 typedef typename strategy_concept<
00038 typename strategy_model<S, untyped_term<Pool> >::model>
00039 ::check require;
00040
00041 typedef untyped_term<Pool> T;
00042 typedef untyped_constructor<Pool> C;
00043
00044 if (t.constructor() == C::AS_LIST) {
00045 try {
00046 T a = s(t[0]);
00047 return T(C::AS_LIST, (a, t[1]));
00048 }
00049 catch (failure) {
00050 T b = (*this)(t[1]);
00051 return T(C::AS_LIST, (t[0], b));
00052 }
00053 }
00054 throw failure();
00055 }
00056 };
00057
00061 template <typename S>
00062 map_one_strategy<S> map_one(const S& s) {
00063 return map_one_strategy<S>(s);
00064 }
00065
00066 }
00067
00068 #endif