works as expected

import std.traits   : isSomeChar;
import std.range    : ElementEncodingType;
import std.stdio;

@safe pure nothrow
template CharEncodingType(Char)
{
    alias ET = ElementEncodingType!Char;

    static if (is (ET == char)) {
        alias CharEncodingType = ubyte;

    } else static if (is (ET == wchar)) {
        alias CharEncodingType = ushort;

    } else static if (is (ET == dchar)) {
        alias CharEncodingType = uint;

    } else {
        alias CharEncodingType = ET;
    }
}

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
immutable(char) ubyte uint ushort



thanks all

Reply via email to