I'm useless at templates, but, inspired by this post:

<hi************ *************** @syrcnyrdrs-01-ge0.nyroc.rr.co m>,

I'm trying to write an algorithm

template <class BidirectionalIt erator, class Function, class Size>

Function for_each_combin ation(Bidirecti onalIterator first,

BidirectionalIt erator last,

Size k,

Function fn);

which does the obvious thing.

The post references some code (from Feb 05 CUJ) which implements

for_each_permut ation. That implementation uses a nice algorithm from

Knuth to generate the permutations which

(i) cycles the elements of [first, last[ in situ, so that the callback can

be called simply as fn(first, last).

(ii) leaves the elements of [first, last[ in their original order.

I can't find such a nice algorithm for combinations. I have a simple

enough algorithm which generates all combinations of the integers 1, ...

(k-1). When it comes to calling the callback fn for each combination, I

copy the corresponding k elements from [first, last[ into a

vector<typename iterator_traits <BidirectionalI terator>::value _type>

but I can't make the call to fn. The caller supplies a callback taking

two parameters of the type BidirectionalIt erator, which isn't matched.

My questions:

Is there a way that I can convert iterators from my vector into the type

of the template parameter BidirectionalIt erator?

Alternatively, and off-topic, can anyone point me to an algorithm for

enumerating combinations which has the properties (i) and (ii) above?

Thanks.