%module friends_template #if defined(SWIGOCTAVE) %warnfilter(SWIGWARN_IGNORE_OPERATOR_RSHIFT_MSG) operator>>; #endif %{ template class MyClass; template int operator<<(double un, const MyClass & x) { return 0; } template int funk_hidden(double is, MyClass & x) { return 2; } template T template_friend_hidden(T t) { return t + 1; } %} %inline %{ template int operator>>(double is, MyClass & x) { return 1; } template int funk_seen(double is, MyClass & x) { return 2; } template T template_friend_seen(T t1, T t2) { return t1 + t2; } int friend_plain_seen(int i) { return i; } template class MyClass { friend int operator<< (double un, const MyClass & x); friend int operator>> (double is, MyClass & x); friend int funk_hidden (double is, MyClass & x); friend int funk_seen (double is, MyClass & x); }; struct MyTemplate { template friend T template_friend_hidden(T); template friend T template_friend_seen(T, T); friend int friend_plain_seen(int i); }; MyClass makeMyClassInt() { return MyClass(); } %} // Although the friends in MyClass are automatically instantiated via %template(MyClassDouble) MyClass, // the operator friends are not valid and hence %rename is needed. %rename(OperatorInputDouble) operator>> ; %rename(OperatorOutputDouble) operator<< ; %template(MyClassDouble) MyClass; %template(TemplateFriendHiddenInt) template_friend_hidden; %template(TemplateFriendSeenInt) template_friend_seen; // These have no %template(XX) MyClass to instantiate, but they can be instantiated separately... %template(OperatorInputInt) operator>> ; %template(OperatorFunkSeenInt) funk_seen ;