All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
algorithm.hpp
Go to the documentation of this file.
//
// Copyright 2010-2011 Ettus Research LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#ifndef INCLUDED_UHD_UTILS_ALGORITHM_HPP
#define INCLUDED_UHD_UTILS_ALGORITHM_HPP
#include <algorithm>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
namespace uhd{
template<typename Range> inline Range sorted(const Range &range){
Range r(range); std::sort(boost::begin(r), boost::end(r)); return r;
}
template<typename Range> inline Range reversed(const Range &range){
Range r(range); std::reverse(boost::begin(r), boost::end(r)); return r;
}
template<typename Range, typename T> 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> 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
#endif /* INCLUDED_UHD_UTILS_ALGORITHM_HPP */