about std.string.representation

bioinfornatics bioinfornatics at fedoraproject.org
Tue Nov 19 16:15:26 PST 2013


I try this





import std.traits       : isSomeChar;
import std.typetuple    : TypeTuple;
import std.stdio;

template CharEncodingType(Char)
{
     // Get representation type
     alias TypeTuple!(ubyte, ushort, uint) U;

     // const and immutable storage classes
     static if (is(Char == immutable)) alias immutable(U) T;
     else static if (is(Char == const)) alias const(U) T;
     else alias U T;

     // shared storage class (because shared(const(T)) is possible)
     static if (is(Char == shared)) alias shared(T)  
CharEncodingType;
     else alias T CharEncodingType;
}

void main()
{
     string  t  = "test";
     char[]  c  = "test".dup;
     dchar[] dc = "test"d.dup;
     wchar[] wc = "test"w.dup;

     alias T  = CharEncodingType!(typeof(t));
     alias C  = CharEncodingType!(typeof(c));
     alias DC = CharEncodingType!(typeof(dc));
     alias WC = CharEncodingType!(typeof(wc));

     writeln( typeid(T), typeid(C), typeid(DC), typeid(WC) );

}





RESULT

$ ~/test_type
(ubyte,ushort,uint)(ubyte,ushort,uint)(ubyte,ushort,uint)(ubyte,ushort,uint)


instead of ubyte,ushort,uint

i will use your way ali

thanks for your useful code


More information about the Digitalmars-d-learn mailing list