[ 
https://issues.apache.org/jira/browse/MESOS-1008?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13902219#comment-13902219
 ] 

Jie Yu commented on MESOS-1008:
-------------------------------

We can also get rid of "new" (additional memory allocation) in 
Option/Try/Result by using unrestricted union in C++11.

> 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)

Reply via email to