1 //===-- A simple sign type --------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_SRC___SUPPORT_SIGN_H
10 #define LLVM_LIBC_SRC___SUPPORT_SIGN_H
12 #include "src/__support/macros/attributes.h" // LIBC_INLINE, LIBC_INLINE_VAR
14 namespace LIBC_NAMESPACE_DECL
{
16 // A type to interact with signed arithmetic types.
18 LIBC_INLINE
constexpr bool is_pos() const { return !is_negative
; }
19 LIBC_INLINE
constexpr bool is_neg() const { return is_negative
; }
21 LIBC_INLINE
friend constexpr bool operator==(Sign a
, Sign b
) {
22 return a
.is_negative
== b
.is_negative
;
25 LIBC_INLINE
friend constexpr bool operator!=(Sign a
, Sign b
) {
29 static const Sign POS
;
30 static const Sign NEG
;
33 LIBC_INLINE
constexpr explicit Sign(bool is_negative
)
34 : is_negative(is_negative
) {}
39 LIBC_INLINE_VAR
constexpr Sign
Sign::NEG
= Sign(true);
40 LIBC_INLINE_VAR
constexpr Sign
Sign::POS
= Sign(false);
42 } // namespace LIBC_NAMESPACE_DECL
43 #endif // LLVM_LIBC_SRC___SUPPORT_SIGN_H