blob: c3ca64a9c01497bfd9c11d4f88b5d7cd0c5214ef [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
Howard Hinnant10419932010-05-28 18:04:31 +000038#include <stddef.h>
Howard Hinnantc51e1022010-05-11 19:42:16 +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
44_LIBCPP_BEGIN_NAMESPACE_STD
45
46using ::ptrdiff_t;
47using ::size_t;
48
Chandler Carruth4dcf1992014-02-21 08:37:30 +000049#if defined(__CLANG_MAX_ALIGN_T_DEFINED) || defined(_GCC_MAX_ALIGN_T)
50// Re-use the compiler's <stddef.h> max_align_t where possible.
51using ::max_align_t;
52#else
Howard Hinnantc51e1022010-05-11 19:42:16 +000053typedef long double max_align_t;
Chandler Carruth4dcf1992014-02-21 08:37:30 +000054#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +000055
56#ifdef _LIBCPP_HAS_NO_NULLPTR
57
Howard Hinnanta37d3cf2013-08-12 18:38:34 +000058struct _LIBCPP_TYPE_VIS_ONLY nullptr_t
Howard Hinnantc51e1022010-05-11 19:42:16 +000059{
Howard Hinnant49e145e2012-10-30 19:06:59 +000060 void* __lx;
Howard Hinnantc51e1022010-05-11 19:42:16 +000061
62 struct __nat {int __for_bool_;};
63
Howard Hinnant49e145e2012-10-30 19:06:59 +000064 _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR nullptr_t() : __lx(0) {}
65 _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR nullptr_t(int __nat::*) : __lx(0) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +000066
Howard Hinnant20bbd0b2012-09-24 23:36:40 +000067 _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR operator int __nat::*() const {return 0;}
Howard Hinnantc51e1022010-05-11 19:42:16 +000068
Howard Hinnantf39463b2010-05-18 17:32:30 +000069 template <class _Tp>
Howard Hinnant20bbd0b2012-09-24 23:36:40 +000070 _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR
Howard Hinnantf39463b2010-05-18 17:32:30 +000071 operator _Tp* () const {return 0;}
Howard Hinnantc51e1022010-05-11 19:42:16 +000072
Howard Hinnantf39463b2010-05-18 17:32:30 +000073 template <class _Tp, class _Up>
Howard Hinnant3b6579a2010-08-22 00:02:43 +000074 _LIBCPP_ALWAYS_INLINE
Howard Hinnantf39463b2010-05-18 17:32:30 +000075 operator _Tp _Up::* () const {return 0;}
Howard Hinnantc51e1022010-05-11 19:42:16 +000076
Howard Hinnant20bbd0b2012-09-24 23:36:40 +000077 friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator==(nullptr_t, nullptr_t) {return true;}
78 friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator!=(nullptr_t, nullptr_t) {return false;}
79 friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator<(nullptr_t, nullptr_t) {return false;}
80 friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator<=(nullptr_t, nullptr_t) {return true;}
81 friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator>(nullptr_t, nullptr_t) {return false;}
82 friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator>=(nullptr_t, nullptr_t) {return true;}
Howard Hinnantc51e1022010-05-11 19:42:16 +000083};
84
Howard Hinnant20bbd0b2012-09-24 23:36:40 +000085inline _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR nullptr_t __get_nullptr_t() {return nullptr_t(0);}
Howard Hinnantc51e1022010-05-11 19:42:16 +000086
Howard Hinnantb1ad5a82011-06-30 21:18:19 +000087#define nullptr _VSTD::__get_nullptr_t()
Howard Hinnantc51e1022010-05-11 19:42:16 +000088
Howard Hinnant3b6579a2010-08-22 00:02:43 +000089#endif // _LIBCPP_HAS_NO_NULLPTR
Howard Hinnantc51e1022010-05-11 19:42:16 +000090
91_LIBCPP_END_NAMESPACE_STD
92
Howard Hinnantc26e9212011-06-05 13:00:46 +000093#ifndef _LIBCPP_HAS_NO_NULLPTR
94
95namespace std
96{
97 typedef decltype(nullptr) nullptr_t;
98}
99
100#endif // _LIBCPP_HAS_NO_NULLPTR
101
Howard Hinnantc51e1022010-05-11 19:42:16 +0000102#endif // _LIBCPP_CSTDDEF