Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Operator Overoverloading

Name: Cudder !MhMRSATORI!fR8duoqGZdD/iE5 2013-02-22 6:56

Studying part of a large complex middleware for a management web application, and wondering why this:
InitechString str1, str2;
...
if(!(str1 != str2))
{
    ...
}


occurred almost as often as this:
InitechString str1, str2;
...
if(str1 == str2)
{
    ...
}


I dug a little deeper and found...


// CASE-SENSITIVE COMPARISON
//
int InitechString::operator==(const InitechString& r) const
{
    return !strcmp(m_ptr, r.m_ptr);
}
// CASE-NONSESTIVE COMPARISON
//
int InitechString::operator!=(const InitechString& r) const
{
    return !!strcmp(m_ptr, r.m_ptr);
}

Name: Anonymous 2013-02-23 1:28

>>21
The funny thing is that the good way in >>7 is what happens when str1.upper() == str2.upper() is evaluated lazily. But the lazy way isn't always the fastest way. But in any case, I wouldn't expect a seeples compiler to detect the equivalence. It would have to prove all sorts of invariants about the custom string class methods, and I don't see this happening easily. Although it could happen. It would need to statically follow loops, understand the return value of malloc, remember what values were put in what positions in malloced memory...it could be hard...and I would be up to the challenge...if I didn't decide to make a different language...instead.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List