I’d like to know if constructors of classes and structs can have type inference. So far, I am using a separate function for this purpose, for example:

```
import std.stdio: writeln;

struct Pair(T, U)
{
  T first;
  U second;
  this(T first, U second)
  {
    this.first = first;
    this.second = second;
  }
}

Pair!(T, U) pair(T, U)(T first, U second)
{
  return Pair!(T, U)(first, second);
}

void main()
{
auto mp = pair("Michael", 32);//standard function inference works //auto m0 = Pair("Michael", 32); //I’d like to be able to do this
  writeln("pair: ", mp);
}
```

On a slightly different note, I was doing some reading in std.typecons (https://github.com/dlang/phobos/blob/3754e92341a393331bd6b0bc9e70335d34e42016/std/typecons.d#L6838) on Github and wondered what `this` in the code below does:

```
auto ref opIndex(this X, D...)(auto ref D i) { return a[i]; }
```

Reply via email to