You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2018/03/13 00:13:39 UTC
mesos git commit: Avoided copying when possible in Option::getOrElse.
Repository: mesos
Updated Branches:
refs/heads/master 64d29b784 -> 56843f3b9
Avoided copying when possible in Option::getOrElse.
This mimics the behavior of std::optional::value_or.
Review: https://reviews.apache.org/r/66031
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/56843f3b
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/56843f3b
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/56843f3b
Branch: refs/heads/master
Commit: 56843f3b93483ba07df9ceb3d9e0a44d3975b567
Parents: 64d29b7
Author: Benjamin Mahler <bm...@apache.org>
Authored: Mon Mar 12 17:07:24 2018 -0700
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Mon Mar 12 17:13:12 2018 -0700
----------------------------------------------------------------------
3rdparty/stout/include/stout/option.hpp | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/56843f3b/3rdparty/stout/include/stout/option.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/option.hpp b/3rdparty/stout/include/stout/option.hpp
index 72403e7..8feed01 100644
--- a/3rdparty/stout/include/stout/option.hpp
+++ b/3rdparty/stout/include/stout/option.hpp
@@ -123,8 +123,17 @@ public:
const T* operator->() const { return &get(); }
T* operator->() { return &get(); }
- // This must return a copy to avoid returning a reference to a temporary.
- T getOrElse(const T& _t) const { return isNone() ? _t : t; }
+ template <typename U>
+ T getOrElse(U&& u) const &
+ {
+ return isNone() ? static_cast<T>(std::forward<U>(u)) : t;
+ }
+
+ template <typename U>
+ T getOrElse(U&& u) &&
+ {
+ return isNone() ? static_cast<T>(std::forward<U>(u)) : std::move(t);
+ }
bool operator==(const Option<T>& that) const
{