On Mon, Oct 20, 2008 at 10:19 PM, Steven Watanabe
AMDG
Peng Yu wrote:
In line 51-55 of you attached file, it says the following.
template
Y ::result_type> operator*(const Y<T1> &y, const T2 &t) { return Y<T1>(y.the_t() * t); } This way requires that I have to explicitly say 'multiply_traits' is from the namespace A. I wanted to use the following instead, which does not need to specify which the namespaces T1 and T2 are. But the following code still results in the compiler error.
template
Y operator*(const Y<T1> &y, const T2 &t) { return Y<T1>(y.the_t() * t); } My question is not resolved. I'm attaching the source file with some comments to avoid any confusion. Would you please take another look at the problem?
Alright. If you don't want to refer to multiply_traits from namespace A, then put a generic multiply_traits somewhere else. When it is defined using Boost.Typeof, it will work for any types. It does not matter what namespace multiply_traits is defined in. Really.
This is a reasonable solution. But no matter which namespace multiply_traits puts, it pollutes that namespace. Since namespace is a way to better organized the code, I'd rather multiply_traits be in the same namespace as that of its associated types. Since Koenig lookup can be used to deduce the namespace of a function based on whether its arugments are from, I'm wondering why C++ does not allow such look up for templates? If Koenig lookup can be used for template, then the problem is solved. Thanks, Peng