D-Programming-Language/phobos — pull request #837 by monarchdodra (2012-10-05 11:37:16+00:00)
Title: Fixes for emplace struct

Contains various fixes for emplace!struct that I happened upon:
* From 8763 http://d.puremagic.com/issues/show_bug.cgi?id=8763 : This was preventing certain structs from default emplacing. EG: "S s = void; emplace(&S);"
* Given a struct with an opAssign, emplace was calling opAssign without first copying over T.init: This creates undefined behavior if the opAssign actually did anything on this.

I also re-implemented "most" of emplace!Struct to entirelly bypass opAssign when possible by doing a move directly "onto" the un-initialized chunk. There is only one case where opAssign is called: If there is absolutely no way to construct a T without it.

The way emplace!struct reimplemented is pretty straight forward, trying (conveniently numbered) cases, and finally giving up with a verbose message. "Don't know how to emplace..."

Also added a message in "initalize" regarding the need to access "T.init". Not that I did not change the behavior, merely asserted it with a message.

Pretty chunky unit tests added too, for coverage.