-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[libc++] Implement ranges::iota #68494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 40 commits
c4a3ccf
1b808ec
574c94c
e4cfe00
7cdfea2
a1d015c
ab4c67d
c44d7d6
a455f42
08e3c77
e658ec2
67fcac1
b132784
88e271a
ff5bf79
b8f07b8
a4d34fd
334088f
8153244
a872e39
0f538aa
b84859b
3bd4c6d
6be79e2
7cde8ed
074d685
72125ea
ce909e8
028ce92
b3f260e
be7faa6
20b848b
2803493
5f0389c
79d6cc5
07b8183
3d5ad73
fd81400
3285f4e
cea6379
3f0670f
a7e77b1
d50b7a1
b4008ad
240d4f0
8f5ffc3
b99c8d8
dc29b80
e325de4
913a8d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ Standard,Name,Assignee,CL,Status | |
C++23,`ranges::to <https://wg21.link/P1206R7>`_,Konstantin Varlamov,`D142335 <https://reviews.llvm.org/D142335>`_,Complete | ||
C++23,`Pipe support for user-defined range adaptors <https://wg21.link/P2387R3>`_,"Louis Dionne, Jakub Mazurkiewicz, and Xiaoyang Liu",Various,Complete | ||
C++23,`Formatting Ranges <https://wg21.link/P2286R8>`_,Mark de Wever,Various,Complete | ||
C++23, `ranges::iota <https://wg21.link/P2440R1>`_, James E T Smith, `PR68494 <https://github.com/llvm/llvm-project/pull/68494>`_, In Progress | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will only be partial after this PR is merged because that paper contains two other methods There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is also the option to mark this as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the suggestion @Zingam, I've updated this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't believe I'd call this a "major ranges feature"; this is an important ranges feature, but isn't quite as large as the other things on this list; I'd remove this change. |
||
C++20,`Stashing stashing iterators for proper flattening <https://wg21.link/P2770R0>`_,Jakub Mazurkiewicz,Various,In progress |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// -*- 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___ALGORITHM_OUT_VALUE_RESULT_H | ||
#define _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H | ||
|
||
#include <__concepts/convertible_to.h> | ||
#include <__config> | ||
#include <__utility/move.h> | ||
|
||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | ||
# pragma GCC system_header | ||
#endif | ||
|
||
_LIBCPP_PUSH_MACROS | ||
#include <__undef_macros> | ||
|
||
_LIBCPP_BEGIN_NAMESPACE_STD | ||
|
||
#if _LIBCPP_STD_VER >= 23 | ||
|
||
namespace ranges { | ||
|
||
template <class _OutIter1, class _ValType1> | ||
strega-nil marked this conversation as resolved.
Show resolved
Hide resolved
|
||
struct out_value_result { | ||
_LIBCPP_NO_UNIQUE_ADDRESS _OutIter1 out; | ||
_LIBCPP_NO_UNIQUE_ADDRESS _ValType1 value; | ||
|
||
template <class _OutIter2, class _ValType2> | ||
requires convertible_to<const _OutIter1&, _OutIter2> && convertible_to<const _ValType1&, _ValType2> | ||
_LIBCPP_HIDE_FROM_ABI constexpr operator out_value_result<_OutIter2, _ValType2>() const& { | ||
return {out, value}; | ||
} | ||
|
||
template <class _OutIter2, class _ValType2> | ||
requires convertible_to<_OutIter1, _OutIter2> && convertible_to<_ValType1, _ValType2> | ||
_LIBCPP_HIDE_FROM_ABI constexpr operator out_value_result<_OutIter2, _ValType2>() && { | ||
return {std::move(out), std::move(value)}; | ||
} | ||
}; | ||
|
||
} // namespace ranges | ||
|
||
#endif // _LIBCPP_STD_VER >= 23 | ||
|
||
_LIBCPP_END_NAMESPACE_STD | ||
|
||
_LIBCPP_POP_MACROS | ||
|
||
#endif // _LIBCPP___ALGORITHM_OUT_VALUE_RESULT_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// -*- 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___NUMERIC_RANGES_IOTA_H | ||
#define _LIBCPP___NUMERIC_RANGES_IOTA_H | ||
|
||
#include <__algorithm/out_value_result.h> | ||
#include <__config> | ||
#include <__ranges/access.h> | ||
#include <__ranges/concepts.h> | ||
#include <__ranges/dangling.h> | ||
#include <__utility/as_const.h> | ||
#include <__utility/move.h> | ||
|
||
philnik777 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | ||
# pragma GCC system_header | ||
#endif | ||
|
||
_LIBCPP_PUSH_MACROS | ||
#include <__undef_macros> | ||
|
||
_LIBCPP_BEGIN_NAMESPACE_STD | ||
|
||
#if _LIBCPP_STD_VER >= 23 | ||
namespace ranges { | ||
template <typename _Out, typename _Tp> | ||
using iota_result = ranges::out_value_result<_Out, _Tp>; | ||
|
||
struct __iota_fn { | ||
public: | ||
template <input_or_output_iterator _Out, sentinel_for<_Out> _Sent, weakly_incrementable _Tp> | ||
requires indirectly_writable<_Out, const _Tp&> | ||
_LIBCPP_HIDE_FROM_ABI static constexpr iota_result<_Out, _Tp> operator()(_Out __first, _Sent __last, _Tp __value) { | ||
while (__first != __last) { | ||
*__first = std::as_const(__value); | ||
++__first; | ||
++__value; | ||
} | ||
return {std::move(__first), std::move(__value)}; | ||
} | ||
|
||
template <weakly_incrementable _Tp, ranges::output_range<const _Tp&> _Range> | ||
_LIBCPP_HIDE_FROM_ABI static constexpr iota_result<ranges::borrowed_iterator_t<_Range>, _Tp> | ||
philnik777 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
operator()(_Range&& __r, _Tp __value) { | ||
return __iota_fn::operator()(ranges::begin(__r), ranges::end(__r), std::move(__value)); | ||
strega-nil marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
}; | ||
|
||
inline constexpr auto iota = __iota_fn{}; | ||
} // namespace ranges | ||
|
||
#endif // _LIBCPP_STD_VER >= 23 | ||
|
||
_LIBCPP_END_NAMESPACE_STD | ||
|
||
_LIBCPP_POP_MACROS | ||
|
||
#endif // _LIBCPP___NUMERIC_RANGES_IOTA_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to @Zingam's suggestion to mark this as
|Partial|
.