1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef _LIBCPP___ITERATOR_FUNCTION_LIKE_H
11 #define _LIBCPP___ITERATOR_FUNCTION_LIKE_H
12 
13 #include <__config>
14 
15 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16 #pragma GCC system_header
17 #endif
18 
19 _LIBCPP_PUSH_MACROS
20 #include <__undef_macros>
21 
22 _LIBCPP_BEGIN_NAMESPACE_STD
23 
24 #if !defined(_LIBCPP_HAS_NO_RANGES)
25 
26 namespace ranges {
27 // Per [range.iter.ops.general] and [algorithms.requirements], functions in namespace std::ranges
28 // can't be found by ADL and inhibit ADL when found by unqualified lookup. The easiest way to
29 // facilitate this is to use function objects.
30 //
31 // Since these are still standard library functions, we use `__function_like` to eliminate most of
32 // the properties that function objects get by default (e.g. semiregularity, addressability), to
33 // limit the surface area of the unintended public interface, so as to curb the effect of Hyrum's
34 // law.
35 struct __function_like {
36   __function_like() = delete;
37   __function_like(__function_like const&) = delete;
38   __function_like& operator=(__function_like const&) = delete;
39 
40   void operator&() const = delete;
41 
42   struct __tag { };
43 
44 protected:
__function_like__function_like45   constexpr explicit __function_like(__tag) noexcept {}
46   ~__function_like() = default;
47 };
48 } // namespace ranges
49 
50 #endif // !defined(_LIBCPP_HAS_NO_RANGES)
51 
52 _LIBCPP_END_NAMESPACE_STD
53 
54 _LIBCPP_POP_MACROS
55 
56 #endif // _LIBCPP___ITERATOR_FUNCTION_LIKE_H
57