Go to the documentation of this file.
15 #ifndef BELUGA_CONTAINERS_TUPLE_VECTOR_HPP
16 #define BELUGA_CONTAINERS_TUPLE_VECTOR_HPP
23 #include <range/v3/algorithm/copy.hpp>
24 #include <range/v3/iterator/insert_iterators.hpp>
25 #include <range/v3/view/const.hpp>
26 #include <range/v3/view/take.hpp>
36 template <
template <
class>
class InternalContainer,
class T>
49 template <
template <
class>
class InternalContainer,
class... Types>
82 template <
typename I,
typename S>
91 [[nodiscard]] constexpr
bool empty() const noexcept {
return std::get<0>(sequences_).empty(); }
94 [[nodiscard]] constexpr
size_type size() const noexcept {
return std::get<0>(sequences_).size(); }
97 [[nodiscard]] constexpr
size_type capacity() const noexcept {
return std::get<0>(sequences_).capacity(); }
101 std::apply([](
auto&&... containers) { (containers.clear(), ...); }, sequences_);
108 template <
typename I,
typename S>
110 auto range = ranges::make_subrange(first, last);
111 static_assert(ranges::input_range<decltype(range)>);
112 if constexpr (ranges::sized_range<decltype(range)>) {
113 resize(ranges::size(range));
114 ranges::copy(range, begin());
130 auto limited_range = range | ranges::views::take(size());
131 auto [last_in, last_out] = ranges::copy(limited_range, begin());
132 const auto copied_size =
static_cast<size_type>(ranges::distance(begin(), last_out));
133 if (size() == copied_size) {
135 ranges::copy(last_in.base(), last, ranges::back_inserter(*
this));
144 template <
typename R>
146 assign(ranges::begin(range), ranges::end(range));
157 std::apply([new_cap](
auto&&... containers) { (containers.reserve(new_cap), ...); }, sequences_);
169 std::apply([count](
auto&&... containers) { (containers.resize(count), ...); }, sequences_);
177 push_back_impl(value, std::make_index_sequence<
sizeof...(Types)>());
182 push_back_impl(std::move(value), std::make_index_sequence<
sizeof...(Types)>());
186 [[nodiscard]] constexpr
auto begin()
const {
return all().begin(); }
189 [[nodiscard]] constexpr
auto end()
const {
return all().end(); }
192 [[nodiscard]] constexpr
auto begin() {
return all().begin(); }
195 [[nodiscard]] constexpr
auto end() {
return all().end(); }
200 template <
typename T, std::size_t... Ids>
202 (std::get<Ids>(sequences_).push_back(std::get<Ids>(value)), ...);
205 [[nodiscard]] constexpr
auto all()
const {
206 return std::apply([](
auto&... containers) {
return beluga::views::zip(containers...); }, sequences_);
209 [[nodiscard]] constexpr
auto all() {
210 return std::apply([](
auto&... containers) {
return beluga::views::zip(containers...); }, sequences_);
216 using Vector = std::vector<T, std::allocator<T>>;
229 template <
class I,
class S,
typename = std::enable_if_t<ranges::input_iterator<I> && ranges::input_iterator<S>>>
constexpr void assign(I first, S last)
Replaces elements in the container with copies of those in the range [first, last).
constexpr void push_back(value_type &&value)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Implementation of a zip range adaptor object.
constexpr auto all() const
Includes all Beluga type traits.
constexpr auto end() const
Returns an iterator to the last element of the container.
constexpr bool empty() const noexcept
Returns true if the container is empty.
std::vector< T, std::allocator< T > > Vector
Shorthand for a vector with the default allocator.
constexpr detail::assign_fn assign
ranges::common_tuple< Types &... > reference_type
Reference type of the container.
constexpr size_type size() const noexcept
Returns the size of the container.
Primary template for a tuple of containers.
constexpr TupleContainer(std::initializer_list< value_type > init)
Constructs a container from an initializer_list.
Shorthand for a tuple of vectors with the default allocator.
constexpr TupleContainer(I first, S last)
Constructs a container from iterators.
constexpr void resize(size_type count)
Resizes the container.
constexpr size_type capacity() const noexcept
Returns the capacity of the container.
constexpr void clear() noexcept
Clears the container.
TupleVector(I, S) -> TupleVector< decay_tuple_like_t< ranges::iter_value_t< I >>>
Deduction guide to construct from iterators.
constexpr auto begin()
This is an overloaded member function, provided for convenience. It differs from the above function o...
constexpr TupleContainer(size_type count)
Constructs a container of size count, all values are default initialized.
constexpr void reserve(size_type new_cap)
Reserves the specified capacity.
constexpr void push_back_impl(T value, std::index_sequence< Ids... >)
void allocator_type
Allocator type.
constexpr auto begin() const
Returns an iterator to the first element of the container.
std::ptrdiff_t difference_type
Difference type of the container.
std::size_t size_type
Size type of the container.
std::tuple< InternalContainer< Types >... > sequences_
constexpr void push_back(const value_type &value)
Adds an element at the end of the container.
constexpr auto end()
This is an overloaded member function, provided for convenience. It differs from the above function o...
constexpr void assign_range(R &&range)
Replaces elements in the container with a copy of each element in range.
constexpr detail::zip_fn zip
Given N ranges, return a new range where the Mth element is a tuple of the Mth elements of all N rang...
std::tuple< Types... > value_type
Value type of the container.
The main Beluga namespace.
beluga
Author(s):
autogenerated on Tue Jul 16 2024 02:59:53