| 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 |
|
| 9 |
#ifndef SUPPORT_OPERATOR_HIJACKER_H |
| 10 |
#define SUPPORT_OPERATOR_HIJACKER_H |
| 11 |
|
| 12 |
#include <cstddef> |
| 13 |
#include <functional> |
| 14 |
|
| 15 |
#include "test_macros.h" |
| 16 |
|
| 17 |
/// Helper struct to test ADL-hijacking in containers. |
| 18 |
/// |
| 19 |
/// The class has some additional operations to be usable in all containers. |
| 20 |
struct operator_hijacker { |
| 21 |
bool operator<(const operator_hijacker&) const { return true; } |
| 22 |
bool operator==(const operator_hijacker&) const { return true; } |
| 23 |
|
| 24 |
template <typename T> |
| 25 |
friend void operator&(T&&) = delete; |
| 26 |
template <class T, class U> |
| 27 |
friend void operator,(T&&, U&&) = delete; |
| 28 |
template <class T, class U> |
| 29 |
friend void operator&&(T&&, U&&) = delete; |
| 30 |
template <class T, class U> |
| 31 |
friend void operator||(T&&, U&&) = delete; |
| 32 |
}; |
| 33 |
|
| 34 |
static_assert(std::is_trivially_copyable<operator_hijacker>::value && // |
| 35 |
std::is_copy_constructible<operator_hijacker>::value && // |
| 36 |
std::is_move_constructible<operator_hijacker>::value && // |
| 37 |
std::is_copy_assignable<operator_hijacker>::value && // |
| 38 |
std::is_move_assignable<operator_hijacker>::value, // |
| 39 |
"does not satisfy the requirements for atomic<operator_hijacker>"); |
| 40 |
|
| 41 |
template <> |
| 42 |
struct std::hash<operator_hijacker> { |
| 43 |
std::size_t operator()(const operator_hijacker&) const { return 0; } |
| 44 |
}; |
| 45 |
|
| 46 |
#endif // SUPPORT_OPERATOR_HIJACKER_H |