'How to redefine a public type alias as a member function in a SWIG interface file?

I have some type with a public type definition iterator.

struct MyType
{
  using iterator = ...;
};

This type needs to be wrapped for usage in Java, and I am experimenting with making this type iterable from Java. For that, I need to extend the type with an iterator() function that returns some proxy type that wraps some iterator, something along the following lines is in the interface file:

%extend MyType {
  MyTypeIterator *iterator() const
  {
    return new MyTypeIterator(*$self);
  }
}

This results in the following SWIG warning:

Warning 302: Identifier 'iterator' redefined (ignored),

One solution is to wrap using iterator in the C++ file with #ifndef SWIG, but I would like to fix this from the interface file. Is it possible to redefine iterator from the interface file and give a custom meaning to it, in this case the member function above?

In case I either rename or ignore iterator in the interface file, this also applies to the extension code, so the end result is either that the extension is ignored (%ignore), or that the warning persists (%rename).



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source