USRP Hardware Driver and USRP Manual Version: 4.2.0.0
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
21namespace uhd {
32template <typename Range>
33UHD_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
50template <typename Range>
51UHD_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
67template <typename Range, typename T>
68UHD_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
80template <typename T>
81UHD_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
#define UHD_INLINE
Definition: config.h:65
Definition: build_info.hpp:12
UHD_INLINE bool has(const Range &range, const T &value)
Definition: algorithm.hpp:68
UHD_INLINE Range sorted(const Range &range)
Definition: algorithm.hpp:33
UHD_INLINE T clip(const T &val, const T &bound1, const T &bound2)
Definition: algorithm.hpp:81
UHD_INLINE Range reversed(const Range &range)
Definition: algorithm.hpp:51