I have a little bit of C++ that I want to make accessible in python.
DynamicArray.h:
#include <vector>
#include <stdexcept>
namespace mspace {
template <class T>
class DynamicArray {
// lets piggyback on std::vector.
std::vector<T> m_implementation;
public:
typedef std::vector::size_type size_type;
typedef T& reference;
typedef const T& const_reference;
const_reference operator [](size_type i) const noexcept(false)
{
if (i >= m_implementation.size())
throw std::out_of_range("Ouch i >= DynamicArray.size() ");
return m_implementation[i];
}
reference operator[](size_type i) noexcept(false)
{
if (i >= m_implementation.size())
throw std::out_of_range("Ouch i >= DynamicArray.size() ");
return m_implementation[i];
}
};
}
The problem is that I use operator[] and swig tells me: DynamicArray.h:25: Warning 389: operator[] ignored (consider using %extend)
. Ok apparently swig has good reasons that it cannot automatically wrap the mspace::DynamicArray::operator[]
I get the warning once for the const and regular version.
What I'm actually doing, like swig suggests, is include an extra file where I extend the dynamic array and once I can see it works in python, then I want to silence the warning.
Let pretend I've actually extended the DynamicArray. TI currently have something less verbose than this, but no matter what I try, I keep having the warning message. My interface file array.i:
%module mspace;
%{
#include "DynamicArray.h"
%}
%include "exception.i"
%warnfilter (389) DynamicArray::operator[] const;
%warnfilter (389) DynamicArray::operator[] ;
%warnfilter (389) DynamicArray<int>::operator[] const;
%warnfilter (389) DynamicArray<int>::operator[] ;
%warnfilter (389) mspace::DynamicArray<int>::operator[] const;
%warnfilter (389) mspace::DynamicArray<int>::operator[] ;
%include "DynamicArray.h"
%warnfilter (389) DynamicArray::operator[] const;
%warnfilter (389) DynamicArray::operator[] ;
%warnfilter (389) DynamicArray<int>::operator[] const;
%warnfilter (389) DynamicArray<int>::operator[] ;
%warnfilter (389) mspace::DynamicArray<int>::operator[] const;
%warnfilter (389) mspace::DynamicArray<int>::operator[] ;
%template (IntArray) mspace::DynamicArray<int>;
I run swig as: swig -python -c++ -Wall array.i
or swig -python -builtin -c++ -Wall array.i
I'use swig 3.0.8 from the ubuntu-16.04 repositories.
I want to see the warnings, but also I want to remove the warnings when I've worked my way around them via extend. Has anyone any Idea what I'm missing. Because, I'm afraid that in my project I'm missing the warnings that I haven't worked around yet, because the list of these kinds of warnings keeps growing as my project grows.