aboutsummaryrefslogtreecommitdiff
path: root/Examples/test-suite
diff options
context:
space:
mode:
authorWilliam S Fulton <wsf@fultondesigns.co.uk>2014-03-12 21:15:14 +0000
committerWilliam S Fulton <wsf@fultondesigns.co.uk>2014-03-14 01:57:16 +0000
commita542c5277d4ae3f9165997666ee6706fea21e579 (patch)
treeb8b0380eeeb44d704c1dddcfdae4f9720cb5b32d /Examples/test-suite
parentfd5f4c25aa1ba62157aded4b4a140485e7fb0506 (diff)
downloadswig-a542c5277d4ae3f9165997666ee6706fea21e579.tar.gz
C++11 std::reference_wrapper example - no support
Diffstat (limited to 'Examples/test-suite')
-rw-r--r--Examples/test-suite/common.mk1
-rw-r--r--Examples/test-suite/cpp11_reference_wrapper.i36
2 files changed, 37 insertions, 0 deletions
diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk
index 4106e17d5..cb792b8b5 100644
--- a/Examples/test-suite/common.mk
+++ b/Examples/test-suite/common.mk
@@ -530,6 +530,7 @@ CPP11_TEST_BROKEN = \
# cpp11_result_of \ # SWIG does not support
# cpp11_strongly_typed_enumerations \ # SWIG not quite getting this right yet in all langs
# cpp11_variadic_templates \ # Broken for some languages (such as Java)
+# cpp11_reference_wrapper \ # No typemaps
#
diff --git a/Examples/test-suite/cpp11_reference_wrapper.i b/Examples/test-suite/cpp11_reference_wrapper.i
new file mode 100644
index 000000000..e50a7ef62
--- /dev/null
+++ b/Examples/test-suite/cpp11_reference_wrapper.i
@@ -0,0 +1,36 @@
+%module cpp11_reference_wrapper
+
+// SWIG could provide some sort of typemaps for reference_wrapper which is acts like a C++ reference,
+// but is copy-constructible and copy-assignable
+
+%inline %{
+#include <iostream>
+#include <functional>
+using namespace std;
+
+struct B {
+ B(int &val) : val(val) {}
+ std::reference_wrapper<int> val;
+// int &val;
+};
+%}
+
+%inline %{
+void go() {
+ int val(999);
+ B b1(val);
+ int const& aa1 = b1.val;
+ cout << aa1 << endl;
+
+ // copy constructible
+ B b2(b1);
+ int const& aa2 = b2.val;
+ cout << aa2 << endl;
+
+ // copy assignable
+ B b3(val);
+ b3 = b1;
+ int const& aa3 = b3.val;
+ cout << aa3 << endl;
+}
+%}