--- Begin Message ---
On 10 Aug 2002 at 17:50, Laurence Withers wrote:
> class fix {
> public:
> // ...
> void radtofix() throw() { v = radtofix(v); }
> void fixtorad() throw() { v = fixtorad(v); }
> };
I used to use no-throw exception specifiers, but check this out:
http://www.boost.org/more/lib_guide.htm#Exception-specification
The bad thing about C++ is even if you declare "throw()" it doesn't mean a
function throws nothing. Any C++ code can throw any exception at any time.
The thing that the "throw()" does is run the bad exception type handler if
you throw something, or if you throw a non-specified exception. This is
the reason why some compilers have to implicitly place try/catch blocks in
your code, and entering these blocks affects performance. Therefore with
the combonation that the exception specifier really means nothing and helps
no one and gives no guarantees and decreases performance, I think I may
agree with Boost's rationale.
While not particularly asking for a change, there is an alternate API
choice we can consider:
class fix {
public:
// ...
fix radtofix() const { return fix(radtofix(v)); }
fix fixtorad() const { return fix(fixtorad(v)); }
static fix radtofix( float x ) { return fix(radtofix(ftofix(x))); }
};
This has the benefit of allowing rad/fix conversions for const fix objects.
The static function is not really related, but might be another useful
addition.
Gillius
--- End Message ---