blob: b4c42b19ddb22f67b11c5e54f0179b5999069faa [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===--------------------------- cstddef ----------------------------------===//
3//
Howard Hinnantc566dc32010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantc51e1022010-05-11 19:42:16 +00005//
Howard Hinnantee11c312010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantc51e1022010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_CSTDDEF
12#define _LIBCPP_CSTDDEF
13
14/*
15 cstddef synopsis
16
17Macros:
18
19 offsetof(type,member-designator)
20 NULL
Howard Hinnant3b6579a2010-08-22 00:02:43 +000021
Howard Hinnantc51e1022010-05-11 19:42:16 +000022namespace std
23{
24
25Types:
26
27 ptrdiff_t
28 size_t
29 max_align_t
30 nullptr_t
Marshall Clowcade1f72017-03-24 05:45:39 +000031 byte // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +000032
33} // std
34
35*/
36
37#include <__config>
Marshall Clow0a1e7502018-09-12 19:41:40 +000038#include <version>
Howard Hinnant59ef87b2010-06-02 18:53:22 +000039
Howard Hinnantaaaa52b2011-10-17 20:05:10 +000040#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +000041#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +000042#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +000043
Richard Smith523b1722015-10-09 00:26:50 +000044// Don't include our own <stddef.h>; we don't want to declare ::nullptr_t.
45#include_next <stddef.h>
46#include <__nullptr>
47
Howard Hinnantc51e1022010-05-11 19:42:16 +000048_LIBCPP_BEGIN_NAMESPACE_STD
49
50using ::ptrdiff_t;
51using ::size_t;
52
David L. Jones8465cf12017-02-10 01:27:42 +000053#if defined(__CLANG_MAX_ALIGN_T_DEFINED) || defined(_GCC_MAX_ALIGN_T) || \
Kamil Rytarowski5678f1e2018-08-20 22:29:20 +000054 defined(__DEFINED_max_align_t) || defined(__NetBSD__)
Chandler Carruth4dcf1992014-02-21 08:37:30 +000055// Re-use the compiler's <stddef.h> max_align_t where possible.
56using ::max_align_t;
57#else
Howard Hinnantc51e1022010-05-11 19:42:16 +000058typedef long double max_align_t;
Chandler Carruth4dcf1992014-02-21 08:37:30 +000059#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +000060
Howard Hinnantc51e1022010-05-11 19:42:16 +000061_LIBCPP_END_NAMESPACE_STD
62
Marshall Clowcade1f72017-03-24 05:45:39 +000063#if _LIBCPP_STD_VER > 14
64namespace std // purposefully not versioned
65{
66enum class byte : unsigned char {};
67
Marshall Clowcade1f72017-03-24 05:45:39 +000068constexpr byte operator| (byte __lhs, byte __rhs) noexcept
Marshall Clow31c8f462017-11-14 01:14:53 +000069{
Louis Dionne44bcff92018-08-03 22:36:53 +000070 return static_cast<byte>(
71 static_cast<unsigned char>(
72 static_cast<unsigned int>(__lhs) | static_cast<unsigned int>(__rhs)
73 ));
Marshall Clow31c8f462017-11-14 01:14:53 +000074}
75
76constexpr byte& operator|=(byte& __lhs, byte __rhs) noexcept
77{ return __lhs = __lhs | __rhs; }
78
79constexpr byte operator& (byte __lhs, byte __rhs) noexcept
80{
Louis Dionne44bcff92018-08-03 22:36:53 +000081 return static_cast<byte>(
82 static_cast<unsigned char>(
83 static_cast<unsigned int>(__lhs) & static_cast<unsigned int>(__rhs)
84 ));
Marshall Clow31c8f462017-11-14 01:14:53 +000085}
Marshall Clowcade1f72017-03-24 05:45:39 +000086
87constexpr byte& operator&=(byte& __lhs, byte __rhs) noexcept
Marshall Clow31c8f462017-11-14 01:14:53 +000088{ return __lhs = __lhs & __rhs; }
89
90constexpr byte operator^ (byte __lhs, byte __rhs) noexcept
91{
Louis Dionne44bcff92018-08-03 22:36:53 +000092 return static_cast<byte>(
93 static_cast<unsigned char>(
94 static_cast<unsigned int>(__lhs) ^ static_cast<unsigned int>(__rhs)
95 ));
Marshall Clow31c8f462017-11-14 01:14:53 +000096}
Marshall Clowcade1f72017-03-24 05:45:39 +000097
Louis Dionne44bcff92018-08-03 22:36:53 +000098constexpr byte& operator^=(byte& __lhs, byte __rhs) noexcept
Marshall Clow31c8f462017-11-14 01:14:53 +000099{ return __lhs = __lhs ^ __rhs; }
Marshall Clowcade1f72017-03-24 05:45:39 +0000100
101constexpr byte operator~ (byte __b) noexcept
Marshall Clow31c8f462017-11-14 01:14:53 +0000102{
103 return static_cast<byte>(
104 static_cast<unsigned char>(
105 ~static_cast<unsigned int>(__b)
106 ));
107}
Marshall Clowcade1f72017-03-24 05:45:39 +0000108
109}
110
111#include <type_traits> // rest of byte
112#endif
113
Howard Hinnantc51e1022010-05-11 19:42:16 +0000114#endif // _LIBCPP_CSTDDEF