1 #ifndef POINTER_COMPARISON_TEST_HELPER_HPP
2 #define POINTER_COMPARISON_TEST_HELPER_HPP
9 #include "test_macros.h"
11 template <class T, template<class> class CompareTemplate>
12 void do_pointer_comparison_test() {
13 typedef CompareTemplate<T*> Compare;
14 typedef CompareTemplate<std::uintptr_t> UIntCompare;
16 typedef CompareTemplate<void> VoidCompare;
18 typedef Compare VoidCompare;
20 std::vector<std::shared_ptr<T> > pointers;
21 const std::size_t test_size = 100;
22 for (size_t i=0; i < test_size; ++i)
23 pointers.push_back(std::shared_ptr<T>(new T()));
27 for (size_t i=0; i < test_size; ++i) {
28 for (size_t j=0; j < test_size; ++j) {
29 T* lhs = pointers[i].get();
30 T* rhs = pointers[j].get();
31 std::uintptr_t lhs_uint = reinterpret_cast<std::uintptr_t>(lhs);
32 std::uintptr_t rhs_uint = reinterpret_cast<std::uintptr_t>(rhs);
33 assert(comp(lhs, rhs) == ucomp(lhs_uint, rhs_uint));
34 assert(vcomp(lhs, rhs) == ucomp(lhs_uint, rhs_uint));
39 #endif // POINTER_COMPARISON_TEST_HELPER_HPP