mn_def.hpp
Go to the documentation of this file.
1 
19 #ifndef _MINLIB_37360095_2231_4183_8f0e_f55524c5cda1_H_
20 #define _MINLIB_37360095_2231_4183_8f0e_f55524c5cda1_H_
21 
22 #include "mn_config.hpp"
23 
24 #include <stddef.h>
25 #include <stdint.h>
26 #include <time.h>
27 #include <sys/time.h>
28 #include <time.h>
29 
30 #include "mn_copyable.hpp"
31 #include "mn_void.hpp"
32 
33 #define MNTHREAD_STATIC_CAST_BYTE(BYTE) static_cast<unsigned char>(BYTE)
34 
35 #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)
36 
38 #define BitsInType(t) (sizeof(t) * CHAR_BIT)
39 
41 #define BitMask(t,n) (t(~t(0)) >> (BitsInType(t) - (n)))
42 
43 namespace mn {
44  using max_align_t = uintptr_t;
45  using nullptr_t = decltype(nullptr);
47 
49  using ptrdiff_t = long;
50  using uptrdiff_t = unsigned long;
51  using intmax_t = signed long;
52  using uintmax_t = unsigned long;
53 
54  const size_t default_alignment = alignof(void*);
55  constexpr size_t max_alignment = alignof(max_align_t);
56 
57  using ::clock_t;
58  using ::time_t;
59  using ::tm;
60 
61  using ::clock;
62  using ::difftime;
63  using ::mktime;
64  using ::time;
65  using ::asctime;
66  using ::ctime;
67  using ::gmtime;
68  using ::localtime;
69  using ::strftime;
70 
71  using ::gettimeofday;
72 
73  class null_type { };
74 
75  namespace math {
76  constexpr double pi = 3.14159265358979;
77  constexpr double pi_reciprocal = 0.31830988618379;
78  constexpr double pi_squared = 9.86960440108936;
79  constexpr double e = 2.71828182845905;
80  constexpr double e_reciprocal = 0.36787944117144;
81  constexpr double e_squared = 7.38905609893065;
82  constexpr double root2 = 1.41421356237310;
83  constexpr double root2_reciprocal = 0.70710678118655;
84  constexpr double euler = 0.57721566490153;
85  constexpr double golden_ratio = 1.61803398874989;
86  }
87 
88  enum class byte : unsigned char { };
89 
90  // __CHAR_MAX__
91 
92  template<typename IntegerType>
93  inline byte& operator <<= (byte& b, IntegerType shift) noexcept {
94  return b = byte(MNTHREAD_STATIC_CAST_BYTE(b) << shift);
95  }
96 
97  template<typename IntegerType>
98  inline byte& operator >>= (byte& b, IntegerType shift) noexcept {
99  return b = byte(MNTHREAD_STATIC_CAST_BYTE(b) >> shift);
100  }
101 
102  template<typename IntegerType>
103  inline constexpr byte operator << (byte& b, IntegerType shift) noexcept {
104  return b = byte(MNTHREAD_STATIC_CAST_BYTE(b) << shift);
105  }
106 
107  template<typename IntegerType>
108  inline constexpr byte operator >> (byte& b, IntegerType shift) noexcept {
109  return b = byte(MNTHREAD_STATIC_CAST_BYTE(b) >> shift);
110  }
111 
112  inline constexpr bool operator==( const byte l, const byte r ) noexcept {
113  return l == r;
114  }
115 
116  inline constexpr bool operator!=( const byte l, const byte r ) noexcept {
117  return !( l == r );
118  }
119 
120  inline constexpr bool operator< ( const byte l, const byte r ) noexcept {
121  return l < r;
122  }
123 
124  inline constexpr bool operator<=( const byte l, const byte r ) noexcept {
125  return !( r < l );
126  }
127 
128  inline constexpr bool operator> ( const byte l, const byte r ) noexcept {
129  return ( r < l );
130  }
131 
132  inline constexpr bool operator>=( const byte l, const byte r ) noexcept {
133  return !( l < r );
134  }
135 
136  inline byte operator |= (byte& lhr, const byte rhr) noexcept {
138  return lhr;
139  }
140 
141  inline byte operator &= (byte& lhr, const byte rhr) noexcept {
143  return lhr;
144  }
145  inline byte operator ^= (byte& lhr, const byte rhr) noexcept {
147  return lhr;
148  }
149 
150  inline constexpr byte operator | (const byte& lhr, const byte& rhr) noexcept {
152  }
153 
154  inline constexpr byte operator ^ (const byte& lhr, const byte& rhr) noexcept {
156  }
157 
158  inline constexpr byte operator & (const byte& lhr, const byte& rhr) noexcept {
160  }
161 
162  inline constexpr byte operator ~ (byte b) noexcept {
163  return byte(~MNTHREAD_STATIC_CAST_BYTE(b));
164  }
165 }
166 
167 #endif
#define MN_THREAD_CONFIG_SIZE_TYPE
Definition: mn_config.hpp:127
#define MNTHREAD_STATIC_CAST_BYTE(BYTE)
Definition: mn_def.hpp:33
constexpr double root2_reciprocal
Definition: mn_def.hpp:83
constexpr double pi_squared
Definition: mn_def.hpp:78
constexpr double e
Definition: mn_def.hpp:79
constexpr double root2
Definition: mn_def.hpp:82
constexpr double pi_reciprocal
Definition: mn_def.hpp:77
constexpr double e_squared
Definition: mn_def.hpp:81
constexpr double euler
Definition: mn_def.hpp:84
constexpr double pi
Definition: mn_def.hpp:76
constexpr double golden_ratio
Definition: mn_def.hpp:85
constexpr double e_reciprocal
Definition: mn_def.hpp:80
Definition: mn_allocator_typetraits.hpp:25
constexpr bool operator==(const byte l, const byte r) noexcept
Definition: mn_def.hpp:112
constexpr byte operator~(byte b) noexcept
Definition: mn_def.hpp:162
nullptr_t addrof_null_t
Definition: mn_def.hpp:46
memory_order operator&(memory_order mMemOrder, modifier::memory_order mod)
Definition: mn_atomic_flags.hpp:63
unsigned long uintmax_t
Definition: mn_def.hpp:52
unsigned long uptrdiff_t
Definition: mn_def.hpp:50
byte operator^=(byte &lhr, const byte rhr) noexcept
Definition: mn_def.hpp:145
constexpr byte operator<<(byte &b, IntegerType shift) noexcept
Definition: mn_def.hpp:103
constexpr bool operator!=(const byte l, const byte r) noexcept
Definition: mn_def.hpp:116
constexpr size_t max_alignment
Definition: mn_def.hpp:55
byte operator|=(byte &lhr, const byte rhr) noexcept
Definition: mn_def.hpp:136
constexpr bool operator<=(const byte l, const byte r) noexcept
Definition: mn_def.hpp:124
constexpr byte operator>>(byte &b, IntegerType shift) noexcept
Definition: mn_def.hpp:108
long ptrdiff_t
Definition: mn_def.hpp:49
memory_order operator|(memory_order mMemOrder, modifier::memory_order mod)
Definition: mn_atomic_flags.hpp:59
constexpr bool operator<(const byte l, const byte r) noexcept
Definition: mn_def.hpp:120
constexpr byte operator^(const byte &lhr, const byte &rhr) noexcept
Definition: mn_def.hpp:154
constexpr bool operator>=(const byte l, const byte r) noexcept
Definition: mn_def.hpp:132
uintptr_t max_align_t
Definition: mn_def.hpp:44
byte
Definition: mn_def.hpp:88
signed long intmax_t
Definition: mn_def.hpp:51
byte & operator<<=(byte &b, IntegerType shift) noexcept
Definition: mn_def.hpp:93
decltype(nullptr) nullptr_t
Definition: mn_def.hpp:45
byte & operator>>=(byte &b, IntegerType shift) noexcept
Definition: mn_def.hpp:98
const size_t default_alignment
Definition: mn_def.hpp:54
byte operator&=(byte &lhr, const byte rhr) noexcept
Definition: mn_def.hpp:141
constexpr bool operator>(const byte l, const byte r) noexcept
Definition: mn_def.hpp:128
Definition: mn_def.hpp:73