Skip to content

Commit 8ddbeb2

Browse files
committed
[libc] Add is_fixed_point type trait.
1 parent 61cc872 commit 8ddbeb2

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

libc/src/__support/CPP/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ add_header_library(
122122
type_traits/is_convertible.h
123123
type_traits/is_destructible.h
124124
type_traits/is_enum.h
125+
type_traits/is_fixed_point.h
125126
type_traits/is_floating_point.h
126127
type_traits/is_function.h
127128
type_traits/is_integral.h
@@ -155,6 +156,7 @@ add_header_library(
155156
libc.src.__support.macros.attributes
156157
libc.src.__support.macros.config
157158
libc.src.__support.macros.properties.float
159+
libc.include.llvm-libc-macros.stdfix_macros
158160
)
159161

160162
add_header_library(

libc/src/__support/CPP/type_traits.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "src/__support/CPP/type_traits/is_convertible.h"
2929
#include "src/__support/CPP/type_traits/is_destructible.h"
3030
#include "src/__support/CPP/type_traits/is_enum.h"
31+
#include "src/__support/CPP/type_traits/is_fixed_point.h"
3132
#include "src/__support/CPP/type_traits/is_floating_point.h"
3233
#include "src/__support/CPP/type_traits/is_function.h"
3334
#include "src/__support/CPP/type_traits/is_integral.h"
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
17+
namespace LIBC_NAMESPACE::cpp {
18+
19+
// is_fixed_point
20+
#ifdef LIBC_COMPILER_HAS_FIXED_POINT
21+
template <typename T> struct is_fixed_point {
22+
private:
23+
template <typename Head, typename... Args>
24+
LIBC_INLINE_VAR static constexpr bool __is_unqualified_any_of() {
25+
return (... || is_same_v<remove_cv_t<Head>, Args>);
26+
}
27+
28+
public:
29+
LIBC_INLINE_VAR static constexpr bool value = __is_unqualified_any_of<
30+
T, short fract, fract, long fract, unsigned short fract, unsigned fract,
31+
unsigned long fract, short accum, accum, long accum, unsigned short accum,
32+
unsigned accum, unsigned long accum>();
33+
};
34+
#else
35+
template <typename T> struct is_fixed_point : false_type {};
36+
#endif // LIBC_COMPILER_HAS_FIXED_POINT
37+
38+
template <typename T>
39+
LIBC_INLINE_VAR constexpr bool is_fixed_point_v = is_fixed_point<T>::value;
40+
41+
} // namespace LIBC_NAMESPACE::cpp
42+
43+
#endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_INTEGRAL_H

0 commit comments

Comments
 (0)