Warning: This file is not a C or C++ file. It does not have highlighting.

1//===-- A self contained equivalent of cstddef ------------------*- 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
9#ifndef LLVM_LIBC_SRC___SUPPORT_CPP_CSTDDEF_H
10#define LLVM_LIBC_SRC___SUPPORT_CPP_CSTDDEF_H
11
12#include "src/__support/macros/attributes.h"
13#include "src/__support/macros/config.h"
14#include "type_traits.h" // For enable_if_t, is_integral_v.
15
16namespace LIBC_NAMESPACE_DECL {
17namespace cpp {
18
19enum class byte : unsigned char {};
20
21template <class IntegerType>
22LIBC_INLINE constexpr enable_if_t<is_integral_v<IntegerType>, byte>
23operator>>(byte b, IntegerType shift) noexcept {
24 return static_cast<byte>(static_cast<unsigned char>(b) >> shift);
25}
26template <class IntegerType>
27LIBC_INLINE constexpr enable_if_t<is_integral_v<IntegerType>, byte &>
28operator>>=(byte &b, IntegerType shift) noexcept {
29 return b = b >> shift;
30}
31template <class IntegerType>
32LIBC_INLINE constexpr enable_if_t<is_integral_v<IntegerType>, byte>
33operator<<(byte b, IntegerType shift) noexcept {
34 return static_cast<byte>(static_cast<unsigned char>(b) << shift);
35}
36template <class IntegerType>
37LIBC_INLINE constexpr enable_if_t<is_integral_v<IntegerType>, byte &>
38operator<<=(byte &b, IntegerType shift) noexcept {
39 return b = b << shift;
40}
41LIBC_INLINE constexpr byte operator|(byte l, byte r) noexcept {
42 return static_cast<byte>(static_cast<unsigned char>(l) |
43 static_cast<unsigned char>(r));
44}
45LIBC_INLINE constexpr byte &operator|=(byte &l, byte r) noexcept {
46 return l = l | r;
47}
48LIBC_INLINE constexpr byte operator&(byte l, byte r) noexcept {
49 return static_cast<byte>(static_cast<unsigned char>(l) &
50 static_cast<unsigned char>(r));
51}
52LIBC_INLINE constexpr byte &operator&=(byte &l, byte r) noexcept {
53 return l = l & r;
54}
55LIBC_INLINE constexpr byte operator^(byte l, byte r) noexcept {
56 return static_cast<byte>(static_cast<unsigned char>(l) ^
57 static_cast<unsigned char>(r));
58}
59LIBC_INLINE constexpr byte &operator^=(byte &l, byte r) noexcept {
60 return l = l ^ r;
61}
62LIBC_INLINE constexpr byte operator~(byte b) noexcept {
63 return static_cast<byte>(~static_cast<unsigned char>(b));
64}
65template <typename IntegerType>
66LIBC_INLINE constexpr enable_if_t<is_integral_v<IntegerType>, IntegerType>
67to_integer(byte b) noexcept {
68 return static_cast<IntegerType>(b);
69}
70
71} // namespace cpp
72} // namespace LIBC_NAMESPACE_DECL
73
74#endif // LLVM_LIBC_SRC___SUPPORT_CPP_CSTDDEF_H
75

Warning: This file is not a C or C++ file. It does not have highlighting.

Provided by KDAB

Privacy Policy
Update your C++ knowledge – Modern C++11/14/17 Training
Find out more

source code of libc/src/__support/CPP/cstddef.h