comp.lang.c++@googlegroups.com | Google Groups | ![]() |
Unsure why you received this message? You previously subscribed to digests from this group, but we haven't been sending them for a while. We fixed that, but if you don't want to get these messages, send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
- to Tiib - 4 Updates
- The scope of __finally (C++ Builder 2010) - 4 Updates
- Name Look Behavior - 1 Update
"Öö Tiib" <ootiib@hot.ee>: Nov 20 11:22PM -0800 On Monday, 17 November 2014 03:36:58 UTC+2, JiiPee wrote: > increases the speed by another 10%. > And it is really impressive that it takes only about 17 seconds on my > machine (1 cpu) to so all the integers from 0 to 4294967293. For the desire of having lot of 'goto' and 'c++' in code I wrote such thing: void uint32ToStr_goto(uint32_t i, char* c) { if (i < 1000000) { if (i < 10000) { if (i < 100) { if (i < 10) goto OneDigit; goto TwoDigits; } if (i < 1000) goto ThreeDigits; goto FourDigits; } if (i < 100000) goto FiveDigits; goto SixDigits; } if (i < 100000000) { if (i < 10000000) goto SevenDigits; goto EightDigits; } if (i < 1000000000) goto NineDigits; // ten digits 1000000000-4294967295 *c++ = '0' + (i / 1000000000); NineDigits: *c++ = '0' + (i % 1000000000) / 100000000; EightDigits: *c++ = '0' + (i % 100000000) / 10000000; SevenDigits: *c++ = '0' + (i % 10000000) / 1000000; SixDigits: *c++ = '0' + (i % 1000000) / 100000; FiveDigits: *c++ = '0' + (i % 100000) / 10000; FourDigits: *c++ = '0' + (i % 10000) / 1000; ThreeDigits: *c++ = '0' + (i % 1000) / 100; TwoDigits: *c++ = '0' + (i % 100) / 10; OneDigit: *c++ = '0' + (i % 10); *c = '\0'; } I don't think it is best performer since the main point was aesthetically and logically clear 'goto' usage. :P |
Martijn Lievaart <m@rtij.nl.invlalid>: Nov 21 01:30PM +0100 On Thu, 20 Nov 2014 23:22:29 -0800, Öö Tiib wrote: > I don't think it is best performer since the main point was > aesthetically and logically clear 'goto' usage. :P Everyone knows you should not use gotos in C++! void uint32ToStr_duff(uint32_t i, char* c) { std::array<uint32_t, 10> x = { 10,100,1000,10000,100000, 1000000,10000000,100000000,1000000000 }; auto it = std::find_if(x.begin(), x.end(), std::bind1st(std::less<uint32_t>(), i)); switch (it-x.begin()) { case 9: *c++ = '0' + (i / 1000000000); case 8: *c++ = '0' + (i % 1000000000) / 100000000; case 7: *c++ = '0' + (i % 100000000) / 10000000; case 6: *c++ = '0' + (i % 10000000) / 1000000; case 5: *c++ = '0' + (i % 1000000) / 100000; case 4: *c++ = '0' + (i % 100000) / 10000; case 3: *c++ = '0' + (i % 10000) / 1000; case 2: *c++ = '0' + (i % 1000) / 100; case 1: *c++ = '0' + (i % 100) / 10; case 0: *c++ = '0' + (i % 10); *c = '\0'; } } :-) M4 |
Juha Nieminen <nospam@thanks.invalid>: Nov 21 03:19PM > 1000000,10000000,100000000,1000000000 }; > auto it = std::find_if(x.begin(), x.end(), > std::bind1st(std::less<uint32_t>(), i)); Wouldn't std::lower_bound() be much better for that purpose? --- news://freenews.netfront.net/ - complaints: news@netfront.net --- |
"Öö Tiib" <ootiib@hot.ee>: Nov 21 07:35AM -0800 On Friday, 21 November 2014 14:35:13 UTC+2, Martijn Lievaart wrote: > > I don't think it is best performer since the main point was > > aesthetically and logically clear 'goto' usage. :P > Everyone knows you should not use gotos in C++! Everyone have been wrong before ... that earth is flat and what not. > } > } > :-) I don't get the joke. Demo: int main() { char str1[20] = "*garbage*"; uint32ToStr_goto(1234567890, str1 ); std::cout << "gotos:" << str1 << ":work" << std::endl; char str2[20] = "*garbage*"; uint32ToStr_duff(1234567890, str2 ); std::cout << "fun:" << str2 << ":here" << std::endl; } Output: gotos:1234567890:work fun:*garbage*:here Program ended with exit code: 0 :-/ |
"A" <a@a.a>: Nov 21 02:07AM +0100 "Paavo Helde" <myfirstname@osa.pri.ee> wrote in message news:XnsA3EC6B464CA4myfirstnameosapriee@216.196.109.131... > implementation (and if I am not mistaken, it is probably meant to be used > together with __try, not try). Maybe it would work better with __try, who > knows. Yes, it is not a standard keyword. But the try - __finally is valid in C++ Builder and it is meant to be used like this. > destructor), so it baffles me why somebody would ever need functionality > of > "finally" in C++, it is just inferior in every sense IMO. I do use scoped variables all the time but in this particular code I require this kind of construct. Anyway, I don't want to get into too deep discussion what is right and what is not, just the reason why is the vector destroyed in the part when it reaches __finally? |
legalize+jeeves@mail.xmission.com (Richard): Nov 21 02:02AM [Please do not mail me a copy of your followup] "A" <a@a.a> spake the secret code > 16 } >aa.size() is 0 as it goes out of scope after return i; in try part of the >block. If you get 0 for aa.size() from this code in C++ Builder, then it's a bug in C++ Builder. aa doesn't go out of scope until line 16. -- "The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline> The Computer Graphics Museum <http://computergraphicsmuseum.org> The Terminals Wiki <http://terminals.classiccmp.org> Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com> |
Paavo Helde <myfirstname@osa.pri.ee>: Nov 20 11:15PM -0600 > Anyway, I don't want to get into too > deep discussion what is right and what is not, just the reason why is > the vector destroyed in the part when it reaches __finally? Well, OK, just be aware you might not get best answers here because this is the wrong group. Cheers Paavo |
David Brown <david.brown@hesbynett.no>: Nov 21 09:03AM +0100 On 20/11/14 23:39, Paavo Helde wrote: > things like ScopeGuard if one is too lazy to write a helper class with a > destructor), so it baffles me why somebody would ever need functionality of > "finally" in C++, it is just inferior in every sense IMO. I have only briefly used C++ Builder, and that was many years ago. But I believe I can give you a more complete reasoning for the __finally extension here. C++ Builder was made by Borland to combine their C/C++ tools with Delphi, which uses their extended "Object Pascal". Object Pascal does not support RAII - its constructors and destructors are called manually rather than automatically, and thus it needs a "finally" clause for its exceptions. C++ Builder uses much of the Delphi library, and many of its users come from Delphi backgrounds - so Borland added a __finally keyword for compatibility here. |
jghickman@gmail.com: Nov 20 03:55PM -0800 I read this line from the standard before posting my original question, but after re-reading it I believe it does indeed contain the answer to the question even though I didn't realize it at the time. The Library namespace is the nearest namespace that encloses both the using directive and the namespace nominated by the using directive (i.e., Library::Inner). In this case, the names "appear as if" they were declared in the Library namespace and lookup can stop there. |
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
No comments:
Post a Comment