diff options
author | Arthur O'Dwyer <arthur.j.odwyer@gmail.com> | 2022-01-03 20:49:24 -0500 |
---|---|---|
committer | Arthur O'Dwyer <arthur.j.odwyer@gmail.com> | 2022-01-08 12:47:54 -0500 |
commit | 6ce732cbadf7b474da1108dc7b3b473b80944aa5 (patch) | |
tree | 7785de2659ef98a0e99a76223b8cbc4ce32872ba | |
parent | 930f3c625e0277c4a28e66f79df7d8ad0de258e5 (diff) | |
download | llvm-6ce732cbadf7b474da1108dc7b3b473b80944aa5.zip llvm-6ce732cbadf7b474da1108dc7b3b473b80944aa5.tar.gz llvm-6ce732cbadf7b474da1108dc7b3b473b80944aa5.tar.bz2 |
[libc++] [ranges] Add namespace __cpo to ranges::{advance,next,prev}.
The reason for those nested namespaces is explained in D115315:
> AIUI, this keeps the CPO's own type from ADL'ing into the `std::ranges`
> namespace; e.g. `foobar(std::ranges::uninitialized_default_construct)`
> should not consider `std::ranges::foobar` a candidate, even if
> `std::ranges::foobar` is not a CPO itself. Also, of course, consistency
> (Chesterton's Fence, the economist's hundred-dollar bill): if it were
> safe to omit the namespace, we'd certainly want to do it everywhere,
> not just here.
This makes these three niebloids more consistent with the other Ranges
niebloids we've already implemented, such as the `ranges::begin` group
and the `ranges::uninitialized_default_construct` group.
FWIW, we still have three different indentation-and-comment styles
among these three groups.
Differential Revision: https://reviews.llvm.org/D116569
-rw-r--r-- | libcxx/include/__iterator/advance.h | 16 | ||||
-rw-r--r-- | libcxx/include/__iterator/next.h | 15 | ||||
-rw-r--r-- | libcxx/include/__iterator/prev.h | 15 |
3 files changed, 33 insertions, 13 deletions
diff --git a/libcxx/include/__iterator/advance.h b/libcxx/include/__iterator/advance.h index 2236a5793..210ce18 100644 --- a/libcxx/include/__iterator/advance.h +++ b/libcxx/include/__iterator/advance.h @@ -67,10 +67,12 @@ void advance(_InputIter& __i, _Distance __orig_n) { #if !defined(_LIBCPP_HAS_NO_RANGES) -namespace ranges { // [range.iter.op.advance] -// TODO(varconst): rename `__advance_fn` to `__fn`. -struct __advance_fn final : private __function_like { + +namespace ranges { +namespace __advance { + +struct __fn final : private __function_like { private: template <class _Tp> _LIBCPP_HIDE_FROM_ABI @@ -97,7 +99,7 @@ private: } public: - constexpr explicit __advance_fn(__tag __x) noexcept : __function_like(__x) {} + 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> @@ -186,7 +188,11 @@ public: } }; -inline constexpr auto advance = __advance_fn(__function_like::__tag()); +} // namespace __advance + +inline namespace __cpo { + inline constexpr auto advance = __advance::__fn(__function_like::__tag()); +} // namespace __cpo } // namespace ranges #endif // !defined(_LIBCPP_HAS_NO_RANGES) diff --git a/libcxx/include/__iterator/next.h b/libcxx/include/__iterator/next.h index d332abf..12c213a 100644 --- a/libcxx/include/__iterator/next.h +++ b/libcxx/include/__iterator/next.h @@ -38,11 +38,14 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 #if !defined(_LIBCPP_HAS_NO_RANGES) +// [range.iter.op.next] + namespace ranges { -// TODO(varconst): rename `__next_fn` to `__fn`. -struct __next_fn final : private __function_like { +namespace __next { + +struct __fn final : private __function_like { _LIBCPP_HIDE_FROM_ABI - constexpr explicit __next_fn(__tag __x) noexcept : __function_like(__x) {} + constexpr explicit __fn(__tag __x) noexcept : __function_like(__x) {} template <input_or_output_iterator _Ip> _LIBCPP_HIDE_FROM_ABI @@ -73,7 +76,11 @@ struct __next_fn final : private __function_like { } }; -inline constexpr auto next = __next_fn(__function_like::__tag()); +} // namespace __next + +inline namespace __cpo { + inline constexpr auto next = __next::__fn(__function_like::__tag()); +} // namespace __cpo } // namespace ranges #endif // !defined(_LIBCPP_HAS_NO_RANGES) diff --git a/libcxx/include/__iterator/prev.h b/libcxx/include/__iterator/prev.h index 57f2d04..84c69f9 100644 --- a/libcxx/include/__iterator/prev.h +++ b/libcxx/include/__iterator/prev.h @@ -37,11 +37,14 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 #if !defined(_LIBCPP_HAS_NO_RANGES) +// [range.iter.op.prev] + namespace ranges { -// TODO(varconst): rename `__prev_fn` to `__fn`. -struct __prev_fn final : private __function_like { +namespace __prev { + +struct __fn final : private __function_like { _LIBCPP_HIDE_FROM_ABI - constexpr explicit __prev_fn(__tag __x) noexcept : __function_like(__x) {} + constexpr explicit __fn(__tag __x) noexcept : __function_like(__x) {} template <bidirectional_iterator _Ip> _LIBCPP_HIDE_FROM_ABI @@ -65,7 +68,11 @@ struct __prev_fn final : private __function_like { } }; -inline constexpr auto prev = __prev_fn(__function_like::__tag()); +} // namespace __prev + +inline namespace __cpo { + inline constexpr auto prev = __prev::__fn(__function_like::__tag()); +} // namespace __cpo } // namespace ranges #endif // !defined(_LIBCPP_HAS_NO_RANGES) |