Foreach and string to string assignment (maybe a bug..)

Jonathan M Davis jmdavisProg at
Thu Oct 14 12:40:56 PDT 2010

On Thursday 14 October 2010 12:20:06 bearophile wrote:
> Steven Schveighoffer:
> > How do you request in a foreach loop that it doesn't dup?
> There are several ways to do this. You may add a boolean value in the
> struct/class template, that switches the safe/unsafe behaviour (defaults
> to safe), or you may let the basic opApply to dup, plus you add another
> method with a name that warns against its non-copying behaviour that
> doesn't dup. In my dlibs1 I have used the first solution for the lazy
> xpermutations/xcombinations.
> > Whether the foreach loop should auto-dup for you is another question, I
> > think it's fine to require you to dup each key's name if you plan on
> > using it later, but this should be in the documentation.
> D Zen follows another design philosophy, documentation is not enough,
> people forget things.
> > Note also, by "unsafe" we just mean surprising :)  It's still safe in
> > terms of memory safety.
> "Safe" has many different meanings. Something that on default acts in a
> bug-prone way is not "safe".
> Bye,
> bearophile

The "safe" that Walter and Andrei are almost always concerned with is memory 
safety. That doesn't mean that other types of safety aren't important, but it 
does mean that that's the sort of safety that dmd and Phobos is generally 
concerned about.

- Jonathan M Davis

More information about the Digitalmars-d-learn mailing list