home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 32,939 of 33,346   
   Jerry to oot...@hot.ee   
   Re: Legacy compiler that should (but doe   
   19 Mar 13 17:11:27   
   
   23c94cd6   
   From: jerry.jeremiah@googlemail.com   
      
   { Please put each of your comments under the relevant quoting. -mod }   
      
   On Mar 20, 1:17 am, Öö Tiib  wrote:   
   > On Tuesday, 19 March 2013 08:00:03 UTC+2, Jerry  wrote:   
   > > Consider this:   
   >   
   > > template   
   > > int operator==(const X& x, const char *y)   
   > > { return 1; }   
   >   
   > Does that legacy compiler have 'bool'? If so use 'bool' as return   
   > value of 'operator==(2)'. Otherwise you are confusing everybody, not   
   > only compilers.   
   >   
   > > template   
   > > int operator==(const X& x, const Y& y)   
   > > { return 2; }   
   >   
   > You compare anything with anything? Pretty broad task.   
   >   
   > > struct A {} a;   
   > > main()   
   > > {   
   > >    return a == "a";   
   > > }   
   >   
   > Well, if a tool is confused then that is good indication that what   
   > you do is confusing to some people too.   
   >   
   > > My question is: does anybody have a suggestion to munge the code so   
   > > that the compiler will pick the same overload GCC does?   
   >   
   > Not sure, but first thing I would get rid of the anything with   
   > anything comparison. That is something that you are incapable of   
   > doing anyway.   
   >   
   > Second thing I would try is that:   
   >   
   >    template   
   >    bool operator==( X const& x, char const (&literal)[N])   
   >    { return true; }   
   >   
   > It is likely best match comparing something with a string   
   > literal. Also you get length of string literal as N.   
   >   
      
   Thanks for the advice.  I did have bool but for testing needed to be   
   able to test more than two variants.  So I changed it to int   
   temporarily - I never intended to leave it that way.   
      
   This code will be in a namespace so will only be found with ADL when a   
   class of that namespace is being compared so the anything with   
   anything comparison makes sense.  That's the reason I don't make a   
   dozen versions of the operator== but in this test program I can see   
   how that wouldn't be obvious.   
      
   I can't believe I didn't even think of using char const (&literal)[N]   
   Of course it works perfectly.  thank you very much.   
      
   Jerry   
      
      
   --   
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca