Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
give_cv_to.hpp
Go to the documentation of this file.
1// Copyright 2026, Toyota Motor Corporation
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_TRAITS_GIVE_CV_TO_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_TRAITS_GIVE_CV_TO_HPP_
7
8// IWYU pragma: private, include "arene/base/type_traits.hpp"
9// IWYU pragma: friend "(arene/base(?!/tests)|stdlib/include/stdlib_detail)/.*"
10
11#include "arene/base/stdlib_choice/is_const.hpp"
12#include "arene/base/stdlib_choice/is_volatile.hpp"
13#include "arene/base/type_traits/conditional.hpp"
14
15namespace arene {
16namespace base {
17namespace give_cv_to_detail {
18
19/// @brief add const qualification to @p T
20/// @tparam T the type to const-qualify
21///
22/// Equivalent to @c T @c const. Provided as a transparent alias to avoid
23/// instantiating the class template behind @c std::add_const_t.
24template <class T>
25using add_const_t = T const;
26
27// parasoft-begin-suppress AUTOSAR-A2_11_1-a-2 "This type trait is required to add volatile"
28/// @brief add volatile qualification to @p T
29/// @tparam T the type to volatile-qualify
30///
31/// Equivalent to @c T @c volatile. Provided as a transparent alias to avoid
32/// instantiating the class template behind @c std::add_volatile_t.
33template <class T>
34using add_volatile_t = T volatile;
35// parasoft-end-suppress AUTOSAR-A2_11_1-a-2
36
37/// @brief add the const qualification from @c From onto @c To
38/// @tparam From the type whose const qualification is copied
39/// @tparam To the type that receives the const qualification
40///
41/// If @c From is const-qualified, the result is <c> To const </c>.
42/// Otherwise the result is @c To unchanged. Existing qualifications
43/// on @c To are preserved.
44template <class From, class To>
45using give_const_to_t = conditional_apply_t<std::is_const<From>::value, add_const_t, conditional_identity_t, To>;
46
47/// @brief add the volatile qualification from @c From onto @c To
48/// @tparam From the type whose volaitle qualification is copied
49/// @tparam To the type that receives the volatile qualification
50///
51/// If @c From is volatile-qualified, the result is <c> To volatile </c>.
52/// Otherwise the result is @c To unchanged. Existing qualifications
53/// on @c To are preserved.
54template <class From, class To>
55using give_volatile_to_t =
56 conditional_apply_t<std::is_volatile<From>::value, add_volatile_t, conditional_identity_t, To>;
57// parasoft-end-suppress AUTOSAR-A2_11_1-a-2
58
59} // namespace give_cv_to_detail
60
61/// @brief Add the cv qualification from one type to another
62/// @tparam From type to copy cv-ref qualification from
63/// @tparam To type to copy cv-ref qualification to
64/// @note Does not decay @c To before adding cv qualification. If
65/// replacement semantics are desired, apply @c std::remove_cvref_t to @c To.
66template <class From, class To>
67using give_cv_to_t = //
69 From, //
71 From,
72 To>>;
73
74/// @brief Add the cv qualification from one type to another
75/// @tparam From type to copy cv-ref qualification from
76/// @tparam To type to copy cv-ref qualification to
77/// @note Does not decay @c To before adding cv qualification. If
78/// replacement semantics are desired, apply @c std::remove_cvref_t to @c To.
79template <class From, class To>
81 public:
82 /// @brief result type
84};
85
86} // namespace base
87} // namespace arene
88
89#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_TRAITS_GIVE_CV_TO_HPP_
Add the cv qualification from one type to another.
Definition give_cv_to.hpp:80
Definition array_exceptions_disabled.cpp:11
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10