[libcxx-commits] [PATCH] D149706: [libc++][PSTL] Implement std::copy{, _n}

Joe Loser via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu May 4 18:18:06 PDT 2023


jloser added inline comments.


================
Comment at: libcxx/test/std/algorithms/alg.modifying.operations/alg.copy/pstl.copy.pass.cpp:98
+int main(int, char**) {
+  types::for_each(types::forward_iterator_list<int*>{}, TestIteratorsInt{});
+  types::for_each(types::forward_iterator_list<CopiedToTester*>{}, TestIteratorsNonTrivial{});
----------------
philnik wrote:
> ldionne wrote:
> > I see this is repeating a lot, and because of C++17 we can't use template lambas. But we can do this:
> > 
> > ```
> > types::for_each(types::forward_iterator_list<int*>{}, types::apply_type_identity([](auto It) {
> >   using Iter = typename decltype(It)::type;
> >   // the rest of your stuff
> > }));
> > 
> > // where
> > template <class F>
> > struct apply_type_identity {
> >   F f;
> >   template <class ...Args>
> >   auto operator()() const {
> >     return f(std::type_identity<Args>{}...);
> >   }
> > };
> > ```
> > 
> > We can bikeshed about the name of `apply_type_identity`, I'm open to anything reasonable. IMO if we apply this throughout, it will localize the "loops" and make the testing code easier to read (and write!). WDYT?
> I'm not a huge fan of the name, but I can't come up with anything better.
I think the name is fine FWIW. Do we have a generic type for applying a generic metafunction (e.g. so a call site could look like `apply<F, std::type_identity>`)? The metafunction would be bound with the `Args` parameter pack on the call operator like it is now.  Then, if you had such generic construct, you wouldn't need to name the entity `apply_type_identity`, it would be obvious from the callers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149706



More information about the libcxx-commits mailing list