123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- #ifndef BOOST_LOG_UTILITY_FUNCTIONAL_LOGICAL_HPP_INCLUDED_
- #define BOOST_LOG_UTILITY_FUNCTIONAL_LOGICAL_HPP_INCLUDED_
- #include <boost/type_traits/is_integral.hpp>
- #include <boost/type_traits/is_unsigned.hpp>
- #include <boost/type_traits/conditional.hpp>
- #include <boost/type_traits/integral_constant.hpp>
- #include <boost/log/detail/config.hpp>
- #include <boost/log/detail/header.hpp>
- #ifdef BOOST_HAS_PRAGMA_ONCE
- #pragma once
- #endif
- namespace boost {
- BOOST_LOG_OPEN_NAMESPACE
- namespace aux {
- template< typename T, typename U, unsigned int TSizeV = sizeof(T), unsigned int USizeV = sizeof(U), bool TSmallerThanU = (sizeof(T) < sizeof(U)) >
- struct make_common_integral_type
- {
- typedef T type;
- };
- template< typename T, typename U, unsigned int TSizeV, unsigned int USizeV >
- struct make_common_integral_type< T, U, TSizeV, USizeV, true >
- {
- typedef U type;
- };
- template< typename T, typename U, unsigned int SizeV >
- struct make_common_integral_type< T, U, SizeV, SizeV, false > :
- public boost::conditional<
- is_unsigned< T >::value,
- T,
- U
- >
- {
- };
- }
- struct equal_to
- {
- typedef bool result_type;
- template< typename T, typename U >
- bool operator() (T const& left, U const& right) const
- {
- return op(left, right, integral_constant< bool, is_integral< T >::value && is_integral< U >::value >());
- }
- private:
- template< typename T, typename U >
- static bool op(T const& left, U const& right, false_type)
- {
- return (left == right);
- }
- template< typename T, typename U >
- static bool op(T const& left, U const& right, true_type)
- {
- typedef typename aux::make_common_integral_type< T, U >::type common_integral_type;
- return static_cast< common_integral_type >(left) == static_cast< common_integral_type >(right);
- }
- };
- struct not_equal_to
- {
- typedef bool result_type;
- template< typename T, typename U >
- bool operator() (T const& left, U const& right) const
- {
- return op(left, right, integral_constant< bool, is_integral< T >::value && is_integral< U >::value >());
- }
- private:
- template< typename T, typename U >
- static bool op(T const& left, U const& right, false_type)
- {
- return (left != right);
- }
- template< typename T, typename U >
- static bool op(T const& left, U const& right, true_type)
- {
- typedef typename aux::make_common_integral_type< T, U >::type common_integral_type;
- return static_cast< common_integral_type >(left) != static_cast< common_integral_type >(right);
- }
- };
- struct less
- {
- typedef bool result_type;
- template< typename T, typename U >
- bool operator() (T const& left, U const& right) const
- {
- return op(left, right, integral_constant< bool, is_integral< T >::value && is_integral< U >::value >());
- }
- private:
- template< typename T, typename U >
- static bool op(T const& left, U const& right, false_type)
- {
- return (left < right);
- }
- template< typename T, typename U >
- static bool op(T const& left, U const& right, true_type)
- {
- typedef typename aux::make_common_integral_type< T, U >::type common_integral_type;
- return static_cast< common_integral_type >(left) < static_cast< common_integral_type >(right);
- }
- };
- struct greater
- {
- typedef bool result_type;
- template< typename T, typename U >
- bool operator() (T const& left, U const& right) const
- {
- return op(left, right, integral_constant< bool, is_integral< T >::value && is_integral< U >::value >());
- }
- private:
- template< typename T, typename U >
- static bool op(T const& left, U const& right, false_type)
- {
- return (left > right);
- }
- template< typename T, typename U >
- static bool op(T const& left, U const& right, true_type)
- {
- typedef typename aux::make_common_integral_type< T, U >::type common_integral_type;
- return static_cast< common_integral_type >(left) > static_cast< common_integral_type >(right);
- }
- };
- struct less_equal
- {
- typedef bool result_type;
- template< typename T, typename U >
- bool operator() (T const& left, U const& right) const
- {
- return op(left, right, integral_constant< bool, is_integral< T >::value && is_integral< U >::value >());
- }
- private:
- template< typename T, typename U >
- static bool op(T const& left, U const& right, false_type)
- {
- return (left <= right);
- }
- template< typename T, typename U >
- static bool op(T const& left, U const& right, true_type)
- {
- typedef typename aux::make_common_integral_type< T, U >::type common_integral_type;
- return static_cast< common_integral_type >(left) <= static_cast< common_integral_type >(right);
- }
- };
- struct greater_equal
- {
- typedef bool result_type;
- template< typename T, typename U >
- bool operator() (T const& left, U const& right) const
- {
- return op(left, right, integral_constant< bool, is_integral< T >::value && is_integral< U >::value >());
- }
- private:
- template< typename T, typename U >
- static bool op(T const& left, U const& right, false_type)
- {
- return (left >= right);
- }
- template< typename T, typename U >
- static bool op(T const& left, U const& right, true_type)
- {
- typedef typename aux::make_common_integral_type< T, U >::type common_integral_type;
- return static_cast< common_integral_type >(left) >= static_cast< common_integral_type >(right);
- }
- };
- BOOST_LOG_CLOSE_NAMESPACE
- }
- #include <boost/log/detail/footer.hpp>
- #endif
|