Eponymous template with static if

Nick Treleaven nick at geany.org
Tue Aug 15 15:39:12 UTC 2023


On Tuesday, 15 August 2023 at 10:54:52 UTC, H. S. Teoh wrote:
  `is(T)` is standard idiom for checking whether T is a valid
> type.
>
> It's usually used with an expression to test whether some 
> operation is valid on a type, e.g.:
>
> 	auto myTemplateFunc(T)(T data)
> 		if (is(data++))	// make sure ++ is valid on T
> 	{
> 		return data++;
> 	}
>
> 	auto myTemplateFunc(T)(T data)
> 		if (is(data+0))	// make sure + int is valid on T
> 	{
> 		return data + 123;
> 	}

Those should be `is(typeof(data++))` and `is(typeof(data+0))`.


More information about the Digitalmars-d mailing list