Revision 15268898 host/include/uhd/utils/algorithm.hpp

b/host/include/uhd/utils/algorithm.hpp
21 21
#include <algorithm>
22 22
#include <boost/range/begin.hpp>
23 23
#include <boost/range/end.hpp>
24
#include <boost/range/size.hpp>
25 24

  
26
/*! \file algorithm.hpp
25
/*!
27 26
 * Useful templated functions and classes that I like to pretend are part of stl.
28 27
 * Many of the range wrapper functions come with recent versions of boost (1.43).
29 28
 */
30
namespace std{
31

  
32
    /*!
33
     * A wrapper around std::sort that takes a range instead of an iterator.
34
     *
35
     * The elements are sorted into ascending order using the less-than operator.
36
     *
37
     * \param range the range of elements to be sorted
38
     */
39
    template<typename Range> inline void sort(Range &range){
40
        return std::sort(boost::begin(range), boost::end(range));
41
    }
29
namespace uhd{
42 30

  
43 31
    /*!
44 32
     * A wrapper around std::sort that takes a range instead of an iterator.
......
51 39
     * \return a new range with the elements sorted
52 40
     */
53 41
    template<typename Range> inline Range sorted(const Range &range){
54
        Range srange(range); std::sort(srange); return srange;
55
    }
56

  
57
    /*!
58
     * A wrapper around std::reverse that takes a range instead of an iterator.
59
     *
60
     * The elements are reversed into descending order using the less-than operator.
61
     *
62
     * \param range the range of elements to be reversed
63
     */
64
    template<typename Range> inline void reverse(Range &range){
65
        return std::reverse(boost::begin(range), boost::end(range));
42
        Range r(range); std::sort(boost::begin(r), boost::end(r)); return r;
66 43
    }
67 44

  
68 45
    /*!
......
76 53
     * \return a new range with the elements reversed
77 54
     */
78 55
    template<typename Range> inline Range reversed(const Range &range){
79
        Range srange(range); std::reverse(srange); return srange;
56
        Range r(range); std::reverse(boost::begin(r), boost::end(r)); return r;
80 57
    }
81 58

  
82 59
    /*!
......
94 71
    }
95 72

  
96 73
    /*!
97
     * Count the number of appearances of a value in a range.
98
     *
99
     * Uses std::count to count the appearances in the range.
100
     *
101
     * \param range the elements to iterate through
102
     * \param value the value to count in the range
103
     * \return the number of appearances of the value
104
     */
105
    template<typename Range, typename T> inline
106
    size_t count(const Range &range, const T &value){
107
        return std::count(boost::begin(range), boost::end(range), value);
108
    }
109

  
110
    /*!
111
     * Are the ranges equal (are their elements equivalent)?
112
     *
113
     * Uses std::equal to search the iterable for an element.
114
     *
115
     * \param range1 the first range of elements
116
     * \param range2 the second range of elements
117
     * \return true when the elements are equivalent
118
     */
119
    template<typename Range> inline
120
    bool equal(const Range &range1, const Range &range2){
121
        return (boost::size(range1) == boost::size(range2)) and
122
        std::equal(boost::begin(range1), boost::end(range1), boost::begin(range2));
123
    }
124

  
125
    /*!
126 74
     * A templated clip implementation.
127 75
     * \param val the value to clip between an upper and lower limit
128 76
     * \param bound1 the upper or lower bound
......
137 85
        return val;
138 86
    }
139 87

  
140
}//namespace std
88
} //namespace uhd
141 89

  
142 90
#endif /* INCLUDED_UHD_UTILS_ALGORITHM_HPP */

Also available in: Unified diff