1 // Copyright 2021 The Pigweed Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not 4 // use this file except in compliance with the License. You may obtain a copy of 5 // the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations under 13 // the License. 14 15 // Configuration macros for the function module. 16 #pragma once 17 18 #include <cstddef> 19 20 // The maximum size of a callable that can be inlined within a function. This is 21 // also the size of the Function object itself. Callables larger than this are 22 // stored externally to the function. 23 // 24 // This defaults to 1 pointer, which is capable of storing common callables 25 // such as function pointers and lambdas with a single capture. 26 #ifndef PW_FUNCTION_INLINE_CALLABLE_SIZE 27 #define PW_FUNCTION_INLINE_CALLABLE_SIZE (sizeof(void*)) 28 #endif // PW_FUNCTION_INLINE_CALLABLE_SIZE 29 30 static_assert(PW_FUNCTION_INLINE_CALLABLE_SIZE > 0 && 31 PW_FUNCTION_INLINE_CALLABLE_SIZE % alignof(void*) == 0); 32 33 // Whether functions should allocate memory dynamically (using operator new) if 34 // a callable is larger than the inline size. 35 #ifndef PW_FUNCTION_ENABLE_DYNAMIC_ALLOCATION 36 #define PW_FUNCTION_ENABLE_DYNAMIC_ALLOCATION 0 37 #endif // PW_FUNCTION_ENABLE_DYNAMIC_ALLOCATION 38 39 namespace pw::function_internal::config { 40 41 inline constexpr size_t kInlineCallableSize = PW_FUNCTION_INLINE_CALLABLE_SIZE; 42 inline constexpr bool kEnableDynamicAllocation = 43 PW_FUNCTION_ENABLE_DYNAMIC_ALLOCATION; 44 45 } // namespace pw::function_internal::config 46