// // ptr_compare.hpp // pointers // // Created by Sam Jaffe on 1/5/17. // #pragma once #define POINTER_TEMPLATE_COMPARE( ptr_t ) \ POINTER_TEMPLATE_COMPARE_FULL( ptr_t, (typename T), (T), (typename U), (U) ) #define EXPAND( ... ) __VA_ARGS__ #define POINTER_TEMPLATE_COMPARE_FULL( ptr_t, T_tname, T, U_tname, U ) \ template \ bool operator==(ptr_t< EXPAND T > const&lhs, ptr_t< EXPAND U > const&rhs) { \ return lhs.get() == rhs.get(); \ } \ \ template \ bool operator!=(ptr_t< EXPAND T > const&lhs, ptr_t< EXPAND U > const&rhs) { \ return !(lhs == rhs); \ } \ \ template \ bool operator< (ptr_t< EXPAND T > const&lhs, ptr_t< EXPAND U > const&rhs) { \ typedef typename std::common_type< \ typename ptr_t< EXPAND T >::pointer, \ typename ptr_t< EXPAND U >::pointer>::type V; \ return std::less(lhs.get(), rhs.get()); \ } \ \ template \ bool operator> (ptr_t< EXPAND T > const&lhs, ptr_t< EXPAND U > const&rhs) { \ return rhs < lhs; \ } \ \ template \ bool operator<=(ptr_t< EXPAND T > const&lhs, ptr_t< EXPAND U > const&rhs) { \ return !(rhs < lhs); \ } \ \ template \ bool operator>=(ptr_t< EXPAND T > const&lhs, ptr_t< EXPAND U > const&rhs) { \ return !(lhs < rhs); \ } \ \ template \ bool operator==(ptr_t< EXPAND T > const&lhs, std::nullptr_t) { \ return !lhs; \ } \ \ template \ bool operator==(std::nullptr_t, ptr_t< EXPAND T > const&rhs) { \ return !rhs; \ } \ \ template \ bool operator!=(ptr_t< EXPAND T > const&lhs, std::nullptr_t) { \ return static_cast(lhs); \ } \ \ template \ bool operator!=(std::nullptr_t, ptr_t< EXPAND T > const&rhs) { \ return static_cast(rhs); \ } \ \ template \ bool operator< (ptr_t< EXPAND T > const&lhs, std::nullptr_t) { \ typedef typename ptr_t< EXPAND T >::pointer V; \ return std::less(lhs.get(), nullptr); \ } \ \ template \ bool operator< (std::nullptr_t, ptr_t< EXPAND T > const&rhs) { \ typedef typename ptr_t< EXPAND T >::pointer V; \ return std::less(nullptr, rhs.get()); \ } \ \ template \ bool operator> (ptr_t< EXPAND T > const&lhs, std::nullptr_t) { \ return nullptr < lhs; \ } \ \ template \ bool operator> (std::nullptr_t, ptr_t< EXPAND T > const&rhs) { \ return rhs < nullptr; \ } \ \ template \ bool operator<=(ptr_t< EXPAND T > const&lhs, std::nullptr_t) { \ return !(nullptr < lhs); \ } \ \ template \ bool operator<=(std::nullptr_t, ptr_t< EXPAND T > const&rhs) { \ return !(rhs < nullptr); \ } \ \ template \ bool operator>=(ptr_t< EXPAND T > const&lhs, std::nullptr_t) { \ return !(lhs < nullptr); \ } \ \ template \ bool operator>=(std::nullptr_t, ptr_t< EXPAND T > const&rhs) { \ return !(nullptr < rhs); \ }