Boost logo

Boost :

Subject: Re: [boost] [range-ex] generators
From: Neil Groves (neil_at_[hidden])
Date: 2009-02-22 09:17:56

Hi Neal,

On Sun, Feb 22, 2009 at 2:05 PM, Neal Becker <ndbecker2_at_[hidden]> wrote:

> I have a question of generate. I believe one usually wants generators to
> have
> state. Yet, generator is passed by value. This is awkward, the workaround
> is
> to manually specify

I have rather blindly followed the standard and passed the Generator by
value. I am open to deviate if there is sufficient justification.

> generate<ForwardRange, Generator&>( rng, gen );
> Since Generator is the 2nd template parameter we must specify ForwardRange,
> which might be complicated.
> I wonder if we should have:
> template<class ForwardRange, class Generator>
> ForwardRange& generate( ForwardRange& rng, Generator & gen );

My usual technique which I apply to for_each and most of the other standard
algorithm functions is to use boost::ref. The standard library passes almost
all functors and predicates by value. I can only remember some of the
random_... functions passing the random generator by reference.

Therefore we can avoid specifying the ForwardRange thus:

generate(rng, ref(gen));

I am concerned that if it is wrong for generate, then it may well be wrong
for many of the other algorithms that take functors and predicates. I
believe that defaulting to pass by value improves the efficiency for many
small functors.

Would someone please enlighten me with the rationale for passing by value in
the standard version?

Does the use of boost::ref sufficiently address your concerns?

Neil Groves

> _______________________________________________
> Unsubscribe & other changes:

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