summaryrefslogtreecommitdiffstats
path: root/cpp/sca/kernel/list.hpp
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2009-11-01 05:24:54 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2009-11-01 05:24:54 +0000
commit9f187b46ae761e8275362d6c1533e9fe79028c7b (patch)
treee2625f63e0c84f172c877e1fe2cbe75adf678208 /cpp/sca/kernel/list.hpp
parent24021bd09a0d5c9664565a244c24e0bdef0908b8 (diff)
Improved memory management using APR memory pools, changed frame allocation in eval library to support forward references and fixed memory leak in XML parsing code. Also simplified a bit the printing of lists to make them easier to read.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@831639 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--cpp/sca/kernel/list.hpp29
1 files changed, 28 insertions, 1 deletions
diff --git a/cpp/sca/kernel/list.hpp b/cpp/sca/kernel/list.hpp
index 62c5d91150..deb4414d98 100644
--- a/cpp/sca/kernel/list.hpp
+++ b/cpp/sca/kernel/list.hpp
@@ -144,7 +144,7 @@ template<typename T> std::ostream& operator<<(std::ostream& out, const list<T>&
ml = cdr(ml);
if (isNil(ml))
break;
- out << ", ";
+ out << " ";
}
return out << ")";
}
@@ -164,6 +164,17 @@ template<typename T> const list<T> cons(const T& car, const list<T>& cdr) {
}
/**
+ * Cons variations for use with the reduce and reduceRight functions.
+ */
+template<typename T> const list<T> lcons(const list<T>& cdr, const T& car) {
+ return cons<T>(car, cdr);
+}
+
+template<typename T> const list<T> rcons(const T& car, const list<T>& cdr) {
+ return cons<T>(car, cdr);
+}
+
+/**
* Construct a list from a single value.
*/
template<typename T> const list<T> cons(const T& car) {
@@ -350,6 +361,22 @@ template<typename T, typename R> const R reduce(const lambda<R(R, T)>& f, const
return reduceAccumulate<T, R> (f)(initial, p);
}
+template<typename T, typename R> struct reduceRightAccumulate {
+ const lambda<R(T, R)> f;
+ reduceRightAccumulate(const lambda<R(T, R)>& f) :
+ f(f) {
+ }
+ R operator()(const list<T>& p, const R& acc) const {
+ if(isNil(p))
+ return acc;
+ return (*this)(cdr(p), f(car(p), acc));
+ }
+};
+
+template<typename T, typename R> const R reduceRight(const lambda<R(T, R)>& f, const R& initial, const list<T>& p) {
+ return reduceRightAccumulate<T, R> (f)(p, initial);
+}
+
/**
* Run a filter lambda function on a list.
*/