How can I check if template variable parameter is iterable before handle it?

Marcone marcone at email.com
Sun Feb 21 11:58:11 UTC 2021


import std;

void foo(T)(T bar){
	static if (bar.isiterable()) // Need Somethin to check if bar is 
iterable.
	{
		// Execute it if bar is iterable.
		foreach (i; bar)
		{

		}
	}
	else {
		// Execute it if bar is NOT iterable.
	}

}

void main(){
	foo(1);
	foo([1, 2, 3, 4, 5]);
}


More information about the Digitalmars-d-learn mailing list