Re: RAnother friend template question
On 28 Okt., 14:26, Daniel Kr?gler <daniel.krueg...@googlemail.com>
wrote:
On 28 Okt., 02:56, "Robert J. Simpson" <rob...@simpson190.fsnet.co.uk>
wrote:
[..]
template <class T> class Test;
template <class T> bool operator == (const typename Test <T>::Local&,
const
typename Test <T>::Local&);
There is a fundamental problem with this signature, namely that
template parameter T is in a non-deducible context. Since you
probably don't want users to use your operator == via explicit
template-argument provision only, like in
bool b = operator==<int>(t1, t2);
I don't see any reasonable approach without a defining friend
function in Test::Local.
And I really mean *reasonable*. It is certainly possible to
chose a different approach, e.g. by declaring up-front a
constrained operator==
template<class>
struct is_Test_Local;
template <class T>
typename std::enable_if<is_Test_Local<T>::value, bool>::type
operator == (const T&, const T&);
nominating this as friend of Test<>::Local and ensuring that
is_Test_Local is defined as a /BinaryPredicate/ that returns
true for any Test<>::Local, and false otherwise. This requires
some ugly tagging tricks, because you cannot directly
partially specialize is_Test_Local like this:
template<class T>
struct is_Test_Local<typename Test<T>::Local>;
because the compiler cannot deduce Test<T>::Local in
this context. In summary, the overall solution with this
approach is rather complicated and I would strongly
recommend the in-class-friend-definition idiom.
HTH & Greetings from Bremen,
Daniel Kr?gler
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]