USRP Hardware Driver and USRP Manual  Version: 4.4.0.HEAD-0-g5fac246b
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 #pragma once
9 
10 #include <uhd/config.hpp>
11 #include <stdint.h>
12 #include <boost/range/begin.hpp>
13 #include <boost/range/end.hpp>
14 #include <algorithm>
15 
21 namespace uhd {
32 template <typename Range>
33 UHD_INLINE Range sorted(const Range& range)
34 {
35  Range r(range);
36  std::sort(boost::begin(r), boost::end(r));
37  return r;
38 }
39 
50 template <typename Range>
51 UHD_INLINE Range reversed(const Range& range)
52 {
53  Range r(range);
54  std::reverse(boost::begin(r), boost::end(r));
55  return r;
56 }
57 
67 template <typename Range, typename T>
68 UHD_INLINE bool has(const Range& range, const T& value)
69 {
70  return boost::end(range) != std::find(boost::begin(range), boost::end(range), value);
71 }
72 
80 template <typename T>
81 UHD_INLINE T clip(const T& val, const T& bound1, const T& bound2)
82 {
83  const T minimum = std::min(bound1, bound2);
84  if (val < minimum)
85  return minimum;
86  const T maximum = std::max(bound1, bound2);
87  if (val > maximum)
88  return maximum;
89  return val;
90 }
91 
92 } // namespace uhd
config.hpp
UHD_INLINE
#define UHD_INLINE
Definition: config.h:65
uhd::reversed
UHD_INLINE Range reversed(const Range &range)
Definition: algorithm.hpp:51
uhd::sorted
UHD_INLINE Range sorted(const Range &range)
Definition: algorithm.hpp:33
uhd
Definition: build_info.hpp:12
uhd::has
UHD_INLINE bool has(const Range &range, const T &value)
Definition: algorithm.hpp:68
uhd::clip
UHD_INLINE T clip(const T &val, const T &bound1, const T &bound2)
Definition: algorithm.hpp:81