Boost logo

Boost :

Subject: Re: [boost] combinations and permutations
From: Howard Hinnant (howard.hinnant_at_[hidden])
Date: 2011-01-04 18:55:47

On Jan 4, 2011, at 3:56 PM, Phil Endecott wrote:

> Howard Hinnant wrote:
>> Warming this up for tr2:
>> Comments welcome. Real world use welcome.
> Hi Howard,
> The only time I've needed to use anything like this was for some sort of search, with termination as soon as a solution is found. With these algorithms it looks like you'd need to throw an exception to do this, which is rather frowned-upon, no? I wonder if the functor could return a bool, or something.

I actually did think of this. And I believe it would not be that difficult. I'm not sure if it is desirable though. It is an awful lot of if-checking added to the algorithm. All that checking would tend to penalize those clients not wanting to break out early.

In a perfect world, if it didn't cost any more to use the next_* interface than the for_each_* interface, I would definitely use the next_* interface along with a break statement, in this situation. That is clean and easy to understand. Though if I didn't need to break out early I believe I would choose for_each_*, and for the same reason. However if I had to choose between clean and 10x (really even 2x) faster, I lean towards speed. As always, it is an engineering judgement where one draws a line like that. And I'm not here to tell anyone where they should draw it.

Perhaps Chris' work (a few posts in the future from yours) will give us the ability to choose between next_* and for_each_* guilt-free. :-)


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