|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | + |
| 9 | +#ifndef _LIBCPP___FUNCTIONAL_MOVE_ONLY_FUNCTION_H |
| 10 | +#define _LIBCPP___FUNCTIONAL_MOVE_ONLY_FUNCTION_H |
| 11 | + |
| 12 | +#include <__config> |
| 13 | + |
| 14 | +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 15 | +# pragma GCC system_header |
| 16 | +#endif |
| 17 | + |
| 18 | +#if _LIBCPP_STD_VER >= 23 && _LIBCPP_HAS_EXPERIMENTAL_MOVE_ONLY_FUNCTION |
| 19 | + |
| 20 | +// move_only_function design: |
| 21 | +// |
| 22 | +// move_only_function has a small buffer with a size of `3 * sizeof(void*)` bytes. This buffer can only be used when the |
| 23 | +// object to be stored is "trivially relocatable" (currently only when it is trivially move constructible and trivially |
| 24 | +// destructible). The vtable entry for the destructor is a null pointer when the stored object is trivially |
| 25 | +// destructible. |
| 26 | +// |
| 27 | +// trivially relocatable: It would also be possible to store nothrow_move_constructible types, but that would mean |
| 28 | +// that move_only_function itself would not be trivially relocatable anymore. The decision to keep move_only_function |
| 29 | +// trivially relocatable was made because we expect move_only_function to be stored persistently most of the time, since |
| 30 | +// std::function_ref can be used for cases where a function object doesn't need to be stored. |
| 31 | +// |
| 32 | +// buffer size: We did a survey of six implementations from various vendors. Three of them had a buffer size of 24 bytes |
| 33 | +// on 64 bit systems. This will also allow storing a function object containing a std::string or std::vector inside the |
| 34 | +// small buffer once there is a language definition of "trivially relocatable". |
| 35 | +// |
| 36 | +// interaction with copyable_function: When converting a copyable_function into a move_only_function we want to avoid |
| 37 | +// wrapping the copyable_function inside the move_only_function to avoid a double indirection. Instead, we copy the |
| 38 | +// small buffer and use copyable_function's vtable. |
| 39 | + |
| 40 | +// NOLINTBEGIN(readability-duplicate-include) |
| 41 | +# define _LIBCPP_IN_MOVE_ONLY_FUNCTION_H |
| 42 | + |
| 43 | +# include <__functional/move_only_function_impl.h> |
| 44 | + |
| 45 | +# define _LIBCPP_MOVE_ONLY_FUNCTION_REF & |
| 46 | +# include <__functional/move_only_function_impl.h> |
| 47 | + |
| 48 | +# define _LIBCPP_MOVE_ONLY_FUNCTION_REF && |
| 49 | +# include <__functional/move_only_function_impl.h> |
| 50 | + |
| 51 | +# define _LIBCPP_MOVE_ONLY_FUNCTION_CV const |
| 52 | +# include <__functional/move_only_function_impl.h> |
| 53 | + |
| 54 | +# define _LIBCPP_MOVE_ONLY_FUNCTION_CV const |
| 55 | +# define _LIBCPP_MOVE_ONLY_FUNCTION_REF & |
| 56 | +# include <__functional/move_only_function_impl.h> |
| 57 | + |
| 58 | +# define _LIBCPP_MOVE_ONLY_FUNCTION_CV const |
| 59 | +# define _LIBCPP_MOVE_ONLY_FUNCTION_REF && |
| 60 | +# include <__functional/move_only_function_impl.h> |
| 61 | + |
| 62 | +# define _LIBCPP_MOVE_ONLY_FUNCTION_NOEXCEPT true |
| 63 | +# include <__functional/move_only_function_impl.h> |
| 64 | + |
| 65 | +# define _LIBCPP_MOVE_ONLY_FUNCTION_NOEXCEPT true |
| 66 | +# define _LIBCPP_MOVE_ONLY_FUNCTION_REF & |
| 67 | +# include <__functional/move_only_function_impl.h> |
| 68 | + |
| 69 | +# define _LIBCPP_MOVE_ONLY_FUNCTION_NOEXCEPT true |
| 70 | +# define _LIBCPP_MOVE_ONLY_FUNCTION_REF && |
| 71 | +# include <__functional/move_only_function_impl.h> |
| 72 | + |
| 73 | +# define _LIBCPP_MOVE_ONLY_FUNCTION_NOEXCEPT true |
| 74 | +# define _LIBCPP_MOVE_ONLY_FUNCTION_CV const |
| 75 | +# include <__functional/move_only_function_impl.h> |
| 76 | + |
| 77 | +# define _LIBCPP_MOVE_ONLY_FUNCTION_NOEXCEPT true |
| 78 | +# define _LIBCPP_MOVE_ONLY_FUNCTION_CV const |
| 79 | +# define _LIBCPP_MOVE_ONLY_FUNCTION_REF & |
| 80 | +# include <__functional/move_only_function_impl.h> |
| 81 | + |
| 82 | +# define _LIBCPP_MOVE_ONLY_FUNCTION_NOEXCEPT true |
| 83 | +# define _LIBCPP_MOVE_ONLY_FUNCTION_CV const |
| 84 | +# define _LIBCPP_MOVE_ONLY_FUNCTION_REF && |
| 85 | +# include <__functional/move_only_function_impl.h> |
| 86 | + |
| 87 | +# undef _LIBCPP_IN_MOVE_ONLY_FUNCTION_H |
| 88 | +// NOLINTEND(readability-duplicate-include) |
| 89 | + |
| 90 | +#endif // _LIBCPP_STD_VER >= 23 && _LIBCPP_HAS_EXPERIMENTAL_MOVE_ONLY_FUNCTION |
| 91 | + |
| 92 | +#endif // _LIBCPP___FUNCTIONAL_MOVE_ONLY_FUNCTION_H |
0 commit comments