D's equivalent to C++'s std::move?
Matt Elkins via Digitalmars-d
digitalmars-d at puremagic.com
Wed Feb 3 16:48:49 PST 2016
On Tuesday, 2 February 2016 at 22:36:22 UTC, Ali Çehreli wrote:
> Have you used something similar before? Is this a correct
> approach to this problem?
This reminds me of C++ prior to C++11; there were libraries with
whole sets of data structures intended to make move-like
semantics work. While functional (C++ certainly did fine with it
for many years), it's not ideal. That said, I don't know a better
solution. For my resource handles, I am expanding the array and
then assigning the handle in to the new slots, but that's only
acceptable because I happen to know my assignments are cheap. And
even then, it is a bit ugly.
Thus far in my (admittedly short) explorations of D, this has
been my only major gripe. It feels like a significant step down
from C++, but that significance is probably unique to my use case
-- the particular project I am working with happens to use a lot
of non-memory, non-copyable (but movable) resources. In some of
the projects I do at work, I would hardly notice this.
This [apparent] lack of clean move semantics is one of only a
handful of things keeping me from wholeheartedly converting to D,
and proselytizing the gospel to my coworkers (most of the other
issues are transient, like compiler bugs). Everything else in D
has been pretty awesome so far, and I definitely plan on
continuing to use it for my pet projects for the time being :).
Anecdote: just after porting one of my C++ classes to D, I
realized that without sacrificing generality, performance, or
readability I had cut away something like 1/3 of the code,
primarily from the cleaner syntax (this actually increased
readability). I know D isn't _just_ "cleaner C++", but it sure is
cleaner than C++!
More information about the Digitalmars-d
mailing list