randomUUID for runtime / how to generate UUIDs in runtime
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Apr 17 07:18:06 PDT 2015
On 04/17/2015 07:05 AM, "Ozan =?UTF-8?B?U8O8ZWwi?=
<ozan.sueel at gmail.com>" wrote:
> CTFE: This function is not supported at compile time.
>
> Than trying a call like
> auto uuid = randomUUID()
>
> results in an error message:
> /usr/include/dmd/phobos/std/random.d(1138,10): Error: static
> variable seeded cannot be read at compile time
I don't see the issue. Both of those errors indicate the same thing:
"not available at compile time." You may have read one of them wrong. (?)
There is no problem with randomUUID() at run time. However, you may be
needing an expression at compile time, which in turn needs randomUUID():
import std.uuid;
int foo()
{
auto uuid = randomUUID(); // <-- Compiles and runs fine
return 42;
}
void main()
{
enum e = foo(); // <-- The actual problem
}
Although, the error message I received is not exactly the same as yours:
Error: static variable initialized cannot be read at compile time
Ali
More information about the Digitalmars-d-learn
mailing list