[PATCH] D36089: [ELF] - Replace parallelForEach with ranged form.

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 3 15:58:09 PDT 2017


Rafael Avila de Espindola <rafael.espindola at gmail.com> writes:

BTW, an amusing example that demonstrates this use of &&:

--------------------------------------------------------------------------
template <typename T> void foo(const T &x) { std::cout << "const T&\n"; }
template <typename T> void foo(T &x) { std::cout << "T&\n"; }
template <typename T> void foo(T &&x) { std::cout << "T&&\n"; }

template <typename T> void bar(T &&X) { foo(std::forward<T>(X)); }

int main() {
  int a = 42;
  const int b = 42;
  bar(a);
  bar(b);
  bar(42);
  return 0;
}
--------------------------------------------------------------------------

Thanks,
Rafael


> David Blaikie <dblaikie at gmail.com> writes:
>
>> If "const T&" is used, then users can't pass mutable data - which seems
>> like a reasonable thing users of a parallel API might want (I want to do a
>> parellel mutation of data - like if I have a vector of vectors and want to
>> reduce the subvectors in some way - replace them with a single-element
>> vector containing the sum of the elements of the original vector)
>>
>> If "T" is used, then they can mutate data, but would've had to copy it
>> first, which probably defeats the point (since then the side effects get
>> thrown away at the end)
>>
>> But sure - if you want to restrict the use of the API to non-mutating cases
>> for now, it's your/LLD's code. But it seems like a reasonable
>> implementation to use T&& thus allowing mutation or non-mutation (same as a
>> normal for loop, or std::for_each, etc) without waiting for the specific
>> use case.
>
> No, it is perfectly reasonable to allow mutations.
>
> So LGTM with &&.
>
> Thanks,
> Rafael


More information about the llvm-commits mailing list