1 /* This testcase shows a few simple ways to deal with the new initializer_list
2    introduced in C++11. */
3 %module cpp11_initializer_list
4 
5 %warnfilter(SWIGWARN_TYPEMAP_INITIALIZER_LIST) B::B;
6 %ignore A::A(std::initializer_list<int>);
7 %ignore B::method;
8 
9 %typemap(in) std::initializer_list<const char *> %{
10   $1 = {"Ab", "Fab"};
11 %}
12 
13 %begin %{
14 #if __GNUC__ >= 9
15 /* warning: ‘new’ of initializer_list does not extend the lifetime of the underlying array [-Winit-list-lifetime] */
16 /* incorrect warning for C::C(std::initializer_list<const char *>) */
17 #pragma GCC diagnostic ignored "-Winit-list-lifetime"
18 #endif
19 %}
20 
21 %inline %{
22 #include <initializer_list>
23 #include <string>
24 
25 class A {
26 public:
A(std::initializer_list<int>)27   A(std::initializer_list<int>) {}
A()28   A() {}
A(double d)29   A(double d) {}
30 };
31 class B {
32 public:
B(std::initializer_list<int>,std::initializer_list<double>)33   B(std::initializer_list<int>, std::initializer_list<double>) {}
B()34   B() {}
method(std::initializer_list<int> init)35   void method(std::initializer_list<int> init) {}
36 };
37 class C {
38   std::string joined;
39 public:
C(std::initializer_list<const char * > init)40   C(std::initializer_list<const char *> init) {
41     for (auto& val : init)
42       joined += val;
43   }
C()44   C() {}
get_joined_string()45   const char * get_joined_string() {
46     return joined.c_str();
47   }
48 };
49 %}
50 
51