%module li_boost_array #if defined(SWIGPYTHON) || defined(SWIGRUBY) // Hack to use the std::array support for boost::array. // Is limited as it currently exposes some 'using' bugs in SWIG though. // For example, the type system fails to see that pointers to std::array // and pointers to boost::array are the same. %{ #if __cplusplus >= 201103 || (defined(_MSC_VER) && _MSC_VER >= 1900) // Use C++11 array as this is unfortunately sometimes included by #include namespace boost { using std::array; } #else #include namespace std { using boost::array; } #endif %} namespace boost { using std::array; } %include %template(ArrayInt6) std::array; %inline %{ boost::array arrayOutVal() { const signed char carray[] = { -2, -1, 0, 0, 1, 2 }; boost::array myarray; for (size_t i=0; i<6; ++i) { myarray[i] = carray[i]; } return myarray; } boost::array & arrayOutRef() { static boost::array a = { -2, -1, 0, 0, 1, 2 }; return a; } const boost::array & arrayOutConstRef() { static boost::array a = { -2, -1, 0, 0, 1, 2 }; return a; } boost::array * arrayOutPtr() { static boost::array a = { -2, -1, 0, 0, 1, 2 }; return &a; } boost::array arrayInVal(boost::array myarray) { for (boost::array::iterator it = myarray.begin(); it!=myarray.end(); ++it) { *it *= 10; } return myarray; } const boost::array & arrayInConstRef(const boost::array & myarray) { static boost::array a = myarray; for (boost::array::iterator it = a.begin(); it!=a.end(); ++it) { *it *= 10; } return a; } void arrayInRef(boost::array & myarray) { for (boost::array::iterator it = myarray.begin(); it!=myarray.end(); ++it) { *it *= 10; } } void arrayInPtr(boost::array * myarray) { for (boost::array::iterator it = myarray->begin(); it!=myarray->end(); ++it) { *it *= 10; } } %} #endif