indigoX
quad.hpp
Go to the documentation of this file.
1 #include <type_traits>
2 #include <utility>
3 
4 #ifndef INDIGOX_UTILS_QUAD_HPP
5 #define INDIGOX_UTILS_QUAD_HPP
6 
7 #include "serialise.hpp"
8 
9 namespace stdx { // extended std namespace
10 
11  template <class _T1, class _T2 = _T1, class _T3 = _T2, class _T4 = _T3>
12  struct quad {
13  typedef _T1 first_type;
14  typedef _T2 second_type;
15  typedef _T3 third_type;
16  typedef _T4 fourth_type;
17 
18  _T1 first;
19  _T2 second;
20  _T3 third;
21  _T4 fourth;
22 
23  quad(quad const &) = default;
24  quad(quad &&) = default;
25 
26  inline constexpr quad() : first(), second(), third(), fourth() {}
27 
28  inline constexpr quad(_T1 const &__t1, _T2 const &__t2, _T3 const &__t3,
29  _T4 const &__t4)
30  : first(__t1), second(__t2), third(__t3), fourth(__t4) {}
31 
32  template <class _U1, class _U2, class _U3, class _U4>
33  inline constexpr quad(_U1 &&__u1, _U2 &&__u2, _U3 &&__u3, _U4 &&__u4)
34  : first(std::forward<_U1>(__u1)), second(std::forward<_U2>(__u2)),
35  third(std::forward<_U3>(__u3)), fourth(std::forward<_U4>(__u4)) {}
36 
37  template <class _U1, class _U2, class _U3, class _U4>
38  inline constexpr quad(quad<_U1, _U2, _U3, _U4> const &__p)
39  : first(__p.first), second(__p.second), third(__p.third),
40  fourth(__p.fourth) {}
41 
42  template <class _U1, class _U2, class _U3, class _U4>
43  inline constexpr quad(quad<_U1, _U2, _U3, _U4> &&__p)
44  : first(std::forward<_U1>(__p.first)),
45  second(std::forward<_U2>(__p.second)),
46  third(std::forward<_U3>(__p.third)),
47  fourth(std::forward<_U4>(__p.fourth)) {}
48 
49  inline quad &operator=(
50  typename std::conditional<
51  std::is_copy_assignable<first_type>::value &&
52  std::is_copy_assignable<second_type>::value &&
53  std::is_copy_assignable<third_type>::value &&
54  std::is_copy_assignable<fourth_type>::value,
55  quad, stdx::typeless>::type const
56  &__p) noexcept(std::is_nothrow_copy_assignable<first_type>::value
57  &&std::is_nothrow_copy_assignable<second_type>::
58  value &&std::is_nothrow_copy_assignable<
59  third_type>::value
60  &&std::is_nothrow_copy_assignable<
61  fourth_type>::value) {
62  first = __p.first;
63  second = __p.second;
64  third = __p.third;
65  fourth = __p.fourth;
66  return *this;
67  }
68 
69  inline quad &operator=(
70  typename std::conditional<
71  std::is_move_assignable<first_type>::value &&
72  std::is_move_assignable<second_type>::value &&
73  std::is_move_assignable<third_type>::value &&
74  std::is_move_assignable<fourth_type>::value,
75  quad, stdx::typeless>::type
76  &&__p) noexcept(std::is_nothrow_move_assignable<first_type>::value
77  &&std::is_nothrow_move_assignable<second_type>::
78  value &&std::is_nothrow_move_assignable<
79  third_type>::value
80  &&std::is_nothrow_move_assignable<
81  fourth_type>::value) {
82  first = std::forward<first_type>(__p.first);
83  second = std::forward<second_type>(__p.second);
84  third = std::forward<third_type>(__p.third);
85  fourth = std::forward<fourth_type>(__p.fourth);
86  return *this;
87  }
88 
89  inline void swap(quad &__p) noexcept(
90  std::is_nothrow_swappable<first_type>::value
91  &&std::is_nothrow_swappable<second_type>::value
92  &&std::is_nothrow_swappable<third_type>::value
93  &&std::is_nothrow_swappable<fourth_type>::value) {
94  using std::swap;
95  swap(first, __p.first);
96  swap(second, __p.second);
97  swap(third, __p.third);
98  swap(fourth, __p.fourth);
99  }
100 
101  template <typename Archive>
102  void serialise(Archive &archive, const uint32_t) {
103  archive(INDIGOX_SERIAL_NVP("first", first),
104  INDIGOX_SERIAL_NVP("second", second),
105  INDIGOX_SERIAL_NVP("third", third),
106  INDIGOX_SERIAL_NVP("fourth", fourth));
107  }
108  };
109 
110  template <class _T1, class _T2, class _T3, class _T4>
111  inline constexpr bool operator==(const quad<_T1, _T2, _T3, _T4> &__x,
112  const quad<_T1, _T2, _T3, _T4> &__y) {
113  return __x.first == __y.first && __x.second == __y.second &&
114  __x.third == __y.third && __x.fourth == __y.fourth;
115  }
116 
117  template <class _T1, class _T2, class _T3, class _T4>
118  inline constexpr bool operator!=(const quad<_T1, _T2, _T3, _T4> &__x,
119  const quad<_T1, _T2, _T3, _T4> &__y) {
120  return !(__x == __y);
121  }
122 
123  template <class _T1, class _T2, class _T3, class _T4>
124  inline constexpr bool operator<(const quad<_T1, _T2, _T3, _T4> &__x,
125  const quad<_T1, _T2, _T3, _T4> &__y) {
126  return __x.first < __y.first ||
127  (!(__y.first < __x.first) && __x.second < __y.second) ||
128  (!(__y.first < __x.first) && !(__y.second < __x.second) &&
129  __x.third < __y.third) ||
130  (!(__y.first < __x.first) && !(__y.second < __x.second) &&
131  !(__y.third < __x.third) && __x.fourth < __y.fourth);
132  }
133 
134  template <class _T1, class _T2, class _T3, class _T4>
135  inline constexpr bool operator>(const quad<_T1, _T2, _T3, _T4> &__x,
136  const quad<_T1, _T2, _T3, _T4> &__y) {
137  return __y < __x;
138  }
139 
140  template <class _T1, class _T2, class _T3, class _T4>
141  inline constexpr bool operator>=(const quad<_T1, _T2, _T3, _T4> &__x,
142  const quad<_T1, _T2, _T3, _T4> &__y) {
143  return !(__x < __y);
144  }
145 
146  template <class _T1, class _T2, class _T3, class _T4>
147  inline constexpr bool operator<=(const quad<_T1, _T2, _T3, _T4> &__x,
148  const quad<_T1, _T2, _T3, _T4> &__y) {
149  return !(__y < __x);
150  }
151 
152  template <class _T1, class _T2, class _T3, class _T4>
153  inline typename std::enable_if<
154  std::is_swappable<_T1>::value && std::is_swappable<_T2>::value &&
155  std::is_swappable<_T3>::value && std::is_swappable<_T4>::value,
156  void>::type
158  (std::is_nothrow_swappable<_T1>::value &&
159  std::is_nothrow_swappable<_T2>::value &&
160  std::is_nothrow_swappable<_T3>::value &&
161  std::is_nothrow_swappable<_T4>::value)) {
162  __x.swap(__y);
163  }
164 
165  template <class _Tp> struct __make_quad_return_impl { typedef _Tp type; };
166 
167  template <class _Tp>
168  struct __make_quad_return_impl<std::reference_wrapper<_Tp>> {
169  typedef _Tp &type;
170  };
171 
172  template <class _Tp> struct __make_quad_return {
173  typedef
176  };
177 
178  template <class _T1, class _T2, class _T3, class _T4>
183  make_quad(_T1 &&__t1, _T2 &&__t2, _T3 &&__t3, _T4 &&__t4) {
188  std::forward<_T1>(__t1), std::forward<_T2>(__t2),
189  std::forward<_T3>(__t3), std::forward<_T4>(__t4));
190  }
191 } // namespace stdx
192 
193 #endif /* INDIGOX_UTILS_TRIPLE_HPP */
quad & operator=(typename std::conditional< std::is_move_assignable< first_type >::value &&std::is_move_assignable< second_type >::value &&std::is_move_assignable< third_type >::value &&std::is_move_assignable< fourth_type >::value, quad, stdx::typeless >::type &&__p) noexcept(std::is_nothrow_move_assignable< first_type >::value &&std::is_nothrow_move_assignable< second_type >::value &&std::is_nothrow_move_assignable< third_type >::value &&std::is_nothrow_move_assignable< fourth_type >::value)
Definition: quad.hpp:69
_T3 third_type
Definition: quad.hpp:15
void swap(quad &__p) noexcept(std::is_nothrow_swappable< first_type >::value &&std::is_nothrow_swappable< second_type >::value &&std::is_nothrow_swappable< third_type >::value &&std::is_nothrow_swappable< fourth_type >::value)
Definition: quad.hpp:89
std::enable_if< std::is_swappable< _T1 >::value &&std::is_swappable< _T2 >::value &&std::is_swappable< _T3 >::value &&std::is_swappable< _T4 >::value, void >::type swap(quad< _T1, _T2, _T3, _T4 > &__x, quad< _T1, _T2, _T3, _T4 > &__y) noexcept((std::is_nothrow_swappable< _T1 >::value &&std::is_nothrow_swappable< _T2 >::value &&std::is_nothrow_swappable< _T3 >::value &&std::is_nothrow_swappable< _T4 >::value))
Definition: quad.hpp:157
constexpr bool operator>(const quad< _T1, _T2, _T3, _T4 > &__x, const quad< _T1, _T2, _T3, _T4 > &__y)
Definition: quad.hpp:135
quad & operator=(typename std::conditional< std::is_copy_assignable< first_type >::value &&std::is_copy_assignable< second_type >::value &&std::is_copy_assignable< third_type >::value &&std::is_copy_assignable< fourth_type >::value, quad, stdx::typeless >::type const &__p) noexcept(std::is_nothrow_copy_assignable< first_type >::value &&std::is_nothrow_copy_assignable< second_type >::value &&std::is_nothrow_copy_assignable< third_type >::value &&std::is_nothrow_copy_assignable< fourth_type >::value)
Definition: quad.hpp:49
constexpr quad(quad< _U1, _U2, _U3, _U4 > &&__p)
Definition: quad.hpp:43
_T3 third
Definition: quad.hpp:20
Definition: quad.hpp:165
constexpr quad()
Definition: quad.hpp:26
_Tp type
Definition: quad.hpp:165
_T4 fourth_type
Definition: quad.hpp:16
void serialise(Archive &archive, const uint32_t)
Definition: quad.hpp:102
#define INDIGOX_SERIAL_NVP(name, value)
Definition: serialise.hpp:66
constexpr quad(_U1 &&__u1, _U2 &&__u2, _U3 &&__u3, _U4 &&__u4)
Definition: quad.hpp:33
constexpr bool operator<(const quad< _T1, _T2, _T3, _T4 > &__x, const quad< _T1, _T2, _T3, _T4 > &__y)
Definition: quad.hpp:124
__make_quad_return_impl< typename std::decay< _Tp >::type >::type type
Definition: quad.hpp:175
constexpr quad(quad< _U1, _U2, _U3, _U4 > const &__p)
Definition: quad.hpp:38
constexpr bool operator!=(const quad< _T1, _T2, _T3, _T4 > &__x, const quad< _T1, _T2, _T3, _T4 > &__y)
Definition: quad.hpp:118
_T2 second
Definition: quad.hpp:19
Definition: serialise.hpp:24
_T1 first_type
Definition: quad.hpp:13
Definition: quad.hpp:172
constexpr quad(_T1 const &__t1, _T2 const &__t2, _T3 const &__t3, _T4 const &__t4)
Definition: quad.hpp:28
Definition: quad.hpp:9
_T4 fourth
Definition: quad.hpp:21
_T2 second_type
Definition: quad.hpp:14
constexpr quad< typename __make_quad_return< _T1 >::type, typename __make_quad_return< _T2 >::type, typename __make_quad_return< _T3 >::type, typename __make_quad_return< _T4 >::type > make_quad(_T1 &&__t1, _T2 &&__t2, _T3 &&__t3, _T4 &&__t4)
Definition: quad.hpp:183
_T1 first
Definition: quad.hpp:18
Definition: quad.hpp:12
constexpr bool operator>=(const quad< _T1, _T2, _T3, _T4 > &__x, const quad< _T1, _T2, _T3, _T4 > &__y)
Definition: quad.hpp:141
constexpr bool operator<=(const quad< _T1, _T2, _T3, _T4 > &__x, const quad< _T1, _T2, _T3, _T4 > &__y)
Definition: quad.hpp:147
constexpr bool operator==(const quad< _T1, _T2, _T3, _T4 > &__x, const quad< _T1, _T2, _T3, _T4 > &__y)
Definition: quad.hpp:111