Boost logo

Boost Users :

From: Daryle Walker (darylew_at_[hidden])
Date: 2008-07-17 06:02:22


On Jul 16, 2008, at 6:24 PM, Joshua Perry wrote:

> A function like you mention (maybe vector<OrderPtr>
> Customer::GetUnfulfilledOrders( void ); ) could return an vector
> or custom collection with 0 elements, however with a function like
> OrderPtr Customer::GetOrder(int ordern); to me it feels natural to
> throw an exception.

I think this is more like a find function, so you could return an
iterator to the appropriate element, and return a one-past-the-end
iterator if the order number wasn't found. In your example, you're
effectively trying to run a find and then return a dereferenced
result. I guess that you are trying to hide any container-ness about
the order system, so either returning an order reference or throwing
is probably better, but only if you expect the user to never try
entering invalid order numbers. If entering invalid numbers is a
standard occurrence (pre-checking is too hard and/or not expected),
then it wouldn't be a post-condition violation, and a null-pointer
should be returned instead.

-- 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT hotmail DOT com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net