Commit c63e0608 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

tweak ShallowCopyRequestContextScopeGuard ctor

Summary: DRY the `ShallowCopyRequestContextScopeGuard` ctor taking multiple items.

Differential Revision: D27698685

fbshipit-source-id: 7f23305855918c4248da11c15e5fab839592d372
parent 68104e03
......@@ -419,20 +419,10 @@ struct ShallowCopyRequestContextScopeGuard {
* Accepts iterators to a container of <string/RequestToken, RequestData
* pointer> pairs
*/
template <typename... TItems>
template <typename... Item>
explicit ShallowCopyRequestContextScopeGuard(
RequestDataItem&& first, TItems&&... rest)
: ShallowCopyRequestContextScopeGuard() {
auto rc = RequestContext::get();
auto overwriteContextData = [&rc](RequestDataItem&& item) {
rc->overwriteContextData(item.first, std::move(item.second), true);
};
overwriteContextData(std::move(first));
using _ = int[];
void(_{0, (void(overwriteContextData(std::forward<TItems>(rest))), 0)...});
}
RequestDataItem&& first, Item&&... rest)
: ShallowCopyRequestContextScopeGuard(MultiTag{}, first, rest...) {}
~ShallowCopyRequestContextScopeGuard() {
RequestContext::setContext(std::move(prev_));
......@@ -448,6 +438,19 @@ struct ShallowCopyRequestContextScopeGuard {
ShallowCopyRequestContextScopeGuard&&) = delete;
private:
struct MultiTag {};
template <typename... Item>
explicit ShallowCopyRequestContextScopeGuard(MultiTag, Item&... item)
: ShallowCopyRequestContextScopeGuard() {
auto rc = RequestContext::get();
auto go = [&](RequestDataItem& i) {
rc->overwriteContextData(i.first, std::move(i.second), true);
};
using _ = int[];
void(_{0, (go(item), 0)...});
}
std::shared_ptr<RequestContext> prev_;
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment