GCC Code Coverage Report


Directory: include/kumi/
File: include/kumi/utils/streamable.hpp
Date: 2026-10-14 16:33:56
Exec Total Coverage
Lines: 4 4 100.0%
Functions: 217 282 77.0%
Branches: 0 0 -%

Line Branch Exec Source
1 //======================================================================================================================
2 /*
3 KUMI - Compact Tuple Tools
4 Copyright : KUMI Project Contributors
5 SPDX-License-Identifier: BSL-1.0
6 */
7 //======================================================================================================================
8 #pragma once
9
10 #ifdef KUMI_DOXYGEN_INVOKED
11 //======================================================================================================================
12 /**
13 @ingroup kumi_utility
14 @brief Provides an extension point `as_streamable` in order to output types with no stream
15 operator defined.
16
17 This function does not exist in the kumi namespace, it is supposed to be found via Argument Dependant Lookup for
18 user defined types.
19
20 @param e The value of the element to output.
21 @return A value that can be passed to an output stream.
22
23 ## Example:
24 @include doc/infra/as_streamable.cpp
25 **/
26 //======================================================================================================================
27 auto as_streamable(auto e);
28
29 //======================================================================================================================
30 /**
31 @ingroup kumi_utility
32 @brief Provides an extension point `to_str` in order to output types with no textual
33 representation defined.
34
35 This function does not exist in the kumi namespace, it is supposed to be found via Argument Dependant Lookup for
36 user defined types. It is used in order to handle identifiers/fields display and manipulations.
37 to_str needs to be constexpr callable, if not some concepts might fail unexpectedly.
38
39 @param e The value of the element to output.
40 @return A kumi::str representing the input type
41
42 ## Example:
43 @include doc/infra/to_str.cpp
44 **/
45 //======================================================================================================================
46 kumi::str constexpr to_str(auto e);
47 #endif
48
49 namespace kumi::_
50 {
51 3776 template<typename T> auto make_streamable(T const& e)
52 {
53 3762 if constexpr (requires(std::ostream& os) { os << e; }) return e;
54 10 else if constexpr (requires { as_streamable(e); }) return as_streamable(e);
55 4 else return kumi::unknown{};
56 }
57
58 template<kumi::_::valid_label T> consteval kumi::_::str_like auto make_str(T const& t)
59 {
60 if constexpr (requires { to_str(t); }) return to_str(t);
61 else return kumi::typer<std::remove_cvref_t<T>>();
62 }
63 }
64