D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 10882 - std.random.MersenneTwisterEngine.seed() fails if passed a static array
Summary: std.random.MersenneTwisterEngine.seed() fails if passed a static array
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-08-24 09:26 UTC by Joseph Rushton Wakeling
Modified: 2020-03-21 03:56 UTC (History)
0 users

See Also:


Attachments
Example code to illustrate the bug. Comment out last line and the program runs correctly. (170 bytes, text/x-dsrc)
2013-08-24 09:26 UTC, Joseph Rushton Wakeling
Details

Note You need to log in before you can comment on or make changes to this issue.
Description Joseph Rushton Wakeling 2013-08-24 09:26:09 UTC
Created attachment 1243 [details]
Example code to illustrate the bug.  Comment out last line and the program runs correctly.

MersenneTwisterEngine can take as seed either a single unsigned integer or a
range of 624 unsigned integers.  However, if a static array uint[624] is passed
to it, it fails with the following error:

----------------------------------------------
Error: template std.random.MersenneTwisterEngine!(uint, 32, 624, 397, 31,
2567483615u, 11, 7, 2636928640u, 15, 4022730752u,
18).MersenneTwisterEngine.seed does not match any function template
declaration. Candidates are:
/opt/dmd/include/d2/std/random.d(574):       
std.random.MersenneTwisterEngine!(uint, 32, 624, 397, 31, 2567483615u, 11, 7,
2636928640u, 15, 4022730752u, 18).MersenneTwisterEngine.seed()(UIntType value =
defaultSeed)
/opt/dmd/include/d2/std/random.d(613):       
std.random.MersenneTwisterEngine!(uint, 32, 624, 397, 31, 2567483615u, 11, 7,
2636928640u, 15, 4022730752u, 18).MersenneTwisterEngine.seed(T)(T range) if
(isInputRange!T && is(Unqual!(ElementType!T) == UIntType))
mtseed.d(10): Error: template std.random.MersenneTwisterEngine!(uint, 32, 624,
397, 31, 2567483615u, 11, 7, 2636928640u, 15, 4022730752u,
18).MersenneTwisterEngine.seed()(UIntType value = defaultSeed) cannot deduce
template function from argument types !()(uint[624LU])
----------------------------------------------

The attached test code illustrates the problem, with Mt19937 accepting a
dynamic array of length 624 as seed, but not a static array of equal length.
Comment 1 basile-z 2016-01-23 09:57:31 UTC
A static array is not an input range, it can't be consumed. The constaint in see() clearly only takes input ranges.