23#ifndef VULPES_UTILS_VVUTILS_HPP_
24#define VULPES_UTILS_VVUTILS_HPP_
43template <
typename... Args>
46template <
typename... Args>
49template <
typename T, std::
size_t N>
66template <
typename Container>
69 const Container& container,
70 const std::string& separator =
",",
71 const std::string& postpend =
"\n",
72 const std::string& prepend =
"") {
73 auto it = container.begin();
74 if (!prepend.empty()) {
77 if (it != container.end()) {
80 for (; it != container.end(); ++it) {
81 os << separator << *it;
84 if (!postpend.empty()) {
97template <
typename Container>
98typename std::enable_if<
99 vvutils::internal::is_printable_container<Container>::value,
101operator<<(std::ostream& os,
const Container& container) {
102 return print(os, container);
116template <
typename T,
typename IndexType>
118 const std::vector<T>& source,
const std::vector<IndexType>& indices) {
119 std::vector<T> result;
120 result.reserve(indices.size());
121 for (
size_t index : indices) {
122 result.push_back(source[index]);
129template <
typename Tuple,
typename Func, std::size_t... Is>
131 (func(std::get<Is>(tuple)), ...);
141template <
typename Tuple,
typename Func>
144 std::forward<Tuple>(tuple), std::forward<Func>(func),
145 std::make_index_sequence<std::tuple_size<std::decay_t<Tuple>>::value>{});
150template <
typename Tuple,
typename Func, std::size_t... Is>
152 Tuple&& tuple, Func&& func, std::index_sequence<Is...>) {
153 (func(std::get<Is>(tuple), Is), ...);
164template <
typename Tuple,
typename Func>
167 std::forward<Tuple>(tuple), std::forward<Func>(func),
168 std::make_index_sequence<std::tuple_size<std::decay_t<Tuple>>::value>{});
std::vector< T > slice(const std::vector< T > &source, const std::vector< IndexType > &indices)
Build a new vector by selecting elements of source at the given indices.
Definition vvutils.hpp:117
void for_each_impl(Tuple &&tuple, Func &&func, std::index_sequence< Is... >)
Definition vvutils.hpp:130
void for_each_impl_idxed(Tuple &&tuple, Func &&func, std::index_sequence< Is... >)
Definition vvutils.hpp:151
void for_each_idxed(Tuple &&tuple, Func &&func)
Apply func to every element of tuple together with its index.
Definition vvutils.hpp:165
void for_each(Tuple &&tuple, Func &&func)
Apply func to every element of tuple, in order.
Definition vvutils.hpp:142
Definition vvutils.hpp:37
Definition vvutils.hpp:36
Definition cell_manager.hpp:38
std::ostream & print(std::ostream &os, const Container &container, const std::string &separator=",", const std::string &postpend="\n", const std::string &prepend="")
Print a container's elements to a stream, separated and wrapped by the given strings.
Definition vvutils.hpp:67
std::enable_if< vvutils::internal::is_printable_container< Container >::value, std::ostream & >::type operator<<(std::ostream &os, const Container &container)
Stream a std::vector, std::set, or std::array via print().
Definition vvutils.hpp:101
Definition vvutils.hpp:41