swig/Examples/test-suite/cpp11_initializer_list.i
William S Fulton 0c2d0fea0f Move SwigValueWrapper to header section
Recent change to SwigValueWrapper required the <utility> header.
Included headers should be after the include of the language
specific header files (which go into the earlier runtime section).

Testcase required -Winit-list-lifetime warning suppression change
for Perl which somehow lost the warning suppression when put
into the %begin section.
2022-09-09 19:36:08 +01:00

50 lines
1.1 KiB
OpenEdge ABL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* This testcase shows a few simple ways to deal with the new initializer_list
introduced in C++11. */
%module cpp11_initializer_list
%warnfilter(SWIGWARN_TYPEMAP_INITIALIZER_LIST) B::B;
%ignore A::A(std::initializer_list<int>);
%ignore B::method;
%typemap(in) std::initializer_list<const char *> %{
$1 = {"Ab", "Fab"};
%}
%runtime %{
#if __GNUC__ >= 9
/* warning: new of initializer_list does not extend the lifetime of the underlying array [-Winit-list-lifetime] */
/* incorrect warning for C::C(std::initializer_list<const char *>) */
#pragma GCC diagnostic ignored "-Winit-list-lifetime"
#endif
%}
%inline %{
#include <initializer_list>
#include <string>
class A {
public:
A(std::initializer_list<int>) {}
A() {}
A(double d) {}
};
class B {
public:
B(std::initializer_list<int>, std::initializer_list<double>) {}
B() {}
void method(std::initializer_list<int> init) {}
};
class C {
std::string joined;
public:
C(std::initializer_list<const char *> init) {
for (auto& val : init)
joined += val;
}
C() {}
const char * get_joined_string() {
return joined.c_str();
}
};
%}