pRC
multi-purpose Tensor Train library for C++
Loading...
Searching...
No Matches
print.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_CORE_LOG_PRINT_H
4#define pRC_CORE_LOG_PRINT_H
5
6#include <cstdio>
7#include <string>
8
10
11namespace pRC
12{
13 template<class T>
14 static inline constexpr auto name();
15
16 template<auto T>
17 static inline constexpr auto name();
18
19 template<class T, T V, class S>
20 static inline auto print(Constant<T, V> const, S &&stream)
21 {
22 print("pRC::Constant<" + name<T>() + ", " + name<V>() + ">", stream);
23 }
24
25 template<class T, If<IsSame<T, Bool>> = 0>
26 static inline auto print(T const value, std::FILE *stream)
27 {
28 if(value)
29 {
30 std::fprintf(stream, "True");
31 }
32 else
33 {
34 std::fprintf(stream, "False");
35 }
36 }
37
38 template<class T, If<IsIntegral<T>> = 0>
39 static inline auto print(T const value, std::FILE *stream)
40 {
41 if constexpr(IsSame<T, int>())
42 {
43 std::fprintf(stream, "% d", value);
44 }
45 else if constexpr(IsSame<T, short>())
46 {
47 std::fprintf(stream, "% hd", value);
48 }
49 else if constexpr(IsSame<T, long>())
50 {
51 std::fprintf(stream, "% ld", value);
52 }
53 else if constexpr(IsSame<T, long long>())
54 {
55 std::fprintf(stream, "% lld", value);
56 }
57 else if constexpr(IsSame<T, unsigned>())
58 {
59 std::fprintf(stream, "%u", value);
60 }
61 else if constexpr(IsSame<T, unsigned short>())
62 {
63 std::fprintf(stream, "%hu", value);
64 }
65 else if constexpr(IsSame<T, unsigned long>())
66 {
67 std::fprintf(stream, "%lu", value);
68 }
69 else if constexpr(IsSame<T, unsigned long long>())
70 {
71 std::fprintf(stream, "%llu", value);
72 }
73 else if constexpr(IsSame<T, char>() || IsSame<T, unsigned char>() ||
75 {
76 std::fputc(value, stream);
77 }
78 }
79
80 static inline auto print(char const *const string, std::FILE *stream)
81 {
82 std::fputs(string, stream);
83 }
84
85 static inline auto print(std::string const &string, std::FILE *stream)
86 {
87 print(string.c_str(), stream);
88 }
89}
90#endif // pRC_CORE_LOG_PRINT_H
Definition cholesky.hpp:18
static auto print(String< N > const &string, std::FILE *stream)
Definition print.hpp:18
std::integral_constant< T, V > Constant
Definition type_traits.hpp:34
static constexpr Conditional< IsSatisfied< C >, RemoveConstReference< X >, X > copy(X &&a)
Definition copy.hpp:13
static constexpr auto name()
Definition type_name.hpp:11