Avoid the gcc warning -Wno-non-template-friend

To avoid this warning, friend declarations inside template classes
must be declared as templates:
http://stackoverflow.com/questions/4039817/friend-declaration-declares-a-non-template-function