function argument for map: why shorter form does not compile?

Nick Treleaven nick at geany.org
Sat Jun 20 12:10:47 UTC 2026


On Saturday, 20 June 2026 at 10:28:24 UTC, Ivan Kazmenko wrote:
> void main ()
> {
> 	auto a = [1, 2, 3];
> 	auto b = a.map !(x => format !("%d") (x));  // ok
> 	auto c = a.map !(format !("%d"));  // orphan format specifier
> }
> ```
>
> Why the line with `b` compiles, but the line with `c` does not?
> Shouldn't the compiler deduce the type for the format argument 
> as a.front?

The signature is:
```d
typeof(fmt) format(alias fmt, Args...)(Args args);
```

https://dlang.org/phobos/std_format.html#format

You only provided the `fmt` template argument, so `Args` is 
inferred as an empty sequence. Your code could be supported if 
`format` was changed to:
```d
template format(alias fmt)
{
   typeof(fmt) format(Args...)(Args args) { ... }
}
```

Perhaps file an issue:
https://github.com/dlang/phobos/issues


More information about the Digitalmars-d-learn mailing list