
"Jonathan Turkanis" <technews@kangaroologic.com> wrote in message news:d7j8it$1pt$1@sea.gmane.org...
christopher diggins wrote:
violates the container postconditions. Just for example consider the following common idiom:
template<class Container_T> void some_very_dangerous_code(Container_T& x) { x = Container_T(); if (x.empty()} { SayHelloToAlphaCentauri(); } else { SendNukesToAlphaCentauri(); } }
Obviously this will not work as expected.
What's expected here?
What was expected was that the SendNukesToAlphaCentauri() control path should never be executed BUT I made a big mistake (and a common one at that). I assumed x == y implied x.size() == y.size() for standard containers. That is not in fact an explicit postcondition of containers as far as I know. Since the example is unsatisfactory here is another: template<class Container_T> void some_very_dangerous_code() { Container_T x(); if (x.empty()} { SayHelloToAlphaCentauri(); } else { SendNukesToAlphaCentauri(); } } The point is not whether or not this is a good example but rather that incorrect and unexpected (possibly disastrous) behaviour will be exhibited in existing code by using a non-conformant container in a context where a conformant container is expected. -- Christopher Diggins http://www.cdiggins.com