If front()
returns a reference and the container is empty what do I get, an undefined reference? Does it mean I need to check empty()
before each
You've always have to be sure your container is not empty before calling front() on this instance. Calling empty() as a safe guard is good.
Of course, depending on your programm design, always having a non-empty container could be an invariant statement allowing you to prevent and save the call to empty() each time you call front(). (or at least in some part of your code?)
But as stated above, if you want to avoid undefinied behavior in your program, make it a strong invariant.