You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by mp...@apache.org on 2016/01/20 00:58:59 UTC

[3/4] mesos git commit: Added SFINAE-friendly `result_of` in stout.

Added SFINAE-friendly `result_of` in stout.

Review: https://reviews.apache.org/r/41461


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/576fa0ee
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/576fa0ee
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/576fa0ee

Branch: refs/heads/master
Commit: 576fa0ee11f81006950094d4e35d231e7cb11472
Parents: a5a42d5
Author: Michael Park <mp...@apache.org>
Authored: Sat Dec 12 11:29:12 2015 -0500
Committer: Michael Park <mp...@apache.org>
Committed: Tue Jan 19 15:51:56 2016 -0800

----------------------------------------------------------------------
 .../3rdparty/stout/include/Makefile.am          |  1 +
 .../3rdparty/stout/include/stout/result_of.hpp  | 82 ++++++++++++++++++++
 2 files changed, 83 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/576fa0ee/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/Makefile.am b/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
index b257ab2..1c452fb 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
+++ b/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
@@ -133,6 +133,7 @@ nobase_include_HEADERS =		\
   stout/recordio.hpp			\
   stout/representation.hpp			\
   stout/result.hpp			\
+  stout/result_of.hpp			\
   stout/set.hpp				\
   stout/some.hpp			\
   stout/stopwatch.hpp			\

http://git-wip-us.apache.org/repos/asf/mesos/blob/576fa0ee/3rdparty/libprocess/3rdparty/stout/include/stout/result_of.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/result_of.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/result_of.hpp
new file mode 100644
index 0000000..ee2bbd9
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/result_of.hpp
@@ -0,0 +1,82 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//  http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef __STOUT_RESULT_OF_HPP__
+#define __STOUT_RESULT_OF_HPP__
+
+#include <type_traits>
+
+#ifndef __WINDOWS__
+using std::result_of;
+#else
+// TODO(mpark): Switch back to simply using `std::result_of` this once we
+// upgrade our Windows support to VS 2015 Update 2 (MESOS-3993).
+
+#include <utility>
+
+namespace internal {
+
+// TODO(mpark): Consider pulling this out to something like <stout/meta.hpp>,
+// This pattern already exists in `<process/future.hpp>`.
+struct LessPrefer {};
+struct Prefer : LessPrefer {};
+
+
+// A tag type that indicates substitution failure.
+struct Fail;
+
+// Perform the necessary expression SFINAE in a context supported in VS 2015
+// Update 1. Note that it leverages `std::invoke` which is carefully written to
+// avoid the limitations around the partial expression SFINAE support.
+
+// `std::invoke` is a C++17 feature, but we only compile this code for Windows,
+// which has it implemented in VS 2015 Update 1. It is also supposed to be
+// defined in `<functional>`, but is included in `<utility>` in VS.
+template <typename F, typename... Args>
+auto result_of_test(Prefer)
+  -> decltype(std::invoke(std::declval<F>(), std::declval<Args>()...));
+
+
+// Report `Fail` if expression SFINAE fails in the above overload.
+template <typename, typename...>
+Fail result_of_test(LessPrefer);
+
+
+// The generic case where `std::invoke(f, args...)` is well-formed.
+template <typename T>
+struct result_of_impl { using type = T; };
+
+
+// The specialization for SFINAE failure case where
+// `std::invoke(f, args...)` is ill-formed.
+template <>
+struct result_of_impl<Fail> {};
+
+
+template <typename F>
+struct result_of;  // undefined.
+
+
+// `decltype(result_of_test<F, Args...>(Prefer()))` is either `Fail` in the case
+// of substitution failure, or the return type of `std::invoke(f, args...)`.
+// `result_of_impl` provides a member typedef `type = T` only if `T != Fail`.
+template <typename F, typename... Args>
+struct result_of<F(Args...)>
+  : result_of_impl<decltype(result_of_test<F, Args...>(Prefer()))> {};
+
+} // namespace internal {
+
+using internal::result_of;
+
+#endif // __WINDOWS__
+
+#endif // __STOUT_RESULT_OF_HPP__