Clingo
Loading...
Searching...
No Matches
debug.hh
1#include <string>
2
3namespace CppClingo::Util {
4
7
9inline auto replace_all(std::string str, std::string_view from, const std::string_view to) -> std::string {
10 size_t start_pos = 0;
11 while ((start_pos = str.find(from, start_pos)) != std::string::npos) {
12 str.replace(start_pos, from.length(), to);
13 start_pos += to.length(); // Handles case where 'to' is a substring of 'from'
14 }
15 return str;
16}
17
19inline auto type_short(std::string sig) -> std::string {
20 sig = replace_all(std::move(sig),
21 "std::variant<CppClingo::Input::LiteralBoolean, CppClingo::Input::LiteralRelation, "
22 "CppClingo::Input::LiteralSymbolic>",
23 "CppClingo::Input::Literal");
24 return sig;
25}
26
28template <class T> constexpr auto type_name() -> std::string_view {
29 // NOLINTBEGIN(readability-magic-numbers)
30 using namespace std;
31#ifdef __clang__
32 string_view p = __PRETTY_FUNCTION__;
33 return {p.data() + 34, p.size() - 34 - 1};
34#elif defined(__GNUC__)
35 string_view p = __PRETTY_FUNCTION__;
36#if __cplusplus < 201402
37 return {p.data() + 36, p.size() - 36 - 1};
38#else
39 return {p.data() + 49, p.find(';', 49) - 49};
40#endif
41#elif defined(_MSC_VER)
42 string_view p = __FUNCSIG__;
43 return {p.data() + 84, p.size() - 84 - 7};
44#endif
45 // NOLINTEND(readability-magic-numbers)
46}
47
49
50} // namespace CppClingo::Util
auto replace_all(std::string str, std::string_view from, const std::string_view to) -> std::string
Replace all occurrences of from by to in str.
Definition debug.hh:9
constexpr auto type_name() -> std::string_view
Return a nice string representation of T.
Definition debug.hh:28
auto type_short(std::string sig) -> std::string
Replaces complex types used in this project by shorter aliases.
Definition debug.hh:19