1 | //===-- is_signed 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_SIGNED_H |
9 | #define LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_SIGNED_H |
10 | |
11 | #include "src/__support/CPP/type_traits/bool_constant.h" |
12 | #include "src/__support/CPP/type_traits/is_arithmetic.h" |
13 | #include "src/__support/macros/attributes.h" |
14 | |
15 | namespace LIBC_NAMESPACE::cpp { |
16 | |
17 | // is_signed |
18 | template <typename T> |
19 | struct is_signed : bool_constant<(is_arithmetic_v<T> && (T(-1) < T(0)))> { |
20 | LIBC_INLINE constexpr operator bool() const { return is_signed::value; } |
21 | LIBC_INLINE constexpr bool operator()() const { return is_signed::value; } |
22 | }; |
23 | template <typename T> |
24 | LIBC_INLINE_VAR constexpr bool is_signed_v = is_signed<T>::value; |
25 | |
26 | } // namespace LIBC_NAMESPACE::cpp |
27 | |
28 | #endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_SIGNED_H |
29 | |