On 10/11/13 06:13, Agustin wrote: > I have a function that needs to check if the template provided inherit a > class. > > For example: > > public void function(T, A...)(auto ref A values) > { > // static assert(IsBaseOf(L, T)); > } > > Check if T inherit class "L". Same result that std::is_base_of<L, T>::value > using C++. Any clean way to do it, without a dirty hack.
As others have said, a "T:L" template arg specialization will often be enough. When you really need to restrict the i/f (which can be a good idea), something like this will work: template isBaseOf(BASE, C) { static if (is(C S == super)) enum isBaseOf = { foreach (A; S) static if (is(A==BASE)) return true; return is(C==BASE); }(); else enum isBaseOf = is(C==BASE); } artur