USRP Hardware Driver and USRP Manual  Version: 3.11.0.HEAD-0-gdca39145
UHD and USRP Manual
algorithm.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2010-2015 Ettus Research LLC
3 //
4 // SPDX-License-Identifier: GPL-3.0
5 //
6 
7 #ifndef INCLUDED_UHD_UTILS_ALGORITHM_HPP
8 #define INCLUDED_UHD_UTILS_ALGORITHM_HPP
9 
10 #include <algorithm>
11 #include <stdint.h>
12 #include <boost/range/begin.hpp>
13 #include <boost/range/end.hpp>
14 
20 namespace uhd{
31  template<typename Range> UHD_INLINE Range sorted(const Range &range){
32  Range r(range); std::sort(boost::begin(r), boost::end(r)); return r;
33  }
34 
45  template<typename Range> UHD_INLINE Range reversed(const Range &range){
46  Range r(range); std::reverse(boost::begin(r), boost::end(r)); return r;
47  }
48 
58  template<typename Range, typename T> UHD_INLINE
59  bool has(const Range &range, const T &value){
60  return boost::end(range) != std::find(boost::begin(range), boost::end(range), value);
61  }
62 
70  template<typename T> UHD_INLINE T clip(const T &val, const T &bound1, const T &bound2){
71  const T minimum = std::min(bound1, bound2);
72  if (val < minimum) return minimum;
73  const T maximum = std::max(bound1, bound2);
74  if (val > maximum) return maximum;
75  return val;
76  }
77 
78 } //namespace uhd
79 
80 #endif /* INCLUDED_UHD_UTILS_ALGORITHM_HPP */
UHD_INLINE Range reversed(const Range &range)
Definition: algorithm.hpp:45
UHD_INLINE bool has(const Range &range, const T &value)
Definition: algorithm.hpp:59
UHD_INLINE T clip(const T &val, const T &bound1, const T &bound2)
Definition: algorithm.hpp:70
Definition: build_info.hpp:14
#define UHD_INLINE
Definition: config.h:52
UHD_INLINE Range sorted(const Range &range)
Definition: algorithm.hpp:31