Back to home page

EIC code displayed by LXR

 
 

    


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

0001 
0002 // Copyright (C) 2009-2012 Lorenzo Caminiti
0003 // Distributed under the Boost Software License, Version 1.0
0004 // (see accompanying file LICENSE_1_0.txt or a copy at
0005 // http://www.boost.org/LICENSE_1_0.txt)
0006 // Home at http://www.boost.org/libs/local_function
0007 
0008 #ifndef BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_HPP_
0009 #define BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_HPP_
0010 
0011 #include <boost/local_function/aux_/symbol.hpp>
0012 #include <boost/local_function/aux_/preprocessor/traits/decl_returns.hpp>
0013 #include <boost/scope_exit.hpp>
0014 #include <boost/typeof/typeof.hpp>
0015 #include <boost/type_traits/remove_pointer.hpp>
0016 #include <boost/type_traits/function_traits.hpp>
0017 #include <boost/preprocessor/control/iif.hpp>
0018 #include <boost/preprocessor/control/expr_iif.hpp>
0019 #include <boost/preprocessor/list/adt.hpp>
0020 #include <boost/preprocessor/cat.hpp>
0021 
0022 // PRIVATE //
0023 
0024 #define BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_FUNC_(id) \
0025     /* symbol (not internal) also gives error if missing result type */ \
0026     BOOST_PP_CAT( \
0027   ERROR_missing_result_type_before_the_local_function_parameter_macro_id, \
0028             id)
0029 
0030 #define BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_PARAMS_(id) \
0031     BOOST_LOCAL_FUNCTION_AUX_SYMBOL( (deduce_result_params)(id) )
0032 
0033 #define BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_TYPE_(id) \
0034     BOOST_LOCAL_FUNCTION_AUX_SYMBOL( (result_type)(id) )
0035 
0036 #define BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_INDEX_ \
0037     /* this does not have to be an integral index because ScopeExit uses */ \
0038     /* just as a symbol to concatenate go generate unique symbols (but */ \
0039     /* if it'd ever needed to became integral, the number of function */ \
0040     /* params + 1 as in the macro CONFIG_ARITY_MAX could be used) */ \
0041     result
0042 
0043 // User did not explicitly specified result type, deduce it (using Typeof).
0044 #define BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_DEDUCE_( \
0045         id, typename01, decl_traits) \
0046     /* user specified result type here */ \
0047     BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_DECL(id) \
0048     /* tagging, wrapping, etc as from ScopeExit type deduction are */ \
0049     /* necessary within templates (at least on GCC) to work around an */ \
0050     /* compiler internal errors) */ \
0051     BOOST_SCOPE_EXIT_DETAIL_TAG_DECL(0, /* no recursive step r */ \
0052             id, BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_INDEX_, \
0053             BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_FUNC_(id)) \
0054     BOOST_SCOPE_EXIT_DETAIL_CAPTURE_DECL(0, /* no recursive step r */ \
0055             ( id, BOOST_PP_EXPR_IIF(typename01, typename) ), \
0056             BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_INDEX_, \
0057             BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_FUNC_(id)) \
0058     /* extra struct to workaround GCC and other compiler's issues */ \
0059     struct BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_PARAMS_(id) { \
0060         typedef \
0061             BOOST_PP_EXPR_IIF(typename01, typename) \
0062             ::boost::function_traits< \
0063                 BOOST_PP_EXPR_IIF(typename01, typename) \
0064                 ::boost::remove_pointer< \
0065                     BOOST_SCOPE_EXIT_DETAIL_CAPTURE_T(id, \
0066                             BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_INDEX_, \
0067                             BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_FUNC_(id)) \
0068                 >::type \
0069             >::result_type \
0070             BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_TYPE_(id) \
0071         ; \
0072     };
0073 
0074 // Use result type as explicitly specified by user (no type deduction needed).
0075 // Precondition: RETURNS(decl_traits) != NIL
0076 #define BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_TYPED_( \
0077         id, typename01, decl_traits) \
0078     /* user specified result type here */ \
0079     struct BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_PARAMS_(id) { \
0080         typedef \
0081             BOOST_PP_LIST_FIRST( \
0082                     BOOST_LOCAL_FUNCTION_AUX_PP_DECL_TRAITS_RETURNS( \
0083                             decl_traits)) \
0084             BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_TYPE_(id) \
0085         ; \
0086     };
0087 
0088 // PUBLIC //
0089 
0090 #define BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_TYPE(id, typename01) \
0091     BOOST_PP_EXPR_IIF(typename01, typename) \
0092     BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_PARAMS_(id) :: \
0093     BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_TYPE_(id)
0094 
0095 #define BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_DECL(id) \
0096     /* result type here */ (*BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_FUNC_(id))();
0097 
0098 #define BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT(id, typename01, decl_traits) \
0099     BOOST_PP_IIF(BOOST_PP_LIST_IS_CONS( \
0100             BOOST_LOCAL_FUNCTION_AUX_PP_DECL_TRAITS_RETURNS(decl_traits)), \
0101         BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_TYPED_ \
0102     , \
0103         BOOST_LOCAL_FUNCTION_AUX_CODE_RESULT_DEDUCE_ \
0104     )(id, typename01, decl_traits)
0105 
0106 #endif // #include guard
0107