3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-05-05 23:05:46 +00:00

Better search stack printing

This commit is contained in:
Jakob Rath 2022-04-12 13:48:06 +02:00
parent 59f2603a3a
commit 00fa4b3320
4 changed files with 106 additions and 14 deletions

View file

@ -18,29 +18,51 @@ Author:
#pragma once
#include <iostream>
#include <sstream>
#include <utility>
#include "util/ref.h"
#include "util/util.h"
template <typename T>
struct show_deref_t {
T const* ptr;
T const* ptr;
};
template <typename T>
std::ostream& operator<<(std::ostream& os, show_deref_t<T> s) {
if (s.ptr)
return os << *s.ptr;
else
return os << "<null>";
if (s.ptr)
return os << *s.ptr;
else
return os << "<null>";
}
template <typename T>
show_deref_t<T> show_deref(T* ptr) {
return show_deref_t<T>{ptr};
return show_deref_t<T>{ptr};
}
template <typename Ptr, typename T = typename std::remove_pointer<decltype(std::declval<Ptr>().get())>::type>
show_deref_t<T> show_deref(Ptr const& ptr) {
return show_deref_t<T>{ptr.get()};
return show_deref_t<T>{ptr.get()};
}
/// Fill with spaces to the right:
/// out << rpad(8, "hello")
/// writes "hello ".
template <typename T>
struct rpad {
unsigned width;
T const& obj;
rpad(unsigned width, T const& obj): width(width), obj(obj) {}
};
template <typename T>
std::ostream& operator<<(std::ostream& out, rpad<T> const& pad) {
std::stringstream tmp;
tmp << pad.obj;
auto s = tmp.str();
out << s;
if (s.length() < pad.width)
out << std::string(pad.width - s.length(), ' ');
return out;
}