Kimon Hoffmann wrote:
> What I'd like to know is whether there is some way to make HalfWorking
> work with fully qualified calls to func() like the one in
> cool_algorithm_2(), besides the obvious solution to move HalfWorking
> together with the function overload into the default_impl namespace.
Fully qualified no, but something similar is possible. It is quite
commonly
used:
using default_impl::func;
func(x);
This will call ::func(const HalfWorking&) for arguments of type
HalfWorking,
and default_impl::func for anything convertible to DefaultType.
The usual use for this idiom is std::swap, because you want to use
std::swap
for anything that doesn't have a swap function, and find the overloads by
ADL where there is one. Also, you should use it for all std functions that
operate on standard types if you want to overload them for your types and
find the overloads by ADL (you obviously cannot move your overloads to
std::) For example, you can create class your_ns::matrix, which would be
eg. a real matrix. Then, you can define a function
your_ns::matrix your_ns::exp(your_ns::matrix);
which would be an exponential of the matrix. In generic code, you would
then
do
using std::exp;
T y=exp(2*x); // .. or whatever ..
and that would call std::exp for double, float, long double (also int),
and
your_ns::exp for your matrices.
Note that you also need this if a C library leaves its definitions in the
::
scope. For example, abs(0.5) might call ::abs(int) which is really sad :-(
Regards
Jiri Palecek
--
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


|