how to propagate computed type during CTFE?

Timothee Cour thelastmammoth at gmail.com
Fri Feb 23 00:54:34 UTC 2018


in example below, how do I propagate RET (or even `typeof(a)`) to the
result value of `inferType`?

does this need a language change to allow this?


```
template inference(alias emitter) {
  auto inference(){
    auto inferType(){
      emitter!((a){
        enum RET=typeof(a).stringof; // type is known here, how to propagate?
        pragma(msg, RET);  // string
        }) ();
      return "unknown";
    }
    // how to get RET? (or even typeof(a) )
    enum temp=inferType;
    pragma(msg, temp);
  }
}

void main(){
  static void fun(alias put)(){
    put("hello");
  }
  inference!fun;
}
```

use case: allow type inference in `emit`

https://github.com/timotheecour/dtools/blob/master/dtools/util/emit.d
(see forum discussion here:
https://forum.dlang.org/post/mailman.538.1458560190.26339.digitalmars-d@puremagic.com)


More information about the Digitalmars-d mailing list