Back to home page

EIC code displayed by LXR

 
 

    


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

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   function_traits.hpp
0009  * \author Andrey Semashev
0010  * \date   30.08.2009
0011  *
0012  * \brief  This header is the Boost.Log library implementation, see the library documentation
0013  *         at http://www.boost.org/doc/libs/release/libs/log/doc/html/index.html.
0014  */
0015 
0016 #ifndef BOOST_LOG_DETAIL_FUNCTION_TRAITS_HPP_INCLUDED_
0017 #define BOOST_LOG_DETAIL_FUNCTION_TRAITS_HPP_INCLUDED_
0018 
0019 #include <boost/mpl/has_xxx.hpp>
0020 #include <boost/log/detail/config.hpp>
0021 
0022 #if defined(BOOST_NO_SFINAE) || defined(BOOST_MPL_CFG_NO_HAS_XXX)
0023 #   if !defined(BOOST_LOG_NO_FUNCTION_TRAITS)
0024 #      define BOOST_LOG_NO_FUNCTION_TRAITS
0025 #   endif
0026 #else
0027 
0028 #include <boost/mpl/int.hpp>
0029 #include <boost/mpl/front.hpp>
0030 #include <boost/mpl/pop_front.hpp>
0031 #include <boost/type_traits/remove_cv.hpp>
0032 #include <boost/type_traits/remove_reference.hpp>
0033 #include <boost/function_types/function_arity.hpp>
0034 #include <boost/function_types/parameter_types.hpp>
0035 #include <boost/function_types/is_nonmember_callable_builtin.hpp>
0036 #include <boost/log/detail/header.hpp>
0037 
0038 #ifdef BOOST_HAS_PRAGMA_ONCE
0039 #pragma once
0040 #endif
0041 
0042 namespace boost {
0043 
0044 BOOST_LOG_OPEN_NAMESPACE
0045 
0046 namespace aux {
0047 
0048     //  A number of traits to deal with functors
0049     BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_argument_type, argument_type, false)
0050     BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_first_argument_type, first_argument_type, false)
0051     BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_second_argument_type, second_argument_type, false)
0052     BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_arg1_type, arg1_type, false)
0053     BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_arg2_type, arg2_type, false)
0054 
0055     namespace has_arity_no_adl {
0056 
0057         typedef char yes_type;
0058         struct no_type
0059         {
0060             char dummy[2];
0061         };
0062 
0063         template< typename FunT, int ArityV = FunT::arity >
0064         struct checker
0065         {
0066         };
0067 
0068         template< typename FunT >
0069         yes_type has_arity_impl(FunT const&, checker< FunT >*);
0070         template< typename FunT >
0071         no_type has_arity_impl(FunT const&, ...);
0072 
0073     } // namespace has_arity_no_adl
0074 
0075     //! The metafunction detects if the type has an arity static constant member
0076     template< typename FunT >
0077     struct has_arity
0078     {
0079         static FunT const& get_FunT();
0080 
0081         enum value_t { value = (sizeof(has_arity_no_adl::has_arity_impl(get_FunT(), 0)) == sizeof(has_arity_no_adl::yes_type)) };
0082         typedef mpl::bool_< value > type;
0083     };
0084 
0085     //! The metafunction results in an unqualified type with removed reference
0086     template< typename T >
0087     struct root_type :
0088         public remove_cv<
0089             typename remove_reference<
0090                 T
0091             >::type
0092         >
0093     {
0094     };
0095 
0096     template<
0097         typename FunT,
0098         bool = function_types::is_nonmember_callable_builtin< FunT >::value,
0099         bool = has_argument_type< FunT >::value,
0100         bool = has_first_argument_type< FunT >::value,
0101         bool = has_arg1_type< FunT >::value
0102     >
0103     struct first_argument_type_of_impl
0104     {
0105     };
0106     template< typename FunT >
0107     struct first_argument_type_of_impl< FunT, true, false, false, false >
0108     {
0109         typedef typename root_type<
0110             typename mpl::front<
0111                 typename function_types::parameter_types< FunT >::type
0112             >::type
0113         >::type type;
0114     };
0115     template< typename FunT, bool HasFirstArgumentV, bool HasArg1V >
0116     struct first_argument_type_of_impl< FunT, false, true, HasFirstArgumentV, HasArg1V >
0117     {
0118         typedef typename root_type<
0119             typename FunT::argument_type
0120         >::type type;
0121     };
0122     template< typename FunT, bool HasArg1V >
0123     struct first_argument_type_of_impl< FunT, false, false, true, HasArg1V >
0124     {
0125         typedef typename root_type<
0126             typename FunT::first_argument_type
0127         >::type type;
0128     };
0129     template< typename FunT >
0130     struct first_argument_type_of_impl< FunT, false, false, false, true >
0131     {
0132         typedef typename root_type<
0133             typename FunT::arg1_type
0134         >::type type;
0135     };
0136 
0137     //! The metafunction returns the first argument type of a function
0138     template< typename FunT >
0139     struct first_argument_type_of :
0140         public first_argument_type_of_impl< FunT >
0141     {
0142     };
0143 
0144 
0145     template<
0146         typename FunT,
0147         bool = function_types::is_nonmember_callable_builtin< FunT >::value,
0148         bool = has_second_argument_type< FunT >::value,
0149         bool = has_arg2_type< FunT >::value
0150     >
0151     struct second_argument_type_of_impl
0152     {
0153     };
0154     template< typename FunT >
0155     struct second_argument_type_of_impl< FunT, true, false, false >
0156     {
0157         typedef typename root_type<
0158             typename mpl::front<
0159                 typename mpl::pop_front<
0160                     typename function_types::parameter_types< FunT >::type
0161                 >::type
0162             >::type
0163         >::type type;
0164     };
0165     template< typename FunT, bool HasArg2V >
0166     struct second_argument_type_of_impl< FunT, false, true, HasArg2V >
0167     {
0168         typedef typename root_type<
0169             typename FunT::second_argument_type
0170         >::type type;
0171     };
0172     template< typename FunT >
0173     struct second_argument_type_of_impl< FunT, false, false, true >
0174     {
0175         typedef typename root_type<
0176             typename FunT::arg2_type
0177         >::type type;
0178     };
0179 
0180     //! The metafunction returns the second argument type of a function
0181     template< typename FunT >
0182     struct second_argument_type_of :
0183         public second_argument_type_of_impl< FunT >
0184     {
0185     };
0186 
0187 
0188     template<
0189         typename FunT,
0190         bool = function_types::is_nonmember_callable_builtin< FunT >::value,
0191         bool = has_arity< FunT >::value,
0192         bool = has_argument_type< FunT >::value,
0193         bool = has_second_argument_type< FunT >::value
0194     >
0195     struct arity_of_impl
0196     {
0197     };
0198     template< typename FunT >
0199     struct arity_of_impl< FunT, true, false, false, false > :
0200         public function_types::function_arity< FunT >
0201     {
0202     };
0203     template< typename FunT, bool HasArgumentTypeV, bool HasSecondArgumentTypeV >
0204     struct arity_of_impl< FunT, false, true, HasArgumentTypeV, HasSecondArgumentTypeV > :
0205         public mpl::int_< FunT::arity >
0206     {
0207     };
0208     template< typename FunT, bool HasArgumentTypeV >
0209     struct arity_of_impl< FunT, false, false, HasArgumentTypeV, true > :
0210         public mpl::int_< 2 >
0211     {
0212     };
0213     template< typename FunT >
0214     struct arity_of_impl< FunT, false, false, true, false > :
0215         public mpl::int_< 1 >
0216     {
0217     };
0218 
0219     //! The metafunction returns the arity of a function
0220     template< typename FunT >
0221     struct arity_of :
0222         public arity_of_impl< FunT >
0223     {
0224     };
0225 
0226 } // namespace aux
0227 
0228 BOOST_LOG_CLOSE_NAMESPACE // namespace log
0229 
0230 } // namespace boost
0231 
0232 #include <boost/log/detail/footer.hpp>
0233 
0234 #endif // defined(BOOST_NO_SFINAE) || defined(BOOST_MPL_CFG_NO_HAS_XXX)
0235 
0236 #endif // BOOST_LOG_DETAIL_FUNCTION_TRAITS_HPP_INCLUDED_