[PATCH] D100672: [ADT] Add new type traits for type pack indexes
David Blaikie via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 16 14:39:25 PDT 2021
dblaikie added a comment.
Are there (future) STL equivalents of TypesAreDistinct or FirsntIndexOfType?
================
Comment at: llvm/include/llvm/ADT/STLExtras.h:151-154
+ for (size_t I = 1; I <= sizeof...(Ts); ++I)
+ if (Matches[I])
+ return I - 1;
+ return sizeof...(Ts);
----------------
Could this be replaced with:
```
return llvm::find(Matches, true) - std::begin(Matches);
```
or something like that?
(similarly below in "AreTypesDistinct")?
Hmm, what's the purpose of the first element of the array being 'false', and then iterating from the second element and subtracting one from the index before returning?
Oh, that's to support the zero-length case? Fair enough. I don't mind either way, but maybe it'd be simpler/more obvious if that were done via specialization? - oh, what happens if you put the buffer value at the end rather than the beginning. In this algorithm you could put "true" at the end (and remove "false" from the start) and then it'd return 1 when sizeof...(Ts) is zero?
================
Comment at: llvm/include/llvm/ADT/STLExtras.h:163
+template <typename... Ts> static constexpr bool areTypesDistinct() {
+ constexpr size_t IndexOf[] = {0, getFirstIndexOfType<Ts, Ts...>()...};
+ for (size_t I = 1; I <= sizeof...(Ts); ++I)
----------------
Any concerns about the quadratic complexity here? Any more efficient way to write this, maybe? (what's the libc++ equivalent implementation look like, I wonder?)
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D100672/new/
https://reviews.llvm.org/D100672
More information about the llvm-commits
mailing list