kokkos-execution
0.0.1
Toggle main menu visibility
Loading...
Searching...
No Matches
streamers.hpp
Go to the documentation of this file.
1
#ifndef KOKKOS_EXECUTION_UTILS_STREAMERS_HPP
2
#define KOKKOS_EXECUTION_UTILS_STREAMERS_HPP
3
4
#include <concepts>
5
#include <ostream>
6
#include <ranges>
7
#include <vector>
8
9
namespace
Kokkos::Execution::Utils
{
10
11
namespace
detail
{
12
13
template
<
typename
T>
14
concept
char_like
= std::same_as<std::remove_cv_t<T>,
char
> || std::same_as<std::remove_cv_t<T>,
wchar_t
>
15
|| std::same_as<std::remove_cv_t<T>,
char8_t
> || std::same_as<std::remove_cv_t<T>,
char16_t
>
16
|| std::same_as<std::remove_cv_t<T>,
char32_t
>;
17
19
template
<
class
R>
20
concept
streamable_range
= std::ranges::input_range<const R> && !
char_like<std::ranges::range_value_t<const R>
>
21
&&
requires
(std::ostream& out, std::ranges::range_reference_t<const R> value) { out << value; };
22
}
// namespace detail
23
24
template
<detail::streamable_range R>
25
std::ostream&
operator<<
(std::ostream& out,
const
R& values) {
26
out <<
'['
;
27
for
(
bool
first =
true
;
const
auto
& value: values) {
28
if
(!first)
29
out <<
", "
;
30
out << value;
31
first =
false
;
32
}
33
return
out <<
']'
;
34
}
35
36
}
// namespace Kokkos::Execution::Utils
37
38
#if defined(__cpp_impl_reflection)
39
40
# include <meta>
41
42
namespace
Kokkos::Execution::Utils
{
43
46
struct
Streamable { };
47
48
inline
constexpr
Streamable streamable{};
50
52
consteval
bool
is_streamable(std::meta::info type) {
53
return
!std::meta::annotations_of_with_type(type, ^^Streamable).empty();
54
}
55
57
template
<
typename
T>
58
concept
IsStreamable = is_streamable(^^T);
59
60
template
<
typename
T>
61
std::ostream& stream_to(std::ostream& out,
const
T& obj) {
62
static
constexpr
auto
members = std::define_static_array(
63
std::meta::nonstatic_data_members_of(^^T, std::meta::access_context::current()));
64
65
out << std::meta::identifier_of(^^T) <<
": {"
;
66
67
template
for
(
constexpr
std::meta::info member: members) {
68
if
constexpr
(member != members.front()) {
69
out <<
", "
;
70
}
71
out << std::meta::identifier_of(member) <<
" = "
<< obj.[:member:];
72
}
73
74
return
out <<
'}'
;
75
}
76
78
template
<IsStreamable T>
79
std::ostream&
operator<<
(std::ostream& out,
const
T& obj) {
80
return
stream_to(out, obj);
81
}
82
83
}
// namespace Kokkos::Execution::Utils
84
85
# define KOKKOS_EXECUTION_UTILS_STREAMABLE [[= Kokkos::Execution::Utils::streamable]]
86
#else
87
# define KOKKOS_EXECUTION_UTILS_STREAMABLE
88
#endif
89
90
#endif
// KOKKOS_EXECUTION_UTILS_STREAMERS_HPP
Kokkos::Execution::Utils::detail::char_like
Definition
streamers.hpp:14
Kokkos::Execution::Utils::detail::streamable_range
A (const-iterable) range of streamable, non-character elements.
Definition
streamers.hpp:20
Kokkos::Execution::Utils::detail
Definition
streamers.hpp:11
Kokkos::Execution::Utils
Definition
streamers.hpp:9
Kokkos::Execution::Utils::operator<<
std::ostream & operator<<(std::ostream &out, const R &values)
Definition
streamers.hpp:25
kokkos-execution
utils
streamers.hpp
Generated on
for kokkos-execution by
1.18.0