Photon microGUI widgets library 0.6.0
type_zero.hpp
1#ifndef _STDEX_TYPE_ZERO_H
2#define _STDEX_TYPE_ZERO_H
3
4// stdex includes
5/*none*/
6
7// POSIX includes
8/*none*/
9
10// std includes
11#include <memory.h>
12#include <cstddef>
13
14namespace stdex
15{
16 template<class T>
17 struct type_zero :
18 public T
19 {
20 type_zero() { memset(&static_cast<T&>(*this), 0, sizeof(T)); }
21 };
22
23 template<class T, std::size_t N>
24 struct type_zero<T[N]>
25 {
26 typedef T array_t[N];
27
28 array_t data;
29
30 type_zero() { memset(data, 0, sizeof(data)); }
31
32 T& operator[](int n) { return data[n]; }
33 const T& operator[](int n) const { return data[n]; }
34
35 T& operator*() { return *data; }
36 const T& operator*() const { return *data; }
37
38 friend T* operator+(type_zero &arr, int n) { return arr.data + n; }
39 friend T* operator+(int n, type_zero &arr) { return n + arr.data; }
40 friend const T* operator+(const type_zero &arr, int n) { return arr.data + n; }
41 friend const T* operator+(int n, const type_zero &arr) { return n + arr.data; }
42
43 friend T* operator-(type_zero &arr, int n) { return arr.data - n; }
44 friend T* operator-(int n, type_zero &arr) { return n - arr.data; }
45 friend const T* operator-(const type_zero &arr, int n) { return arr.data - n; }
46 friend const T* operator-(int n, const type_zero &arr) { return n - arr.data; }
47
48 friend bool operator>(const type_zero &lhs, const type_zero &rhs) { return lhs.data > rhs.data; }
49 friend bool operator>(const T *lhs, const type_zero &rhs) { return lhs > rhs.data; }
50 friend bool operator>(const type_zero &lhs, const T *rhs) { return lhs.data > rhs; }
51
52 friend bool operator>=(const type_zero &lhs, const type_zero &rhs) { return lhs.data >= rhs.data; }
53 friend bool operator>=(const T *lhs, const type_zero &rhs) { return lhs >= rhs.data; }
54 friend bool operator>=(const type_zero &lhs, const T *rhs) { return lhs.data >= rhs; }
55
56 friend bool operator<(const type_zero &lhs, const type_zero &rhs) { return lhs.data < rhs.data; }
57 friend bool operator<(const T *lhs, const type_zero &rhs) { return lhs < rhs.data; }
58 friend bool operator<(const type_zero &lhs, const T *rhs) { return lhs.data < rhs; }
59
60 friend bool operator<=(const type_zero &lhs, const type_zero &rhs) { return lhs.data <= rhs.data; }
61 friend bool operator<=(const T *lhs, const type_zero &rhs) { return lhs <= rhs.data; }
62 friend bool operator<=(const type_zero &lhs, const T *rhs) { return lhs.data <= rhs; }
63
64 friend bool operator==(const type_zero &lhs, const type_zero &rhs) { return lhs.data == rhs.data; }
65
66 operator array_t&() { return data; }
67 operator const array_t&() const { return data; }
68 };
69
70 template<class T, std::size_t N>
71 struct type_zero<const T[N]>
72 {
73 typedef T array_t[N];
74
75 array_t data;
76
77 type_zero() { memset(data, 0, sizeof(data)); }
78
79 T& operator[](int n) { return data[n]; }
80 const T& operator[](int n) const { return data[n]; }
81
82 T& operator*() { return *data; }
83 const T& operator*() const { return *data; }
84
85 friend T* operator+(type_zero &arr, int n) { return arr.data + n; }
86 friend T* operator+(int n, type_zero &arr) { return n + arr.data; }
87 friend const T* operator+(const type_zero &arr, int n) { return arr.data + n; }
88 friend const T* operator+(int n, const type_zero &arr) { return n + arr.data; }
89
90 friend T* operator-(type_zero &arr, int n) { return arr.data - n; }
91 friend T* operator-(int n, type_zero &arr) { return n - arr.data; }
92 friend const T* operator-(const type_zero &arr, int n) { return arr.data - n; }
93 friend const T* operator-(int n, const type_zero &arr) { return n - arr.data; }
94
95 friend bool operator>(const type_zero &lhs, const type_zero &rhs) { return lhs.data > rhs.data; }
96 friend bool operator>(const T *lhs, const type_zero &rhs) { return lhs > rhs.data; }
97 friend bool operator>(const type_zero &lhs, const T *rhs) { return lhs.data > rhs; }
98
99 friend bool operator>=(const type_zero &lhs, const type_zero &rhs) { return lhs.data >= rhs.data; }
100 friend bool operator>=(const T *lhs, const type_zero &rhs) { return lhs >= rhs.data; }
101 friend bool operator>=(const type_zero &lhs, const T *rhs) { return lhs.data >= rhs; }
102
103 friend bool operator<(const type_zero &lhs, const type_zero &rhs) { return lhs.data < rhs.data; }
104 friend bool operator<(const T *lhs, const type_zero &rhs) { return lhs < rhs.data; }
105 friend bool operator<(const type_zero &lhs, const T *rhs) { return lhs.data < rhs; }
106
107 friend bool operator<=(const type_zero &lhs, const type_zero &rhs) { return lhs.data <= rhs.data; }
108 friend bool operator<=(const T *lhs, const type_zero &rhs) { return lhs <= rhs.data; }
109 friend bool operator<=(const type_zero &lhs, const T *rhs) { return lhs.data <= rhs; }
110
111 friend bool operator==(const type_zero &lhs, const type_zero &rhs) { return lhs.data == rhs.data; }
112
113 operator array_t&() { return data; }
114 operator const array_t&() const { return data; }
115 };
116}
117#endif