carbon-lang icon indicating copy to clipboard operation
carbon-lang copied to clipboard

Inferring parameter types with `auto`

Open jarble opened this issue 1 year ago • 3 comments

In C++, it is possible to infer parameter types and return types of functions using the auto keyword:

auto square(auto x){
   return x*x;
}

I tried to use this keyword in Carbon, but this program didn't compile successfully:

package sample api;

fn Square(x: auto) -> auto {
  return x * x;
}

fn Main() -> i32 {
  return Square(12);
}

Will this feature be supported in Carbon?

jarble avatar Aug 07 '22 16:08 jarble