RT/CT Type
Alex
AJ at gmail.com
Tue Apr 2 12:38:39 UTC 2019
On Tuesday, 2 April 2019 at 10:45:37 UTC, Jacob Carlborg wrote:
> On 2019-04-02 09:48, Alex wrote:
>> Since D has a highly evolved meta programming and it should
>> have unitifed type that works two ways:
>>
>> 1. At CT, the type acts as an type or sorta like an alias.
>> 2. At RT the type acts as a string.
>>
>> Type t = int;
>>
>> At compile time,
>>
>> t x;
>>
>> is the same at
>>
>> int x;
>>
>>
>> At RT t = "int"
>>
>>
>> Why is this important?
>>
>>
>> The purpose is to unify certain CT and RT code. Because CTFE
>> acts as runtime we might use it to build a type, but as a
>> string, such as
>>
>> return getType(T)(T x)
>> {
>> return T.stringof; // CTFE/RT
>> //return T // would be simpler
>> }
>>
>> But then we could do
>>
>> getType(32) x;
>>
>> at CT.
>>
>> or use getType at runtime.
>>
>> This is a contrived example but I'm finding that I'm having to
>> use CTFE to deal with types which requires strings and then
>> convert those strings back in to types using string mixins,
>> which is a PIBA.
>
> I would much rather that D had first class types. That is, it
> would be possible to store types in variables and in arrays and
> so on.
Sure, but that isn't likely to happen and probably will be far
more work. By simply having them convert to strings in RT helps a
lot. When combined with CTFE and mixins it works well because one
can go back and forth between type and strings.
More information about the Digitalmars-d
mailing list