Traits

Ali Çehreli acehreli at yahoo.com
Thu Oct 10 21:35:37 PDT 2013


On 10/10/2013 09:13 PM, 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)

function happens to be a keyword. :)

 > {
 >    // 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.

One of the uses of the is expression determines "whether implicitly 
convertible to". It may work for you:

public void foo(T, A...)(auto ref A values)
{
     static assert(is (T : L));
}

class L
{}

class LL : L
{}

void main()
{
     foo!LL(1, 2.3, "4");
}

Ali



More information about the Digitalmars-d-learn mailing list