Required safety checks

D

Dave

Hello all,

In general, the STL doesn't have to perform safety checks. But there are
some exceptions, and I'm trying to find as many examples as I can. For
example, vector::at() must perform checking and throw an exception if the
safety checks fail. For people who know of cases where the Standard
*requires* a check, please shout it out!

Thanks,
Dave
 
V

Victor Bazarov

Dave said:
In general, the STL doesn't have to perform safety checks. But there are
some exceptions, and I'm trying to find as many examples as I can. For
example, vector::at() must perform checking and throw an exception if the
safety checks fail. For people who know of cases where the Standard
*requires* a check, please shout it out!

Uh... Why don't you get a copy of the Standard and just read all the
"examples" from there. It specifies precisely which functions throw
(or may throw) what exceptions.

V
 
E

E. Robert Tisdale

Dave said:
In general, the STL doesn't have to perform safety checks.
But there are some exceptions
and I'm trying to find as many examples as I can.
For example, vector::at() must perform [range] checking
and throw an exception if the safety checks fail.

My GNU C++ compiler defines:

reference
operator[](size_type __n) { return *(begin() + __n); }

const_reference
operator[](size_type __n) const { return *(begin() + __n); }

You could redefine them:

reference
operator[](size_type __n) {
assert(__n < this->size()); return *(begin() + __n); }

const_reference
operator[](size_type __n) const {
assert(__n < this->size()); return *(begin() + __n); }
 
M

Mike Wahler

Dave said:
Hello all,

In general, the STL doesn't have to perform safety checks. But there are
some exceptions, and I'm trying to find as many examples as I can. For
example, vector::at() must perform checking and throw an exception if the
safety checks fail. For people who know of cases where the Standard
*requires* a check, please shout it out!

Gimme twenty dollars and I'll tell ya.

No, wait, if you have twenty dollars, you can purchase
your very own copy of the ISO C++ standard, and learn
about this (and many other interesting things) for yourself.
www.webstore.ansi.org Search for "14882".

-Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,127
Latest member
CyberDefense
Top