[libc++][Android] Allow testing libc++ with clang-r536225 (#116149)
[llvm-project.git] / libc / src / __support / sign.h
blob4a629e448819567977cebabc4bafc094e10bc1ff
1 //===-- A simple sign type --------------------------------------*- 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 //===----------------------------------------------------------------------===//
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.
17 struct Sign {
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) {
26 return !(a == b);
29 static const Sign POS;
30 static const Sign NEG;
32 private:
33 LIBC_INLINE constexpr explicit Sign(bool is_negative)
34 : is_negative(is_negative) {}
36 bool 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