2 * Copyright Andrey Semashev 2007 - 2015.
3 * Distributed under the Boost Software License, Version 1.0.
4 * (See accompanying file LICENSE_1_0.txt or copy at
5 * http://www.boost.org/LICENSE_1_0.txt)
9 * \author Andrey Semashev
12 * This header contains a predicate for checking if the provided value is within a half-open range.
15 #ifndef BOOST_LOG_UTILITY_FUNCTIONAL_IN_RANGE_HPP_INCLUDED_
16 #define BOOST_LOG_UTILITY_FUNCTIONAL_IN_RANGE_HPP_INCLUDED_
19 #include <boost/log/detail/config.hpp>
20 #include <boost/log/utility/functional/logical.hpp> // make_common_integral_type
21 #include <boost/log/detail/header.hpp>
23 #ifdef BOOST_HAS_PRAGMA_ONCE
29 BOOST_LOG_OPEN_NAMESPACE
31 //! The in_range functor
34 typedef bool result_type;
36 template< typename T, typename U >
37 bool operator() (T const& value, std::pair< U, U > const& rng) const
39 return op(value, rng, typename mpl::and_< is_integral< T >, is_integral< U > >::type());
43 template< typename T, typename U >
44 static bool op(T const& value, std::pair< U, U > const& rng, mpl::false_ const&)
46 return (value >= rng.first && value < rng.second);
48 template< typename T, typename U >
49 static bool op(T const& value, std::pair< U, U > const& rng, mpl::true_ const&)
51 typedef typename aux::make_common_integral_type< T, U >::type common_integral_type;
52 return (static_cast< common_integral_type >(value) >= static_cast< common_integral_type >(rng.first))
53 && (static_cast< common_integral_type >(value) < static_cast< common_integral_type >(rng.second));
57 BOOST_LOG_CLOSE_NAMESPACE // namespace log
61 #include <boost/log/detail/footer.hpp>
63 #endif // BOOST_LOG_UTILITY_FUNCTIONAL_IN_RANGE_HPP_INCLUDED_