Skip to content

Commit 3b33f54

Browse files
committed
Added generic visitation mechanism.
[SVN r19288]
1 parent 42ab6b6 commit 3b33f54

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

include/boost/python/class.hpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ namespace boost { namespace python {
6161

6262
enum no_init_t { no_init };
6363

64+
template <class Derived>
65+
struct def_arg {}; // Generic visitor
66+
6467
namespace detail
6568
{
6669
// This function object is used with mpl::for_each to write the id
@@ -88,7 +91,7 @@ namespace detail
8891

8992
template <detail::operator_id, class L, class R>
9093
struct operator_;
91-
94+
9295
// Register to_python converters for a class T. The first argument
9396
// will be mpl::true_ unless noncopyable was specified as a
9497
// class_<...> template parameter. The 2nd argument is a pointer to
@@ -269,6 +272,14 @@ class class_ : public objects::class_base
269272
return *this;
270273
}
271274

275+
// Generic visitation
276+
template <class Derived>
277+
self& def(def_arg<Derived> const& visitor)
278+
{
279+
static_cast<Derived const&>(visitor).visit(*this);
280+
return *this;
281+
}
282+
272283
// Wrap a member function or a non-member function which can take
273284
// a T, T cv&, or T cv* as its first parameter, or a callable
274285
// python object.

0 commit comments

Comments
 (0)