USRP Hardware Driver and USRP Manual  Version: 3.13.0.HEAD-0-gf114cfa0
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 <algorithm>
12 #include <stdint.h>
13 #include <boost/range/begin.hpp>
14 #include <boost/range/end.hpp>
15 
21 namespace uhd{
32  template<typename Range> UHD_INLINE Range sorted(const Range &range){
33  Range r(range); std::sort(boost::begin(r), boost::end(r)); return r;
34  }
35 
46  template<typename Range> UHD_INLINE Range reversed(const Range &range){
47  Range r(range); std::reverse(boost::begin(r), boost::end(r)); return r;
48  }
49 
59  template<typename Range, typename T> UHD_INLINE
60  bool has(const Range &range, const T &value){
61  return boost::end(range) != std::find(boost::begin(range), boost::end(range), value);
62  }
63 
71  template<typename T> UHD_INLINE T clip(const T &val, const T &bound1, const T &bound2){
72  const T minimum = std::min(bound1, bound2);
73  if (val < minimum) return minimum;
74  const T maximum = std::max(bound1, bound2);
75  if (val > maximum) return maximum;
76  return val;
77  }
78 
79 } //namespace uhd
80 
81 #endif /* INCLUDED_UHD_UTILS_ALGORITHM_HPP */
UHD_INLINE Range reversed(const Range &range)
Definition: algorithm.hpp:46
UHD_INLINE bool has(const Range &range, const T &value)
Definition: algorithm.hpp:60
UHD_INLINE T clip(const T &val, const T &bound1, const T &bound2)
Definition: algorithm.hpp:71
Definition: build_info.hpp:14
#define UHD_INLINE
Definition: config.h:53
UHD_INLINE Range sorted(const Range &range)
Definition: algorithm.hpp:32