C++11 rvalue reference docs updated.
This commit is contained in:
parent
7a96fba836
commit
5f7f8f17eb
1 changed files with 55 additions and 26 deletions
|
|
@ -62,12 +62,15 @@
|
||||||
|
|
||||||
<p>This chapter gives you a brief overview about the SWIG
|
<p>This chapter gives you a brief overview about the SWIG
|
||||||
implementation of the C++11 standard. This part of SWIG is still a work in
|
implementation of the C++11 standard. This part of SWIG is still a work in
|
||||||
progress. Initial C++11 support for SWIG was written during the
|
progress.
|
||||||
Google Summer of Code 2009 period.</p>
|
</p>
|
||||||
<p>SWIG supports all the new C++ syntax changes with some minor limitations
|
<p>SWIG supports the new C++ syntax changes with some minor limitations
|
||||||
(decltype expressions, variadic templates number). Wrappers for the
|
(decltype expressions, variadic templates number). Wrappers for the
|
||||||
new STL types (unordered_ containers, result_of, tuples) are not supported
|
new STL types (unordered_ containers, result_of, tuples) are incomplete.
|
||||||
yet.</p>
|
The wrappers for the new containers would work much like the C++03 containers and
|
||||||
|
users are welcome to help by adapting the existing container interface files and submitting them
|
||||||
|
as a patch for inclusion in future versions of SWIG.
|
||||||
|
</p>
|
||||||
|
|
||||||
<H2><a name="CPlusPlus11_core_language_changes"></a>7.2 Core language changes</H2>
|
<H2><a name="CPlusPlus11_core_language_changes"></a>7.2 Core language changes</H2>
|
||||||
|
|
||||||
|
|
@ -75,19 +78,45 @@ yet.</p>
|
||||||
<H3><a name="CPlusPlus11_rvalue_reference_and_move_semantics"></a>7.2.1 Rvalue reference and move semantics</H3>
|
<H3><a name="CPlusPlus11_rvalue_reference_and_move_semantics"></a>7.2.1 Rvalue reference and move semantics</H3>
|
||||||
|
|
||||||
|
|
||||||
<p>SWIG correctly parses the new operator && the same as the reference operator &.</p>
|
<p>
|
||||||
|
SWIG correctly parses the rvalue reference syntax '&&',
|
||||||
|
for example the typical usage of it in the move constructor and move assignment operator below:
|
||||||
|
</p>
|
||||||
|
|
||||||
<p>The wrapper for the following code is correctly produced:</p>
|
|
||||||
<div class="code"><pre>
|
<div class="code"><pre>
|
||||||
class MyClass {
|
class MyClass {
|
||||||
MyClass(MyClass&& p) : ptr(p.ptr) {p.ptr = 0;}
|
...
|
||||||
MyClass& operator=(MyClass&& p) {
|
std::vector<int> numbers;
|
||||||
std::swap(ptr, p.ptr);
|
public:
|
||||||
|
MyClass(MyClass &&other) : numbers(std::move(other.numbers)) {}
|
||||||
|
MyClass & operator=(MyClass &&other) {
|
||||||
|
numbers = std::move(other.numbers);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Rvalue references are designed for C++ temporaries and so are not very useful when used from non-C++ target languages.
|
||||||
|
Generally you would just ignore them via <tt>%ignore</tt> before parsing the class.
|
||||||
|
For example, ignore the move constructor:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="code"><pre>
|
||||||
|
%ignore MyClass::MyClass(MyClass &&);
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The plan is to ignore them by default in a future version of SWIG. Note that both normal assignment operators as well as move assignment operators are ignored by default in most target languages with the following warning:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="shell">
|
||||||
|
<pre>
|
||||||
|
example.i:18: Warning 503: Can't wrap 'operator =' unless renamed to a valid identifier.
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<H3><a name="CPlusPlus11_generalized_constant_expressions"></a>7.2.2 Generalized constant expressions</H3>
|
<H3><a name="CPlusPlus11_generalized_constant_expressions"></a>7.2.2 Generalized constant expressions</H3>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue