forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add butter/function.h (facebook#35385)
Summary: Pull Request resolved: facebook#35385 In OpenSource builds folly:: types are not always easy to consume. With butter:: we actually allow consumers to opt-into other/non folly:: types (by providing a custom butter:: implementation). This change adds a butter::function for that purpose. It is especially useful for react-native-windows which prefers Mso::Functor over folly::Function. You can use it by setting those compiler flags: -DBUTTER_FUNCTION_OVERRIDE_INCLUDE=<functional/functor.h> -DBUTTER_FUNCTION_OVERRIDE=Mso::Functor std::function is no option as it is not move-only and we can't wait till 2025 > https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p0288r9.html Changelog: [Internal] Reviewed By: sammy-SC Differential Revision: D41388193 fbshipit-source-id: 56f58b9ddc602aa4b13000031d50de5228b4a16b
- Loading branch information
1 parent
f12b12c
commit 6c315de
Showing
3 changed files
with
65 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <butter/butter.h> | ||
|
||
#if ( \ | ||
defined(BUTTER_FUNCTION_OVERRIDE_INCLUDE) && \ | ||
defined(BUTTER_FUNCTION_OVERRIDE)) | ||
|
||
#include BUTTER_FUNCTION_OVERRIDE_INCLUDE | ||
|
||
#elif defined(BUTTER_USE_FOLLY_CONTAINERS) | ||
|
||
#include <folly/Function.h> | ||
|
||
#else | ||
|
||
#include <functional> | ||
|
||
#endif | ||
|
||
namespace facebook { | ||
namespace butter { | ||
|
||
#if ( \ | ||
defined(BUTTER_FUNCTION_OVERRIDE_INCLUDE) && \ | ||
defined(BUTTER_FUNCTION_OVERRIDE)) | ||
|
||
template <typename... Ts> | ||
using function = BUTTER_FUNCTION_OVERRIDE<Ts...>; | ||
|
||
#elif defined(BUTTER_USE_FOLLY_CONTAINERS) | ||
|
||
template <typename... Ts> | ||
using function = folly::Function<Ts...>; | ||
|
||
#else | ||
|
||
template <typename... Ts> | ||
using function = std::function<Ts...>; | ||
|
||
#endif | ||
|
||
} // namespace butter | ||
} // namespace facebook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters