Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
function.hpp
Go to the documentation of this file.
1// Copyright 2024, Toyota Motor Corporation
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_INLINE_CONTAINER_FUNCTION_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_INLINE_CONTAINER_FUNCTION_HPP_
7
8// IWYU pragma: private, include "arene/base/functional.hpp"
9
10// parasoft-begin-suppress AUTOSAR-A16_2_2-a-2 "Arene Base aggregate headers permitted by A16-2-2 Permit #1"
16#include "arene/base/stdlib_choice/cstddef.hpp"
17#include "arene/base/stdlib_choice/decay.hpp"
18#include "arene/base/stdlib_choice/enable_if.hpp"
19#include "arene/base/stdlib_choice/forward.hpp"
20#include "arene/base/stdlib_choice/is_base_of.hpp"
21#include "arene/base/stdlib_choice/is_move_constructible.hpp"
22#include "arene/base/stdlib_choice/is_same.hpp"
23#include "arene/base/stdlib_choice/move.hpp"
26// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
27
28// parasoft-begin-suppress CERT_C-EXP37-a-3 "False positive: The rule does not mention naming all parameters"
29// parasoft-begin-suppress AUTOSAR-M2_10_1-a-2 "Similar names permitted by M2-10-1 Permit #1"
30// parasoft-begin-suppress AUTOSAR-A15_4_3-a-2 "False positive: This file is the only declaration of these functions"
31
32namespace arene {
33namespace base {
34
35// parasoft-begin-suppress AUTOSAR-A5_1_1-a "False positive: The literal here is a scalar for a multiply."
36/// @brief The default size of the buffer used for @c inline_function .
37static constexpr std::size_t default_inline_function_size{4U * sizeof(void*)};
38// parasoft-end-suppress AUTOSAR-A5_1_1-a
39
40/// @brief The default alignment of the buffer used for @c inline_function .
41/// @note Storing an over-aligned invocable requires requesting a larger alignment explicitly.
43
44/// @brief A function wrapper akin to @c std::function that always stores the wrapped invocable internally.
45/// @tparam Signature The signature of the function call operator.
46/// @tparam BufferSize The size of the internal buffer. It defaults to 4 times the size of a pointer.
47/// @tparam IsNoexcept If @c true , the function will have a @c noexcept qualified call operator. Otherwise, it will
48/// not.
49/// @tparam Alignment The alignment of the internal buffer. It defaults to @c alignof(std::max_align_t) .
50/// @note If the signature is const-qualified (e.g. <c> int (int,double) const</c> ) then the function call operator for
51/// this class will also be const-qualified. If the signature is *not* const-qualified, then only non-const objects will
52/// be invocable.
53/// @note An invocable whose alignment requirement exceeds @c Alignment cannot be stored, because doing so would place
54/// it at an under-aligned address. Such an invocable is rejected by a @c static_assert. Note that
55/// @c std::is_constructible and @c std::is_assignable still report @c true for such an invocable.
56template <
57 typename Signature,
59 bool IsNoexcept = false,
62
63/// @brief A function wrapper to a noexcept-qualified invocable akin to @c std::function that always stores the wrapped
64/// invocable internally.
65/// @tparam Signature The signature of the function call operator.
66/// @tparam BufferSize The size of the internal buffer. It defaults to 4 times the size of a pointer.
67/// @tparam Alignment The alignment of the internal buffer. It defaults to @c alignof(std::max_align_t) .
68/// @note If the signature is const-qualified (e.g. <c> int (int,double) const</c> ) then the function call operator for
69/// this class will also be const-qualified. If the signature is *not* const-qualified, then only non-const objects will
70/// be invocable.
71template <
72 typename Signature,
76
77namespace inline_function_detail {
78
79// parasoft-begin-suppress AUTOSAR-A12_1_5-a-2 "False positive: delegating constructors are used"
80/// @brief Base class for @c inline_function that provides the implementation details
81/// @tparam BufferSize The size of the internal buffer.
82/// @tparam Alignment The alignment of the internal buffer.
83/// @tparam IsConst Should this function have a const-qualified function call operator?
84/// @tparam IsNoexcept Should this function require a noexcept-qualified callable?
85/// @tparam ReturnType The return type of the function call operator
86/// @tparam Args The argument types of the function call operator
87template <
88 std::size_t BufferSize,
89 std::size_t Alignment,
90 bool IsConst,
91 bool IsNoexcept,
92 typename ReturnType,
93 typename... Args>
94class inline_function_base {
95 /// @brief The type of the @c self argument for the @c invoke function
97
98 /// @brief The function signature of the @c invoke function
99 using invoke_func_type = ReturnType(invoke_self_type self, Args&&... args);
100
101 /// @brief A table of operations that can be applied to the wrapped invocable.
102 /// The members are @c const so that the compiler can see the values don't change: there should be exactly one of
103 /// these objects per type of callable.
104 struct operation_functions {
105 /// @brief A pointer to a function that destroys the wrapped invocable
106 // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
107 void (*const destroy)(inline_function_base& self) noexcept;
108 /// @brief A pointer to a function that moves the wrapped invocable from @c source
109 /// to @c target, leaving @c source empty
110 // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
111 void (*const move)(inline_function_base& target, inline_function_base& source) noexcept;
112 /// @brief A pointer to a function that invokes the wrapped invocable with the
113 /// supplied arguments
114 // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
115 invoke_func_type* const invoke;
116 };
117
118 /// @brief Destroy a wrapped invocable.
119 /// @tparam T The type of the wrapped invocable
120 /// @param self The wrapper object that holds the invocable
121 template <typename T>
122 static void do_destroy(inline_function_base& self) noexcept {
123 // parasoft-begin-suppress AUTOSAR-M0_1_3-b-2 "False positive: The variable is used on the next line"
124 T& wrapped_invocable{*self.template get_ptr<T>()};
125 // parasoft-end-suppress AUTOSAR-M0_1_3-b-2
126 wrapped_invocable.~T();
127 self.operations_ = nullptr;
128 }
129
130 /// @brief Move a wrapped invocable from one wrapper to another and leaves the source
131 /// empty.
132 /// @tparam T The type of the wrapped invocable
133 /// @param source The wrapper object that holds the source invocable
134 /// @param target The wrapper object that will hold the moved invocable
135 template <typename T>
136 static void do_move(inline_function_base& target, inline_function_base& source) noexcept {
137 target.construct_from(std::move(*source.template get_ptr<T>()));
138 target.operations_ = source.operations_;
139 do_destroy<T>(source);
140 }
141
142 /// @brief Invoke the wrapped invocable as a const or non-const object as applicable,
143 /// with the supplied arguments.
144 /// @tparam T The type of the wrapped invocable
145 /// @param self The wrapper object that holds the invocable
146 /// @param args The function call arguments
147 /// @return The result of the invocation
148 template <typename T>
149 static auto do_invoke(invoke_self_type self, Args&&... args) -> ReturnType {
150 auto& wrapped_invocable = *self.template get_ptr<T>();
151 // parasoft-begin-suppress AUTOSAR-A18_9_2-a-2 "Use of 'forward' here ensures rvalues are correctly moved"
152 return static_cast<ReturnType>(wrapped_invocable(std::forward<Args>(args)...));
153 // parasoft-end-suppress AUTOSAR-A18_9_2-a-2
154 }
155
156 /// @brief The table of function pointers for a given invocable type
157 /// @tparam T The type of the wrapped invocable
158 template <typename T>
159 static constexpr operation_functions call_table{&do_destroy<T>, &do_move<T>, &do_invoke<T>};
160
161 protected:
162 /// @brief Trait to determine if a functor is invocable with matching constness, noexcept, return and arguments.
163 /// @tparam T the function type to test.
164 /// @return If @c IsNoexcept , then equivalent to @c is_nothrow_invocable_r_v<ReturnType,T,Args...> . Otherwise,
165 /// equivalent to @c is_invocable_r_v<ReturnType,T,Args...>
166 template <typename T>
167 static constexpr bool
168 is_invocable_n_r_v{IsNoexcept ? ::arene::base::is_nothrow_invocable_r_v<ReturnType, T, Args...> : ::arene::base::is_invocable_r_v<ReturnType, T, Args...>};
169
170 public:
171 /// @brief Default construct with no wrapped invocable
172 inline_function_base() noexcept
173 : buffer_{},
174 operations_{nullptr} {}
175
176 /// @brief Not copyable
177 inline_function_base(inline_function_base const&) = delete;
178 /// @brief Not copyable
179 auto operator=(inline_function_base const&) -> inline_function_base& = delete;
180
181 /// @brief Construct with a wrapped invocable
182 /// @tparam T The type of the wrapped invocable
183 /// @param invocable The invocable to wrap
184 /// @pre The supplied invocable must be invocable with @c Args, with a return
185 /// type that can be converted to @c ReturnType, both as a const and non-const
186 /// object. The invocable must also be nothrow-move-constructible, must fit in
187 /// the buffer, and must not require stricter alignment than the buffer has.
188 template <
189 typename T,
191 std::enable_if_t<(sizeof(std::decay_t<T>) <= BufferSize)>,
193 std::enable_if_t<is_invocable_n_r_v<conditional_t<IsConst, std::decay_t<T> const, std::decay_t<T>>>>> =
194 nullptr>
195 // NOLINTNEXTLINE(bugprone-forwarding-reference-overload,google-explicit-constructor,hicpp-explicit-conversions)
196 inline_function_base(T&& invocable) noexcept
197 : buffer_{},
198 operations_(&call_table<std::decay_t<T>>) {
199 construct_from(std::forward<T>(invocable));
200 }
201
202 /// @brief Deleted constructor for an invocable that is too large for the buffer. The
203 /// template parameter and parameter names are specified to make the error
204 /// message clearer.
205 /// @tparam InvocableTooBigForBuffer The type of the supplied invocable
206 /// @param buffer_too_small The supplied invocable
207 template <
208 typename InvocableTooBigForBuffer,
212 nullptr>
213 // NOLINTNEXTLINE(bugprone-forwarding-reference-overload,google-explicit-constructor,hicpp-explicit-conversions)
214 inline_function_base(InvocableTooBigForBuffer&& buffer_too_small) = delete;
215
216 /// @brief Assign from an invocable
217 /// @tparam T The type of the invocable
218 /// @param invocable The invocable to wrap
219 /// @pre The supplied invocable must be invocable with @c Args, with a return
220 /// type that can be converted to @c ReturnType, both as a const and non-const
221 /// object. The invocable must also be nothrow-move-constructible, must fit in
222 /// the buffer, and must not require stricter alignment than the buffer has.
223 template <
224 typename T,
226 std::enable_if_t<(sizeof(std::decay_t<T>) <= BufferSize)>,
228 std::enable_if_t<is_invocable_n_r_v<conditional_t<IsConst, std::decay_t<T> const, std::decay_t<T>>>>> =
229 nullptr>
230 void assign_from(T&& invocable) noexcept {
231 destroy();
232 operations_ = &call_table<std::decay_t<T>>;
233 construct_from(std::forward<T>(invocable));
234 }
235
236 /// @brief Construct from an invocable
237 /// @tparam T The type of the invocable
238 /// @param invocable The invocable to wrap
239 /// @pre The supplied invocable must be invocable with @c Args, with a return
240 /// type that can be converted to @c ReturnType, both as a const and non-const
241 /// object. The invocable must also be nothrow-move-constructible, must fit in
242 /// the buffer, and must not require stricter alignment than the buffer has.
243 template <
244 typename T,
246 std::enable_if_t<(sizeof(std::decay_t<T>) <= BufferSize)>,
248 std::enable_if_t<is_invocable_n_r_v<conditional_t<IsConst, std::decay_t<T> const, std::decay_t<T>>>>> =
249 nullptr>
250 void construct_from(T&& invocable) noexcept {
251 // parasoft-begin-suppress CERT_C-PRE31-c "False positive: static_assert is a compile-time assert and can have no
252 // side-effects, and alignof is an operator rather than a function"
253 static_assert(
254 alignof(std::decay_t<T>) <= Alignment,
255 "This invocable requires stricter alignment than the inline_function it "
256 "is stored in: increase the Alignment "
257 "template argument of inline_function to at least alignof(the invocable)."
258 );
259 // parasoft-end-suppress CERT_C-PRE31-c
260 construct_at(get_ptr<std::decay_t<T>>(), std::forward<T>(invocable));
261 }
262
263 /// @brief Destroy the wrapped invocable
264 ~inline_function_base() { destroy(); }
265
266 /// @brief Is this function initialized with an invocable?
267 /// @return @c true if the object is initialized, @c false otherwise
268 auto is_initialized() const noexcept -> bool { return operations_ != nullptr; }
269
270 /// @brief Get a pointer to the invoke function
271 /// @return A pointer to the function
272 auto get_invoke() const noexcept -> invoke_func_type* {
273 ARENE_PRECONDITION(is_initialized());
274 return operations_->invoke;
275 }
276
277 /// @brief Check if there is a wrapped invocable
278 /// @return true If there is a wrapped invocable.
279 /// @return false Otherwise.
280 explicit operator bool() const noexcept { return is_initialized(); }
281
282 protected:
283 // parasoft-begin-suppress AUTOSAR-A8_4_6-a-2 "False positive: The data is moved via the 'move_from' function"
284 // parasoft-begin-suppress AUTOSAR-A8_4_5-a-2 "False positive: The data is moved via the 'move_from' function"
285 // parasoft-begin-suppress AUTOSAR-A12_8_4-a-2 "False positive: The data is moved via the 'move_from' function"
286 /// @brief Construct a new object that takes ownership of the invocable held by the
287 /// source. Leaves the source without an invocable.
288 /// @param other The object to move from
289 inline_function_base(inline_function_base&& other) noexcept
290 : inline_function_base{} {
291 move_from(other);
292 }
293 // parasoft-end-suppress AUTOSAR-A8_4_6-a-2
294 // parasoft-end-suppress AUTOSAR-A8_4_5-a-2
295 // parasoft-end-suppress AUTOSAR-A12_8_4-a-2
296
297 // parasoft-begin-suppress AUTOSAR-A8_4_6-a-2 "False positive: The data is moved via the 'move_from' function"
298 // parasoft-begin-suppress AUTOSAR-A8_4_5-a-2 "False positive: The data is moved via the 'move_from' function"
299 // parasoft-begin-suppress AUTOSAR-A12_8_4-a-2 "False positive: this is not a move constructor"
300 /// @brief Transfer ownership of an invocable from another object. Leaves the source
301 /// without an invocable.
302 /// @param other The object to move from
303 /// @return A reference to @c *this
304 auto operator=(inline_function_base&& other) noexcept -> inline_function_base& {
305 if (&other != this) {
306 destroy();
307 move_from(other);
308 }
309 return *this;
310 }
311 // parasoft-end-suppress AUTOSAR-A8_4_6-a-2
312 // parasoft-end-suppress AUTOSAR-A8_4_5-a-2
313 // parasoft-end-suppress AUTOSAR-A12_8_4-a-2
314
315 private:
316 /// @brief Destroy the invocable if there is one
317 void destroy() noexcept {
318 if (is_initialized()) {
319 operations_->destroy(*this);
320 }
321 }
322
323 /// @brief Transfer ownership of an invocable from another object, if it has one
324 /// @param other The object to move from
325 void move_from(inline_function_base& other) {
326 if (other.is_initialized()) {
327 other.operations_->move(*this, other);
328 }
329 }
330
331 /// @brief Get a pointer to the wrapped invocable or its storage (if not yet
332 /// constructed)
333 /// @tparam T The type of the wrapped invocable
334 /// @return A pointer to the object or storage
335 template <typename T>
336 auto get_ptr() noexcept -> T* {
337 return static_cast<T*>(static_cast<void*>(buffer_.data()));
338 }
339
340 /// @brief Get a const pointer to the wrapped invocable
341 /// @tparam T The type of the wrapped invocable
342 /// @return A pointer to the object
343 template <typename T>
344 auto get_ptr() const noexcept -> T const* {
345 return static_cast<T const*>(static_cast<void const*>(buffer_.data()));
346 }
347
348 /// @brief The storage for the wrapped invocable
349 alignas(Alignment) array<byte, BufferSize> buffer_;
350
351 /// @brief The pointer to the operation table
352 operation_functions const* operations_;
353};
354// parasoft-end-suppress AUTOSAR-A12_1_5-a-2
355
356/// @brief Out-of-line definition for the operation table
357/// @tparam ReturnType The return type of the function call operator
358/// @tparam Args The argument types of the function call operator
359/// @tparam BufferSize The size of the internal buffer.
360/// @tparam Alignment The alignment of the internal buffer.
361/// @tparam T The type of the wrapped invocable
362template <
363 std::size_t BufferSize,
364 std::size_t Alignment,
365 bool IsConst,
366 bool IsNoexcept,
367 typename ReturnType,
368 typename... Args>
369template <typename T>
370constexpr
371 typename inline_function_base<BufferSize, Alignment, IsConst, IsNoexcept, ReturnType, Args...>::operation_functions
372 inline_function_base<BufferSize, Alignment, IsConst, IsNoexcept, ReturnType, Args...>::call_table;
373
374} // namespace inline_function_detail
375
376/// @brief A function wrapper akin to @c std::function that always stores the
377/// wrapped invocable internally. This specialization is for where
378/// the function type is not @c const qualified
379/// @tparam ReturnType The return type of the function call operator
380/// @tparam Args The argument types of the function call operator
381/// @tparam BufferSize The size of the internal buffer.
382/// @tparam IsNoexcept If @c true , the function will have a @c noexcept qualified call operator. Otherwise, it will
383/// not.
384/// @tparam Alignment The alignment of the internal buffer.
385template <typename ReturnType, typename... Args, std::size_t BufferSize, bool IsNoexcept, std::size_t Alignment>
386class inline_function<ReturnType(Args...), BufferSize, IsNoexcept, Alignment>
387 : inline_function_detail::inline_function_base<BufferSize, Alignment, false, IsNoexcept, ReturnType, Args...> {
388 /// @brief The type of the base class
389 using base_class =
390 inline_function_detail::inline_function_base<BufferSize, Alignment, false, IsNoexcept, ReturnType, Args...>;
391
392 public:
393 /// @brief Inherit the base class converting constructors
394 using base_class::base_class;
395
396 /// @brief Default construct with no stored invocable
397 inline_function() noexcept = default;
398
399 /// @brief Transfer ownership of an invocable from another object. Leaves the source
400 /// without an invocable.
401 /// @param other The object to move from
402 inline_function(inline_function&& other) noexcept = default;
403
404 /// @brief Transfer ownership of an invocable from another object. Leaves the source
405 /// without an invocable.
406 /// @param other The object to move from
407 /// @return A reference to @c *this
408 auto operator=(inline_function&& other) noexcept -> inline_function& = default;
409
410 /// @brief Assign from a wrapped invocable
411 /// @tparam T The type of the wrapped invocable
412 /// @param invocable The invocable to wrap
413 /// @return A reference to @c *this
414 /// @pre The supplied invocable must be invocable with @c Args, with a return
415 /// type that can be converted to @c ReturnType, both as a const and non-const
416 /// object. The invocable must also be nothrow-move-constructible, must fit in
417 /// the buffer, and must not require stricter alignment than the buffer has.
418 template <
419 typename T,
421 std::enable_if_t<(sizeof(std::decay_t<T>) <= BufferSize)>,
422 std::enable_if_t<std::is_nothrow_move_constructible<std::decay_t<T>>::value>,
423 std::enable_if_t<base_class::template is_invocable_n_r_v<std::decay_t<T>>>> = nullptr>
424 auto operator=(T&& invocable) noexcept -> inline_function& {
425 this->assign_from(std::forward<T>(invocable));
426 return *this;
427 }
428
429 /// @brief Deleted assignment operator for an invocable that is too large for the
430 /// buffer. The template parameter and parameter names are specified to make
431 /// the error message clearer.
432 /// @tparam InvocableTooBigForBuffer The type of the supplied invocable
433 /// @param buffer_too_small The supplied invocable
434 template <
435 typename InvocableTooBigForBuffer,
439 auto operator=(InvocableTooBigForBuffer&& buffer_too_small) -> inline_function& = delete;
440
441 /// @brief Not copyable
443 /// @brief Not copyable
444 auto operator=(inline_function const&) -> inline_function& = delete;
445
446 /// @brief Destroy the wrapped invocable
447 ~inline_function() = default;
448
449 /// @brief Inherit the base class boolean conversion operator
450 using base_class::operator bool;
451
452 /// @brief Invoke the wrapped invocable as a non-const object, with the supplied
453 /// arguments
454 /// @param args The arguments for the call
455 /// @return The value returned from the call
456 auto operator()(Args... args) noexcept(IsNoexcept) -> ReturnType {
457 ARENE_PRECONDITION(this->is_initialized());
458 // parasoft-begin-suppress AUTOSAR-A18_9_2-a-2 "Use of 'forward' here ensures rvalues are correctly moved"
459 return this->get_invoke()(*this, std::forward<Args>(args)...);
460 // parasoft-end-suppress AUTOSAR-A18_9_2-a-2
461 }
462};
463
464/// @brief A function wrapper akin to @c std::function that always stores the
465/// wrapped invocable internally. This specialization is for where the
466/// function type is @c const qualified
467/// @tparam ReturnType The return type of the function call operator
468/// @tparam Args The argument types of the function call operator
469/// @tparam BufferSize The size of the internal buffer.
470/// @tparam IsNoexcept If @c true , the function will have a @c noexcept qualified call operator. Otherwise, it will
471/// not.
472/// @tparam Alignment The alignment of the internal buffer.
473template <typename ReturnType, typename... Args, std::size_t BufferSize, bool IsNoexcept, std::size_t Alignment>
474class inline_function<ReturnType(Args...) const, BufferSize, IsNoexcept, Alignment>
475 : inline_function_detail::inline_function_base<BufferSize, Alignment, true, IsNoexcept, ReturnType, Args...> {
476 /// @brief Internal type alias for the base class
477 using base_class =
478 inline_function_detail::inline_function_base<BufferSize, Alignment, true, IsNoexcept, ReturnType, Args...>;
479
480 public:
481 /// @brief Inherit the base class converting constructors
482 using base_class::base_class;
483
484 /// @brief Default construct with no stored invocable
485 inline_function() noexcept = default;
486
487 /// @brief Transfer ownership of an invocable from another object. Leaves the source
488 /// without an invocable.
489 /// @param other The object to move from
490 inline_function(inline_function&& other) noexcept = default;
491
492 /// @brief Transfer ownership of an invocable from another object. Leaves the source
493 /// without an invocable.
494 /// @param other The object to move from
495 /// @return A reference to @c *this
496 auto operator=(inline_function&& other) noexcept -> inline_function& = default;
497
498 /// @brief Assign from a wrapped invocable
499 /// @tparam T The type of the wrapped invocable
500 /// @param invocable The invocable to wrap
501 /// @return A reference to @c *this
502 /// @pre The supplied invocable must be invocable with @c Args, with a return
503 /// type that can be converted to @c ReturnType, both as a const and non-const
504 /// object. The invocable must also be nothrow-move-constructible, must fit in
505 /// the buffer, and must not require stricter alignment than the buffer has.
506 template <
507 typename T,
509 std::enable_if_t<(sizeof(std::decay_t<T>) <= BufferSize)>,
510 std::enable_if_t<std::is_nothrow_move_constructible<std::decay_t<T>>::value>,
511 std::enable_if_t<base_class::template is_invocable_n_r_v<std::decay_t<T> const>>> = nullptr>
512 auto operator=(T&& invocable) noexcept -> inline_function& {
513 this->assign_from(std::forward<T>(invocable));
514 return *this;
515 }
516
517 /// @brief Deleted assignment operator for an invocable that is too large for the
518 /// buffer. The template parameter and parameter names are specified to make
519 /// the error message clearer.
520 /// @tparam InvocableTooBigForBuffer The type of the supplied invocable
521 /// @param buffer_too_small The supplied invocable
522 template <
523 typename InvocableTooBigForBuffer,
527 auto operator=(InvocableTooBigForBuffer&& buffer_too_small) -> inline_function& = delete;
528
529 /// @brief Not copyable
531 /// @brief Not copyable
532 auto operator=(inline_function const&) -> inline_function& = delete;
533
534 /// @brief Destroy the wrapped invocable
535 ~inline_function() = default;
536
537 /// @brief Inherit the base class boolean conversion operator
538 using base_class::operator bool;
539
540 /// @brief Invoke the wrapped invocable as a const object, with the supplied
541 /// arguments
542 /// @param args The arguments for the call
543 /// @return The value returned from the call
544 auto operator()(Args... args) const noexcept(IsNoexcept) -> ReturnType {
545 ARENE_PRECONDITION(this->is_initialized());
546 return this->get_invoke()(*this, std::forward<Args>(args)...);
547 }
548};
549
550} // namespace base
551} // namespace arene
552
553// parasoft-end-suppress AUTOSAR-M2_10_1-a-2
554
555#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_INLINE_CONTAINER_FUNCTION_HPP_
A fixed-size array of T objects.
Definition array.hpp:77
auto operator=(inline_function const &) -> inline_function &=delete
Not copyable.
auto operator()(Args... args) noexcept(IsNoexcept) -> ReturnType
Invoke the wrapped invocable as a non-const object, with the supplied arguments.
Definition function.hpp:456
inline_function() noexcept=default
Default construct with no stored invocable.
auto operator()(Args... args) const noexcept(IsNoexcept) -> ReturnType
Invoke the wrapped invocable as a const object, with the supplied arguments.
Definition function.hpp:544
inline_function() noexcept=default
Default construct with no stored invocable.
auto operator=(inline_function const &) -> inline_function &=delete
Not copyable.
A function wrapper akin to std::function that always stores the wrapped invocable internally.
Definition function.hpp:61
Type trait to detect if Base is a base class of Derived.
Definition is_base_of.hpp:30
Type trait to detect if an instance of T is move constructible without throwing.
Definition is_move_constructible.hpp:70
Trait to detect if the two template parameters are the same or not. The value member is true if the t...
Definition is_same.hpp:35
#define ARENE_PRECONDITION(condition)
Check that a precondition holds, and terminate the application if it does not.
Definition contract.hpp:150
Definition accumulate.hpp:37
constexpr auto move(InIterator first, InIterator last, OutIterator output) noexcept(noexcept(*first++) &&noexcept(output++) &&//CODEQLFP(EXP52-CPP) CODEQLFP(A5-2-6) noexcept(first !=last) &&//CODEQLFP(A5-2-6) std::is_nothrow_assignable<, typename std::iterator_traits< InIterator >::value_type >::value) -> OutIterator
Moves the elements in the range [first, last), to another range beginning at output,...
Definition move.hpp:46
typename static_if< B >::template then_else< T, F > conditional_t
lazily select between two types based on a boolean condition
Definition conditional.hpp:28
constexpr bool is_invocable_r_v
Determine if a functor type is invocable with the specified return and argument types.
static constexpr std::size_t default_inline_function_size
The default size of the buffer used for inline_function .
Definition function.hpp:37
constexpr bool is_nothrow_invocable_r_v
Determine if a functor type is no-throw invocable with the specified return and argument types.
constexpr auto invoke(F &&func, Args &&... args) noexcept(is_nothrow_invocable_v< F, Args... >) ->
Implementation of std::invoke from C++23: invokes the specified callable with the specified arguments...
Definition invoke.hpp:281
static constexpr std::size_t default_inline_function_alignment
The default alignment of the buffer used for inline_function .
Definition function.hpp:42
inline_function< Signature, BufferSize, true, Alignment > noexcept_inline_function
A function wrapper to a noexcept-qualified invocable akin to std::function that always stores the wra...
Definition function.hpp:75
typename constraints_impl::constraints< EnableIfs... >::type constraints
Helper used to express template constraints in a consistent way using std::enable_if_t.
Definition constraints.hpp:51
Definition accumulate.hpp:36
STL namespace.
constexpr auto move(T &&value) noexcept -> remove_reference_t< T > &&
Cast a value to an rvalue.
Definition move.hpp:30
::max_align_t max_align_t
A POD type which has the maximum alignment required for any built-in type.
Definition cstddef.hpp:35
::size_t size_t
A type suitable for holding the size of an object.
Definition cstddef.hpp:29
typename enable_if< Condition, Type >::type enable_if_t
Type alias to support constraining templates. Is an alias for the specified type if the Condition is ...
Definition enable_if.hpp:41
typename decay< Type >::type decay_t
A conversion equivalent to those performed when passing function arguments by value.
Definition decay.hpp:48
constexpr auto forward(remove_reference_t< T > &value) noexcept -> T &&
Cast a value to an rvalue if T is an rvalue or rvalue reference, otherwise forward an lvalue referenc...
Definition forward.hpp:24