[libcxx-commits] [PATCH] D130552: [libc++][ranges] Implement `ranges::generate{, _n}`.
Konstantin Varlamov via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jul 27 15:41:06 PDT 2022
var-const marked an inline comment as done.
var-const added inline comments.
================
Comment at: libcxx/include/__algorithm/ranges_generate_n.h:42
+ for (; __n > 0; --__n) {
+ *__first = __gen();
+ ++__first;
----------------
huixie90 wrote:
> ldionne wrote:
> > We should technically be using `std::invoke` here according to the concept requirements specified in the signature (all we have is `invocable<_Func&>`). However, I don't think there is any way to distinguish `__gen()` from `invoke(gen)` given that it's being called with no arguments. I tried finding a case but couldn't.
> >
> > So, nothing to do.
> I was about to say the same and actually tried very hard. but could not find an example where `gen()` does not work while `invoke(gen)` works.
>
> Although nothing to do here, I'd like to share how far I went.
> You can use `gen()` even if `gen` doesn't have `operator()` but convertible to a function pointer.
> https://godbolt.org/z/b11erWhcc
Thank you! This idea is pretty ingenious, cool that calling it directly still works.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D130552/new/
https://reviews.llvm.org/D130552
More information about the libcxx-commits
mailing list