[libcxx-commits] [PATCH] D121523: [libc++][ranges] Implement ranges::count{, _if}

Konstantin Varlamov via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Apr 4 12:45:35 PDT 2022


var-const accepted this revision.
var-const added inline comments.


================
Comment at: libcxx/test/std/algorithms/alg.nonmodifying/alg.count/ranges.count.pass.cpp:245
+      int a[] = {5, 5, 4, 3, 2, 1};
+      std::same_as<signed char> auto ret = std::ranges::count(DiffTypeIterator(a), DiffTypeIterator(a + 6), 4);
+      assert(ret == 1);
----------------
philnik wrote:
> var-const wrote:
> > Nit: `s/auto/decltype(auto)/` (here and below).
> I think we should stick with `auto` and only use `decltype(auto)` if we want to check that a reference is returned.
I think that
```
std::same_as<Foo> auto x = Bar();
```
and
```
static_assert(std::same_as<decltype(Bar()), Foo>);
```
should be exactly equivalent as far as checking the return type is concerned. If `Bar()` were to return `const Foo&`, the second check would catch that but not the first. Yes, it is highly unlikely that `count` could return a reference; however, I think it's easier to use an approach that is always guaranteed to work rather than deciding on a case-by-case basis.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121523



More information about the libcxx-commits mailing list