Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
is_constructible.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_STDLIB_INCLUDE_STDLIB_DETAIL_IS_CONSTRUCTIBLE_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_IS_CONSTRUCTIBLE_HPP_
7
8// parasoft-begin-suppress CERT_CPP-DCL58-a-2 "Part of a standard library implementation"
9// parasoft-begin-suppress AUTOSAR-A17_6_1-a-2 "Part of a standard library implementation"
10
11// IWYU pragma: private, include <type_traits>
12// IWYU pragma: friend "stdlib_detail/.*"
13
14#include "stdlib/include/stdlib_detail/cstddef.hpp"
15#include "stdlib/include/stdlib_detail/declval.hpp"
16#include "stdlib/include/stdlib_detail/integral_constant.hpp"
17
18namespace std {
19/// @brief Type trait to detect if a type is constructible from arguments of the specified types
20/// @tparam Type The type to (try to) construct
21/// @tparam Args The types of the arguments to (try to) construct from
22template <typename Type, typename... Args>
23extern constexpr bool is_constructible_v = __is_constructible(Type, Args...);
24
25/// @brief Type trait to detect if a type is constructible from arguments of the specified types
26/// @tparam Type The type to (try to) construct
27/// @tparam Args The types of the arguments to (try to) construct from
28template <typename Type, typename... Args>
30
32
33// parasoft-begin-suppress AUTOSAR-A2_7_3-a "False positive: all declarations
34// and typedefs *are* preceded by a comment with @brief"
35
36/// @brief Internal implementation of @c is_nothrow_constructible
37/// @tparam IsConstructible The result of @c is_constructible_v<Type,Args...>
38/// @tparam Type The type to (try to) construct
39/// @tparam Args The types of the arguments to (try to) construct from
40///
41/// This handles the case where @c IsConstructible is @c false
42template <bool IsConstructible, typename Type, typename... Args>
44
45/// @brief Internal implementation of @c is_nothrow_constructible
46/// @tparam Type The type to (try to) construct
47/// @tparam Args The types of the arguments to (try to) construct from
48///
49/// This handles the case where @c IsConstructible is @c true
50template <typename Type, typename... Args>
51class is_nothrow_constructible_impl<true, Type, Args...> : public bool_constant<noexcept(Type(declval<Args>()...))> {};
52
53/// @brief Internal implementation of @c is_nothrow_constructible
54/// @tparam Type The type of array to (try to) construct
55/// @tparam N The size of array to (try to) construct
56/// @tparam Args The types of the arguments to (try to) construct from
57///
58/// This handles the case where we're checking a C array. A C array is nothrow constructible if the underlying type has
59/// a noexcept default constructor.
60template <typename Type, size_t N, typename... Args>
61// NOLINTNEXTLINE(hicpp-avoid-c-arrays)
62class is_nothrow_constructible_impl<true, Type[N], Args...> : public is_nothrow_constructible_impl<true, Type> {};
63
64/// @brief Internal implementation of @c is_nothrow_constructible
65/// @tparam Type The type to (try to) construct
66/// @tparam Args The types of the arguments to (try to) construct from
67///
68/// Delegate to the appropriate @c is_nothrow_constructible_impl specialization depending on the result of @c
69/// is_constructible_v
70template <typename Type, typename... Args>
72 : public is_nothrow_constructible_impl<is_constructible_v<Type, Args...>, Type, Args...> {};
73
74// parasoft-end-suppress AUTOSAR-A2_7_3-a
75
76} // namespace is_nothrow_constructible_detail
77
78/// @brief Type trait to detect if a type is constructible from arguments of the specified types and is noexcept.
79/// @tparam Type The type to (try to) construct
80/// @tparam Args The types of the arguments to (try to) construct from
81///
82/// @note This type trait also implicitly checks if the *destructor* is noexcept.
83template <typename Type, typename... Args>
85
86/// @brief Type trait to detect if a type is constructible from arguments of the specified types and is noexcept.
87/// @tparam Type The type to (try to) construct
88/// @tparam Args The types of the arguments to (try to) construct from
89///
90/// @note This type trait also implicitly checks if the *destructor* is noexcept.
91template <typename Type, typename... Args>
93
94} // namespace std
95
96#endif // INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_IS_CONSTRUCTIBLE_HPP_
Type trait to detect if a type is constructible from arguments of the specified types.
Definition is_constructible.hpp:29
Internal implementation of is_nothrow_constructible.
Definition is_constructible.hpp:43
Internal implementation of is_nothrow_constructible.
Definition is_constructible.hpp:72
Type trait to detect if a type is constructible from arguments of the specified types and is noexcept...
Definition is_constructible.hpp:84
Definition is_constructible.hpp:31
constexpr bool is_nothrow_constructible_v
Type trait to detect if a type is constructible from arguments of the specified types and is noexcept...
constexpr bool is_constructible_v
Type trait to detect if a type is constructible from arguments of the specified types.
constexpr auto operator()(::arene::base::result< void, E > const &value) const noexcept(noexcept(hash< E >{}(std::declval< E const & >()))) -> std::size_t
Calculate the hash of a result.
Definition result.hpp:1827