Libmagicxx v5.5.0
A C++ wrapper library over the Magic Number Recognition Library.
 
Loading...
Searching...
No Matches
utility.hpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: Copyright (c) 2024-2025 Oğuz Toraman <oguz.toraman@tutanota.com> */
2/* SPDX-License-Identifier: LGPL-3.0-only */
3
4#ifndef UTILITY_HPP
5#define UTILITY_HPP
6
7#include <concepts>
8#include <ranges>
9#include <string>
10
11namespace utility {
12
18template <typename ContainerType>
19concept range_container = std::ranges::range<ContainerType>
20 && requires(ContainerType c) {
21 typename ContainerType::value_type;
22 };
23
30template <typename ValueType, typename StringConverterType>
31concept string_converter = std::same_as<
32 std::invoke_result_t<StringConverterType, ValueType>,
33 std::string>;
34
47template <range_container ContainerType, typename StringConverterType>
48requires string_converter<
49 typename ContainerType::value_type,
50 StringConverterType>
51[[nodiscard]] inline std::string to_string(
52 const ContainerType& container,
53 const std::string& value_separator,
54 StringConverterType string_converter
55)
56{
57 return container | std::views::transform(string_converter)
58 | std::views::join_with(value_separator)
59 | std::ranges::to<std::string>();
60}
61
62} /* namespace utility */
63
64#endif /* UTILITY_HPP */
Define requirements for a range container.
Definition utility.hpp:19
Define requirements for a string converter.
Definition utility.hpp:31
Definition utility.hpp:11
std::string to_string(const ContainerType &container, const std::string &value_separator, StringConverterType string_converter)
Convert any container to string using the string_converter.
Definition utility.hpp:51