USRP Hardware Driver and USRP Manual Version: 3.15.0.0-MacPorts-Release
UHD and USRP Manual
algorithm.hpp
Go to the documentation of this file.
1//
2// Copyright 2010-2015 Ettus Research LLC
3// Copyright 2018 Ettus Research, a National Instruments Company
4//
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
7
8#ifndef INCLUDED_UHD_UTILS_ALGORITHM_HPP
9#define INCLUDED_UHD_UTILS_ALGORITHM_HPP
10
11#include <stdint.h>
12#include <boost/range/begin.hpp>
13#include <boost/range/end.hpp>
14#include <algorithm>
15
21namespace uhd {
32template <typename Range> UHD_INLINE Range sorted(const Range& range)
33{
34 Range r(range);
35 std::sort(boost::begin(r), boost::end(r));
36 return r;
37}
38
49template <typename Range> UHD_INLINE Range reversed(const Range& range)
50{
51 Range r(range);
52 std::reverse(boost::begin(r), boost::end(r));
53 return r;
54}
55
65template <typename Range, typename T>
66UHD_INLINE bool has(const Range& range, const T& value)
67{
68 return boost::end(range) != std::find(boost::begin(range), boost::end(range), value);
69}
70
78template <typename T> UHD_INLINE T clip(const T& val, const T& bound1, const T& bound2)
79{
80 const T minimum = std::min(bound1, bound2);
81 if (val < minimum)
82 return minimum;
83 const T maximum = std::max(bound1, bound2);
84 if (val > maximum)
85 return maximum;
86 return val;
87}
88
89} // namespace uhd
90
91#endif /* INCLUDED_UHD_UTILS_ALGORITHM_HPP */
#define UHD_INLINE
Definition: config.h:53
Definition: build_info.hpp:13
UHD_INLINE bool has(const Range &range, const T &value)
Definition: algorithm.hpp:66
UHD_INLINE Range sorted(const Range &range)
Definition: algorithm.hpp:32
UHD_INLINE T clip(const T &val, const T &bound1, const T &bound2)
Definition: algorithm.hpp:78
UHD_INLINE Range reversed(const Range &range)
Definition: algorithm.hpp:49