diff --git a/include/boost/python/detail/def_helper.hpp b/include/boost/python/detail/def_helper.hpp new file mode 100644 index 00000000..1222f71b --- /dev/null +++ b/include/boost/python/detail/def_helper.hpp @@ -0,0 +1,61 @@ +// Copyright David Abrahams 2002. Permission to copy, use, +// modify, sell and distribute this software is granted provided this +// copyright notice appears in all copies. This software is provided +// "as is" without express or implied warranty, and with no claim as +// to its suitability for any purpose. +#ifndef DEF_HELPER_DWA200287_HPP +# define DEF_HELPER_DWA200287_HPP + +# include +# include +# include + +namespace boost { namespace python { namespace detail { + +// +// def_helper -- +// +// A helper for def() functions which determines how to interpret +// an argument of type T which could be either CallPolicies or a +// string literal representing a docstring. +// +// Generates two static functions: +// +// get_policy(x), where x is of type T, returns a policies +// object: either a reference to x or default_call_policies() +// if x is a string literal. +// +// get_doc(x, s), where s convertible to char const*, returns x +// if x is a string literal, s otherwise. + +template +struct def_helper_impl +{ + template + static P const& get_policy(P const& x) { return x; } + + template + static char const* get_doc(P const&, char const* doc) { return doc; } +}; + +template <> +struct def_helper_impl +{ + static python::default_call_policies get_policy(char const*) { return default_call_policies(); } + static char const* get_doc(char const* doc, char const*) { return doc; } +}; + +template +struct def_helper + : def_helper_impl< + type_traits::ice_or< + is_string_literal::value + , is_same::value + , is_same::value +>::value +> +{}; + +}}} // namespace boost::python::detail + +#endif // DEF_HELPER_DWA200287_HPP