identify literals

Dom DiSc dominikus at scherkl.de
Sun Jan 26 13:16:02 UTC 2025


On Friday, 24 January 2025 at 19:12:59 UTC, monkyyy wrote:
> On Friday, 24 January 2025 at 10:50:15 UTC, Dom DiSc wrote:

>> do they have some other, more specific property?

> complete solutions: probably not, partial solutions well....
>
> ```d
> import std;
> bool isctfe(alias i)(){
> 	bool _isctfe(alias i)(int i2){
> 		i2=i;
> 		return __ctfe;
> 	}
> 	static if(__traits(compiles,(){enum b=_isctfe!(i)(i);}())){
> 		return true;
> 	} else {
> 		return false;
> 	}
> }
> unittest{
> 	int i;
> 	isctfe!(i).writeln;
> 	isctfe!(3).writeln;
> }
>
> void foo(alias i)(float f){
> 	static if(isctfe!i){
> 		"i is ct ".write;
> 	} else {
> 		"i isnt ct ".write;
> 	}
> 	writeln("f is ",f);
> }
> unittest{
> 	int i;
> 	foo!(3)(13.37);
> 	foo!(i)(4.20);
> }
> ```

Wow.
Thanks.


More information about the Digitalmars-d-learn mailing list