forked from OSchip/llvm-project
[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
This commit is contained in:
parent
930f3c625e
commit
6ce732cbad
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue