Boost logo

Boost :

From: Andrew Sutton (asutton_at_[hidden])
Date: 2007-07-10 09:55:18

> I'm not clear what your "truly optional" parameters are actually
> for, but if (for example) they supply a functor could the default
> value be some sort of identity functor?

I guess it might be worthwhile to distinguish formally between
optional parameters and those with default values. A parameter with
default values is still a required input to a function even if the
user doesn't explicitly pass a corresponding value. It's value is
supplied by the specification. An optional parameter is one affects
the function's behavior by its absence or presence in the argument list.

There are actually a number of examples in Boost.Graph. Consider
dijkstra_shortest_paths(). There are two optional (output) parameters
that can be passed - a predecessor map that records the parents in
the shortest path tree and a distance map that records the distance
to each vertex. If they aren't supplied the algorithm doesn't do any
extra work. If one or both is supplied, the algorithm records parents
and/or distances. This isn't an extreme example of affected behavior,
but it is probably the most common.

The idea of using functors is interesting... but for some reason, I'm
having trouble seeing how the solution would work this morning. I'll
have to give it some thought. I think, however, that I'm doing
something similar with my `not_given` type - it's being used as a
sort of token that, when passed to template functions doesn't do


Andrew Sutton

Boost list run by bdawes at, gregod at, cpdaniel at, john at