7

Is there a reason std::front and std::back are not present in C++11? There is std::begin and std::end so to me, having the equivalent with regards to actual instances would make sense.

1 Answer 1

6

std::begin() and std::end() are supposed to work for all fundamental containers (including C-style arrays).

In fact, if the container supports member begin() and end() functions, std::begin() and std::end() forward the call to those member functions.

However, not all containers support front() and back() member functions.

11
  • Just to clarify, all containers really mean all containers, even plain arrays. Feb 14, 2013 at 17:09
  • @JoachimPileborg: Sure. But I will emphasize this, thank you.
    – Andy Prowl
    Feb 14, 2013 at 17:09
  • 2
    Though, std::stack does not support begin and end.
    – abergmeier
    Feb 14, 2013 at 17:10
  • 4
    @LCIDFire: True. That's a container adapter though, not a fundamental container.
    – Andy Prowl
    Feb 14, 2013 at 17:13
  • 2
    @LCIDFire: Not all fundamental containers have a bidirectional iterator though (see forward_list).
    – Andy Prowl
    Feb 14, 2013 at 17:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.