xref: /aosp_15_r20/external/llvm-libc/src/__support/CPP/type_traits/is_fixed_point.h (revision 71db0c75aadcf003ffe3238005f61d7618a3fead)
1 //===-- is_fixed_point type_traits ------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 #ifndef LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_FIXED_POINT_H
9 #define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_FIXED_POINT_H
10 
11 #include "src/__support/CPP/type_traits/is_same.h"
12 #include "src/__support/CPP/type_traits/remove_cv.h"
13 #include "src/__support/macros/attributes.h"
14 
15 #include "include/llvm-libc-macros/stdfix-macros.h"
16 #include "src/__support/macros/config.h"
17 
18 namespace LIBC_NAMESPACE_DECL {
19 namespace cpp {
20 
21 // is_fixed_point
22 #ifdef LIBC_COMPILER_HAS_FIXED_POINT
23 template <typename T> struct is_fixed_point {
24 private:
25   template <typename Head, typename... Args>
__is_unqualified_any_ofis_fixed_point26   LIBC_INLINE static constexpr bool __is_unqualified_any_of() {
27     return (... || is_same_v<remove_cv_t<Head>, Args>);
28   }
29 
30 public:
31   LIBC_INLINE_VAR static constexpr bool value = __is_unqualified_any_of<
32       T, short fract, fract, long fract, unsigned short fract, unsigned fract,
33       unsigned long fract, short accum, accum, long accum, unsigned short accum,
34       unsigned accum, unsigned long accum, short sat fract, sat fract,
35       long sat fract, unsigned short sat fract, unsigned sat fract,
36       unsigned long sat fract, short sat accum, sat accum, long sat accum,
37       unsigned short sat accum, unsigned sat accum, unsigned long sat accum>();
38 };
39 #else
40 template <typename T> struct is_fixed_point : false_type {};
41 #endif // LIBC_COMPILER_HAS_FIXED_POINT
42 
43 template <typename T>
44 LIBC_INLINE_VAR constexpr bool is_fixed_point_v = is_fixed_point<T>::value;
45 
46 } // namespace cpp
47 } // namespace LIBC_NAMESPACE_DECL
48 
49 #endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_FIXED_POINT_H
50