[libc++] Eliminate the `__function_like` helper.
As prefigured in the comments on D115315.
This gives us one unified style for all niebloids,
and also simplifies the modulemap.
Differential Revision: https://reviews.llvm.org/D116570
NOKEYCHECK=True
GitOrigin-RevId: 63a991d0358970d76700d084f05eb95cd29234c0
diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt
index 7d56123..b722254 100644
--- a/include/CMakeLists.txt
+++ b/include/CMakeLists.txt
@@ -182,7 +182,6 @@
__format/formatter_integral.h
__format/formatter_string.h
__format/parser_std_format_spec.h
- __function_like.h
__functional/binary_function.h
__functional/binary_negate.h
__functional/bind.h
diff --git a/include/__function_like.h b/include/__function_like.h
deleted file mode 100644
index 4075355..0000000
--- a/include/__function_like.h
+++ /dev/null
@@ -1,51 +0,0 @@
-// -*- C++ -*-
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef _LIBCPP___ITERATOR_FUNCTION_LIKE_H
-#define _LIBCPP___ITERATOR_FUNCTION_LIKE_H
-
-#include <__config>
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
-_LIBCPP_BEGIN_NAMESPACE_STD
-
-#if !defined(_LIBCPP_HAS_NO_RANGES)
-
-namespace ranges {
-// Per [range.iter.ops.general] and [algorithms.requirements], functions in namespace std::ranges
-// can't be found by ADL and inhibit ADL when found by unqualified lookup. The easiest way to
-// facilitate this is to use function objects.
-//
-// Since these are still standard library functions, we use `__function_like` to eliminate most of
-// the properties that function objects get by default (e.g. semiregularity, addressability), to
-// limit the surface area of the unintended public interface, so as to curb the effect of Hyrum's
-// law.
-struct __function_like {
- __function_like() = delete;
- __function_like(__function_like const&) = delete;
- __function_like& operator=(__function_like const&) = delete;
-
- void operator&() const = delete;
-
- struct __tag { };
-
-protected:
- constexpr explicit __function_like(__tag) noexcept {}
- ~__function_like() = default;
-};
-} // namespace ranges
-
-#endif // !defined(_LIBCPP_HAS_NO_RANGES)
-
-_LIBCPP_END_NAMESPACE_STD
-
-#endif // _LIBCPP___ITERATOR_FUNCTION_LIKE_H
diff --git a/include/__iterator/advance.h b/include/__iterator/advance.h
index ee3fba3..831f88f 100644
--- a/include/__iterator/advance.h
+++ b/include/__iterator/advance.h
@@ -12,7 +12,6 @@
#include <__config>
#include <__debug>
-#include <__function_like.h>
#include <__iterator/concepts.h>
#include <__iterator/incrementable_traits.h>
#include <__iterator/iterator_traits.h>
@@ -72,7 +71,7 @@
namespace ranges {
namespace __advance {
-struct __fn final : private __function_like {
+struct __fn {
private:
template <class _Tp>
_LIBCPP_HIDE_FROM_ABI
@@ -99,8 +98,6 @@
}
public:
- constexpr explicit __fn(__tag __x) noexcept : __function_like(__x) {}
-
// Preconditions: If `I` does not model `bidirectional_iterator`, `n` is not negative.
template <input_or_output_iterator _Ip>
_LIBCPP_HIDE_FROM_ABI
@@ -191,7 +188,7 @@
} // namespace __advance
inline namespace __cpo {
- inline constexpr auto advance = __advance::__fn(__function_like::__tag());
+ inline constexpr auto advance = __advance::__fn{};
} // namespace __cpo
} // namespace ranges
diff --git a/include/__iterator/next.h b/include/__iterator/next.h
index 12c213a..b9bdd6b 100644
--- a/include/__iterator/next.h
+++ b/include/__iterator/next.h
@@ -12,7 +12,6 @@
#include <__config>
#include <__debug>
-#include <__function_like.h>
#include <__iterator/advance.h>
#include <__iterator/concepts.h>
#include <__iterator/incrementable_traits.h>
@@ -43,10 +42,7 @@
namespace ranges {
namespace __next {
-struct __fn final : private __function_like {
- _LIBCPP_HIDE_FROM_ABI
- constexpr explicit __fn(__tag __x) noexcept : __function_like(__x) {}
-
+struct __fn {
template <input_or_output_iterator _Ip>
_LIBCPP_HIDE_FROM_ABI
constexpr _Ip operator()(_Ip __x) const {
@@ -79,7 +75,7 @@
} // namespace __next
inline namespace __cpo {
- inline constexpr auto next = __next::__fn(__function_like::__tag());
+ inline constexpr auto next = __next::__fn{};
} // namespace __cpo
} // namespace ranges
diff --git a/include/__iterator/prev.h b/include/__iterator/prev.h
index 84c69f9..870cbe6 100644
--- a/include/__iterator/prev.h
+++ b/include/__iterator/prev.h
@@ -12,7 +12,6 @@
#include <__config>
#include <__debug>
-#include <__function_like.h>
#include <__iterator/advance.h>
#include <__iterator/concepts.h>
#include <__iterator/incrementable_traits.h>
@@ -42,10 +41,7 @@
namespace ranges {
namespace __prev {
-struct __fn final : private __function_like {
- _LIBCPP_HIDE_FROM_ABI
- constexpr explicit __fn(__tag __x) noexcept : __function_like(__x) {}
-
+struct __fn {
template <bidirectional_iterator _Ip>
_LIBCPP_HIDE_FROM_ABI
constexpr _Ip operator()(_Ip __x) const {
@@ -71,7 +67,7 @@
} // namespace __prev
inline namespace __cpo {
- inline constexpr auto prev = __prev::__fn(__function_like::__tag());
+ inline constexpr auto prev = __prev::__fn{};
} // namespace __cpo
} // namespace ranges
diff --git a/include/__memory/ranges_construct_at.h b/include/__memory/ranges_construct_at.h
index 9b0edb7..1a72da7 100644
--- a/include/__memory/ranges_construct_at.h
+++ b/include/__memory/ranges_construct_at.h
@@ -12,7 +12,6 @@
#include <__concepts/destructible.h>
#include <__config>
-#include <__function_like.h>
#include <__iterator/incrementable_traits.h>
#include <__iterator/readable_traits.h>
#include <__memory/concepts.h>
@@ -37,9 +36,7 @@
namespace __construct_at {
-struct __fn final : private __function_like {
- _LIBCPP_HIDE_FROM_ABI constexpr explicit __fn(__tag __x) noexcept : __function_like(__x) {}
-
+struct __fn {
template<class _Tp, class... _Args, class = decltype(
::new (declval<void*>()) _Tp(declval<_Args>()...)
)>
@@ -52,16 +49,14 @@
} // namespace __construct_at
inline namespace __cpo {
- inline constexpr auto construct_at = __construct_at::__fn(__function_like::__tag());
+ inline constexpr auto construct_at = __construct_at::__fn{};
} // namespace __cpo
// destroy_at
namespace __destroy_at {
-struct __fn final : private __function_like {
- _LIBCPP_HIDE_FROM_ABI constexpr explicit __fn(__tag __x) noexcept : __function_like(__x) {}
-
+struct __fn {
template <destructible _Tp>
_LIBCPP_HIDE_FROM_ABI
constexpr void operator()(_Tp* __location) const noexcept {
@@ -72,16 +67,14 @@
} // namespace __destroy_at
inline namespace __cpo {
- inline constexpr auto destroy_at = __destroy_at::__fn(__function_like::__tag());
+ inline constexpr auto destroy_at = __destroy_at::__fn{};
} // namespace __cpo
// destroy
namespace __destroy {
-struct __fn final : private __function_like {
- _LIBCPP_HIDE_FROM_ABI constexpr explicit __fn(__tag __x) noexcept : __function_like(__x) {}
-
+struct __fn {
template <__nothrow_input_iterator _InputIterator, __nothrow_sentinel_for<_InputIterator> _Sentinel>
requires destructible<iter_value_t<_InputIterator>>
_LIBCPP_HIDE_FROM_ABI
@@ -100,16 +93,14 @@
} // namespace __destroy
inline namespace __cpo {
- inline constexpr auto destroy = __destroy::__fn(__function_like::__tag());
+ inline constexpr auto destroy = __destroy::__fn{};
} // namespace __cpo
// destroy_n
namespace __destroy_n {
-struct __fn final : private __function_like {
- _LIBCPP_HIDE_FROM_ABI constexpr explicit __fn(__tag __x) noexcept : __function_like(__x) {}
-
+struct __fn {
template <__nothrow_input_iterator _InputIterator>
requires destructible<iter_value_t<_InputIterator>>
_LIBCPP_HIDE_FROM_ABI
@@ -121,10 +112,11 @@
} // namespace __destroy_n
inline namespace __cpo {
- inline constexpr auto destroy_n = __destroy_n::__fn(__function_like::__tag());
+ inline constexpr auto destroy_n = __destroy_n::__fn{};
} // namespace __cpo
} // namespace ranges
+
#endif // !defined(_LIBCPP_HAS_NO_RANGES)
_LIBCPP_END_NAMESPACE_STD
diff --git a/include/__memory/ranges_uninitialized_algorithms.h b/include/__memory/ranges_uninitialized_algorithms.h
index 8cd2748..6a8f9f0 100644
--- a/include/__memory/ranges_uninitialized_algorithms.h
+++ b/include/__memory/ranges_uninitialized_algorithms.h
@@ -13,7 +13,6 @@
#include <__algorithm/in_out_result.h>
#include <__concepts/constructible.h>
#include <__config>
-#include <__function_like.h>
#include <__iterator/concepts.h>
#include <__iterator/incrementable_traits.h>
#include <__iterator/iter_move.h>
@@ -40,9 +39,7 @@
namespace __uninitialized_default_construct {
-struct __fn final : private __function_like {
- constexpr explicit __fn(__tag __x) noexcept : __function_like(__x) {}
-
+struct __fn {
template <__nothrow_forward_iterator _ForwardIterator,
__nothrow_sentinel_for<_ForwardIterator> _Sentinel>
requires default_initializable<iter_value_t<_ForwardIterator>>
@@ -62,16 +59,14 @@
} // namespace __uninitialized_default_construct
inline namespace __cpo {
- inline constexpr auto uninitialized_default_construct = __uninitialized_default_construct::__fn(__function_like::__tag());
+ inline constexpr auto uninitialized_default_construct = __uninitialized_default_construct::__fn{};
} // namespace __cpo
// uninitialized_default_construct_n
namespace __uninitialized_default_construct_n {
-struct __fn final : private __function_like {
- constexpr explicit __fn(__tag __x) noexcept : __function_like(__x) {}
-
+struct __fn {
template <__nothrow_forward_iterator _ForwardIterator>
requires default_initializable<iter_value_t<_ForwardIterator>>
_ForwardIterator operator()(_ForwardIterator __first,
@@ -84,18 +79,14 @@
} // namespace __uninitialized_default_construct_n
inline namespace __cpo {
- inline constexpr auto uninitialized_default_construct_n =
- __uninitialized_default_construct_n::__fn(__function_like::__tag());
+ inline constexpr auto uninitialized_default_construct_n = __uninitialized_default_construct_n::__fn{};
} // namespace __cpo
// uninitialized_value_construct
namespace __uninitialized_value_construct {
-struct __fn final : private __function_like {
-
- constexpr explicit __fn(__tag __x) noexcept : __function_like(__x) {}
-
+struct __fn {
template <__nothrow_forward_iterator _ForwardIterator,
__nothrow_sentinel_for<_ForwardIterator> _Sentinel>
requires default_initializable<iter_value_t<_ForwardIterator>>
@@ -110,24 +101,19 @@
borrowed_iterator_t<_ForwardRange> operator()(_ForwardRange&& __range) const {
return (*this)(ranges::begin(__range), ranges::end(__range));
}
-
};
} // namespace __uninitialized_value_construct
inline namespace __cpo {
- inline constexpr auto uninitialized_value_construct =
- __uninitialized_value_construct::__fn(__function_like::__tag());
+ inline constexpr auto uninitialized_value_construct = __uninitialized_value_construct::__fn{};
} // namespace __cpo
// uninitialized_value_construct_n
namespace __uninitialized_value_construct_n {
-struct __fn final : private __function_like {
-
- constexpr explicit __fn(__tag __x) noexcept : __function_like(__x) {}
-
+struct __fn {
template <__nothrow_forward_iterator _ForwardIterator>
requires default_initializable<iter_value_t<_ForwardIterator>>
_ForwardIterator operator()(_ForwardIterator __first,
@@ -135,24 +121,19 @@
using _ValueType = remove_reference_t<iter_reference_t<_ForwardIterator>>;
return _VSTD::__uninitialized_value_construct_n<_ValueType>(_VSTD::move(__first), __n);
}
-
};
} // namespace __uninitialized_value_construct_n
inline namespace __cpo {
- inline constexpr auto uninitialized_value_construct_n =
- __uninitialized_value_construct_n::__fn(__function_like::__tag());
+ inline constexpr auto uninitialized_value_construct_n = __uninitialized_value_construct_n::__fn{};
} // namespace __cpo
// uninitialized_fill
namespace __uninitialized_fill {
-struct __fn final : private __function_like {
-
- constexpr explicit __fn(__tag __x) noexcept : __function_like(__x) {}
-
+struct __fn {
template <__nothrow_forward_iterator _ForwardIterator,
__nothrow_sentinel_for<_ForwardIterator> _Sentinel,
class _Tp>
@@ -167,23 +148,19 @@
borrowed_iterator_t<_ForwardRange> operator()(_ForwardRange&& __range, const _Tp& __x) const {
return (*this)(ranges::begin(__range), ranges::end(__range), __x);
}
-
};
} // namespace __uninitialized_fill
inline namespace __cpo {
- inline constexpr auto uninitialized_fill = __uninitialized_fill::__fn(__function_like::__tag());
+ inline constexpr auto uninitialized_fill = __uninitialized_fill::__fn{};
} // namespace __cpo
// uninitialized_fill_n
namespace __uninitialized_fill_n {
-struct __fn final : private __function_like {
-
- constexpr explicit __fn(__tag __x) noexcept : __function_like(__x) {}
-
+struct __fn {
template <__nothrow_forward_iterator _ForwardIterator, class _Tp>
requires constructible_from<iter_value_t<_ForwardIterator>, const _Tp&>
_ForwardIterator operator()(_ForwardIterator __first,
@@ -192,13 +169,12 @@
using _ValueType = remove_reference_t<iter_reference_t<_ForwardIterator>>;
return _VSTD::__uninitialized_fill_n<_ValueType>(_VSTD::move(__first), __n, __x);
}
-
};
} // namespace __uninitialized_fill_n
inline namespace __cpo {
- inline constexpr auto uninitialized_fill_n = __uninitialized_fill_n::__fn(__function_like::__tag());
+ inline constexpr auto uninitialized_fill_n = __uninitialized_fill_n::__fn{};
} // namespace __cpo
// uninitialized_copy
@@ -208,9 +184,7 @@
namespace __uninitialized_copy {
-struct __fn final : private __function_like {
- constexpr explicit __fn(__tag __x) noexcept : __function_like(__x) {}
-
+struct __fn {
template <input_iterator _InputIterator,
sentinel_for<_InputIterator> _Sentinel1,
__nothrow_forward_iterator _OutputIterator,
@@ -237,7 +211,7 @@
} // namespace __uninitialized_copy
inline namespace __cpo {
- inline constexpr auto uninitialized_copy = __uninitialized_copy::__fn(__function_like::__tag());
+ inline constexpr auto uninitialized_copy = __uninitialized_copy::__fn{};
} // namespace __cpo
// uninitialized_copy_n
@@ -247,9 +221,7 @@
namespace __uninitialized_copy_n {
-struct __fn final : private __function_like {
- constexpr explicit __fn(__tag __x) noexcept : __function_like(__x) {}
-
+struct __fn {
template <input_iterator _InputIterator,
__nothrow_forward_iterator _OutputIterator,
__nothrow_sentinel_for<_OutputIterator> _Sentinel>
@@ -267,7 +239,7 @@
} // namespace __uninitialized_copy_n
inline namespace __cpo {
- inline constexpr auto uninitialized_copy_n = __uninitialized_copy_n::__fn(__function_like::__tag());
+ inline constexpr auto uninitialized_copy_n = __uninitialized_copy_n::__fn{};
} // namespace __cpo
// uninitialized_move
@@ -277,9 +249,7 @@
namespace __uninitialized_move {
-struct __fn final : private __function_like {
- constexpr explicit __fn(__tag __x) noexcept : __function_like(__x) {}
-
+struct __fn {
template <input_iterator _InputIterator,
sentinel_for<_InputIterator> _Sentinel1,
__nothrow_forward_iterator _OutputIterator,
@@ -289,7 +259,6 @@
operator()(_InputIterator __ifirst, _Sentinel1 __ilast, _OutputIterator __ofirst, _Sentinel2 __olast) const {
using _ValueType = remove_reference_t<iter_reference_t<_OutputIterator>>;
auto __iter_move = [](auto&& __iter) -> decltype(auto) { return ranges::iter_move(__iter); };
-
auto __result = _VSTD::__uninitialized_move<_ValueType>(_VSTD::move(__ifirst), _VSTD::move(__ilast),
_VSTD::move(__ofirst), _VSTD::move(__olast), __iter_move);
return {_VSTD::move(__result.first), _VSTD::move(__result.second)};
@@ -307,7 +276,7 @@
} // namespace __uninitialized_move
inline namespace __cpo {
- inline constexpr auto uninitialized_move = __uninitialized_move::__fn(__function_like::__tag());
+ inline constexpr auto uninitialized_move = __uninitialized_move::__fn{};
} // namespace __cpo
// uninitialized_move_n
@@ -317,9 +286,7 @@
namespace __uninitialized_move_n {
-struct __fn final : private __function_like {
- constexpr explicit __fn(__tag __x) noexcept : __function_like(__x) {}
-
+struct __fn {
template <input_iterator _InputIterator,
__nothrow_forward_iterator _OutputIterator,
__nothrow_sentinel_for<_OutputIterator> _Sentinel>
@@ -329,9 +296,8 @@
_OutputIterator __ofirst, _Sentinel __olast) const {
using _ValueType = remove_reference_t<iter_reference_t<_OutputIterator>>;
auto __iter_move = [](auto&& __iter) -> decltype(auto) { return ranges::iter_move(__iter); };
-
- auto __result = _VSTD::__uninitialized_move_n<_ValueType>(_VSTD::move(__ifirst), __n, _VSTD::move(__ofirst),
- _VSTD::move(__olast), __iter_move);
+ auto __result = _VSTD::__uninitialized_move_n<_ValueType>(_VSTD::move(__ifirst), __n,
+ _VSTD::move(__ofirst), _VSTD::move(__olast), __iter_move);
return {_VSTD::move(__result.first), _VSTD::move(__result.second)};
}
};
@@ -339,7 +305,7 @@
} // namespace __uninitialized_move_n
inline namespace __cpo {
- inline constexpr auto uninitialized_move_n = __uninitialized_move_n::__fn(__function_like::__tag());
+ inline constexpr auto uninitialized_move_n = __uninitialized_move_n::__fn{};
} // namespace __cpo
} // namespace ranges
diff --git a/include/module.modulemap b/include/module.modulemap
index c17ecc9..a927f9d 100644
--- a/include/module.modulemap
+++ b/include/module.modulemap
@@ -592,10 +592,7 @@
module __iterator {
module access { private header "__iterator/access.h" }
- module advance {
- private header "__iterator/advance.h"
- export __function_like
- }
+ module advance { private header "__iterator/advance.h" }
module back_insert_iterator { private header "__iterator/back_insert_iterator.h" }
module common_iterator { private header "__iterator/common_iterator.h" }
module concepts { private header "__iterator/concepts.h" }
@@ -616,16 +613,10 @@
module iterator { private header "__iterator/iterator.h" }
module iterator_traits { private header "__iterator/iterator_traits.h" }
module move_iterator { private header "__iterator/move_iterator.h" }
- module next {
- private header "__iterator/next.h"
- export __function_like
- }
+ module next { private header "__iterator/next.h" }
module ostream_iterator { private header "__iterator/ostream_iterator.h" }
module ostreambuf_iterator { private header "__iterator/ostreambuf_iterator.h" }
- module prev {
- private header "__iterator/prev.h"
- export __function_like
- }
+ module prev { private header "__iterator/prev.h" }
module projected { private header "__iterator/projected.h" }
module readable_traits { private header "__iterator/readable_traits.h" }
module reverse_access { private header "__iterator/reverse_access.h" }
@@ -673,14 +664,8 @@
module concepts { private header "__memory/concepts.h" }
module construct_at { private header "__memory/construct_at.h" }
module pointer_traits { private header "__memory/pointer_traits.h" }
- module ranges_construct_at {
- private header "__memory/ranges_construct_at.h"
- export __function_like
- }
- module ranges_uninitialized_algorithms {
- private header "__memory/ranges_uninitialized_algorithms.h"
- export __function_like
- }
+ module ranges_construct_at { private header "__memory/ranges_construct_at.h" }
+ module ranges_uninitialized_algorithms { private header "__memory/ranges_uninitialized_algorithms.h" }
module raw_storage_iterator { private header "__memory/raw_storage_iterator.h" }
module shared_ptr { private header "__memory/shared_ptr.h" }
module temporary_buffer { private header "__memory/temporary_buffer.h" }
@@ -988,7 +973,6 @@
module __bits { private header "__bits" export * }
module __debug { header "__debug" export * }
module __errc { private header "__errc" export * }
- module __function_like { private header "__function_like.h" export * }
module __hash_table { header "__hash_table" export * }
module __locale { private header "__locale" export * }
module __mbstate_t { private header "__mbstate_t.h" export * }