How to return user name from vibed session?

Mike Parker via Digitalmars-d-learn digitalmars-d-learn at
Thu Dec 10 06:29:46 PST 2015

On Thursday, 10 December 2015 at 13:46:19 UTC, Suliman wrote:

> because set return void, and get return T?

No, it has nothing to do with the return type declarations. It's 
about whether or not the compiler has enough information to 
deduce the types.

V get(V, K)(K key, V defaultVal);

auto i = 10;
i = get("key", i);

This works because the compiler sees that you have given it a 
string where it expects a K and an int where it expects a V, so 
it knows that K = string and V = int. On the other hand:

V get(V, K)(K key);

auto i = get("key");

What type is this supposed to return? Even if you do this:

int i = get("key");

Obviously, the compiler knows that i is int, but that plays no 
role in template type deduction. Only the template declaration 
and instantiation do. So we have to explicitly tell the compiler 
what type V should be in this case by passing the type as a 
template argument.

auto i = get!int("key");

More information about the Digitalmars-d-learn mailing list