From 7905926c413e843d9497948cb824059f2c017f6a Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Mon, 26 Aug 2013 03:04:23 +0000 Subject: Support sorting database search results by rank, and add a rank attribute to ATOM entries. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1517412 13f79535-47bb-0310-9956-ffa450edef68 --- sca-cpp/trunk/kernel/list.hpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'sca-cpp/trunk/kernel/list.hpp') diff --git a/sca-cpp/trunk/kernel/list.hpp b/sca-cpp/trunk/kernel/list.hpp index 753b33b6a0..e20f3fbd8e 100644 --- a/sca-cpp/trunk/kernel/list.hpp +++ b/sca-cpp/trunk/kernel/list.hpp @@ -522,6 +522,17 @@ template inline const T listRef(const list& l, const size_t i) no return listRef(cdr(l), i - 1); } +/** + * Returns a new list consisting of the first k elements of a list. + */ +template inline const list listHead(const list& l, const size_t k) noexcept { + if(k == 0) + return list(); + if(isNull(l)) + return l; + return cons(car(l), listHead(cdr(l), k - 1)); +} + /** * Returns the tail of a list, ommiting the first k elements. */ -- cgit v1.2.3