Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: Simulating ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 11 of 11 Topic 9498 of 10096
Post > Topic >>

Re: Simulating new user-defined operators

by Vidar Hasfjord <vattilah-groups@[EMAIL PROTECTED] > Apr 16, 2008 at 04:13 AM

On Apr 15, 4:25 am, Michael Aaron Safyan <michaelsaf...@[EMAIL PROTECTED]
>
wrote:
> Using operator% in this manner would never pass my code review, because
> this usage has absolutely nothing to do with taking the modulus of a
> value, and -- therefore -- this usage is unintuitive.

Reserving the % operator for the modulus operation seems a waste of a
good operator among a sparse selection. In an application close to 100
thousand lines of C++ code I can count on one hand the number of times
% is used for modulus (5 out of 761 hits on '%', some of which are in
comments).

Knowledge about operator plus type is required to understand any C++
code. That's the nature of overloading. You may have noticed that I
included the use of Boost Format in my example. It also makes good use
of the % operator (and the operator choice is not arbitrary).

> For the second example, functions should throw exceptions, by default.

My usage example made use of the Win32 DeleteFile function. Sometimes
you need to deal with C or C++ libraries that use error codes. In
these cases it is very convenient to tag all the calls with E%
"operators" to ensure that no error code will go untested. I'm sure
untested error codes is a major issue throughout the C/C++ programming
world, not just in my code. E% makes it as little hassle as possible
to add the tests.

Regards,
Vidar Hasfjord

-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 11 Posts in Topic:
Simulating new user-defined operators
Vidar Hasfjord <vattil  2008-04-14 12:43:32 
Re: Simulating new user-defined operators
Michael Aaron Safyan <  2008-04-14 21:25:12 
Re: Simulating new user-defined operators
"Martin T." <  2008-04-15 12:28:37 
Re: Simulating new user-defined operators
Edward Rosten <Edward.  2008-04-15 12:33:04 
Re: Simulating new user-defined operators
Alberto Ganesh Barbati &l  2008-04-15 23:19:14 
Re: Simulating new user-defined operators
Seungbeom Kim <musiphi  2008-04-15 23:18:03 
Re: Simulating new user-defined operators
ManicQin <ManicQin@[EM  2008-04-16 03:58:47 
Re: Simulating new user-defined operators
Vidar Hasfjord <vattil  2008-04-16 03:55:06 
Re: Simulating new user-defined operators
Carl Barron <cbarron41  2008-04-16 03:59:56 
Re: Simulating new user-defined operators
Michael Aaron Safyan <  2008-04-16 04:13:19 
Re: Simulating new user-defined operators
Vidar Hasfjord <vattil  2008-04-16 04:13:19 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Oct 14 8:30:59 CDT 2008.