[
https://issues.apache.org/jira/browse/MESOS-1008?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13902274#comment-13902274
]
Benjamin Hindman commented on MESOS-1008:
-----------------------------------------
Even before C++11, if we've already allocated memory we could avoid the
deallocation and allocation in the assignment operators and just do copies
instead.
> Reduce copying in stout primitives {Try, Option, Result}.
> ---------------------------------------------------------
>
> Key: MESOS-1008
> URL: https://issues.apache.org/jira/browse/MESOS-1008
> Project: Mesos
> Issue Type: Improvement
> Reporter: Benjamin Mahler
>
> The following will discuss Try, but the same applies to Option and Result.
> Currently retrieving the value from a Try requires a copy:
> T get() const { ... return *t; }
> Instead, we can return a const&:
> const T& get() const { ... return *t; }
> For existing callers, this should be fairly seamless:
> const T& t = try.get(); // No change needed.
> T t = try.get(); // No change needed, T is already required to be copyable.
> try.get().mutator(); // Will no longer compile, but we should not allow
> this anyway!
> We can also add C++11 support for move to pilfer the Try, to avoid copies in
> the caller entirely:
> T&& move() const { ... } // After a move(), we must guard Try operations.
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)