From 3b33f54fb8ecdc7fa655a9e3e57da118e624169a Mon Sep 17 00:00:00 2001 From: Joel de Guzman Date: Thu, 24 Jul 2003 01:44:18 +0000 Subject: [PATCH] Added generic visitation mechanism. [SVN r19288] --- include/boost/python/class.hpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/include/boost/python/class.hpp b/include/boost/python/class.hpp index 0f0adba6..bba99585 100644 --- a/include/boost/python/class.hpp +++ b/include/boost/python/class.hpp @@ -61,6 +61,9 @@ namespace boost { namespace python { enum no_init_t { no_init }; +template +struct def_arg {}; // Generic visitor + namespace detail { // This function object is used with mpl::for_each to write the id @@ -88,7 +91,7 @@ namespace detail template struct operator_; - + // Register to_python converters for a class T. The first argument // will be mpl::true_ unless noncopyable was specified as a // class_<...> template parameter. The 2nd argument is a pointer to @@ -269,6 +272,14 @@ class class_ : public objects::class_base return *this; } + // Generic visitation + template + self& def(def_arg const& visitor) + { + static_cast(visitor).visit(*this); + return *this; + } + // Wrap a member function or a non-member function which can take // a T, T cv&, or T cv* as its first parameter, or a callable // python object.