Update contrib.
1 // Copyright David Abrahams 2002.
2 // Distributed under the Boost Software License, Version 1.0. (See
3 // accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5 #ifndef KEYWORDS_DWA2002323_HPP
6 # define KEYWORDS_DWA2002323_HPP
8 # include <boost/python/detail/prefix.hpp>
10 # include <boost/python/args_fwd.hpp>
11 # include <boost/config.hpp>
12 # include <boost/python/detail/preprocessor.hpp>
13 # include <boost/python/detail/type_list.hpp>
15 # include <boost/type_traits/is_reference.hpp>
16 # include <boost/type_traits/remove_reference.hpp>
17 # include <boost/type_traits/remove_cv.hpp>
19 # include <boost/preprocessor/enum_params.hpp>
20 # include <boost/preprocessor/repeat.hpp>
21 # include <boost/preprocessor/facilities/intercept.hpp>
22 # include <boost/preprocessor/iteration/local.hpp>
24 # include <boost/python/detail/mpl_lambda.hpp>
25 # include <boost/python/object_core.hpp>
27 # include <boost/mpl/bool.hpp>
32 namespace boost { namespace python {
34 typedef detail::keywords<1> arg;
35 typedef arg arg_; // gcc 2.96 workaround
39 template <std::size_t nkeywords>
42 BOOST_STATIC_CONSTANT(std::size_t, size = nkeywords);
44 keyword_range range() const
46 return keyword_range(elements, elements + nkeywords);
49 keyword elements[nkeywords];
52 operator,(python::arg const &k) const;
54 keywords<nkeywords + 1>
55 operator,(char const *name) const;
58 template <std::size_t nkeywords>
59 struct keywords : keywords_base<nkeywords>
64 struct keywords<1> : keywords_base<1>
66 explicit keywords(char const *name)
68 elements[0].name = name;
72 python::arg& operator=(T const& value)
75 elements[0].default_value = handle<>(python::borrowed(object(value).ptr()));
79 operator detail::keyword const&() const
85 template <std::size_t nkeywords>
88 keywords_base<nkeywords>::operator,(python::arg const &k) const
90 keywords<nkeywords> const& l = *static_cast<keywords<nkeywords> const*>(this);
91 python::detail::keywords<nkeywords+1> res;
92 std::copy(l.elements, l.elements+nkeywords, res.elements);
93 res.elements[nkeywords] = k.elements[0];
97 template <std::size_t nkeywords>
99 keywords<nkeywords + 1>
100 keywords_base<nkeywords>::operator,(char const *name) const
102 return this->operator,(python::arg(name));
105 # ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
109 BOOST_STATIC_CONSTANT(bool, value = false);
112 template<std::size_t nkeywords>
113 struct is_keywords<keywords<nkeywords> >
115 BOOST_STATIC_CONSTANT(bool, value = true);
118 struct is_reference_to_keywords
120 BOOST_STATIC_CONSTANT(bool, is_ref = is_reference<T>::value);
121 typedef typename remove_reference<T>::type deref;
122 typedef typename remove_cv<deref>::type key_t;
123 BOOST_STATIC_CONSTANT(bool, is_key = is_keywords<key_t>::value);
124 BOOST_STATIC_CONSTANT(bool, value = (is_ref & is_key));
126 typedef mpl::bool_<value> type;
127 BOOST_PYTHON_MPL_LAMBDA_SUPPORT(1,is_reference_to_keywords,(T))
130 typedef char (&yes_keywords_t)[1];
131 typedef char (&no_keywords_t)[2];
133 no_keywords_t is_keywords_test(...);
135 template<std::size_t nkeywords>
136 yes_keywords_t is_keywords_test(void (*)(keywords<nkeywords>&));
138 template<std::size_t nkeywords>
139 yes_keywords_t is_keywords_test(void (*)(keywords<nkeywords> const&));
142 class is_reference_to_keywords
145 BOOST_STATIC_CONSTANT(
147 sizeof(detail::is_keywords_test( (void (*)(T))0 ))
148 == sizeof(detail::yes_keywords_t)));
150 typedef mpl::bool_<value> type;
151 BOOST_PYTHON_MPL_LAMBDA_SUPPORT(1,is_reference_to_keywords,(T))
156 inline detail::keywords<1> args(char const* name)
158 return detail::keywords<1>(name);
161 # define BOOST_PYTHON_ASSIGN_NAME(z, n, _) result.elements[n].name = name##n;
162 # define BOOST_PP_LOCAL_MACRO(n) \
163 inline detail::keywords<n> args(BOOST_PP_ENUM_PARAMS_Z(1, n, char const* name)) \
165 detail::keywords<n> result; \
166 BOOST_PP_REPEAT_1(n, BOOST_PYTHON_ASSIGN_NAME, _) \
169 # define BOOST_PP_LOCAL_LIMITS (2, BOOST_PYTHON_MAX_ARITY)
170 # include BOOST_PP_LOCAL_ITERATE()
172 }} // namespace boost::python
175 # endif // KEYWORDS_DWA2002323_HPP