Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
construct.hpp
Go to the documentation of this file.
1// parasoft-suppress ALL "False Positive: there is no executable code on line 1"
2// parasoft-begin-suppress CERT_C-EXP37-a "False positive: The rule does not mention naming all parameters"
3// parasoft-begin-suppress AUTOSAR-A2_8_1-a-2 "False positive: this header intentionally defines both an implementation
4// class and variable template API."
5
6// Copyright 2026, Toyota Motor Corporation
7//
8// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_FUNCTIONAL_CONSTRUCT_HPP_
10#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_FUNCTIONAL_CONSTRUCT_HPP_
11
12// IWYU pragma: private, include "arene/base/functional.hpp"
13// IWYU pragma: friend "(arene/base(?!/tests)|stdlib/include/stdlib_detail)/.*"
14
15// parasoft-begin-suppress AUTOSAR-A16_2_2-a-2 "Arene Base aggregate headers permitted by A16-2-2 Permit #1"
18#include "arene/base/stdlib_choice/enable_if.hpp"
19#include "arene/base/stdlib_choice/forward.hpp"
20#include "arene/base/stdlib_choice/is_constructible.hpp"
21// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
22
23namespace arene {
24namespace base {
25
26namespace construct_detail {
27
28/// @brief Implementation of Construct function object.
29/// @tparam To The type to construct.
30template <typename To>
31// parasoft-begin-suppress CERT_C-EXP37-a "False positive: The rule does not mention naming all parameters."
32// parasoft-begin-suppress AUTOSAR-M2_10_1-a-2 "Similar names permitted by M2-10-1 Permit #1"
33class construct_fn {
34 public:
35 /// @brief Construct an object of type To from the given arguments.
36 /// @tparam Args The types of the arguments to construct To from.
37 /// @param args The arguments to construct To from.
38 /// @return To An object of type @c To constructed from the given arguments as if via
39 /// @c To(std::forward<Args>(args)...) .
40 template <
41 typename... Args,
42 base::constraints<std::enable_if_t<std::is_constructible<To, Args&&...>::value>> = nullptr>
43 constexpr auto operator()(Args&&... args) const noexcept(std::is_nothrow_constructible<To, Args&&...>::value) -> To {
44 // parasoft-begin-suppress AUTOSAR-A5_2_2-a-2 "False positive: C-style cast not used."
45 // NOLINTNEXTLINE(google-readability-casting) constructor call, not a c-style cast
46 return To(std::forward<Args>(args)...);
47 // parasoft-end-suppress AUTOSAR-A5_2_2-a-2
48 }
49};
50// parasoft-end-suppress AUTOSAR-M2_10_1-a-2
51// parasoft-end-suppress CERT_C-EXP37-a "False positive: The rule does not mention naming all parameters."
52} // namespace construct_detail
53
54// parasoft-begin-suppress AUTOSAR-M7_3_3-a CERT_CPP-DCL59-a "Per-TU references all refer to the same object"
55// NOLINTNEXTLINE(google-build-namespaces) explicitly want per-TU instantiations
56namespace {
57// NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) FP, there is no non-const global variable here.
58/// @brief Construct an object of type To from the given arguments.
59/// @tparam To The type of object to construct.
60/// @copydoc construct_detail::construct_fn::operator()
61template <typename To>
62ARENE_MAYBE_UNUSED constexpr auto const& construct = construct_detail::construct_fn<To>{};
63// NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables)
64} // namespace
65// parasoft-end-suppress AUTOSAR-M7_3_3-a CERT_CPP-DCL59-a
66
67} // namespace base
68} // namespace arene
69
70// parasoft-end-suppress AUTOSAR-A2_8_1-a-2
71// parasoft-end-suppress CERT_C-EXP37-a
72
73#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_FUNCTIONAL_CONSTRUCT_HPP_
#define ARENE_MAYBE_UNUSED
An alias for [[maybe_unused]] , or a no-op if the attribute is not supported.
Definition maybe_unused.hpp:25
Definition accumulate.hpp:37
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
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
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