www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Can I run this at compile time?

reply Marc <jckj33 gmail.com> writes:
Give this function I'd like to run it at compile time:

	import std.concurrency : Generator, yield;
	Generator!string getNonIntegralMembers() {
		return new Generator!string({
			enum allMembers = __traits(derivedMembers, C);
			foreach(enum string member; allMembers) {
				bool isInteg = __traits(isIntegral, >__traits(getMember, C, 
member));
				if(!isInteg) {
					yield(member);
				}
			}
		});
	}
but when I do:
 enum string[] members = getNonIntegralMembers();
 writeln(members);
I get the following erros: C:\D\dmd2\windows\bin\..\..\src\druntime\import\core\thread.d(4059): Error: static variable PAGESIZE cannot be read at compile time C:\D\dmd2\windows\bin\..\..\src\phobos\std\concurrency.d(1548): called from here: super.this(dg, PAGESIZE * 4u, PAGESIZE) app.d(96): called from here: getNonIntegralMembers()
Dec 20 2017
parent reply Mengu <mengukagan gmail.com> writes:
On Wednesday, 20 December 2017 at 16:54:35 UTC, Marc wrote:
 Give this function I'd like to run it at compile time:

 	import std.concurrency : Generator, yield;
[...]
but when I do:
 [...]
I get the following erros: C:\D\dmd2\windows\bin\..\..\src\druntime\import\core\thread.d(4059): Error: static variable PAGESIZE cannot be read at compile time C:\D\dmd2\windows\bin\..\..\src\phobos\std\concurrency.d(1548): called from here: super.this(dg, PAGESIZE * 4u, PAGESIZE) app.d(96): called from here: getNonIntegralMembers()
if PAGESIZE is not dynamic, it will not work at compile time. make it an enum or const and give it a try.
Dec 20 2017
parent Marc <jckj33 gmail.com> writes:
On Wednesday, 20 December 2017 at 17:16:50 UTC, Mengu wrote:
 On Wednesday, 20 December 2017 at 16:54:35 UTC, Marc wrote:
 Give this function I'd like to run it at compile time:

 	import std.concurrency : Generator, yield;
[...]
but when I do:
 [...]
I get the following erros: C:\D\dmd2\windows\bin\..\..\src\druntime\import\core\thread.d(4059): Error: static variable PAGESIZE cannot be read at compile time C:\D\dmd2\windows\bin\..\..\src\phobos\std\concurrency.d(1548): called from here: super.this(dg, PAGESIZE * 4u, PAGESIZE) app.d(96): called from here: getNonIntegralMembers()
if PAGESIZE is not dynamic, it will not work at compile time. make it an enum or const and give it a try.
the problem is, PAGESIZE part of D's library so I can't change it. I'm looking for a way to make Generators work at runtime actually. Or a replacement for it.
Dec 20 2017