[libcxx-commits] [PATCH] D136268: [libc++][ranges] implement `std::views::elements_view`

Hui via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sun Nov 20 07:32:53 PST 2022


huixie90 added inline comments.


================
Comment at: libcxx/include/__ranges/elements_view.h:141
+struct __elements_view_iterator_category_base<_Base, _Np> {
+  static consteval auto __get_iterator_category() {
+    using _Result = decltype(std::get<_Np>(*std::declval<iterator_t<_Base>>()));
----------------
var-const wrote:
> This doesn't need `_LIBCPP_HIDE_FROM_ABI` because it's `consteval`?
That is my understanding. After all it is a function used only at compile time so it does not have any ABI concerns. Or did I miss anything?


================
Comment at: libcxx/include/__ranges/elements_view.h:343
+  __get_current(const elements_view<_View, _Np>::__iterator<_AnyConst>& __iter) {
+    return (__iter.__current_);
+  }
----------------
var-const wrote:
> Question: the parentheses are to make sure `decltype(auto)` deduces a reference, right?
yes. 


================
Comment at: libcxx/include/__tuple/make_tuple_types.h:65
+  template <size_t _Index>
+  using __element_type = std::conditional_t<_Index == 0, _Iter, _Sent>;
+  template <class _Tp, class _ApplyFn = __apply_cv_t<_Tp>>
----------------
var-const wrote:
> Question: can you explain the idea here?
the spec defines `subrange` is also a `tuple-like`
https://eel.is/c++draft/tuple.like#concept:tuple-like

Before this patch, libc++ defines tuple-like to be only `pair`, `array` and `tuple`
https://github.com/llvm/llvm-project/blob/main/libcxx/include/__tuple/tuple_like.h

This patch makes `subrange` also a `tuple-like`. (see the diff in tuple_like.h)

The file in question is creating some meta functions to create a flat list of underlying types given a tuple-like type, and this function is used in the conversions between tuple-like types. One example would be `pair::pair(pair-like auto&&)`

You will see the few line above there are several specialisations.
1. for `tuple<Ts...>` it just produces `Ts...`
2. for `array<T, N>` it produces `T, T, T, T, ...`
3. for `pair<First, Second>`, it produces `First, Second`
Now I am adding another one
4. for `subrange<Iter, Sent, Kind>`, it produces `Iter, Sent` (note that `subrange` has a non-type template parameter at the 3rd place, so it won't match any of the existing specialisations.




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136268/new/

https://reviews.llvm.org/D136268



More information about the libcxx-commits mailing list