"Debugging" meta programs

Hi,

I have some code and I want to verify which template is being instantiated. The code is as follows:

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
namespace detail
{
	template <typename... StaticChecks>
	struct static_combined_check_impl;

	template <typename StaticCheck, typename... Rest>
	struct static_combined_check_impl<StaticCheck, Rest...>
	{
		using type = StaticCheck;
	};

	template <typename... Rest>
	struct static_combined_check_impl<consistent_t, Rest...>
	{
		using type = typename static_combined_check_impl<Rest...>::type;
	};

	template <>
	struct static_combined_check_impl<>
        {
		using type = consistent_t;
	};
}  // namespace detail

using combined = detail::static_combined_check_impl<consistent_t, inconsistent_t>::type;


For a given code (e.g. see the type 'combined' above), I can figure out which templates are instantiated and called; but I want some help from the compiler. There must be a way to trigger an error only when a particular template is instantiated, allowing for better debugging a meta program. But how?

By the way, consistent_t and inconsistent_t are just plain empty structs.

Any suggestions?

Regards,
Juan Dent
template <unsigned long N>
struct binary
{
static unsigned const value
= binary<N/10>::value << 1 // prepend higher bits
| N%10; // to lowest bit
};

template <> // specialization
struct binary<0> // terminates recursion
{
static unsigned const value = 0;
};

http://www.cetpainfotech.com/technology/c-language-training
Thanks JLBorges as usual!!

great suggestion this metashell tool!

Juan
Topic archived. No new replies allowed.