I'm back

eskimo jfanatiker at gmx.at
Thu Nov 15 05:14:15 PST 2012


On Wed, 2012-11-14 at 18:31 -0800, Andrei Alexandrescu wrote:
> > array(map!"a.dup"(stdin.byLine()))

As it seems there is a good way of handling ranges with transient front
for algorithms that need a persistent front?

Why not simply document any transient range to be transient (should be
anyway) and add the little hint to map. Also note that some algorithms
might not work as expected with transient fronts. In addition, at least
the algorithms in phobos should state in their documentation whether
they rely on non transient front or not.

To me it seems that ranges and algorithms already offer a solution to
the problem.

The other way round it would of course be better (safe behaviour the
default, fast the option) but as a matter of fact there is no real
unsafe behaviour, it just might be unexpected if you don't know what you
are doing.

On the other hand if an algorithm depends unnecessarily on non transient
fronts it should be fixed. If there are many algorithms which can be
more efficient with the dependency on non transient front, we could
simply provide a second module, called std.transalgorithm (or something)
offering dedicated algorithms for transient fronts. (So people don't
have to role their own)

I think this is a very clean and straight forward solution. If you want
something that simply works you just use map!"a.dup" ( or whatever you
need to copy your elements) and don't care. If you want performance then
you would have to check what algorithms to use and have a look at
std.transalgorithm.

My apologies if someone else already suggested something like this, I
haven't read all the threads about this topic entirely.  



More information about the Digitalmars-d mailing list