1 %module friends_template
2
3 #if defined(SWIGOCTAVE)
4 %warnfilter(SWIGWARN_IGNORE_OPERATOR_RSHIFT_MSG) operator>>;
5 #endif
6
7
8 %{
9 template <typename Type> class MyClass;
10
11 template <typename Type> int operator<<(double un, const MyClass <Type> & x) { return 0; }
funk_hidden(double is,MyClass<Type> & x)12 template <typename Type> int funk_hidden(double is, MyClass <Type> & x) { return 2; }
13
template_friend_hidden(T t)14 template <typename T> T template_friend_hidden(T t) { return t + 1; }
15 %}
16
17 %inline %{
18 template <typename Type> int operator>>(double is, MyClass <Type> & x) { return 1; }
funk_seen(double is,MyClass<Type> & x)19 template <typename Type> int funk_seen(double is, MyClass <Type> & x) { return 2; }
template_friend_seen(T t1,T t2)20 template <typename T> T template_friend_seen(T t1, T t2) { return t1 + t2; }
friend_plain_seen(int i)21 int friend_plain_seen(int i) { return i; }
22
23 template <class Type> class MyClass
24 {
25 friend int operator<< <Type>(double un, const MyClass <Type> & x);
26 friend int operator>> <Type>(double is, MyClass <Type> & x);
27 friend int funk_hidden <Type>(double is, MyClass <Type> & x);
28 friend int funk_seen <Type>(double is, MyClass <Type> & x);
29 };
30
31 struct MyTemplate {
32 template <typename T> friend T template_friend_hidden(T);
33 template <typename T> friend T template_friend_seen(T, T);
34 friend int friend_plain_seen(int i);
35 };
36
makeMyClassInt()37 MyClass<int> makeMyClassInt() { return MyClass<int>(); }
38 %}
39
40 // Although the friends in MyClass are automatically instantiated via %template(MyClassDouble) MyClass<int>,
41 // the operator friends are not valid and hence %rename is needed.
42 %rename(OperatorInputDouble) operator>> <double>;
43 %rename(OperatorOutputDouble) operator<< <double>;
44 %template(MyClassDouble) MyClass<double>;
45
46 %template(TemplateFriendHiddenInt) template_friend_hidden<int>;
47 %template(TemplateFriendSeenInt) template_friend_seen<int>;
48
49 // These have no %template(XX) MyClass<int> to instantiate, but they can be instantiated separately...
50 %template(OperatorInputInt) operator>> <int>;
51 %template(OperatorFunkSeenInt) funk_seen <int>;
52