On 02/18/2016 05:04 AM, Seb wrote:

> However on the other side we learn the stack syntax with return at
> university

You must have seen it in the context of reference types, no? There is no problem in languages that don't have value types. The problem is with the final copying of the value to the caller's context. If that operation throws, then the function is not strongly exception safe.

> (it's even on wikipedia [2]) and thus I am a friend of such a
> syntax:

> [2] https://en.wikipedia.org/wiki/Stack_(abstract_data_type)

That Wikipedia article has no mention of "exception". Dismissed... :)

Exception safety involves "cohesion". That's the term Herb Sutter had used in the context of C++ exception safety. One of his guidelines:

"Prefer cohesion. Always endeavor to give each piece of code—each module, each class, each function—a single, well-defined responsibility."

The next() you are proposing is inferior to front() and popFront() because it mixes the two concerns: access and mutation.

I guess it would be acceptable if next() required that the copy operation on the elements were @nothrow. I think then it would be safe.

Ali

Reply via email to