test_compare.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef TEST_COMPARE_H
  9. #define TEST_COMPARE_H
  10. #include <cstddef>
  11. #include <type_traits>
  12. #include <cstdlib>
  13. #include <new>
  14. #include <climits>
  15. template <class C>
  16. class test_compare
  17. : private C
  18. {
  19. int data_;
  20. public:
  21. explicit test_compare(int data = 0) : data_(data) {}
  22. typename C::result_type
  23. operator()(typename std::add_lvalue_reference<const typename C::first_argument_type>::type x,
  24. typename std::add_lvalue_reference<const typename C::second_argument_type>::type y) const
  25. {return C::operator()(x, y);}
  26. bool operator==(const test_compare& c) const
  27. {return data_ == c.data_;}
  28. };
  29. template <class C>
  30. class non_const_compare
  31. {
  32. // operator() deliberately not marked as 'const'
  33. bool operator()(const C& x, const C& y) { return x < y; }
  34. };
  35. #endif // TEST_COMPARE_H