diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2014-03-10 18:55:57 +0000 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2014-03-14 01:57:15 +0000 |
commit | adc3cfeb571f8dd6d072bbab52eebda0bf612656 (patch) | |
tree | 4e0b124e0b5b3bc8898f3aae780b6b7b7d22ccff | |
parent | 3fb973644eaf939ef6100a03d926aafe93a7a7de (diff) | |
download | swig-adc3cfeb571f8dd6d072bbab52eebda0bf612656.tar.gz |
More C++11 doc and test improvements
-rw-r--r-- | Doc/Manual/CPlusPlus11.html | 32 | ||||
-rw-r--r-- | Examples/test-suite/cpp11_inheriting_constructors.i | 11 |
2 files changed, 38 insertions, 5 deletions
diff --git a/Doc/Manual/CPlusPlus11.html b/Doc/Manual/CPlusPlus11.html index 4317c189e..d79c3172e 100644 --- a/Doc/Manual/CPlusPlus11.html +++ b/Doc/Manual/CPlusPlus11.html @@ -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>. -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> <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++ -%template(VectorInt) std::vector<int>; // SWIG instantiation +%template(VectorInt) std::vector<int>; // SWIG instantiation </pre></div> <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> -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> <div class="code"><pre> @@ -418,7 +419,13 @@ public: </pre></div> <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. 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> +<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> <p> diff --git a/Examples/test-suite/cpp11_inheriting_constructors.i b/Examples/test-suite/cpp11_inheriting_constructors.i index e1adb4caa..ccdf050c3 100644 --- a/Examples/test-suite/cpp11_inheriting_constructors.i +++ b/Examples/test-suite/cpp11_inheriting_constructors.i @@ -4,6 +4,7 @@ %module cpp11_inheriting_constructors %inline %{ +// Delegating constructors class BaseClass { private: int _val; @@ -11,8 +12,18 @@ public: BaseClass(int iValue) { _val = iValue; } }; +// Constructor inheritance via using declaration class DerivedClass: public BaseClass { public: 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; +}; %} |