Sharg 1.1.2-rc.1
The argument parser for bio-c++ tools.
Loading...
Searching...
No Matches
to_string.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin
2// SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik
3// SPDX-License-Identifier: BSD-3-Clause
4
10#pragma once
11
12#include <sstream>
13
14#include <sharg/concept.hpp>
16
17namespace sharg::detail
18{
19
21static std::string const supported_exports =
22#if SHARG_HAS_TDL
23 "[html, man, ctd, cwl]";
24#else
25 "[html, man]";
26#endif
27
29template <typename container_t>
31
38template <typename... value_types>
39 requires (ostreamable<value_types> && ...)
40std::string to_string(value_types &&... values)
41{
42 std::stringstream stream;
43
44 auto print = [&stream](auto && val)
45 {
46 using value_t = std::remove_cvref_t<decltype(val)>;
47
48 // When passing a `std::vector<std::string> | std::views::transform(...)` which returns `std::quoted(str)` for
49 // each element, the `std::quoted`'s return value does not model a range, but is ostreamable.
51 {
52 if (val.empty())
53 {
54 stream << "[]";
55 }
56 else
57 {
58 stream << '[';
59 auto it = val.begin();
60 stream << *it++;
61 for (; it != val.end(); ++it)
62 stream << ", " << *it;
63 stream << ']';
64 }
65 }
67 {
68 stream << static_cast<int16_t>(val);
69 }
70 else
71 {
72 stream << val;
73 }
74 };
75
76 (print(std::forward<value_types>(values)), ...);
77
78 return stream.str();
79}
80
81} // namespace sharg::detail
Provides helper concepts.
Whether the option type is considered to be a container.
Definition detail/concept.hpp:38
Concept for views whose value type is ostreamable.
Definition to_string.hpp:30
Concept for types that can be parsed into a std::ostream via the stream operator.
Definition concept.hpp:61
Provides the concept sharg::detail::is_container_option.
std::string to_string(value_types &&... values)
Streams all parameters via std::ostringstream and returns a concatenated string.
Definition to_string.hpp:40
T is_same_v
T str(T... args)
Hide me