-
Notifications
You must be signed in to change notification settings - Fork 5
/
mpdebug.hh
66 lines (55 loc) · 1.77 KB
/
mpdebug.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// -*- mode: c++; coding: utf-8 -*-
// ra-ra - Metaprogramming debug utilities.
// (c) Daniel Llorens - 2011, 2019
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by the Free
// Software Foundation; either version 3 of the License, or (at your option) any
// later version.
#pragma once
#include "ra/tuples.hh"
#include <typeinfo>
#include <sys/types.h>
namespace ra::mp {
template <class type_, bool condition=false>
struct show
{
using type = type_;
static bool const value = condition;
static_assert(condition, "bad type");
};
// Prints value recursively, e.g. for int_c trees.
template <class A> struct print_int_list {};
template <class A> std::ostream &
operator<<(std::ostream & o, print_int_list<A> const & a)
{
if constexpr (is_tuple<A>) {
std::apply([&o](auto ... a) { ((o << "[") << ... << print_int_list<decltype(a)> {}) << "]"; }, A {});
return o;
} else {
return (o << A::value << " ");
}
}
template <class T>
std::string
type_name()
{
using TR = std::remove_cvref_t<T>;
std::string r = typeid(TR).name();
if (std::is_const_v<TR>)
r += " const";
if (std::is_volatile_v<TR>)
r += " volatile";
if (std::is_lvalue_reference_v<T>)
r += " &";
else if (std::is_rvalue_reference_v<T>)
r += " &&";
return r;
}
template <class A, int ... I> struct check_idx { constexpr static bool value = false; };
template <> struct check_idx<nil> { constexpr static bool value = true; };
template <class A0, int I0, class ... A, int ... I>
struct check_idx<tuple<A0, A ...>, I0, I ...>
{
constexpr static bool value = (A0::value==I0) && check_idx<tuple<A ...>, I ...>::value;
};
} // namespace ra::mp