1 // Copyright 2016 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef BASE_POST_TASK_AND_REPLY_WITH_RESULT_INTERNAL_H_ 6 #define BASE_POST_TASK_AND_REPLY_WITH_RESULT_INTERNAL_H_ 7 8 #include <utility> 9 10 #include "base/callback.h" 11 12 namespace base { 13 14 namespace internal { 15 16 // Adapts a function that produces a result via a return value to 17 // one that returns via an output parameter. 18 template <typename ReturnType> ReturnAsParamAdapter(OnceCallback<ReturnType ()> func,ReturnType * result)19void ReturnAsParamAdapter(OnceCallback<ReturnType()> func, ReturnType* result) { 20 *result = std::move(func).Run(); 21 } 22 23 // Adapts a T* result to a callblack that expects a T. 24 template <typename TaskReturnType, typename ReplyArgType> ReplyAdapter(OnceCallback<void (ReplyArgType)> callback,TaskReturnType * result)25void ReplyAdapter(OnceCallback<void(ReplyArgType)> callback, 26 TaskReturnType* result) { 27 std::move(callback).Run(std::move(*result)); 28 } 29 30 } // namespace internal 31 32 } // namespace base 33 34 #endif // BASE_POST_TASK_AND_REPLY_WITH_RESULT_INTERNAL_H_ 35