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 { ...@@ -419,20 +419,10 @@ struct ShallowCopyRequestContextScopeGuard {
* Accepts iterators to a container of <string/RequestToken, RequestData * Accepts iterators to a container of <string/RequestToken, RequestData
* pointer> pairs * pointer> pairs
*/ */
template <typename... TItems> template <typename... Item>
explicit ShallowCopyRequestContextScopeGuard( explicit ShallowCopyRequestContextScopeGuard(
RequestDataItem&& first, TItems&&... rest) RequestDataItem&& first, Item&&... rest)
: ShallowCopyRequestContextScopeGuard() { : ShallowCopyRequestContextScopeGuard(MultiTag{}, first, rest...) {}
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)...});
}
~ShallowCopyRequestContextScopeGuard() { ~ShallowCopyRequestContextScopeGuard() {
RequestContext::setContext(std::move(prev_)); RequestContext::setContext(std::move(prev_));
...@@ -448,6 +438,19 @@ struct ShallowCopyRequestContextScopeGuard { ...@@ -448,6 +438,19 @@ struct ShallowCopyRequestContextScopeGuard {
ShallowCopyRequestContextScopeGuard&&) = delete; ShallowCopyRequestContextScopeGuard&&) = delete;
private: 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_; 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