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 #include "src/__support/macros/config.h" 15 16 namespace LIBC_NAMESPACE_DECL { 17 namespace cpp { 18 19 // is_signed 20 template <typename T> 21 struct is_signed : bool_constant<(is_arithmetic_v<T> && (T(-1) < T(0)))> { 22 LIBC_INLINE constexpr operator bool() const { return is_signed::value; } 23 LIBC_INLINE constexpr bool operator()() const { return is_signed::value; } 24 }; 25 template <typename T> 26 LIBC_INLINE_VAR constexpr bool is_signed_v = is_signed<T>::value; 27 28 } // namespace cpp 29 } // namespace LIBC_NAMESPACE_DECL 30 31 #endif // LLVM_LIBC_SRC___SUPPORT_CPP_TYPE_TRAITS_IS_SIGNED_H 32