|
||||
File indexing completed on 2025-01-18 09:28:26
0001 /* 0002 Copyright (c) Ivan Matek, Marshall Clow 2021. 0003 0004 Distributed under the Boost Software License, Version 1.0. (See accompanying 0005 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 0006 0007 */ 0008 0009 /// \file is_clamped.hpp 0010 /// \brief IsClamped algorithm 0011 /// \authors Ivan Matek, Marshall Clow 0012 /// 0013 0014 #ifndef BOOST_ALGORITHM_IS_CLAMPED_HPP 0015 #define BOOST_ALGORITHM_IS_CLAMPED_HPP 0016 0017 #include <functional> // for std::less 0018 #include <cassert> 0019 0020 #include <boost/type_traits/type_identity.hpp> // for boost::type_identity 0021 0022 namespace boost { namespace algorithm { 0023 0024 /// \fn is_clamped ( T const& val, 0025 /// typename boost::type_identity<T>::type const & lo, 0026 /// typename boost::type_identity<T>::type const & hi, Pred p ) 0027 /// \returns true if value "val" is in the range [ lo, hi ] 0028 /// using the comparison predicate p. 0029 /// If p ( val, lo ) return false. 0030 /// If p ( hi, val ) return false. 0031 /// Otherwise, returns true. 0032 /// 0033 /// \param val The value to be checked 0034 /// \param lo The lower bound of the range 0035 /// \param hi The upper bound of the range 0036 /// \param p A predicate to use to compare the values. 0037 /// p ( a, b ) returns a boolean. 0038 /// 0039 template <typename T, typename Pred> 0040 BOOST_CXX14_CONSTEXPR bool is_clamped( 0041 T const& val, typename boost::type_identity<T>::type const& lo, 0042 typename boost::type_identity<T>::type const& hi, Pred p) { 0043 // assert ( !p ( hi, lo )); // Can't assert p ( lo, hi ) b/c they 0044 // might be equal 0045 return p(val, lo) ? false : p(hi, val) ? false : true; 0046 } 0047 0048 /// \fn is_clamped ( T const& val, 0049 /// typename boost::type_identity<T>::type const & lo, 0050 /// typename boost::type_identity<T>::type const & hi) 0051 /// \returns true if value "val" is in the range [ lo, hi ] 0052 /// using operator < for comparison. 0053 /// If the value is less than lo, return false. 0054 /// If the value is greater than hi, return false. 0055 /// Otherwise, returns true. 0056 /// 0057 /// \param val The value to be checked 0058 /// \param lo The lower bound of the range 0059 /// \param hi The upper bound of the range 0060 /// 0061 0062 template<typename T> 0063 BOOST_CXX14_CONSTEXPR bool is_clamped ( const T& val, 0064 typename boost::type_identity<T>::type const & lo, 0065 typename boost::type_identity<T>::type const & hi ) 0066 { 0067 return boost::algorithm::is_clamped ( val, lo, hi, std::less<T>()); 0068 } 0069 0070 }} 0071 0072 #endif // BOOST_ALGORITHM_CLAMP_HPP
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |