FlatImage
A configurable Linux containerization system
Loading...
Searching...
No Matches
vector.hpp
Go to the documentation of this file.
1
8
9#pragma once
10
11#include <vector>
12
13#include "concept.hpp"
14#include "string.hpp"
15
25namespace ns_vector
26{
27
38template<ns_concept::Iterable R1, ns_concept::Iterable R2>
39inline void append_range(R1& to, R2 const& from) noexcept
40{
41 std::ranges::for_each(from, [&](auto&& e){ to.push_back(e); });
42}
43
52template<ns_concept::Iterable R, typename... Args>
53requires ( std::convertible_to<Args, typename R::value_type> && ... )
54inline void push_back(R& r, Args&&... args) noexcept
55{
56 ( r.push_back(std::forward<Args>(args)), ... );
57}
58
67template<ns_concept::Iterable R, typename... Args>
68requires ( std::convertible_to<Args, typename R::value_type> && ... )
69inline void push_front(R& r, Args&&... args) noexcept
70{
71 auto it = r.begin();
72 ( (it = r.insert(it, std::forward<Args>(args)), ++it), ... );
73}
74
83template<ns_concept::Iterable R = std::vector<std::string>>
84inline R from_string(ns_concept::StringRepresentable auto&& t, char delimiter) noexcept
85{
86 R tokens;
87 std::string token;
88 std::istringstream stream_token(ns_string::to_string(t));
89
90 while (std::getline(stream_token, token, delimiter))
91 {
92 tokens.push_back(token);
93 }
94
95 return tokens;
96}
97
98} // namespace ns_vector
99
100/* vim: set expandtab fdm=marker ts=2 sw=2 tw=100 et :*/
Custom C++ concepts for type constraints and compile-time validation.
Concept for iterable containers (has begin() and end())
Definition concept.hpp:227
Concept for types that can be represented as a string.
Definition concept.hpp:442
std::string to_string(T &&t) noexcept
Converts a type to a string.
Definition string.hpp:97
Vector and container manipulation utilities.
void append_range(R1 &to, R2 const &from) noexcept
Appends a range of values from a src to a dst.
Definition vector.hpp:39
void push_back(R &r, Args &&... args) noexcept
Helper to push back multiple elements into an input iterator.
Definition vector.hpp:54
void push_front(R &r, Args &&... args) noexcept
Helper to prepend multiple elements to the front of a container.
Definition vector.hpp:69
R from_string(ns_concept::StringRepresentable auto &&t, char delimiter) noexcept
Creates a range from a string.
Definition vector.hpp:84
String helpers.