Skip to content

Commit 6ce732c

Browse files
author
Arthur O'Dwyer
committed
[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
1 parent 930f3c6 commit 6ce732c

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

libcxx/include/__iterator/advance.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,12 @@ void advance(_InputIter& __i, _Distance __orig_n) {
6767

6868
#if !defined(_LIBCPP_HAS_NO_RANGES)
6969

70-
namespace ranges {
7170
// [range.iter.op.advance]
72-
// TODO(varconst): rename `__advance_fn` to `__fn`.
73-
struct __advance_fn final : private __function_like {
71+
72+
namespace ranges {
73+
namespace __advance {
74+
75+
struct __fn final : private __function_like {
7476
private:
7577
template <class _Tp>
7678
_LIBCPP_HIDE_FROM_ABI
@@ -97,7 +99,7 @@ struct __advance_fn final : private __function_like {
9799
}
98100

99101
public:
100-
constexpr explicit __advance_fn(__tag __x) noexcept : __function_like(__x) {}
102+
constexpr explicit __fn(__tag __x) noexcept : __function_like(__x) {}
101103

102104
// Preconditions: If `I` does not model `bidirectional_iterator`, `n` is not negative.
103105
template <input_or_output_iterator _Ip>
@@ -186,7 +188,11 @@ struct __advance_fn final : private __function_like {
186188
}
187189
};
188190

189-
inline constexpr auto advance = __advance_fn(__function_like::__tag());
191+
} // namespace __advance
192+
193+
inline namespace __cpo {
194+
inline constexpr auto advance = __advance::__fn(__function_like::__tag());
195+
} // namespace __cpo
190196
} // namespace ranges
191197

192198
#endif // !defined(_LIBCPP_HAS_NO_RANGES)

libcxx/include/__iterator/next.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,14 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
3838

3939
#if !defined(_LIBCPP_HAS_NO_RANGES)
4040

41+
// [range.iter.op.next]
42+
4143
namespace ranges {
42-
// TODO(varconst): rename `__next_fn` to `__fn`.
43-
struct __next_fn final : private __function_like {
44+
namespace __next {
45+
46+
struct __fn final : private __function_like {
4447
_LIBCPP_HIDE_FROM_ABI
45-
constexpr explicit __next_fn(__tag __x) noexcept : __function_like(__x) {}
48+
constexpr explicit __fn(__tag __x) noexcept : __function_like(__x) {}
4649

4750
template <input_or_output_iterator _Ip>
4851
_LIBCPP_HIDE_FROM_ABI
@@ -73,7 +76,11 @@ struct __next_fn final : private __function_like {
7376
}
7477
};
7578

76-
inline constexpr auto next = __next_fn(__function_like::__tag());
79+
} // namespace __next
80+
81+
inline namespace __cpo {
82+
inline constexpr auto next = __next::__fn(__function_like::__tag());
83+
} // namespace __cpo
7784
} // namespace ranges
7885

7986
#endif // !defined(_LIBCPP_HAS_NO_RANGES)

libcxx/include/__iterator/prev.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,14 @@ inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
3737

3838
#if !defined(_LIBCPP_HAS_NO_RANGES)
3939

40+
// [range.iter.op.prev]
41+
4042
namespace ranges {
41-
// TODO(varconst): rename `__prev_fn` to `__fn`.
42-
struct __prev_fn final : private __function_like {
43+
namespace __prev {
44+
45+
struct __fn final : private __function_like {
4346
_LIBCPP_HIDE_FROM_ABI
44-
constexpr explicit __prev_fn(__tag __x) noexcept : __function_like(__x) {}
47+
constexpr explicit __fn(__tag __x) noexcept : __function_like(__x) {}
4548

4649
template <bidirectional_iterator _Ip>
4750
_LIBCPP_HIDE_FROM_ABI
@@ -65,7 +68,11 @@ struct __prev_fn final : private __function_like {
6568
}
6669
};
6770

68-
inline constexpr auto prev = __prev_fn(__function_like::__tag());
71+
} // namespace __prev
72+
73+
inline namespace __cpo {
74+
inline constexpr auto prev = __prev::__fn(__function_like::__tag());
75+
} // namespace __cpo
6976
} // namespace ranges
7077

7178
#endif // !defined(_LIBCPP_HAS_NO_RANGES)

0 commit comments

Comments
 (0)