blob: 0030ec289a8ca2f41680bb58fc114d88663a6ff0 [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
31
32} // std
33
34*/
35
36#include <__config>
Howard Hinnant59ef87b2010-06-02 18:53:22 +000037
38#ifdef __GLIBC__
39#define __need_NULL
40#define __need_ptrdiff_t
41#define __need_size_t
Howard Hinnant3b6579a2010-08-22 00:02:43 +000042#endif // __GLIBC__
Howard Hinnant59ef87b2010-06-02 18:53:22 +000043
Howard Hinnant10419932010-05-28 18:04:31 +000044#include <stddef.h>
Howard Hinnantc51e1022010-05-11 19:42:16 +000045
Howard Hinnantaaaa52b2011-10-17 20:05:10 +000046#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +000047#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +000048#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +000049
50_LIBCPP_BEGIN_NAMESPACE_STD
51
52using ::ptrdiff_t;
53using ::size_t;
54
Chandler Carruth4dcf1992014-02-21 08:37:30 +000055#if defined(__CLANG_MAX_ALIGN_T_DEFINED) || defined(_GCC_MAX_ALIGN_T)
56// Re-use the compiler's <stddef.h> max_align_t where possible.
57using ::max_align_t;
58#else
Howard Hinnantc51e1022010-05-11 19:42:16 +000059typedef long double max_align_t;
Chandler Carruth4dcf1992014-02-21 08:37:30 +000060#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +000061
62#ifdef _LIBCPP_HAS_NO_NULLPTR
63
Howard Hinnanta37d3cf2013-08-12 18:38:34 +000064struct _LIBCPP_TYPE_VIS_ONLY nullptr_t
Howard Hinnantc51e1022010-05-11 19:42:16 +000065{
Howard Hinnant49e145e2012-10-30 19:06:59 +000066 void* __lx;
Howard Hinnantc51e1022010-05-11 19:42:16 +000067
68 struct __nat {int __for_bool_;};
69
Howard Hinnant49e145e2012-10-30 19:06:59 +000070 _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR nullptr_t() : __lx(0) {}
71 _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR nullptr_t(int __nat::*) : __lx(0) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +000072
Howard Hinnant20bbd0b2012-09-24 23:36:40 +000073 _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR operator int __nat::*() const {return 0;}
Howard Hinnantc51e1022010-05-11 19:42:16 +000074
Howard Hinnantf39463b2010-05-18 17:32:30 +000075 template <class _Tp>
Howard Hinnant20bbd0b2012-09-24 23:36:40 +000076 _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR
Howard Hinnantf39463b2010-05-18 17:32:30 +000077 operator _Tp* () const {return 0;}
Howard Hinnantc51e1022010-05-11 19:42:16 +000078
Howard Hinnantf39463b2010-05-18 17:32:30 +000079 template <class _Tp, class _Up>
Howard Hinnant3b6579a2010-08-22 00:02:43 +000080 _LIBCPP_ALWAYS_INLINE
Howard Hinnantf39463b2010-05-18 17:32:30 +000081 operator _Tp _Up::* () const {return 0;}
Howard Hinnantc51e1022010-05-11 19:42:16 +000082
Howard Hinnant20bbd0b2012-09-24 23:36:40 +000083 friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator==(nullptr_t, nullptr_t) {return true;}
84 friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator!=(nullptr_t, nullptr_t) {return false;}
85 friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator<(nullptr_t, nullptr_t) {return false;}
86 friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator<=(nullptr_t, nullptr_t) {return true;}
87 friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator>(nullptr_t, nullptr_t) {return false;}
88 friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator>=(nullptr_t, nullptr_t) {return true;}
Howard Hinnantc51e1022010-05-11 19:42:16 +000089};
90
Howard Hinnant20bbd0b2012-09-24 23:36:40 +000091inline _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR nullptr_t __get_nullptr_t() {return nullptr_t(0);}
Howard Hinnantc51e1022010-05-11 19:42:16 +000092
Howard Hinnantb1ad5a82011-06-30 21:18:19 +000093#define nullptr _VSTD::__get_nullptr_t()
Howard Hinnantc51e1022010-05-11 19:42:16 +000094
Howard Hinnant3b6579a2010-08-22 00:02:43 +000095#endif // _LIBCPP_HAS_NO_NULLPTR
Howard Hinnantc51e1022010-05-11 19:42:16 +000096
97_LIBCPP_END_NAMESPACE_STD
98
Howard Hinnantc26e9212011-06-05 13:00:46 +000099#ifndef _LIBCPP_HAS_NO_NULLPTR
100
101namespace std
102{
103 typedef decltype(nullptr) nullptr_t;
104}
105
106#endif // _LIBCPP_HAS_NO_NULLPTR
107
Howard Hinnantc51e1022010-05-11 19:42:16 +0000108#endif // _LIBCPP_CSTDDEF