Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
is_implicitly_constructible.hpp
Go to the documentation of this file.
1// parasoft-begin-suppress AUTOSAR-A2_8_1-a-2 "False positive: also defines arene::base::is_implicitly_constructible"
2
3// Copyright 2026, Toyota Motor Corporation
4//
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
7#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_TRAITS_IS_IMPLICITLY_CONSTRUCTIBLE_HPP_
8#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_TRAITS_IS_IMPLICITLY_CONSTRUCTIBLE_HPP_
9
10#include "arene/base/stdlib_choice/declval.hpp"
11#include "arene/base/stdlib_choice/integral_constant.hpp"
12#include "arene/base/type_traits/priority_tag.hpp"
13
14// parasoft-begin-suppress CERT_C-EXP37-a "False positive: The rule does not mention naming all parameters"
15// parasoft-begin-suppress AUTOSAR-A2_7_3-a "False positive: Everything is preceeded by a comment with @brief"
16// parasoft-begin-suppress AUTOSAR-A2_7_3-b "False positive: Every function is preceeded by a comment with @return"
17
18namespace arene {
19namespace base {
20
21namespace is_implicitly_constructible_detail {
22
23// parasoft-begin-suppress AUTOSAR-M3_3_2-a "False positive: inline function used in multiple translation units"
24
25/// @brief A function which takes a @c T to implicitly construct it.
26/// @tparam T The type to check if it can be implicitly constructed.
27/// @return Always return @c std::true_type
28template <class T>
29constexpr auto implicitly_construct(T) noexcept -> std::true_type;
30
31/// @brief A function to try to implicitly construct @c T from @c Args via brace initialization.
32/// @tparam T The type to check if it can be implicitly constructed.
33/// @tparam Args The arguments to try to implicitly construct with.
34/// @return @c std::true_type if @c T is able to be implicitly constructed from @c Args
35template <class T, class... Args>
36constexpr auto try_to_implicitly_construct(priority_tag<1>) noexcept(
37 noexcept(implicitly_construct<T>({std::declval<Args>()...}))
38) -> decltype(implicitly_construct<T>({std::declval<Args>()...}));
39
40/// @brief A fallback function to indicate that @c T is not implicitly constructible
41/// @tparam T The type to check if it can be implicitly constructed.
42/// @tparam Args The arguments to try to implicitly construct with.
43/// @return @c Always returns @c std::false_type
44template <class T, class... Args>
45constexpr auto try_to_implicitly_construct(priority_tag<0>) noexcept -> std::false_type;
46
47/// @brief Helper to determine if a type is nothrow implicitly constructible
48/// @tparam IsConstructible True if @c T is implicitly constructible from @c Args
49/// @tparam T The type to check if it can be implicitly constructed.
50/// @tparam Args The arguments to try to implicitly construct with.
51template <bool IsConstructible, class T, class... Args>
52class is_nothrow_implicitly_constructible_impl : public std::false_type {};
53
54/// @brief Helper to determine if a type is nothrow implicitly constructible
55/// @tparam T The type to check if it can be implicitly constructed.
56/// @tparam Args The arguments to try to implicitly construct with.
57template <class T, class... Args>
58class is_nothrow_implicitly_constructible_impl<true, T, Args...> {
59 public:
60 // parasoft-begin-suppress AUTOSAR-M11_0_1-a "False positive: this is not 'member data', it is a public property"
61 /// @brief True if @c T if nothrow implicitly constructible from @c Args
62 static constexpr bool value{
63 noexcept(is_implicitly_constructible_detail::try_to_implicitly_construct<T, Args...>(priority_tag<1>{}))
64 };
65 // parasoft-end-suppress AUTOSAR-M11_0_1-a
66};
67
68// parasoft-end-suppress AUTOSAR-M3_3_2-a "False positive: inline function used in multiple translation units"
69
70} // namespace is_implicitly_constructible_detail
71
72/// @brief Type trait to detect if a type is implicitly constructible from arguments of the specified types
73/// @tparam T The type to check if it can be implicitly constructed.
74/// @tparam Args The arguments to try to implicitly construct with.
75template <class T, class... Args>
78
79/// @brief Type trait to detect if a type is implicitly constructible from arguments of the specified types
80/// @tparam T The type to check if it can be implicitly constructed.
81/// @tparam Args The arguments to try to implicitly construct with.
82template <class T, class... Args>
84
85/// @brief Type trait to detect if a type is nothrow implicitly constructible from arguments of the specified types
86/// @tparam T The type to check if it can be nothrow implicitly constructed.
87/// @tparam Args The arguments to try to nothrow implicitly construct with.
88template <class T, class... Args>
89using is_nothrow_implicitly_constructible = is_implicitly_constructible_detail::
90 is_nothrow_implicitly_constructible_impl<is_implicitly_constructible_v<T, Args...>, T, Args...>;
91
92/// @brief Type trait to detect if a type is nothrow implicitly constructible from arguments of the specified types
93/// @tparam T The type to check if it can be nothrow implicitly constructed.
94/// @tparam Args The arguments to try to nothrow implicitly construct with.
95template <class T, class... Args>
97
98} // namespace base
99} // namespace arene
100
101#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_TRAITS_IS_IMPLICITLY_CONSTRUCTIBLE_HPP_
Definition array_exceptions_disabled.cpp:11
constexpr bool is_nothrow_implicitly_constructible_v
Type trait to detect if a type is nothrow implicitly constructible from arguments of the specified ty...
constexpr bool is_implicitly_constructible_v
Type trait to detect if a type is implicitly constructible from arguments of the specified types.
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10