Loading...
Searching...
No Matches
algorithm.hpp
Go to the documentation of this file.
//
// Copyright 2010-2015 Ettus Research LLC
// Copyright 2018 Ettus Research, a National Instruments Company
//
// SPDX-License-Identifier: GPL-3.0-or-later
//
#pragma once
#include <uhd/config.hpp>
#include <stdint.h>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <algorithm>
namespace uhd {
template <typename Range>
UHD_INLINE Range sorted(const Range& range)
{
Range r(range);
std::sort(boost::begin(r), boost::end(r));
return r;
}
template <typename Range>
UHD_INLINE Range reversed(const Range& range)
{
Range r(range);
std::reverse(boost::begin(r), boost::end(r));
return r;
}
template <typename Range, typename T>
UHD_INLINE bool has(const Range& range, const T& value)
{
return boost::end(range) != std::find(boost::begin(range), boost::end(range), value);
}
template <typename T>
UHD_INLINE T clip(const T& val, const T& bound1, const T& bound2)
{
const T minimum = std::min(bound1, bound2);
if (val < minimum)
return minimum;
const T maximum = std::max(bound1, bound2);
if (val > maximum)
return maximum;
return val;
}
} // namespace uhd
UHD_INLINE
#define UHD_INLINE
Definition config.h:65
config.hpp
uhd
Definition build_info.hpp:12
uhd::has
UHD_INLINE bool has(const Range &range, const T &value)
Definition algorithm.hpp:68
uhd::sorted
UHD_INLINE Range sorted(const Range &range)
Definition algorithm.hpp:33
uhd::clip
UHD_INLINE T clip(const T &val, const T &bound1, const T &bound2)
Definition algorithm.hpp:81
uhd::reversed
UHD_INLINE Range reversed(const Range &range)
Definition algorithm.hpp:51