More C++11 doc and test improvements
This commit is contained in:
parent
3fb973644e
commit
adc3cfeb57
2 changed files with 38 additions and 5 deletions
|
|
@ -138,13 +138,13 @@ When either of these is used from a target language, a runtime call is made to o
|
||||||
|
|
||||||
|
|
||||||
<p>SWIG correctly parses the keywords <tt>extern template</tt>.
|
<p>SWIG correctly parses the keywords <tt>extern template</tt>.
|
||||||
However, this template instantiation suppression in a translation unit has no relevance for SWIG.
|
However, this template instantiation suppression in a translation unit has no relevance outside of the C++ compiler and so is not used by SWIG.
|
||||||
SWIG only uses <tt>%template</tt> for instantiating and wrapping templates.</p>
|
SWIG only uses <tt>%template</tt> for instantiating and wrapping templates.</p>
|
||||||
|
|
||||||
<div class="code"><pre>
|
<div class="code"><pre>
|
||||||
template class std::vector<int>; // C++03 explicit instantiation in C++
|
template class std::vector<int>; // C++03 explicit instantiation in C++
|
||||||
extern template class std::vector<int>; // C++11 explicit instantiation suppression in C++
|
extern template class std::vector<int>; // C++11 explicit instantiation suppression in C++
|
||||||
%template(VectorInt) std::vector<int>; // SWIG instantiation
|
%template(VectorInt) std::vector<int>; // SWIG instantiation
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<H3><a name="CPlusPlus11_initializer_lists"></a>7.2.4 Initializer lists</H3>
|
<H3><a name="CPlusPlus11_initializer_lists"></a>7.2.4 Initializer lists</H3>
|
||||||
|
|
@ -400,7 +400,8 @@ auto square(float a, float b) -> decltype(a);
|
||||||
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
SWIG is able to handle constructor delegation, such as:
|
There are three parts to object construction improvement.
|
||||||
|
The first improvement is constructor delegation such as the following:
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div class="code"><pre>
|
<div class="code"><pre>
|
||||||
|
|
@ -418,7 +419,13 @@ public:
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Constructor inheritance is parsed correctly, but the additional constructors are not currently added to the derived proxy class in the target language. Example is shown below:
|
where peer constructors can be called. SWIG handles this without any issue.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The second improvement is constructor inheritance via a <tt>using</tt> declaration.
|
||||||
|
This is parsed correctly, but the additional constructors are not currently added to the derived proxy class in the target language.
|
||||||
|
An example is shown below:
|
||||||
<!--
|
<!--
|
||||||
The extra constructors provided by the <tt>using</tt> syntax will add the appropriate constructors into the target language proxy derived classes.
|
The extra constructors provided by the <tt>using</tt> syntax will add the appropriate constructors into the target language proxy derived classes.
|
||||||
In the example below a wrapper for the <tt>DerivedClass(int)</tt> is added to <tt>DerivedClass</tt>:
|
In the example below a wrapper for the <tt>DerivedClass(int)</tt> is added to <tt>DerivedClass</tt>:
|
||||||
|
|
@ -437,6 +444,21 @@ class DerivedClass: public BaseClass {
|
||||||
};
|
};
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The final part is member initialization at the site of the declaration.
|
||||||
|
This kind of initialization is handled by SWIG.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="code"><pre>
|
||||||
|
class SomeClass {
|
||||||
|
public:
|
||||||
|
SomeClass() {}
|
||||||
|
explicit SomeClass(int new_value) : value(new_value) {}
|
||||||
|
|
||||||
|
int value = 5;
|
||||||
|
};
|
||||||
|
</pre></div>
|
||||||
|
|
||||||
<H3><a name="CPlusPlus11_explicit_overrides_final"></a>Explicit overrides and final</H3>
|
<H3><a name="CPlusPlus11_explicit_overrides_final"></a>Explicit overrides and final</H3>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
%module cpp11_inheriting_constructors
|
%module cpp11_inheriting_constructors
|
||||||
|
|
||||||
%inline %{
|
%inline %{
|
||||||
|
// Delegating constructors
|
||||||
class BaseClass {
|
class BaseClass {
|
||||||
private:
|
private:
|
||||||
int _val;
|
int _val;
|
||||||
|
|
@ -11,8 +12,18 @@ public:
|
||||||
BaseClass(int iValue) { _val = iValue; }
|
BaseClass(int iValue) { _val = iValue; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Constructor inheritance via using declaration
|
||||||
class DerivedClass: public BaseClass {
|
class DerivedClass: public BaseClass {
|
||||||
public:
|
public:
|
||||||
using BaseClass::BaseClass; // Adds DerivedClass(int) constructor
|
using BaseClass::BaseClass; // Adds DerivedClass(int) constructor
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Member initialization at the site of the declaration
|
||||||
|
class SomeClass {
|
||||||
|
public:
|
||||||
|
SomeClass() {}
|
||||||
|
explicit SomeClass(int new_value) : value(new_value) {}
|
||||||
|
|
||||||
|
int value = 5;
|
||||||
|
};
|
||||||
%}
|
%}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue