[libcxx-commits] [PATCH] D127557: [libc++][ranges] Implement `ranges::sort`.

Konstantin Varlamov via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jun 16 12:30:25 PDT 2022


var-const added inline comments.


================
Comment at: libcxx/include/__algorithm/ranges_common.h:40-42
+auto __make_projected_comp(_Comp& __comp, _Proj& __proj) {
+  static_assert(!same_as<_Proj, identity>,
+      "If the projection is std::identity, just pass the comparator directly.");
----------------
ldionne wrote:
> How about this instead:
> 
> ```
> template <class _Comp, class _Proj>
> _LIBCPP_HIDE_FROM_ABI constexpr static
> decltype(auto) __make_projected_comp(_Comp& __comp, _Proj& __proj) {
>   if constexpr (same_as<_Proj, identity>) {
>     return __comp;
>   } else {
>     return <lambda>;
>   }
> }
> ```
> 
> and then from the caller side, use:
> 
> ```
> auto&& __projected_comp = __make_projected_comp(__comp, __proj);
> ```
> 
> I'm not sure which one is better, but this is another option. The benefit with this version is that we can forego the `if constexpr` inside `__sort_fn_impl` (and possibly other algorithms in the future).
> 
> You can also centralize your comment about `// Avoid creating the lambda [...]` in `__sort_fn_impl` here.
Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127557



More information about the libcxx-commits mailing list