1 /*
2 * Inkscape::Util::reverse_list - generate a reversed list from iterator range
3 *
4 * Authors:
5 * MenTaLguY <mental@rydia.net>
6 *
7 * Copyright (C) 2004 MenTaLguY
8 *
9 * Released under GNU GPL, read the file 'COPYING' for more information
10 */
12 #ifndef SEEN_INKSCAPE_UTIL_REVERSE_LIST_H
13 #define SEEN_INKSCAPE_UTIL_REVERSE_LIST_H
15 #include "util/list.h"
16 #include "traits/list-copy.h"
18 namespace Inkscape {
20 namespace Util {
22 template <typename InputIterator>
23 inline typename Traits::ListCopy<InputIterator>::ResultList
24 reverse_list(InputIterator start, InputIterator end) {
25 typename Traits::ListCopy<InputIterator>::ResultList head;
26 while ( start != end ) {
27 head = cons(*start, head);
28 ++start;
29 }
30 return head;
31 }
33 template <typename T>
34 inline typename Traits::ListCopy<List<T> >::ResultList
35 reverse_list(List<T> const &list) {
36 return reverse_list(list, List<T>());
37 }
39 template <typename T>
40 inline MutableList<T>
41 reverse_list_in_place(MutableList<T> start,
42 MutableList<T> end=MutableList<T>())
43 {
44 MutableList<T> reversed(end);
45 while ( start != end ) {
46 MutableList<T> temp(start);
47 ++start;
48 set_rest(temp, reversed);
49 reversed = temp;
50 }
51 return reversed;
52 }
54 }
56 }
58 #endif
59 /*
60 Local Variables:
61 mode:c++
62 c-file-style:"stroustrup"
63 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
64 indent-tabs-mode:nil
65 fill-column:99
66 End:
67 */
68 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :