Commit 32799998 authored by Tom Niget's avatar Tom Niget

Reorder items in print.hpp to fix template lookup

parent 39585e1b
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
#include <iostream> #include <iostream>
#include <ostream> #include <ostream>
#include <typon/typon.hpp>
#include "str.hpp" #include "str.hpp"
#include <typon/typon.hpp>
template <typename T> template <typename T>
concept Streamable = requires(const T &x, std::ostream &s) { concept Streamable = requires(const T &x, std::ostream &s) {
...@@ -19,6 +19,22 @@ concept Streamable = requires(const T &x, std::ostream &s) { ...@@ -19,6 +19,22 @@ concept Streamable = requires(const T &x, std::ostream &s) {
template <Streamable T> void print_to(const T &x, std::ostream &s) { s << x; } template <Streamable T> void print_to(const T &x, std::ostream &s) { s << x; }
template <Streamable T> void repr_to(const T &x, std::ostream &s) { s << x; } template <Streamable T> void repr_to(const T &x, std::ostream &s) { s << x; }
template <typename T>
concept PyPrint = requires(const T &x, std::ostream &s) {
{ x.py_print(s) } -> std::same_as<void>;
};
template <PyPrint T> void print_to(const T &x, std::ostream &s) {
x.py_print(s);
}
template <typename T>
concept PyRepr = requires(const T &x, std::ostream &s) {
{ x.py_repr(s) } -> std::same_as<void>;
};
template <PyRepr T> void repr_to(const T &x, std::ostream &s) { x.py_repr(s); }
template <typename T> template <typename T>
concept Printable = requires(const T &x, std::ostream &s) { concept Printable = requires(const T &x, std::ostream &s) {
{ print_to(x, s) } -> std::same_as<void>; { print_to(x, s) } -> std::same_as<void>;
...@@ -35,53 +51,32 @@ concept FunctionPointer = ...@@ -35,53 +51,32 @@ concept FunctionPointer =
std::is_function_v<std::remove_pointer_t<T>>; std::is_function_v<std::remove_pointer_t<T>>;
template <Streamable T> template <Streamable T>
requires(FunctionPointer<T>) requires(FunctionPointer<T>)
void repr_to(const T &x, std::ostream &s) { void repr_to(const T &x, std::ostream &s) {
s << "<function at 0x" << std::hex << (size_t)x << std::dec << ">"; s << "<function at 0x" << std::hex << (size_t)x << std::dec << ">";
} }
template <> template <> void repr_to(const PyStr &x, std::ostream &s) {
void repr_to(const PyStr &x, std::ostream &s) {
s << '"' << x << '"'; s << '"' << x << '"';
} }
template <Streamable T> template <Streamable T>
requires(Reprable<T>) requires(Reprable<T>)
void print_to(const T &x, std::ostream &s) { void print_to(const T &x, std::ostream &s) {
repr_to(x, s); repr_to(x, s);
} }
template <typename T>
concept PyPrint = requires(const T &x, std::ostream &s) {
{ x.py_print(s) } -> std::same_as<void>;
};
template <PyPrint T> void print_to(const T &x, std::ostream &s) {
x.py_print(s);
}
template <typename T>
concept PyRepr = requires(const T &x, std::ostream &s) {
{ x.py_repr(s) } -> std::same_as<void>;
};
template <PyRepr T> void repr_to(const T &x, std::ostream &s) {
x.py_repr(s);
}
template <Printable T> template <Printable T>
void print_to(const std::shared_ptr<T> &x, std::ostream &s) { void print_to(const std::shared_ptr<T> &x, std::ostream &s) {
print_to(*x, s); print_to(*x, s);
} }
template <Printable T> template <Reprable T>
void repr_to(const std::shared_ptr<T> &x, std::ostream &s) { void repr_to(const std::shared_ptr<T> &x, std::ostream &s) {
repr_to(*x, s); repr_to(*x, s);
} }
template <> void print_to<PyStr>(const PyStr &x, std::ostream &s) { template <> void print_to<PyStr>(const PyStr &x, std::ostream &s) { s << x; }
s << x;
}
/* /*
template <Printable T, Printable... Args> template <Printable T, Printable... Args>
typon::Task<void> print(T const &head, Args const &...args) { typon::Task<void> print(T const &head, Args const &...args) {
...@@ -100,5 +95,5 @@ struct { ...@@ -100,5 +95,5 @@ struct {
std::cout << '\n'; std::cout << '\n';
} }
} print; } print;
//typon::Task<void> print() { std::cout << '\n'; co_return; } // typon::Task<void> print() { std::cout << '\n'; co_return; }
#endif // TYPON_PRINT_HPP #endif // TYPON_PRINT_HPP
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment