MAX_CHAR

BCS none at anon.com
Sat Jun 19 08:02:20 PDT 2010


Hello Ben,

> Hi there,
> 
> Can anyone tell me how to get the maximum char value from a string
> type? I have a template struct which can take string or wstring and
> need to determine the character type from the string type.
> 

If you are looking for the X sutch that the following is true (as long as 
fn returns a valid string)

someStringType foo = fn();
assert(foo[rand()%$] <= X);  // check a random position.


Bits out of the following should work:

template Max(T)  { 
  static if(is(T U : U[]))
    const string Max = U.stringof ~ ":" ~ (cast(int)(U.max)).stringof;
  else static assert(false, "oops");
}
import std.stdio;

void main()
{
   writef("%s\n", Max!(string));
   writef("%s\n", Max!(wchar[]));
   writef("%s\n", Max!(dchar[]));
}


Output:
  char:cast(int)'\xff'
  wchar:cast(int)'\U0000ffff'
  dchar:cast(int)'\U0010ffff'

> Thanks,
> 
> Ben
> 
-- 
... <IXOYE><





More information about the Digitalmars-d mailing list