|
| 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 | +#pragma once |
| 10 | + |
| 11 | +#pragma GCC system_header |
| 12 | + |
| 13 | +// move_only_function design: |
| 14 | +// |
| 15 | +// move_only_function has a small buffer with a size of `3 * sizeof(void*)` bytes. This buffer can only be used when the |
| 16 | +// object that should be stored is trivially relocatable (currently only when it is trivially move constructible and |
| 17 | +// trivially destructible). There is also a bool in the lower bits of the vptr stored which is set when the contained |
| 18 | +// object is not trivially destructible. |
| 19 | +// |
| 20 | +// trivially relocatable: It would also be possible to store nothrow_move_constructible types, but that would mean |
| 21 | +// that move_only_function itself would not be trivially relocatable anymore. The decision to keep move_only_function |
| 22 | +// trivially relocatable was made because we expect move_only_function to be mostly used to store a functor. To only |
| 23 | +// forward functors there is std::function_ref (not voted in yet, expected in C++26). |
| 24 | +// |
| 25 | +// buffer size: We did a survey of six implementations from various vendors. Three of them had a buffer size of 24 bytes |
| 26 | +// on 64 bit systems. This also allows storing a std::string or std::vector inside the small buffer (once the compiler |
| 27 | +// has full support of trivially_relocatable annotations). |
| 28 | +// |
| 29 | +// trivially-destructible bit: This allows us to keep the overall binary size smaller because we don't have to store |
| 30 | +// a pointer to a noop function inside the vtable. It also avoids loading the vtable during destruction, potentially |
| 31 | +// resulting in fewer cache misses. The downside is that calling the function now also requires setting the lower bits |
| 32 | +// of the pointer to zero, but this is a very fast operation on modern CPUs. |
| 33 | + |
| 34 | +// NOLINTBEGIN(readability-duplicate-include) |
| 35 | +# define USERVER_IN_MOVE_ONLY_FUNCTION_H |
| 36 | + |
| 37 | +# include "move_only_function_impl.h" |
| 38 | + |
| 39 | +# define USERVER_MOVE_ONLY_FUNCTION_REF & |
| 40 | +# include "move_only_function_impl.h" |
| 41 | + |
| 42 | +# define USERVER_MOVE_ONLY_FUNCTION_REF && |
| 43 | +# include "move_only_function_impl.h" |
| 44 | + |
| 45 | +# define USERVER_MOVE_ONLY_FUNCTION_CV const |
| 46 | +# include "move_only_function_impl.h" |
| 47 | + |
| 48 | +# define USERVER_MOVE_ONLY_FUNCTION_CV const |
| 49 | +# define USERVER_MOVE_ONLY_FUNCTION_REF & |
| 50 | +# include "move_only_function_impl.h" |
| 51 | + |
| 52 | +# define USERVER_MOVE_ONLY_FUNCTION_CV const |
| 53 | +# define USERVER_MOVE_ONLY_FUNCTION_REF && |
| 54 | +# include "move_only_function_impl.h" |
| 55 | + |
| 56 | +# define USERVER_MOVE_ONLY_FUNCTION_NOEXCEPT true |
| 57 | +# include "move_only_function_impl.h" |
| 58 | + |
| 59 | +# define USERVER_MOVE_ONLY_FUNCTION_NOEXCEPT true |
| 60 | +# define USERVER_MOVE_ONLY_FUNCTION_REF & |
| 61 | +# include "move_only_function_impl.h" |
| 62 | + |
| 63 | +# define USERVER_MOVE_ONLY_FUNCTION_NOEXCEPT true |
| 64 | +# define USERVER_MOVE_ONLY_FUNCTION_REF && |
| 65 | +# include "move_only_function_impl.h" |
| 66 | + |
| 67 | +# define USERVER_MOVE_ONLY_FUNCTION_NOEXCEPT true |
| 68 | +# define USERVER_MOVE_ONLY_FUNCTION_CV const |
| 69 | +# include "move_only_function_impl.h" |
| 70 | + |
| 71 | +# define USERVER_MOVE_ONLY_FUNCTION_NOEXCEPT true |
| 72 | +# define USERVER_MOVE_ONLY_FUNCTION_CV const |
| 73 | +# define USERVER_MOVE_ONLY_FUNCTION_REF & |
| 74 | +# include "move_only_function_impl.h" |
| 75 | + |
| 76 | +# define USERVER_MOVE_ONLY_FUNCTION_NOEXCEPT true |
| 77 | +# define USERVER_MOVE_ONLY_FUNCTION_CV const |
| 78 | +# define USERVER_MOVE_ONLY_FUNCTION_REF && |
| 79 | +# include "move_only_function_impl.h" |
| 80 | + |
| 81 | +# undef USERVER_IN_MOVE_ONLY_FUNCTION_H |
| 82 | +// NOLINTEND(readability-duplicate-include) |
0 commit comments