Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:39:27

0001 /*
0002  *          Copyright Andrey Semashev 2007 - 2015.
0003  * Distributed under the Boost Software License, Version 1.0.
0004  *    (See accompanying file LICENSE_1_0.txt or copy at
0005  *          http://www.boost.org/LICENSE_1_0.txt)
0006  */
0007 /*!
0008  * \file   in_range.hpp
0009  * \author Andrey Semashev
0010  * \date   30.03.2008
0011  *
0012  * This header contains a predicate for checking if the provided value is within a half-open range.
0013  */
0014 
0015 #ifndef BOOST_LOG_UTILITY_FUNCTIONAL_IN_RANGE_HPP_INCLUDED_
0016 #define BOOST_LOG_UTILITY_FUNCTIONAL_IN_RANGE_HPP_INCLUDED_
0017 
0018 #include <utility>
0019 #include <boost/type_traits/is_integral.hpp>
0020 #include <boost/type_traits/integral_constant.hpp>
0021 #include <boost/log/detail/config.hpp>
0022 #include <boost/log/utility/functional/logical.hpp> // make_common_integral_type
0023 #include <boost/log/detail/header.hpp>
0024 
0025 #ifdef BOOST_HAS_PRAGMA_ONCE
0026 #pragma once
0027 #endif
0028 
0029 namespace boost {
0030 
0031 BOOST_LOG_OPEN_NAMESPACE
0032 
0033 //! The in_range functor
0034 struct in_range_fun
0035 {
0036     typedef bool result_type;
0037 
0038     template< typename T, typename U >
0039     bool operator() (T const& value, std::pair< U, U > const& rng) const
0040     {
0041         return op(value, rng, integral_constant< bool, is_integral< T >::value && is_integral< U >::value >());
0042     }
0043 
0044 private:
0045     template< typename T, typename U >
0046     static bool op(T const& value, std::pair< U, U > const& rng, false_type)
0047     {
0048         return (value >= rng.first && value < rng.second);
0049     }
0050     template< typename T, typename U >
0051     static bool op(T const& value, std::pair< U, U > const& rng, true_type)
0052     {
0053         typedef typename aux::make_common_integral_type< T, U >::type common_integral_type;
0054         return (static_cast< common_integral_type >(value) >= static_cast< common_integral_type >(rng.first))
0055             && (static_cast< common_integral_type >(value) < static_cast< common_integral_type >(rng.second));
0056     }
0057 };
0058 
0059 BOOST_LOG_CLOSE_NAMESPACE // namespace log
0060 
0061 } // namespace boost
0062 
0063 #include <boost/log/detail/footer.hpp>
0064 
0065 #endif // BOOST_LOG_UTILITY_FUNCTIONAL_IN_RANGE_HPP_INCLUDED_