commit 8783f7c97b8365a5405f7373f155f854c7093f19
parent b65595de75ef12e42c09ed6a624630c93bfdc615
Author: Oshgnacknak <osh@oshgnacknak.de>
Date: Sat, 18 Dec 2021 21:42:40 +0100
Introduce concept IsPrintable to type-save print1
Diffstat:
2 files changed, 14 insertions(+), 11 deletions(-)
diff --git a/examples/print.cpp b/examples/print.cpp
@@ -59,6 +59,7 @@ int main() {
Vector2 v = { 69, 420 };
osh::println("Printing costume types (see print1 above): ", v);
+ osh::println("^ Comment it out, error message is ACTUALLY readable");
return 0;
}
diff --git a/osh.h b/osh.h
@@ -4,9 +4,11 @@
namespace osh {
template<typename T>
- void print1(T& t);
+ concept IsPrintable = requires(T t) {
+ print1(t);
+ };
- template<typename... Args>
+ template<IsPrintable... Args>
void print(Args... args);
template<typename... Args>
@@ -30,39 +32,39 @@ namespace osh {
}
template<typename T>
- void print1(T* p) {
+ void print1(const T* p) {
printf("%p", p);
}
- void print1(char& c) {
+ void print1(const char& c) {
putchar(c);
}
- void print1(int& n) {
+ void print1(const int& n) {
printf("%d", n);
}
- void print1(short int& n) {
+ void print1(const short int& n) {
printf("%d", n);
}
- void print1(long int& n) {
+ void print1(const long int& n) {
printf("%ld", n);
}
- void print1(long long int& n) {
+ void print1(const long long int& n) {
printf("%lld", n);
}
- void print1(float& f) {
+ void print1(const float& f) {
printf("%f", f);
}
- void print1(double& d) {
+ void print1(const double& d) {
printf("%f", d);
}
- void print1(long double& d) {
+ void print1(const long double& d) {
printf("%Lf", d);
}