diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2013-08-26 03:04:23 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2013-08-26 03:04:23 +0000 |
commit | 7905926c413e843d9497948cb824059f2c017f6a (patch) | |
tree | 0f88f849a2b6a170319b9ba22b6434ab586a1283 /sca-cpp/trunk/kernel/list.hpp | |
parent | 64fed3fe80c115c775d45f9b46f661a4d6043e5a (diff) |
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
Diffstat (limited to 'sca-cpp/trunk/kernel/list.hpp')
-rw-r--r-- | sca-cpp/trunk/kernel/list.hpp | 11 |
1 files changed, 11 insertions, 0 deletions
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 @@ -523,6 +523,17 @@ template<typename T> inline const T listRef(const list<T>& l, const size_t i) no } /** + * Returns a new list consisting of the first k elements of a list. + */ +template<typename T> inline const list<T> listHead(const list<T>& l, const size_t k) noexcept { + if(k == 0) + return list<T>(); + if(isNull(l)) + return l; + return cons<T>(car(l), listHead(cdr(l), k - 1)); +} + +/** * Returns the tail of a list, ommiting the first k elements. */ template<typename T> inline const list<T> listTail(const list<T>& l, const size_t k) noexcept { |