rbegin() in STL container class templates

I once told someone that not every container supports rbegin(). Now I know all standard STL container class templates define rbegin(). STL string class also supports rbegin(). By the way, If you specialize vector (or any container) class-template with your own Account class, you end up with a specialized class-template. You must re-implement rbegin() and all public methods. That’s part of the “contract”.

Now, WHO don’t support rbegin()?
– The simple array doesn’t support rbegin() or any method for that matter.
– I think ostream and istream don’t provide rbegin().
– How about hashed containers? They don’t have a rbegin()

What if someday someone creates a useful container that doesn’t support rbegin()? If your algorithm insists on a container defining rbegin(), then this algo can’t be used for that new container.

In conclusion, it’s probably more useful in practice to write utility functions accepting iterator arguments, not container arguments. Follow STL algorithm conventions.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s