blob: a5297ec15db79780b0caa978e1e25ad045541f4e [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===--------------------------- cstddef ----------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
6// This file is distributed under the University of Illinois Open Source
7// License. See LICENSE.TXT for details.
8//
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 Hinnant324bb032010-08-22 00:02:43 +000021
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000022namespace std
23{
24
25Types:
26
27 ptrdiff_t
28 size_t
29 max_align_t
30 nullptr_t
31
32} // std
33
34*/
35
36#include <__config>
Howard Hinnanted30e072010-06-02 18:53:22 +000037
38#ifdef __GLIBC__
39#define __need_NULL
40#define __need_ptrdiff_t
41#define __need_size_t
Howard Hinnant324bb032010-08-22 00:02:43 +000042#endif // __GLIBC__
Howard Hinnanted30e072010-06-02 18:53:22 +000043
Howard Hinnante0569242010-05-28 18:04:31 +000044#include <stddef.h>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000045
46#pragma GCC system_header
47
48_LIBCPP_BEGIN_NAMESPACE_STD
49
50using ::ptrdiff_t;
51using ::size_t;
52
53typedef long double max_align_t;
54
55#ifdef _LIBCPP_HAS_NO_NULLPTR
56
57struct nullptr_t
58{
59 void* _;
60
61 struct __nat {int __for_bool_;};
62
63 _LIBCPP_ALWAYS_INLINE nullptr_t(int __nat::*) {}
64
65 _LIBCPP_ALWAYS_INLINE operator int __nat::*() const {return 0;}
66
Howard Hinnantd8bc09b2010-05-18 17:32:30 +000067 template <class _Tp>
Howard Hinnant324bb032010-08-22 00:02:43 +000068 _LIBCPP_ALWAYS_INLINE
Howard Hinnantd8bc09b2010-05-18 17:32:30 +000069 operator _Tp* () const {return 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000070
Howard Hinnantd8bc09b2010-05-18 17:32:30 +000071 template <class _Tp, class _Up>
Howard Hinnant324bb032010-08-22 00:02:43 +000072 _LIBCPP_ALWAYS_INLINE
Howard Hinnantd8bc09b2010-05-18 17:32:30 +000073 operator _Tp _Up::* () const {return 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000074
75 friend _LIBCPP_ALWAYS_INLINE bool operator==(nullptr_t, nullptr_t) {return true;}
76 friend _LIBCPP_ALWAYS_INLINE bool operator!=(nullptr_t, nullptr_t) {return false;}
77 friend _LIBCPP_ALWAYS_INLINE bool operator<(nullptr_t, nullptr_t) {return false;}
78 friend _LIBCPP_ALWAYS_INLINE bool operator<=(nullptr_t, nullptr_t) {return true;}
79 friend _LIBCPP_ALWAYS_INLINE bool operator>(nullptr_t, nullptr_t) {return false;}
80 friend _LIBCPP_ALWAYS_INLINE bool operator>=(nullptr_t, nullptr_t) {return true;}
Howard Hinnant60a0a8e2010-08-10 20:48:29 +000081
82 template <typename _Tp>
83 friend _LIBCPP_ALWAYS_INLINE bool operator==(nullptr_t, _Tp* __p) {return 0 == __p;}
84
85 template <typename _Tp>
86 friend _LIBCPP_ALWAYS_INLINE bool operator==(_Tp* __p, nullptr_t) {return __p == 0;}
87
88 template <class _Tp>
89 friend _LIBCPP_ALWAYS_INLINE bool operator!=(nullptr_t, _Tp* __p) {return 0 != __p;}
90
91 template <class _Tp>
92 friend _LIBCPP_ALWAYS_INLINE bool operator!=(_Tp* __p, nullptr_t) {return __p != 0;}
93
94 template <class _Tp>
95 friend _LIBCPP_ALWAYS_INLINE bool operator<(nullptr_t, _Tp* __p) {return 0 < __p;}
96
97 template <class _Tp>
98 friend _LIBCPP_ALWAYS_INLINE bool operator<(_Tp* __p, nullptr_t) {return __p < 0;}
99
100 template <class _Tp>
101 friend _LIBCPP_ALWAYS_INLINE bool operator<=(nullptr_t, _Tp* __p) {return 0 <= __p;}
102
103 template <class _Tp>
104 friend _LIBCPP_ALWAYS_INLINE bool operator<=(_Tp* __p, nullptr_t) {return __p <= 0;}
105
106 template <class _Tp>
107 friend _LIBCPP_ALWAYS_INLINE bool operator>(nullptr_t, _Tp* __p) {return 0 > __p;}
108
109 template <class _Tp>
110 friend _LIBCPP_ALWAYS_INLINE bool operator>(_Tp* __p, nullptr_t) {return __p > 0;}
111
112 template <class _Tp>
113 friend _LIBCPP_ALWAYS_INLINE bool operator>=(nullptr_t, _Tp* __p) {return 0 >= __p;}
114
115 template <class _Tp>
116 friend _LIBCPP_ALWAYS_INLINE bool operator>=(_Tp* __p, nullptr_t) {return __p >= 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000117};
118
119inline _LIBCPP_ALWAYS_INLINE nullptr_t __get_nullptr_t() {return nullptr_t(0);}
120
121#define nullptr _STD::__get_nullptr_t()
122
Howard Hinnant324bb032010-08-22 00:02:43 +0000123#else // _LIBCPP_HAS_NO_NULLPTR
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000124
125typedef decltype(nullptr) nullptr_t;
126
Howard Hinnant324bb032010-08-22 00:02:43 +0000127#endif // _LIBCPP_HAS_NO_NULLPTR
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000128
129_LIBCPP_END_NAMESPACE_STD
130
131#endif // _LIBCPP_CSTDDEF