post_task_and_reply_with_result_internal.h 1006 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef BASE_POST_TASK_AND_REPLY_WITH_RESULT_INTERNAL_H_
#define BASE_POST_TASK_AND_REPLY_WITH_RESULT_INTERNAL_H_

#include <utility>

#include "base/callback.h"

namespace base {

namespace internal {

// Adapts a function that produces a result via a return value to
// one that returns via an output parameter.
template <typename ReturnType>
19 20
void ReturnAsParamAdapter(OnceCallback<ReturnType()> func, ReturnType* result) {
  *result = std::move(func).Run();
21 22 23 24
}

// Adapts a T* result to a callblack that expects a T.
template <typename TaskReturnType, typename ReplyArgType>
25
void ReplyAdapter(OnceCallback<void(ReplyArgType)> callback,
26
                  TaskReturnType* result) {
27
  std::move(callback).Run(std::move(*result));
28 29 30 31 32 33 34
}

}  // namespace internal

}  // namespace base

#endif  // BASE_POST_TASK_AND_REPLY_WITH_RESULT_INTERNAL_H_