
2011/10/15 Peter Dimov <pdimov@pdimov.com>:
Dave Abrahams wrote:
on Fri Oct 14 2011, "Peter Dimov" <pdimov-AT-pdimov.com> wrote:
try { do some push_backs into a static_vector; we don't know how many } catch( out_of_capacity& ) { // ignore, what we gathered so far is good enough for gov't use }
Yes, it's possible, but highly unusual, for someone to use the class that way.
I'm not sure of that either. What makes you think so? What are the "proper" uses for it?
Exceptions shouldn't be used for something which is not an exceptional case. In this case it's checking how many elements you may push. They shouldn't be used as a part of "normal" program flow. I'd rather use the following: while ( sv.size() < sv.capacity() && keep_pushing ) // do a push_back into a static_vector If someone saw a try/catch block he would think it's something unusual handled here, but it isn't. What would you do if std::vector had thrown std::bad_alloc? Ignore it as well? Probably not because it's an exceptional case and you probably should finish some routine, deallocate memory, release resources, exit your program, redesign your code because blocks of memory you want to allocate are too big or do something similar. Regards, Adam