How to check if string is available at compile time

David Bennett davidbennett at bravevision.com
Thu Sep 21 11:42:36 UTC 2017


Hi Guys,

Is there an easy way to check if the value of string passed to a 
template is available at compile time?

Here is a cut down example of that I'm doing:

```
string[] escapeCTFE(Args...)(){

     static foreach (arg; Args){
         static if(__traits(compiles, ###WHATDOIPUTHERE###)){
             pragma(msg, "Do work on string: ", arg);
         }else{
             pragma(msg, __traits(identifier, arg), " can only be 
read at runtime");
         }
     }

}

void main(){

     string a = "a";
     static string b = "b";
     enum string c = "c";
     immutable string d = "d";
     const string e = "e";

     enum escape_as_much_as_possible = escapeCTFE!(a,b,c,d,e,"f");
}

```

I know for ints I can use __traits(compiles, int[arg]) but I'm 
not sure about strings.

I believe only a and b should be hidden from pragma right?

Thanks,
David.


More information about the Digitalmars-d-learn mailing list