SysTime at compile time

Paolo Invernizzi paolo.invernizzi at gmail.com
Fri Aug 23 13:46:34 PDT 2013


On Friday, 23 August 2013 at 19:07:06 UTC, Jonathan M Davis wrote:
> On Friday, August 23, 2013 10:39:56 Paolo Invernizzi wrote:
>> There's a way to use a SysTime at compile-time? It seems
>> impossible right now for the presence of the TimeZone.
>> 
>> I want to insert some time-related fields in some structs, but 
>> I
>> need to have some compile-time check with 'static assert' here
>> and there...
>
> Getting the system time would require calling C functions 
> (which never works
> in CTFE), so you can't do what you're trying to do with any 
> CTFE solution, let
> alone SysTime. Even if there were no TimeZone, it couldn't be 
> done.

Thank you Jonathan, in reality I'm not interested in obtaining 
the current time ('Clock.currTIme' et similia), but only in 
checking some basic behaviour involving already forged times.

Something works, in a limited and constrained way, but it seems 
that there's a problem with 'Rebindable' in CTFE:

---
enum t = SysTime(0, UTC());
pragma(msg, t); // SysTime(0L, Rebindable(, (UTC("UTC", "UTC", 
"UTC"))))
// enum t2 = t + msecs(1000); // typecons.d(956): Error: cannot 
read uninitialized variable this.original in ctfe
enum d = SysTime(1000, UTC()) - SysTime(10, UTC());
pragma(msg, d); // Duration(990L)
---

Paolo Invernizzi




More information about the Digitalmars-d-learn mailing list