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)
8 * \file parameter_tools.hpp
9 * \author Andrey Semashev
12 * \brief This header is the Boost.Log library implementation, see the library documentation
13 * at http://www.boost.org/doc/libs/release/libs/log/doc/html/index.html.
16 #ifndef BOOST_LOG_DETAIL_PARAMETER_TOOLS_HPP_INCLUDED_
17 #define BOOST_LOG_DETAIL_PARAMETER_TOOLS_HPP_INCLUDED_
19 #include <boost/parameter/keyword.hpp>
20 #include <boost/preprocessor/control/if.hpp>
21 #include <boost/preprocessor/comparison/equal.hpp>
22 #include <boost/preprocessor/repetition/enum_params.hpp>
23 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
24 #include <boost/preprocessor/repetition/repeat_from_to.hpp>
25 #include <boost/preprocessor/facilities/intercept.hpp>
26 #include <boost/preprocessor/arithmetic/dec.hpp>
27 #include <boost/preprocessor/tuple/elem.hpp>
28 #include <boost/log/detail/config.hpp>
29 #include <boost/log/detail/sfinae_tools.hpp>
30 #include <boost/log/detail/header.hpp>
32 #ifdef BOOST_HAS_PRAGMA_ONCE
36 #ifndef BOOST_LOG_MAX_PARAMETER_ARGS
37 //! The maximum number of named arguments that are accepted by constructors and functions
38 #define BOOST_LOG_MAX_PARAMETER_ARGS 16
41 // The macro applies the passed macro with the specified arguments BOOST_LOG_MAX_PARAMETER_ARGS times
42 #define BOOST_LOG_PARAMETRIZED_CONSTRUCTORS_GEN(macro, args)\
44 BOOST_PP_REPEAT_FROM_TO(1, BOOST_LOG_MAX_PARAMETER_ARGS, macro, args)
46 #define BOOST_LOG_CTOR_FORWARD_1(n, types)\
47 template< typename T0 >\
48 explicit BOOST_PP_TUPLE_ELEM(2, 0, types)(T0 const& arg0, typename boost::log::aux::enable_if_named_parameters< T0, boost::log::aux::sfinae_dummy >::type = boost::log::aux::sfinae_dummy()) :\
49 BOOST_PP_TUPLE_ELEM(2, 1, types)((BOOST_PP_ENUM_PARAMS(n, arg))) {}
51 #define BOOST_LOG_CTOR_FORWARD_N(n, types)\
52 template< BOOST_PP_ENUM_PARAMS(n, typename T) >\
53 explicit BOOST_PP_TUPLE_ELEM(2, 0, types)(BOOST_PP_ENUM_BINARY_PARAMS(n, T, const& arg)) :\
54 BOOST_PP_TUPLE_ELEM(2, 1, types)((BOOST_PP_ENUM_PARAMS(n, arg))) {}
56 #define BOOST_LOG_CTOR_FORWARD(z, n, types)\
57 BOOST_PP_IF(BOOST_PP_EQUAL(n, 1), BOOST_LOG_CTOR_FORWARD_1, BOOST_LOG_CTOR_FORWARD_N)(n, types)
59 // The macro expands to a number of templated constructors that aggregate their named arguments
60 // into an ArgumentsPack and pass it to the base class constructor.
61 #define BOOST_LOG_PARAMETRIZED_CONSTRUCTORS_FORWARD(class_type, base_type)\
62 BOOST_LOG_PARAMETRIZED_CONSTRUCTORS_GEN(BOOST_LOG_CTOR_FORWARD, (class_type, base_type))
64 #define BOOST_LOG_CTOR_CALL_1(n, types)\
65 template< typename T0 >\
66 explicit BOOST_PP_TUPLE_ELEM(2, 0, types)(T0 const& arg0, typename boost::log::aux::enable_if_named_parameters< T0, boost::log::aux::sfinae_dummy >::type = boost::log::aux::sfinae_dummy())\
67 { BOOST_PP_TUPLE_ELEM(2, 1, types)((BOOST_PP_ENUM_PARAMS(n, arg))); }
69 #define BOOST_LOG_CTOR_CALL_N(n, types)\
70 template< BOOST_PP_ENUM_PARAMS(n, typename T) >\
71 explicit BOOST_PP_TUPLE_ELEM(2, 0, types)(BOOST_PP_ENUM_BINARY_PARAMS(n, T, const& arg))\
72 { BOOST_PP_TUPLE_ELEM(2, 1, types)((BOOST_PP_ENUM_PARAMS(n, arg))); }
74 #define BOOST_LOG_CTOR_CALL(z, n, types)\
75 BOOST_PP_IF(BOOST_PP_EQUAL(n, 1), BOOST_LOG_CTOR_CALL_1, BOOST_LOG_CTOR_CALL_N)(n, types)
77 // The macro expands to a number of templated constructors that aggregate their named arguments
78 // into an ArgumentsPack and pass it to a function call.
79 #define BOOST_LOG_PARAMETRIZED_CONSTRUCTORS_CALL(class_type, fun)\
80 BOOST_LOG_PARAMETRIZED_CONSTRUCTORS_GEN(BOOST_LOG_CTOR_CALL, (class_type, fun))
84 BOOST_LOG_OPEN_NAMESPACE
88 // Yeah, not too cute. The empty_arg_list class should really be public.
89 // https://svn.boost.org/trac/boost/ticket/7247
90 typedef boost::parameter::aux::empty_arg_list empty_arg_list;
92 #if !(defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) || defined(BOOST_LOG_NO_CXX11_ARG_PACKS_TO_NON_VARIADIC_ARGS_EXPANSION))
94 //! The metafunction generates argument pack
95 template< typename ArgT0, typename... ArgsT >
98 typedef boost::parameter::aux::arg_list< ArgT0, typename make_arg_list< ArgsT... >::type > type;
101 template< typename ArgT0 >
102 struct make_arg_list< ArgT0 >
104 typedef boost::parameter::aux::arg_list< ArgT0 > type;
109 //! The metafunction generates argument pack
110 template< typename ArgT0, BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_DEC(BOOST_LOG_MAX_PARAMETER_ARGS), typename T, = void BOOST_PP_INTERCEPT) >
113 typedef boost::parameter::aux::arg_list< ArgT0, typename make_arg_list< BOOST_PP_ENUM_PARAMS(BOOST_PP_DEC(BOOST_LOG_MAX_PARAMETER_ARGS), T) >::type > type;
116 template< typename ArgT0 >
117 struct make_arg_list< ArgT0, BOOST_PP_ENUM_PARAMS(BOOST_PP_DEC(BOOST_LOG_MAX_PARAMETER_ARGS), void BOOST_PP_INTERCEPT) >
119 typedef boost::parameter::aux::arg_list< ArgT0 > type;
124 template< typename T, typename R >
125 struct enable_if_named_parameters {};
127 template< typename R >
128 struct enable_if_named_parameters< empty_arg_list, R >
133 template< typename Keyword, typename Arg, typename R >
134 struct enable_if_named_parameters< boost::parameter::aux::tagged_argument< Keyword, Arg >, R >
139 template< typename TaggedArg, typename Next, typename R >
140 struct enable_if_named_parameters< boost::parameter::aux::arg_list< TaggedArg, Next >, R >
147 BOOST_LOG_CLOSE_NAMESPACE // namespace log
151 #include <boost/log/detail/footer.hpp>
153 #endif // BOOST_LOG_DETAIL_PARAMETER_TOOLS_HPP_INCLUDED_