www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12835] New: std.random.uniform with open lower bound cannot


          Issue ID: 12835
           Summary: std.random.uniform with open lower bound cannot
                    support smaller integral types or character types
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: Phobos
          Assignee: nobody puremagic.com
          Reporter: joseph.wakeling webdrake.net

Created attachment 1359
  --> https://issues.dlang.org/attachment.cgi?id=1359&action=edit
Code snippet illustrating the problem

std.random.uniform will fail to compile if an open lower bound is specified
(i.e. boundaries == "(]" or "()") and either:

   * the type requested is a character type, or

   * the type requested is an integral type smaller than int (i.e. ushort,
short, ubyte, byte).

The attached code sample will allow the problem to be seen: attempting to
compile it results in errors:

/opt/dmd/import/std/random.d(1336): Error: cannot implicitly convert expression
(cast(int)a + 1) of type int to ushort
/opt/dmd/import/std/random.d(1197): Error: template instance
std.random.uniform!("()", ushort, ushort, MersenneTwisterEngine!(uint, 32LU,
624LU, 397LU, 31LU, 2567483615u, 11LU, 7LU, 2636928640u, 15LU, 4022730752u,
18LU)) error instantiating
uniform.d(10):        instantiated from here: uniform!("()", ushort, ushort)
uniform.d(21):        instantiated from here: uniformTest!ushort

... and so on for the other unsupported types.

Note that this problem persists whether the uniform() is the recently-updated
one provide in PR 1717 or the uniform preceding it, so we can't simply solve
the problem by reverting a patch.

Jun 01 2014