D2: how to cast away const/invariant in template?

Brian Price blprice61 at yahoo.com
Mon Sep 29 12:38:42 PDT 2008


Using D2: given a template with parameter T, how do you strip away
const/invariant from the type T in an overload without creating a separate
overload for each and every possible type?

What I'm looking for is something like:

T strip( T )( T arg )
{
    return arg;
}

T strip( T: const T )( const T arg )
{
    return cast(T) arg;
}

T strip( T: invariant T )( invariant T arg )
{
    return cast(T) arg;
}

The above doesn't work but should be enough to show what I'm asking.
Thanks,
Brian



More information about the Digitalmars-d-learn mailing list