blob: b453f6a790bb162cd228cd2bbeab0bb09ccdab05 [file] [log] [blame]
// Copyright 2018 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <functional>
#include <tuple>
#include <utility>
namespace callback {
// Takes a callback, and a list of pointers. Returns a lambda that takes a list
// of objects, saves these in the pointed variables and runs the callback.
// If one wants to ignore one of the captured value, one can pass &std::ignore.
template <typename C, typename... T>
auto Capture(C callback, T*... ptrs) {
return [callback = std::move(callback), ptrs...](auto&&... values) mutable {
std::tie(*ptrs...) = std::make_tuple(std::forward<decltype(values)>(values)...);
} // namespace callback