63 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef SUPPORT_OPERATOR_HIJACKER_H10#define SUPPORT_OPERATOR_HIJACKER_H11 12#include <cstddef>13#include <functional>14#include <memory>15#include <string>16#include <type_traits>17 18#include "test_macros.h"19 20/// Helper struct to test ADL-hijacking in containers.21///22/// The class has some additional operations to be usable in all containers.23struct operator_hijacker {24 TEST_CONSTEXPR bool operator<(const operator_hijacker&) const { return true; }25 TEST_CONSTEXPR bool operator==(const operator_hijacker&) const { return true; }26 TEST_CONSTEXPR int operator()() const { return 42; }27 28 template <typename T>29 friend void operator&(T&&) = delete;30 template <class T, class U>31 friend void operator,(T&&, U&&) = delete;32 template <class T, class U>33 friend void operator&&(T&&, U&&) = delete;34 template <class T, class U>35 friend void operator||(T&&, U&&) = delete;36};37 38static_assert(std::is_trivially_copyable<operator_hijacker>::value && //39 std::is_copy_constructible<operator_hijacker>::value && //40 std::is_move_constructible<operator_hijacker>::value && //41 std::is_copy_assignable<operator_hijacker>::value && //42 std::is_move_assignable<operator_hijacker>::value, //43 "does not satisfy the requirements for atomic<operator_hijacker>");44 45template <>46struct std::hash<operator_hijacker> {47 std::size_t operator()(const operator_hijacker&) const { return 0; }48};49 50template <class T>51struct operator_hijacker_allocator : std::allocator<T>, operator_hijacker {52#if TEST_STD_VER <= 1753 struct rebind {54 typedef operator_hijacker_allocator<T> other;55 };56#endif57};58 59template <class CharT>60struct operator_hijacker_char_traits : std::char_traits<CharT>, operator_hijacker {};61 62#endif // SUPPORT_OPERATOR_HIJACKER_H63