From: Matthieu Martin Date: Thu, 13 Oct 2016 07:09:32 +0000 (-0700) Subject: Provide a unpackTryTuple function in folly X-Git-Tag: v2016.10.17.00~7 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=347311500aa10d0524ac6db3987a94216e6d76ef;p=folly.git Provide a unpackTryTuple function in folly Summary: This feature already exists in detail, move it to public instead. Reviewed By: andriigrynenko Differential Revision: D4013691 fbshipit-source-id: 1779cc53d114ddc97993b41e0ad63c104008f6b0 --- diff --git a/folly/Makefile.am b/folly/Makefile.am index bc507a77..b7860ee9 100644 --- a/folly/Makefile.am +++ b/folly/Makefile.am @@ -77,6 +77,7 @@ nobase_follyinclude_HEADERS = \ detail/StaticSingletonManager.h \ detail/Stats.h \ detail/ThreadLocalDetail.h \ + detail/TryDetail.h \ detail/TurnSequencer.h \ detail/UncaughtExceptionCounter.h \ Demangle.h \ diff --git a/folly/Try-inl.h b/folly/Try-inl.h index ba988e3d..ed85e3dd 100644 --- a/folly/Try-inl.h +++ b/folly/Try-inl.h @@ -16,6 +16,7 @@ #pragma once +#include #include namespace folly { @@ -173,4 +174,10 @@ makeTryWith(F&& f) { } } +template +std::tuple unwrapTryTuple(std::tuple...>&& ts) { + return detail::TryTuple::unwrap( + std::forward...>>(ts)); +} + } // folly diff --git a/folly/Try.h b/folly/Try.h index edfe6a7e..e6b6ebad 100644 --- a/folly/Try.h +++ b/folly/Try.h @@ -418,6 +418,9 @@ typename std::enable_if< Try>::type makeTryWith(F&& f); +template +std::tuple unwrapTryTuple(std::tuple...>&& ts); + } // folly #include diff --git a/folly/detail/TryDetail.h b/folly/detail/TryDetail.h new file mode 100644 index 00000000..05157631 --- /dev/null +++ b/folly/detail/TryDetail.h @@ -0,0 +1,46 @@ +/* + * Copyright 2016 Facebook, Inc. + * + * 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. + */ + +#pragma once + +namespace folly { +namespace detail { + +template +struct TryTuple { + template + static std::tuple unwrap( + std::tuple...>&& o, + Ts2&&... ts2) { + static_assert( + sizeof...(ts2) < std::tuple_size...>>::value, + "Non-templated unwrap should be used instead"); + + return unwrap( + std::move(o), + std::forward(ts2)..., + std::move(*std::get(o))); + } + + static std::tuple unwrap( + std::tuple...>&& /* o */, + Ts&&... ts) { + return std::tuple(std::forward(ts)...); + } +}; + +} // namespace detail +} // namespace folly diff --git a/folly/futures/detail/Core.h b/folly/futures/detail/Core.h index 66a6e74c..c4beaa4c 100644 --- a/folly/futures/detail/Core.h +++ b/folly/futures/detail/Core.h @@ -468,32 +468,13 @@ struct CollectVariadicContext { } ~CollectVariadicContext() { if (!threw.exchange(true)) { - p.setValue(unwrap(std::move(results))); + p.setValue(unwrapTryTuple(std::move(results))); } } Promise> p; std::tuple...> results; std::atomic threw {false}; typedef Future> type; - - private: - template - static std::tuple unwrap(std::tuple...>&& o, - Ts2&&... ts2) { - static_assert(sizeof...(ts2) < - std::tuple_size...>>::value, - "Non-templated unwrap should be used instead"); - assert(std::get(o).hasValue()); - - return unwrap(std::move(o), - std::forward(ts2)..., - std::move(*std::get(o))); - } - - static std::tuple unwrap(std::tuple...>&& /* o */, - Ts&&... ts) { - return std::tuple(std::forward(ts)...); - } }; template