Sharg 1.1.0
The argument parser for bio-c++ tools.
 
Loading...
Searching...
No Matches
to_string.hpp
Go to the documentation of this file.
1// --------------------------------------------------------------------------------------------------------
2// Copyright (c) 2006-2023, Knut Reinert & Freie Universität Berlin
3// Copyright (c) 2016-2023, Knut Reinert & MPI für molekulare Genetik
4// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
5// shipped with this file and also available at: https://github.com/seqan/sharg-parser/blob/main/LICENSE.md
6// --------------------------------------------------------------------------------------------------------
7
13#pragma once
14
15#include <sstream>
16
17#include <sharg/concept.hpp>
19
20namespace sharg::detail
21{
22
29template <typename... value_types>
30 requires (ostreamable<value_types> && ...)
31std::string to_string(value_types &&... values)
32{
33 std::stringstream stream;
34
35 auto print = [&stream](auto && val)
36 {
37 if constexpr (is_container_option<std::remove_cvref_t<decltype(val)>>)
38 {
39 if (val.empty())
40 {
41 stream << "[]";
42 }
43 else
44 {
45 stream << '[';
46 auto it = val.begin();
47 stream << *it++;
48 for (; it != val.end(); ++it)
49 stream << ", " << *it;
50 stream << ']';
51 }
52 }
53 else if constexpr (std::is_same_v<std::remove_cvref_t<decltype(val)>, int8_t>
54 || std::is_same_v<std::remove_cvref_t<decltype(val)>, uint8_t>)
55 {
56 stream << static_cast<int16_t>(val);
57 }
58 else
59 {
60 stream << val;
61 }
62 };
63
64 (print(std::forward<value_types>(values)), ...);
65
66 return stream.str();
67}
68
69} // namespace sharg::detail
Provides helper concepts.
Provides the concept sharg::detail::is_container_option.
T is_same_v
T str(T... args)
T to_string(T... args)