Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
is_integral_constant_like.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_IS_INTEGRAL_CONSTANT_LIKE_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_TRAITS_IS_INTEGRAL_CONSTANT_LIKE_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/compiler_support/diagnostics.hpp"
12#include "arene/base/constraints/constraints.hpp"
13#include "arene/base/stdlib_choice/enable_if.hpp"
14#include "arene/base/stdlib_choice/integral_constant.hpp"
15#include "arene/base/stdlib_choice/is_convertible.hpp"
16#include "arene/base/stdlib_choice/is_default_constructible.hpp"
17#include "arene/base/stdlib_choice/is_integral.hpp"
18#include "arene/base/stdlib_choice/is_member_object_pointer.hpp"
19#include "arene/base/stdlib_choice/is_same.hpp"
20// IWYU pragma: no_include "arene/base/stdlib_choice/remove_cv.hpp"
21// IWYU pragma: no_include "arene/base/stdlib_choice/remove_reference.hpp"
22#include "arene/base/type_traits/comparison_traits.hpp"
23#include "arene/base/type_traits/remove_cvref.hpp"
24
25namespace arene {
26namespace base {
27namespace is_integral_constant_like_detail {
28
29/// @brief implementation helper for @c arene::base::is_integral_constant_like_v
30/// @tparam T The type to test
31template <class T, class = arene::base::constraints<>>
32extern constexpr bool is_integral_constant_like_v = false;
33
34ARENE_IGNORE_START();
35ARENE_IGNORE_ALL("-Wfloat-equal", "Floats are rejected without the use of their comparison.");
36/// @brief implementation helper for @c arene::base::is_integral_constant_like_v
37/// @tparam T The type to test
38/// @note Use of @c T::value needs to be delayed to avoid hard errors with GCC 8
39template <class T>
40extern constexpr bool is_integral_constant_like_v<
41 T,
42 arene::base::constraints< //
43 std::enable_if_t< //
44 std::is_integral<remove_cvref_t<decltype(T::value)>>::value && //
45 !std::is_same<bool, remove_cvref_t<decltype(T::value)>>::value && //
46 std::is_convertible<T, decltype(T::value)>::value && //
47 is_equality_comparable_v<T, decltype(T::value)> && //
48 !std::is_member_object_pointer<decltype(&T::value)>::value && //
49 std::is_default_constructible<T>::value && //
50 std::integral_constant<bool, (static_cast<decltype(T::value)>(T()), true)>::value> //
51 > //
52 > = std::integral_constant<bool, (T() == T::value)>::value && //
53 std::integral_constant<bool, (static_cast<decltype(T::value)>(T()) == T::value)>::value;
54ARENE_IGNORE_END();
55
56} // namespace is_integral_constant_like_detail
57
58/// @brief Backport for the C++26 exposition-only integral-constant-like concept
59/// @tparam T The type to test
60///
61/// The concept integral-constant-like<T> specifies that all of the following
62/// are true:
63/// * is_integral_v<remove_cvref_t<decltype(T::value)>>
64/// * !is_same_v<bool, remove_cvref_t<decltype(T::value)>>
65/// * convertible_to<T, decltype(T::value)>
66/// * equality_comparable_with<T, decltype(T::value)>
67/// * bool_constant<T() == T::value>::value
68/// * bool_constant<static_cast<decltype(T::value)>(T()) == T::value>::value
69///
70template <class T>
72
73/// @brief Backport for the C++26 exposition-only integral-constant-like concept
74/// @tparam T The type to test
75///
76/// The concept integral-constant-like<T> specifies that all of the following
77/// are true:
78/// * is_integral_v<remove_cvref_t<decltype(T::value)>>
79/// * !is_same_v<bool, remove_cvref_t<decltype(T::value)>>
80/// * convertible_to<T, decltype(T::value)>
81/// * equality_comparable_with<T, decltype(T::value)>
82/// * bool_constant<T() == T::value>::value
83/// * bool_constant<static_cast<decltype(T::value)>(T()) == T::value>::value
84///
85template <class T>
87
88} // namespace base
89} // namespace arene
90
91#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_TRAITS_IS_INTEGRAL_CONSTANT_LIKE_HPP_
Definition array_exceptions_disabled.cpp:11
constexpr bool is_integral_constant_like_v
Backport for the C++26 exposition-only integral-constant-like concept.
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10