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++);
44 friend void swap(
Vector& v1,
Vector& v2)
noexcept(
noexcept(v1.swap(v2))) { v1.swap(v2); }
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>,
60template<
class T,
size_t N,
class A,
class U>
62 auto it = std::remove(c.begin(), c.end(), value);
63 auto r = c.end() - it;
68template<
class T,
size_t N,
class A,
class Pred>
70 auto it = std::remove_if(c.begin(), c.end(), pred);
71 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 ...
constexpr Vector(size_t size, F &&f)
Span< const T > view() const
absl::InlinedVector< T, N, A > Base
friend void swap(Vector &v1, Vector &v2) noexcept(noexcept(v1.swap(v2)))
constexpr Vector(const R &range, F &&f)
Span< const T > span() const
Span(I, E) -> Span< std::remove_reference_t< std::iter_reference_t< I > > >
static constexpr size_t Default_Inlined_Size
constexpr Vector< T, N, A >::size_type erase(Vector< T, N, A > &c, const U &value)
constexpr Vector< T, N, A >::size_type erase_if(Vector< T, N, A > &c, Pred pred)
Vector(I, I, A=A()) -> Vector< typename std::iterator_traits< I >::value_type, Default_Inlined_Size< typename std::iterator_traits< I >::value_type >, A >