[PATCH] KSharedPtr operator== problem
Thiago Macieira
thiago at kde.org
Sat Oct 4 08:29:12 BST 2008
Adriaan de Groot wrote:
>But in this particular case I'd like to doubt Thiago's words: template
> friends are documented to work in MSVC [1], IBM XL C++ [2]. I may be
> missing a subtlety here, though. I haven't actually tried compiling
> KSharedPtr with the earlier proposed patch in Sun Studio, though. I'll
> try it in the morning. Suffice to say the proposed workaround doesn't
> seem nice at all to me. Don't forget that the range of KDE-supported
> compilers is smaller than the range of Qt supported compilers (right?)
> so we need to just check those -- and the C++ standard. A quick search
> didn't turn up any chapter and verse saying you can't have template
> friends.
The range of KDE-supported compilers is a subset (not just smaller) of the
range of Qt supported compilers.
I tried this technique for QSharedPointer (Qt 4.5 code) and the result was
quite clear: only gcc supported it. Not even the latest versions of
Microsoft Visual Studio, Intel CC or HP-UX's aCC support it.
Unfortunately, I couldn't test the latest of SunStudio, but SunCC 5.5
doesn't support either.
I asked our C++ standard experts in-house about the subject. Roberto
couldn't come up with a definitive answer: we can't decide whether the
standard allows it or not.
In any case, the solution is very simple anyways, invert the comparison:
template <class T> bool operator== (const T* p, const KSharedPtr<T>& o)
{ return o == p; }
template <class T> bool operator!= (const T* p, const KSharedPtr<T>& o)
{ return o != p; }
--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
PGP/GPG: 0x6EF45358; fingerprint:
E067 918B B660 DBD1 105C 966C 33F5 F005 6EF4 5358
More information about the kde-core-devel
mailing list