Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===--------------------------- cstddef ----------------------------------===// |
| 3 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // |
| 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 | |
| 17 | Macros: |
| 18 | |
| 19 | offsetof(type,member-designator) |
| 20 | NULL |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame^] | 21 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 22 | namespace std |
| 23 | { |
| 24 | |
| 25 | Types: |
| 26 | |
| 27 | ptrdiff_t |
| 28 | size_t |
| 29 | max_align_t |
| 30 | nullptr_t |
| 31 | |
| 32 | } // std |
| 33 | |
| 34 | */ |
| 35 | |
| 36 | #include <__config> |
Howard Hinnant | ed30e07 | 2010-06-02 18:53:22 +0000 | [diff] [blame] | 37 | |
| 38 | #ifdef __GLIBC__ |
| 39 | #define __need_NULL |
| 40 | #define __need_ptrdiff_t |
| 41 | #define __need_size_t |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame^] | 42 | #endif // __GLIBC__ |
Howard Hinnant | ed30e07 | 2010-06-02 18:53:22 +0000 | [diff] [blame] | 43 | |
Howard Hinnant | e056924 | 2010-05-28 18:04:31 +0000 | [diff] [blame] | 44 | #include <stddef.h> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 45 | |
| 46 | #pragma GCC system_header |
| 47 | |
| 48 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 49 | |
| 50 | using ::ptrdiff_t; |
| 51 | using ::size_t; |
| 52 | |
| 53 | typedef long double max_align_t; |
| 54 | |
| 55 | #ifdef _LIBCPP_HAS_NO_NULLPTR |
| 56 | |
| 57 | struct 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 Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 67 | template <class _Tp> |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame^] | 68 | _LIBCPP_ALWAYS_INLINE |
Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 69 | operator _Tp* () const {return 0;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 70 | |
Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 71 | template <class _Tp, class _Up> |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame^] | 72 | _LIBCPP_ALWAYS_INLINE |
Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 73 | operator _Tp _Up::* () const {return 0;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 74 | |
| 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 Hinnant | 60a0a8e | 2010-08-10 20:48:29 +0000 | [diff] [blame] | 81 | |
| 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 Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 117 | }; |
| 118 | |
| 119 | inline _LIBCPP_ALWAYS_INLINE nullptr_t __get_nullptr_t() {return nullptr_t(0);} |
| 120 | |
| 121 | #define nullptr _STD::__get_nullptr_t() |
| 122 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame^] | 123 | #else // _LIBCPP_HAS_NO_NULLPTR |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 124 | |
| 125 | typedef decltype(nullptr) nullptr_t; |
| 126 | |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame^] | 127 | #endif // _LIBCPP_HAS_NO_NULLPTR |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 128 | |
| 129 | _LIBCPP_END_NAMESPACE_STD |
| 130 | |
| 131 | #endif // _LIBCPP_CSTDDEF |