Deduce template arguments from return value?

Yuxuan Shui via Digitalmars-d digitalmars-d at puremagic.com
Sun Jul 12 02:13:03 PDT 2015


For example:
import std.conv;
T a(T)(int a) {
	return to!T(a);
}
void main(){
	string x = a(2);
}

D is not able to deduce T. Can we make it possible to deduce 
template arguments from where the return value is assigned to?

Rust is able to do this:
fn main() {
	let a : Vec<i32> = Vec::new();
}

(In fact, you can even do this is Rust:
fn main() {
	let mut a = Vec::new();
	a[0] = 0i32;
})


More information about the Digitalmars-d mailing list