StormByte C++ Library 1.2.0
StormByte is a comprehensive, cross-platform C++ library aimed at easing system programming, configuration management, logging, and database handling tasks. This library provides a unified API that abstracts away the complexities and inconsistencies of different platforms (Windows, Linux).
Loading...
Searching...
No Matches
helpers.hxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024-2026 David C. Manuelda (StormBytePP)
3 *
4 * This file is part of StormByte.
5 *
6 * StormByte is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License version 3
8 * or later, as published by the Free Software Foundation.
9 *
10 * StormByte is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with StormByte. If not, see
17 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
18 */
19
20#pragma once
21
24
25#include <span>
26#include <vector>
27#include <version>
28
33namespace StormByte {
42 template<typename T, typename U>
43 void append_vector(std::vector<T>& dest, std::span<U> src) noexcept requires Type::ConvertibleTo<T, U> {
44 dest.reserve(dest.size() + src.size());
45#ifdef __cpp_lib_containers_ranges
46 dest.append_range(src);
47#else
48 dest.insert(dest.end(), src.begin(), src.end());
49#endif
50 }
51
58 template<typename T>
59 void append_vector(std::vector<T>& dest, const std::vector<T>& src) noexcept {
60 return append_vector(dest, std::span<const T>(src.data(), src.size()));
61 }
62
70 template<typename T>
71 void append_vector(std::vector<T>& dest, std::vector<T>&& src) noexcept {
72 dest.reserve(dest.size() + src.size());
73#ifdef __cpp_lib_containers_ranges
74 dest.append_range(std::move(src));
75#else
76 dest.insert(dest.end(), std::make_move_iterator(src.begin()), std::make_move_iterator(src.end()));
77#endif
78 }
79}
From is implicitly convertible to To (std::is_convertible).
Definition conversions.hxx:45
Root namespace of the StormByte suite.
void append_vector(std::vector< T > &dest, std::span< U > src) noexcept
Appends a span of convertible elements onto a vector.
Definition helpers.hxx:43