Topic: reference-returning conversion operators- overload question
Author: bparker@gil.com.au (Brian Parker)
Date: 1997/05/02 Raw View
I have a matrix class that uses a proxy object to differentiate lvalue
and rvalue usage similar to the following-
template<typename T>
class Proxy {
public:
// conversion operator 1
operator const T( ) const { ... };
// conversion operator 2
operator T& ( ) const { ... };
...
};
The intent is that operator 1 will be called to evaluate the proxy for
rvalue usage, and operator 2 will be called only when initialising a
non-const reference (i.e. lvalue usage).
By my reading of the CD2, this should be the case.
operator 2 will be called when initialising a non-const reference as
operator 1 is simply not a viable function in this case.
When initialising a const reference (or calling a function with a
const T & parameter), operator 1 should be preferred as it avoids the
CV conversion that operator 2 would require.
When calling a function with a T parameter, operator 1 would be
preferred as it avoids the lvalue-to-rvalue conversion that operator 2
would require.
Can anyone confirm whether this is an accurate interpretation of the
CD2 rules?
What if operator 1 was changed to operator T( ) const, or T is a
non-class type (where top level cv qualifiers are not significant)?
Thanks,
Brian Parker (bparker@gil.com.au)
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]