Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
constraints.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_CONSTRAINTS_CONSTRAINTS_HPP_
6
#
define
INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_CONSTRAINTS_CONSTRAINTS_HPP_
7
8
// IWYU pragma: private, include "arene/base/constraints.hpp"
9
// IWYU pragma: friend "(arene/base(?!/tests)|stdlib/include/stdlib_detail)/.*"
10
11
namespace
arene
{
12
namespace
base
{
13
namespace
constraints_impl {
14
15
/// @brief Implementation-detail to force arguments of @c Constraints to be a part of
16
/// the mangling of function templates for which they are requirements.
17
template
<
class
...>
18
struct
constraints {
19
/// @brief The type that is actually used for the @c constraints template parameters
20
using
type =
decltype
(
nullptr
);
21
};
22
23
}
// namespace constraints_impl
24
25
// parasoft-begin-suppress AUTOSAR-A2_7_3-a-2 "False positive: the typedef *is* preceded by a comment with @brief"
26
/// @brief Helper used to express template constraints in a consistent way using @c std::enable_if_t.
27
///
28
/// Use with @c std::enable_if_t to group N short-circuited constraints without N top-level template
29
/// parameters and without @c std::conjunction . This preserves error
30
/// information while also minimizing extraneous template parameters. If we
31
/// eventually move all users to C++20, we can remove this and use
32
/// language-level concepts.
33
///
34
/// Usage Example:
35
/// @snippet docs/examples/constraints_examples.cpp contrained_function_example
36
///
37
/// @note @c constraints is an alias to @c std::nullptr_t for two reasons.
38
/// 1) It is unlikely that someone invoking the function-template will
39
/// accidentally pass an explicit "nullptr" as a template argument the
40
/// place that the constraints appear in the template parameter list.
41
/// 2) There is only one possible value for a @c std::nullptr_t argument, so
42
/// the choice for default argument value being @c nullptr is not
43
/// subjective.
44
///
45
/// Users should prefer using @c constraints to form the template parameter
46
/// kind as in the example, as opposed to using its result as a default argument
47
/// for a class template parameter. This is so that constraints in overload sets
48
/// do not conflict with each other as if redeclarations that differ only by
49
/// default arguments.
50
template
<
class
... EnableIfs>
51
using
constraints =
typename
constraints_impl::constraints<EnableIfs...>::type;
52
// parasoft-end-suppress AUTOSAR-A2_7_3-a-2
53
54
}
// namespace base
55
}
// namespace arene
56
57
#
endif
// INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_CONSTRAINTS_CONSTRAINTS_HPP_
arene::base
Definition
array_exceptions_disabled.cpp:11
arene
Copyright 2026, Toyota Motor Corporation.
Definition
array_exceptions_disabled.cpp:10
arene
base
constraints
constraints.hpp
Generated by
1.13.2