D-Programming-Language/phobos — pull request #2015 by monarchdodra (2014-03-17 22:05:06+00:00)
Title: Improve emplaceRef for qualified construction

This further refines the (package) `appenderRef`, to turn it into a template specialized for building a specific types. In particular, for building *qualified* types. This has the advantages of:
1. Callers don't have to jump through hoops and worry about casting the rhs.
2. Avoids unsafe casts: Now, we are actually building const objects from other const objects, rather than casting away both the const, doing the build, and casting it back on.
3. Preserves (mostly) the type system: Instead of mutating immutable data, we place (explicitly) immutable data on a mutable buffer. I think it is a good compromise for the added correctness and convenience.

Point 2 is particularly important in terms of type safety, and in particular for any future "qualified construction/postblit" that @9rnsr is working on.

The simplifications in the `Appender` code, or how `array` now works on *any* type, all in complete safety and without any special casing, I think speaks for itself.

Another nice point (IMO), is having a set of overloaded functions `emplace!T`. This is both convenient in terms of useage, but also in case of errors: The overload set is smaller and more explicit.

Because the design is currently package, I decided to make the type specification explicit. It helped me catch a few wrong cases. We may remove it if it ever becomes public, but for now, I'd rather we keep it that way.

Obligatory change of indentation:
https://github.com/D-Programming-Language/phobos/pull/2015/files?w=1