Closed leissa closed 10 months ago
LGTM. Only the nit that I find the
vector<..>()
helper a bit confusing as I am then looking forusing namespace std
orusing std::vector
to identify if this is coming fromstd::vector
- maybemake_Vector
? :)
Alright, I now subclassed absl::InlinedVector
instead of aliasing it. So the original c'tors are back via:
auto vec = Vector<int>(23, [](size_t i) { return i; });
There btw seems to be a gcc problem for this:
auto vec = Vector<int>(my_range_of_ints, [](auto i) { return i; });
It's a subtle issue with template instantiation, overloading, concepts, etc. I'm pretty sure it's a gcc bug. Works with clang. As a workaround, you have to explicitly specify the argument:
auto vec = Vector<int>(my_range_of_ints, [](int i) { return i; });
Subclassing gives us another benefit to have vec.span()
and vec.view()
methods, which are a bit nicer to use:
for (auto elem : vec.view().subspan(1)) { /*...*/ }
instead of
for (auto elem : View(vec).subspan(1)) { /*...*/ }
This PR removes our home-brew
Array<T>
andSpan<T>
classes withabsl::InlinedVector<T>
and a newSpan<T>
which is only a thin wrapper forstd::span<T>
.Span<T, N>
This is a thin wrapper for
std::span<T, N>
with the following additional features:std::initializer_list
(C++26 will get this ...)N != std::dynamic_extent:
This will save us a few copies as we formerly copied over to
std::array
in order to be able to decompose the array.Vector
This thing behaves like a
std::vector
but is under the hood anabsl::InlinedVector
. The number of inlined elements is 4 for most element types.Misc
DefArray
vsDefVec
. Just useDefVec
=Vector<const Def*>
Array<T>
(the C++ data structure) vsArr
(the thorin type) -Array<T>
is goneSpan
class vs our new one: the old one always usedconst T
internally. Now, you have to do eitherSpan<const T>
orView<T>
(an alias).rewrite.cpp
) as stepping throughstd::function
and friends during debugging becomes super annoying.