[libcxx-commits] [libcxx] 6ce732c - [libc++] [ranges] Add namespace __cpo to ranges::{advance, next, prev}.
Arthur O'Dwyer via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Jan 8 09:48:46 PST 2022
Author: Arthur O'Dwyer
Date: 2022-01-08T12:47:54-05:00
New Revision: 6ce732cbadf7b474da1108dc7b3b473b80944aa5
URL: https://github.com/llvm/llvm-project/commit/6ce732cbadf7b474da1108dc7b3b473b80944aa5
DIFF: https://github.com/llvm/llvm-project/commit/6ce732cbadf7b474da1108dc7b3b473b80944aa5.diff
LOG: [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
Added:
Modified:
libcxx/include/__iterator/advance.h
libcxx/include/__iterator/next.h
libcxx/include/__iterator/prev.h
Removed:
################################################################################
diff --git a/libcxx/include/__iterator/advance.h b/libcxx/include/__iterator/advance.h
index 2236a57936ccd..210ce18f1355d 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 @@ struct __advance_fn final : private __function_like {
}
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 @@ struct __advance_fn final : private __function_like {
}
};
-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 d332abfa8e0eb..12c213a1e4d7c 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 57f2d04a13250..84c69f9c13af6 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)
More information about the libcxx-commits
mailing list