Enhance %extend to extend a class with template methods
This commit is contained in:
parent
c923e3da77
commit
b538070016
7 changed files with 207 additions and 1 deletions
|
|
@ -3635,6 +3635,43 @@ This will generate two overloaded wrapper methods, the first will take a single
|
|||
and the second will take two integer arguments.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
It is even possible to extend a class via <tt>%extend</tt> with template methods, for example:
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
<pre>
|
||||
%include <std_string.i>
|
||||
|
||||
%inline %{
|
||||
class ExtendMe {
|
||||
public:
|
||||
template <typename T>
|
||||
T do_stuff_impl(int a, T b, double d) {
|
||||
return b;
|
||||
}
|
||||
};
|
||||
%}
|
||||
|
||||
%extend ExtendMe {
|
||||
template<typename T>
|
||||
T do_overloaded_stuff(T b) {
|
||||
return $self->do_stuff_impl(0, b, 4.0);
|
||||
}
|
||||
}
|
||||
%template(do_overloaded_stuff) ExtendMe::do_overloaded_stuff<std::string>;
|
||||
%template(do_overloaded_stuff) ExtendMe::do_overloaded_stuff<double>;
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
The wrapped <tt>ExtendMe</tt> class will then have two (overloaded) methods called <tt>do_overloaded_stuff</tt>.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Compatibility Note</b>: Extending a class with template methods was added in version 3.0.12
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Needless to say, SWIG's template support provides plenty of opportunities to
|
||||
break the universe. That said, an important final point is that <b>SWIG does
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue