4 * Copyright 1995-2002 the LyX Team
5 * Read the file COPYING
7 * A variety of useful templates.
24 /// Returns true if the sequence first,last is sorted, false if not.
26 bool sorted(For first, For last)
28 if (first == last) return true;
30 while (++tmp != last) {
31 if (*tmp < *first++) return false;
37 /// Cmp is the same Cmp as you would pass to std::sort.
38 template <class For, class Cmp>
39 bool sorted(For first, For last, Cmp cmp)
41 if (first == last) return true;
43 while (++tmp != last) {
44 if (cmp(*tmp, *first++)) return false;
51 template <class P1, class P2>
52 P1 operator()(std::pair<P1, P2> const & p) {
59 * copy elements in the given range to the output iterator
60 * if the predicate evaluates as true
62 template <class InputIter, class OutputIter, class Func>
63 OutputIter copy_if(InputIter first, InputIter last,
64 OutputIter result, Func func)
66 for (; first != last; ++first) {
75 /// A slot in replacement for std::count for systems where it is broken.
76 template <class Iterator, class T>
77 typename std::iterator_traits<Iterator>::difference_type
78 count (Iterator first, Iterator last, T const & value)
81 return std::count(first, last, value);
83 std::iterator_traits<Iterator>::difference_type n = 0;
85 if (*first++ == value) ++n;