• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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)
6  */
7 /*!
8  * \file   in_range.hpp
9  * \author Andrey Semashev
10  * \date   30.03.2008
11  *
12  * This header contains a predicate for checking if the provided value is within a half-open range.
13  */
14 
15 #ifndef BOOST_LOG_UTILITY_FUNCTIONAL_IN_RANGE_HPP_INCLUDED_
16 #define BOOST_LOG_UTILITY_FUNCTIONAL_IN_RANGE_HPP_INCLUDED_
17 
18 #include <utility>
19 #include <boost/type_traits/is_integral.hpp>
20 #include <boost/type_traits/integral_constant.hpp>
21 #include <boost/log/detail/config.hpp>
22 #include <boost/log/utility/functional/logical.hpp> // make_common_integral_type
23 #include <boost/log/detail/header.hpp>
24 
25 #ifdef BOOST_HAS_PRAGMA_ONCE
26 #pragma once
27 #endif
28 
29 namespace boost {
30 
31 BOOST_LOG_OPEN_NAMESPACE
32 
33 //! The in_range functor
34 struct in_range_fun
35 {
36     typedef bool result_type;
37 
38     template< typename T, typename U >
operator ()boost::in_range_fun39     bool operator() (T const& value, std::pair< U, U > const& rng) const
40     {
41         return op(value, rng, integral_constant< bool, is_integral< T >::value && is_integral< U >::value >());
42     }
43 
44 private:
45     template< typename T, typename U >
opboost::in_range_fun46     static bool op(T const& value, std::pair< U, U > const& rng, false_type)
47     {
48         return (value >= rng.first && value < rng.second);
49     }
50     template< typename T, typename U >
opboost::in_range_fun51     static bool op(T const& value, std::pair< U, U > const& rng, true_type)
52     {
53         typedef typename aux::make_common_integral_type< T, U >::type common_integral_type;
54         return (static_cast< common_integral_type >(value) >= static_cast< common_integral_type >(rng.first))
55             && (static_cast< common_integral_type >(value) < static_cast< common_integral_type >(rng.second));
56     }
57 };
58 
59 BOOST_LOG_CLOSE_NAMESPACE // namespace log
60 
61 } // namespace boost
62 
63 #include <boost/log/detail/footer.hpp>
64 
65 #endif // BOOST_LOG_UTILITY_FUNCTIONAL_IN_RANGE_HPP_INCLUDED_
66