|
3 | 3 |
|
4 | 4 | #include "sass/base.h"
|
5 | 5 |
|
| 6 | +#include <cstddef> |
6 | 7 | #include <iostream>
|
7 | 8 | #include <string>
|
| 9 | +#include <type_traits> |
8 | 10 | #include <vector>
|
9 | 11 |
|
10 | 12 | namespace Sass {
|
@@ -185,6 +187,100 @@ namespace Sass {
|
185 | 187 | T* detach() { return static_cast<T*>(SharedPtr::detach()); }
|
186 | 188 | };
|
187 | 189 |
|
188 |
| -} |
| 190 | + // Comparison operators, based on: |
| 191 | + // https://en.cppreference.com/w/cpp/memory/unique_ptr/operator_cmp |
| 192 | + |
| 193 | + template<class T1, class T2> |
| 194 | + bool operator==(const SharedImpl<T1>& x, const SharedImpl<T2>& y) { |
| 195 | + return x.ptr() == y.ptr(); |
| 196 | + } |
| 197 | + |
| 198 | + template<class T1, class T2> |
| 199 | + bool operator!=(const SharedImpl<T1>& x, const SharedImpl<T2>& y) { |
| 200 | + return x.ptr() != y.ptr(); |
| 201 | + } |
| 202 | + |
| 203 | + template<class T1, class T2> |
| 204 | + bool operator<(const SharedImpl<T1>& x, const SharedImpl<T2>& y) { |
| 205 | + using CT = typename std::common_type<T1*, T2*>::type; |
| 206 | + return std::less<CT>()(x.get(), y.get()); |
| 207 | + } |
| 208 | + |
| 209 | + template<class T1, class T2> |
| 210 | + bool operator<=(const SharedImpl<T1>& x, const SharedImpl<T2>& y) { |
| 211 | + return !(y < x); |
| 212 | + } |
| 213 | + |
| 214 | + template<class T1, class T2> |
| 215 | + bool operator>(const SharedImpl<T1>& x, const SharedImpl<T2>& y) { |
| 216 | + return y < x; |
| 217 | + } |
| 218 | + |
| 219 | + template<class T1, class T2> |
| 220 | + bool operator>=(const SharedImpl<T1>& x, const SharedImpl<T2>& y) { |
| 221 | + return !(x < y); |
| 222 | + } |
| 223 | + |
| 224 | + template <class T> |
| 225 | + bool operator==(const SharedImpl<T>& x, std::nullptr_t) noexcept { |
| 226 | + return x.isNull(); |
| 227 | + } |
| 228 | + |
| 229 | + template <class T> |
| 230 | + bool operator==(std::nullptr_t, const SharedImpl<T>& x) noexcept { |
| 231 | + return x.isNull(); |
| 232 | + } |
| 233 | + |
| 234 | + template <class T> |
| 235 | + bool operator!=(const SharedImpl<T>& x, std::nullptr_t) noexcept { |
| 236 | + return !x.isNull(); |
| 237 | + } |
| 238 | + |
| 239 | + template <class T> |
| 240 | + bool operator!=(std::nullptr_t, const SharedImpl<T>& x) noexcept { |
| 241 | + return !x.isNull(); |
| 242 | + } |
| 243 | + |
| 244 | + template <class T> |
| 245 | + bool operator<(const SharedImpl<T>& x, std::nullptr_t) { |
| 246 | + return std::less<T*>()(x.get(), nullptr); |
| 247 | + } |
| 248 | + |
| 249 | + template <class T> |
| 250 | + bool operator<(std::nullptr_t, const SharedImpl<T>& y) { |
| 251 | + return std::less<T*>()(nullptr, y.get()); |
| 252 | + } |
| 253 | + |
| 254 | + template <class T> |
| 255 | + bool operator<=(const SharedImpl<T>& x, std::nullptr_t) { |
| 256 | + return !(nullptr < x); |
| 257 | + } |
| 258 | + |
| 259 | + template <class T> |
| 260 | + bool operator<=(std::nullptr_t, const SharedImpl<T>& y) { |
| 261 | + return !(y < nullptr); |
| 262 | + } |
| 263 | + |
| 264 | + template <class T> |
| 265 | + bool operator>(const SharedImpl<T>& x, std::nullptr_t) { |
| 266 | + return nullptr < x; |
| 267 | + } |
| 268 | + |
| 269 | + template <class T> |
| 270 | + bool operator>(std::nullptr_t, const SharedImpl<T>& y) { |
| 271 | + return y < nullptr; |
| 272 | + } |
| 273 | + |
| 274 | + template <class T> |
| 275 | + bool operator>=(const SharedImpl<T>& x, std::nullptr_t) { |
| 276 | + return !(x < nullptr); |
| 277 | + } |
| 278 | + |
| 279 | + template <class T> |
| 280 | + bool operator>=(std::nullptr_t, const SharedImpl<T>& y) { |
| 281 | + return !(nullptr < y); |
| 282 | + } |
| 283 | + |
| 284 | +} // namespace Sass |
189 | 285 |
|
190 | 286 | #endif
|
0 commit comments