Say I have a functor that uses tag dispatching to select from multiple implementations of the function, something like this:
// base class for all tags, indicating the "default" implementation
struct tag_base { };
// subclasses for tags that might select a different implementation
struct tag1 : tag_base { };
struct tag2 : tag1 { };
struct tag3 : tag2 { };
struct func
{
void operator()(tag_base) { }
void operator()(tag3) { }
};
In this simple example, therefore, tag types tag1
and tag2
would dispatch to the call operator for func
that takes a tag_base
, the default implementation. However, tag3
would instead dispatch to a different implementation. I'm interested in inspecting at compile time whether, for a given function type func
and two tag types T
and U
, whether they would dispatch to the same overload of func
's call operator.
Basically, I would like a trait like this (only pseudocode, since this approach does not compile):
template <typename Func, typename T, typename U>
struct has_same_tag_overload
{
enum { value = (void (Func::*)(T)) &func::operator() ==
(void (Func::*)(U)) &func::operator() };
}
So in the above example, the following would be true:
tag<func, tag_base, tag1>::value == 1
tag<func, tag_base, tag2>::value == 1
tag<func, tag1, tag2>::value == 1
tag<func, tag1, tag3>::value == 0
tag<func, tag2, tag3>::value == 0
Is this possible? To add to the degree of difficulty, is this possible in C++03?