File indexing completed on 2025-01-18 09:38:50
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 #ifndef BOOST_IOSTREAMS_DETAIL_EXECUTE_HPP_INCLUDED
0029 #define BOOST_IOSTREAMS_DETAIL_EXECUTE_HPP_INCLUDED
0030
0031 #if defined(_MSC_VER)
0032 # pragma once
0033 #endif
0034
0035 #include <boost/config.hpp>
0036 #include <boost/detail/workaround.hpp>
0037 #include <boost/iostreams/detail/config/limits.hpp> // MAX_EXECUTE_ARITY
0038 #include <boost/preprocessor/arithmetic/dec.hpp>
0039 #include <boost/preprocessor/cat.hpp>
0040 #include <boost/preprocessor/iteration/local.hpp>
0041 #include <boost/preprocessor/repetition/enum_params.hpp>
0042 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
0043 #include <boost/preprocessor/punctuation/comma_if.hpp>
0044 #include <boost/utility/result_of.hpp>
0045
0046 namespace boost { namespace iostreams { namespace detail {
0047
0048
0049 template<typename Result>
0050 struct execute_traits_impl {
0051 typedef Result result_type;
0052 template<typename Op>
0053 static Result execute(Op op) { return op(); }
0054 };
0055
0056
0057
0058 template<>
0059 struct execute_traits_impl<void> {
0060 typedef int result_type;
0061 template<typename Op>
0062 static int execute(Op op) { op(); return 0; }
0063 };
0064
0065
0066
0067 template< typename Op,
0068 typename Result =
0069 #if !defined(BOOST_NO_RESULT_OF) && \
0070 !BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x592))
0071 typename boost::result_of<Op()>::type
0072 #else
0073 BOOST_DEDUCED_TYPENAME Op::result_type
0074 #endif
0075 >
0076 struct execute_traits
0077 : execute_traits_impl<Result>
0078 { };
0079
0080
0081 template<typename Op>
0082 typename execute_traits<Op>::result_type
0083 execute_all(Op op)
0084 {
0085 return execute_traits<Op>::execute(op);
0086 }
0087
0088
0089 #define BOOST_PP_LOCAL_MACRO(n) \
0090 template<typename Op, BOOST_PP_ENUM_PARAMS(n, typename C)> \
0091 typename execute_traits<Op>::result_type \
0092 execute_all(Op op, BOOST_PP_ENUM_BINARY_PARAMS(n, C, c)) \
0093 { \
0094 typename execute_traits<Op>::result_type r; \
0095 try { \
0096 r = boost::iostreams::detail::execute_all( \
0097 op BOOST_PP_COMMA_IF(BOOST_PP_DEC(n)) \
0098 BOOST_PP_ENUM_PARAMS(BOOST_PP_DEC(n), c) \
0099 ); \
0100 } catch (...) { \
0101 try { \
0102 BOOST_PP_CAT(c, BOOST_PP_DEC(n))(); \
0103 } catch (...) { } \
0104 throw; \
0105 } \
0106 BOOST_PP_CAT(c, BOOST_PP_DEC(n))(); \
0107 return r; \
0108 } \
0109
0110
0111 #define BOOST_PP_LOCAL_LIMITS (1, BOOST_IOSTREAMS_MAX_EXECUTE_ARITY)
0112 #include BOOST_PP_LOCAL_ITERATE()
0113 #undef BOOST_PP_LOCAL_MACRO
0114
0115 template<class InIt, class Op>
0116 Op execute_foreach(InIt first, InIt last, Op op)
0117 {
0118 if (first == last)
0119 return op;
0120 try {
0121 op(*first);
0122 } catch (...) {
0123 try {
0124 ++first;
0125 boost::iostreams::detail::execute_foreach(first, last, op);
0126 } catch (...) { }
0127 throw;
0128 }
0129 ++first;
0130 return boost::iostreams::detail::execute_foreach(first, last, op);
0131 }
0132
0133 } } }
0134
0135 #endif