3#include <absl/container/inlined_vector.h>
9template<
class T>
static constexpr size_t Default_Inlined_Size = std::max((
size_t)1, 4 *
sizeof(
size_t) /
sizeof(T));
15template<
class T,
size_t N = Default_Inlined_Size<T>,
class A = std::allocator<T>>
16class Vector :
public absl::InlinedVector<T, N, A> {
18 using Base = absl::InlinedVector<T, N, A>;
24 constexpr explicit Vector(
size_t size, F&& f)
requires(std::is_invocable_r_v<T, F, size_t>)
26 for (
size_t i = 0;
i != size; ++
i) (*
this)[
i] = std::invoke(f,
i);
28 template<std::ranges::forward_range R,
class F>
29 constexpr explicit Vector(
const R& range, F&& f)
30 requires(std::is_invocable_r_v<T, F,
decltype(*std::ranges::begin(range))>)
31 :
Base(std::ranges::distance(range)) {
32 auto ri = std::ranges::begin(range);
33 for (
auto&
elem : *
this)
elem = std::invoke(f, *
ri++);
47static_assert(std::ranges::contiguous_range<Vector<int>>);
51template<class I, class A = std::allocator<typename std::iterator_traits<I>::value_type>>
53 Default_Inlined_Size<typename std::iterator_traits<I>::value_type>,
57template<
class R,
class S>
bool equal(R range1, S range2) {
58 if (range1.size() != range2.size())
return false;
59 auto j = range2.begin();
60 for (
auto i = range1.begin(), e = range1.end(); i != e; ++i, ++j)
61 if (*i != *j)
return false;
65template<
class T,
size_t N,
class A,
class U>
67 auto it = std::remove(c.begin(), c.end(), value);
68 auto r = c.end() - it;
73template<
class T,
size_t N,
class A,
class Pred>
75 auto it = std::remove_if(c.begin(), c.end(), pred);
76 auto r = c.end() - it;
This is a thin wrapper for std::span<T, N> with the following additional features:
This is a thin wrapper for absl::InlinedVector<T, N, A> which in turn is a drop-in replacement for st...
Span< const T > view() const
absl::InlinedVector< T, N, A > Base
constexpr Vector(size_t size, F &&f)
constexpr Vector(const R &range, F &&f)
friend void swap(Vector &v1, Vector &v2) noexcept(noexcept(v1.swap(v2)))
Span< const T > span() const
constexpr Vector< T, N, A >::size_type erase_if(Vector< T, N, A > &c, Pred pred)
bool equal(R range1, S range2)
}@
static constexpr size_t Default_Inlined_Size
constexpr Vector< T, N, A >::size_type erase(Vector< T, N, A > &c, const U &value)